出于某种原因,我的模拟设置似乎无法正常工作。
这是我的Moq设置:
_mockMfgViewRespository
.Setup(r => r.Find(It.IsAny<Expression<Func<V_YO_POP_MFGITM, bool>>>(), It.IsAny<bool>(), It.IsAny<Expression<Func<V_YO_POP_MFGITM, object>>>())).
Returns(GenerateViewReturnData());
GenerateViewReturnData返回类型为V_YO_POP_MFGITM的Queryable集合。
Expression<Func<V_YO_POP_MFGITM, bool>> filter = x => x.VENDORID.Equals(vendorId) && x.VENDOR_SKU.Equals(partNumber);
var viewResult = uow.MfgViewRepository.Find(filter);
viewResult始终具有空枚举。我已经尝试了我能想到的每一个组合,我的收藏品永远不会被退回。
编辑:添加了模拟设置:
_mockMfgRepository = new Mock<IGenericRepository<YO_POP_MFGPO>>();
_mockMfgViewRespository = new Mock<IGenericRepository<V_YO_POP_MFGITM>>();
_mockFactory = new Mock<IUnitOfWorkFactory>();
var uow = new Mock<IUnitOfWork>();
uow.SetupGet(x => x.MfgRepository).Returns(_mockMfgRepository.Object);
uow.SetupGet(x => x.MfgViewRepository).Returns(_mockMfgViewRespository.Object);
_mockFactory.Setup(f => f.Create()).Returns(uow.Object);