Moq返回多个Linq表达式

我在我试图模拟的存储库中有以下方法:

IEnumerable GetAll( Expression<Func> filter = null, Func<IQueryable, IOrderedQueryable> orderBy = null, string includeProperties = "") 

我设置了以下内容:

 mockContactNumberRepository.Setup(x => x.GetAll( It.IsAny<Expression<Func>>(), It.IsAny<Func<IQueryable, IOrderedQueryable>>(), It.IsAny())) .Returns(new Func<Expression<Func>, IQueryable>(ex => _contactNumbers.Where(ex.Compile()).AsQueryable())); 

运行unit testing时,我收到有关参数计数不匹配的错误消息。 我理解这是因为Returns仅指定第一个参数,但我不确定如何指定其他参数。

我发现很多问题都提出类似的问题,但没有找到一个有多个lambda表达式的问题。

您将给予的任何帮助将非常感激。

您的GetAll方法接受三个参数并返回IEnumerableReturnsvalueFunction参数需要具有匹配的签名和返回类型。 示例中的valueFunction参数只有两个输入参数,第二个参数与传递给GetAll任何参数类型都不匹配。 它应该看起来像这样(我没有编译器检查我的语法的好处,但我认为我在这里应该是正确的):

 mockContactNumberRepository .Setup(x => x .GetAll( It.IsAny>>(), It.IsAny, IOrderedQueryable>>(), It.IsAny())) .Returns(new Func< Expression>, Func, IOrderedQueryable>, string, IEnumerable>((arg1, arg2, arg3) => { // arg1 is Expression> // arg2 is Func, IOrderedQueryable> // arg3 is string // Do something here and return an IEnumerable }));