1

I am using Moq and trying to setup the GetPagedList mock for IRepository<TEntity>

below is the interface i am trying to mock

IPagedList GetPagedList(Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, int pageIndex = 0, int pageSize = 20, bool = true);

My service

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);
    }
 }

My Unit Test

[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));

}

Getting this error

Using the generic method It.IsAny<TValue>() requires 1 type arguments.

Any ideas on how to fix this would be greatly appreciated.

Quyen T Ho
  • 55
  • 1
  • 5
  • Without a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) that clarifies your specific problem or additional details to highlight exactly what was done, it will be difficult to reproduce the problem that would allow a better understanding of what is the *actual* problem. – Nkosi Oct 07 '19 at 21:59
  • 1
    BTW I just found it this morning, because of the optional argument I have to have an It.IsAny<> for each argument in the setup _mockStudentRepo.Setup(x => x.GetPagedList( It.IsAny>>(), It.IsAny, IOrderedQueryable>>(), It.IsAny, IIncludableQueryable>>(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MockStudentList.Where(a => a.id == studentId ()).ToPagedList(0, 20))); – Quyen T Ho Oct 08 '19 at 14:03
  • Yes that is a must. – Nkosi Oct 08 '19 at 14:03

0 Answers0