【发布时间】:2023-03-30 14:31:01
【问题描述】:
如果我这样做:
var repository = new Mock<IRepository<Banner>>();
repository.Setup(x => x.Where(banner => banner.Is.AvailableForFrontend())).Returns(list);
“Where”是我的存储库中采用Func<T, ISpecification<T> 的方法。 AvailableForFrontend 返回 ISpecification 的实现,list 是存储库泛型类型的 IEnumberable。
它编译得很好,但是当我运行我的测试时出现以下错误。
---- System.NotSupportedException : Expression banner => Convert((banner.Is.AvailableForFrontend() & banner.Is.SmallMediaBanner())) is not supported.
如果我在直接采用 ISpecification 的存储库上使用我的其他重载 Where ,则没有问题。
所以我的新手模拟/起订量问题是:我可以存根以 lamdba 作为参数的方法调用吗?还是我应该以其他方式解决这个问题?
【问题讨论】:
标签: c# .net testing mocking moq