C# Moq通用存储库-TARGETPARAMETERCOUNTEXCEPTION
我正在模拟一个通用存储库,刚刚在我的检索方法中添加了第二个参数,允许我传递对象属性的include字符串,我对如何模拟这个问题有点困惑,并且得到了一个C# Moq通用存储库-TARGETPARAMETERCOUNTEXCEPTION,c#,include,mocking,repository,moq,C#,Include,Mocking,Repository,Moq,我正在模拟一个通用存储库,刚刚在我的检索方法中添加了第二个参数,允许我传递对象属性的include字符串,我对如何模拟这个问题有点困惑,并且得到了一个TargetParameterCountException 如果有人能把我推向正确的方向,那就太好了 接口: IQueryable<T> Retrieve(Expression<Func<T, bool>> predicate); IQueryable<T> Retrieve(Expression&
TargetParameterCountException
如果有人能把我推向正确的方向,那就太好了
接口:
IQueryable<T> Retrieve(Expression<Func<T, bool>> predicate);
IQueryable<T> Retrieve(Expression<Func<T, bool>> predicate, IEnumerable<string> includes);
IQueryable检索(表达式谓词);
IQueryable检索(表达式谓词,IEnumerable包含);
最低起订量:
var mActionRepository=new Mock();
mActionRepository.Setup(m=>m.Retrieve(It.IsAny()))
.返回(可查询的位置);
mActionRepository.Setup(m=>m.Retrieve(It.IsAny(),It.IsAny())
.返回(可查询的位置);
第一个Moq起作用,第二个不起作用。在
返回的方法中,您需要将模拟方法的所有参数类型指定为泛型参数
因此,在第二个返回
调用中缺少IEnumerable
,这就是为什么会得到TargetParameterCountException
因此,您的第二个返回值应如下所示:
mActionRepository.Setup(m=>m.Retrieve(
It.IsAny(),
It.IsAny())
.返回(
(谓词,包括)=>queryable.Where(谓词));
在返回
方法中,您需要将模拟方法的所有参数类型指定为泛型参数
因此,在第二个返回
调用中缺少IEnumerable
,这就是为什么会得到TargetParameterCountException
因此,您的第二个返回值应如下所示:
mActionRepository.Setup(m=>m.Retrieve(
It.IsAny(),
It.IsAny())
.返回(
(谓词,包括)=>queryable.Where(谓词));
var mActionRepository = new Mock<IRepository<ContainerAction>>();
mActionRepository.Setup(m => m.Retrieve(It.IsAny<Expression<Func<ContainerAction, bool>>>()))
.Returns<Expression<Func<ContainerAction, bool>>>(queryable.Where);
mActionRepository.Setup(m => m.Retrieve(It.IsAny<Expression<Func<ContainerAction, bool>>>(), It.IsAny<IEnumerable<string>>()))
.Returns<Expression<Func<ContainerAction, bool>>>(queryable.Where);