我正在使用Moq并尝试为GetPagedList
设置IRepository<TEntity>
模拟
下面是我要模拟的界面
IPagedList GetPagedList(Expression>谓词= null,Func,IOrderedQueryable> orderBy = null,Func,IIncludableQueryable> include = null,int pageIndex = 0,int pageSize = 20,bool = true);
我的服务
public class StudentService
{
private readonly IRepository<Student> _repo;
public StudentService( IUnitOfWork unitOfWork )
{
_repo = unitOfWork.GetRepository<Student>();
_unitOfWork = unitOfWork;
}
public IPagedList<Student> Get(int id)
{
return _repo.GetPagedList(predicate: a => a.id == id);
}
}
我的单元测试
[Fact]
public void StudentService_GetStudentClasses_ReturnListOfClasses()
{
int studentId = 100;
_mockStudentRepo.Setup(x => x.GetPagedList(It.IsAny <
Expression<Func<Student, bool>>,
Func<IQueryable<Student>, IOrderedQueryable<Student>>,
Func<IQueryable<Student>, IIncludableQueryable<Student, object>>,
int, int, bool > ())).Returns(MockStudentList.Where(a => a.id == studentId ()).ToPagedList(0, 20));
}
遇到此错误
使用通用方法
It.IsAny<TValue>()
需要1个类型参数。
任何解决此问题的想法将不胜感激。