Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以(使用Moq)使用Lambda参数来存根方法调用?_C#_.net_Testing_Mocking_Moq - Fatal编程技术网

C# 是否可以(使用Moq)使用Lambda参数来存根方法调用?

C# 是否可以(使用Moq)使用Lambda参数来存根方法调用?,c#,.net,testing,mocking,moq,C#,.net,Testing,Mocking,Moq,如果我这样做: var repository = new Mock<IRepository<Banner>>(); repository.Setup(x => x.Where(banner => banner.Is.AvailableForFrontend())).Returns(list); 如果我在存储库中使用直接接受isspecification的Where重载,那么就没有问题了 所以我的新手mock/Moq问题是:我可以用lamdba作为参数来存根一

如果我这样做:

var repository = new Mock<IRepository<Banner>>();
repository.Setup(x => x.Where(banner => banner.Is.AvailableForFrontend())).Returns(list);
如果我在存储库中使用直接接受isspecification的Where重载,那么就没有问题了


所以我的新手mock/Moq问题是:我可以用lamdba作为参数来存根一个方法调用吗?或者我应该用另一种方式来处理这个问题?

您是否尝试过以下语法:

repository.Setup(x => x.Where(It.IsAny<Func<T, ISpecification<T>>()).Returns(list);

repository.Setup(x=>x.Where(It.isany)如何验证是否使用特定的lambda表达式作为参数调用了一个方法?是否可以使用Moq?repository.Verify(x=>x.Where(banner=>banner.Is.AvailableForFrontend());如果在设置.repository.Setup(x=>x.Where)时指定该方法是可验证的,则可以(It.IsAny
repository.Setup(x => x.Where(It.IsAny<Func<T, ISpecification<T>>()).Returns(list);