我认为,我已经非常直截了当地建立了搜索类型,并通过一个服务层和把一个领域清单归还的存放处。 搜索型除了在储存方法中建造一个表达树外,基本上从数据库中得出结果。 简单
接口:
public interface IDoNotSolicitRepo
{
IList<DNSContract> SelectWithCriteria(DNS_Search searchriteria);
}
保管人执行服务:
public class DoNotSolicitService : BaseBLLService, IDoNotSolicitService
{
private readonly IDoNotSolicitRepo repo;
private readonly IPartnerService partnerService;
private readonly IDoNotSolicitReasonService dnsReasonSvc;
public DoNotSolicitService(IDoNotSolicitRepo _repo, IPartnerService _partnerSvc, IDoNotSolicitReasonService _dnsReasonSvc)
{
repo = _repo;
partnerService = _partnerSvc;
dnsReasonSvc = _dnsReasonSvc;
}
public ServiceResult<DNSContract> SelectWithCriteria(DNS_Search searchriteria)
{
var results = repo.SelectWithCriteria(searchriteria);
return ReturnServiceResult(results);
}
}
我在学习该项目的Moq时工作,如果Im本应使用“反馈”或“回归”的话,我可以 figure。 我拿到了这两个方面的总体观点,但现在似乎对我来说,两者都没有适当工作。
测试:
[Test]
public void SelectWithCriteria_FirstName()
{
mockRepository.Setup(mr => mr.SelectWithCriteria(It.IsAny<DNS_Search>()))
.Returns((IList<DNSContract> records) => new List<DNSContract>
{
new DNSContract {FirstName = "unit", LastName = "test"},
new DNSContract {FirstName = "moq", LastName = "setup"}
});
dnsSvc = new DoNotSolicitService(mockRepository.Object, new PartnerServiceStub(), new DoNotSoicitReasonServiceStub());
var result = dnsSvc.SelectWithCriteria(new DNS_Search { FirstName = "unit" });
Assert.IsNotNull(result);
Assert.IsTrue(result.Data.Any());
}
The error:
System.ArgumentException was unhandled by user code
Message=Object of type EP.Rest.Common.RestHelpers.DNS_Search cannot be converted to type System.Collections.Generic.IList`1[EP.Rest.Domain.Contracts.DNSContract] .
Now, I ve read that the Returns() method returns the type passed in, so I can see that s the cause of that error. But in the real world I want the different type returned. I ve attempted to create a callback delegate but none of that felt right.