Moq Returns with multiple Linq Expressions

别等时光非礼了梦想. 提交于 2019-12-02 05:38:15

Your GetAll method takes three arguments and returns an IEnumerable<TEntity>. The valueFunction parameter in Returns needs to have a matching signature and return type. The valueFunction parameter in your example only has two input arguments and the second argument does not match any of the argument types passed to GetAll. It should look something like this (I don't have the benefit of the compiler checking my syntax but I think what I have here should be correct):

mockContactNumberRepository
.Setup(x => 
    x
    .GetAll(
        It.IsAny<Expression<Func<ContactNumber, bool>>>(), 
        It.IsAny<Func<IQueryable<ContactNumber>, IOrderedQueryable<ContactNumber>>>(),
        It.IsAny<string>()))
.Returns(new Func<
    Expression<Func<ContactNumber, bool>>, 
    Func<IQueryable<ContactNumber>, IOrderedQueryable<ContactNumber>>,
    string,
    IEnumerable<TEntity>>((arg1, arg2, arg3) => 
        {
            // arg1 is Expression<Func<ContactNumber, bool>>
            // arg2 is Func<IQueryable<ContactNumber>, IOrderedQueryable<ContactNumber>>
            // arg3 is string
            // Do something here and return an IEnumerable<TEntity>
        }));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!