My mock setup are like below
public class LicensePathControllerTest
{
private MockRepository mockRepository;
}
public LicensePathControllerTest()
{
this.mockRepository = new MockRepository(MockBehavior.Strict);
this.mockIJobLicensePathService =
this.mockRepository.Create<IJobLicensePathService>();
this.mockLog = this.mockRepository.Create<ILog>();
}
private LicensePathController CreateLicensePathController()
{
return new LicensePathController(
this.mockIJobLicensePathService.Object,this.mockLog.Object);
}
My method is
public async Task<IActionResult> GetLicensePath([FromBody] PathSearch pathSearch)
{
var (paths, pagination) = await _pathService.GetJobPathByFilters(pathSearch); //need to mock this line.
return ok(new OkResponse<IList<JobLicensePath>>(licensePaths, pagination.PageNumber, pagination.PageSize, pagination.TotalPages, pagination.TotalCount));
}
my service class method returning as well
public async Task<(IList<JobLicensePath>, PaginationModel)> GetJobPathByFilters(PathSearch pathSearch)
{
//...
IEnumerable<JobLicensePath> objJobLicensePath = null;
objJobLicensePath = await _baseRepository.GetAsync<JobLicensePath>(filter: expression, null, null, skip: skipVal, take: take, false);
return (objJobPath.ToList(), new PaginationModel(pageNumber, pageSize, totalCount));
}
I am trying to mock like below few trials but which all are not setup.
First Try
mockIJobLicensePathService
.Setup(x => x.GetJobPathByFilters(It.IsAny<PathSearch>()))
.Returns(Task.FromResult(It.IsAny<Task(IList<JobLicensePath>, PaginationModel)>()));
The type arguments for method 'Task.FromResult(TResult)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Second Try
mockIJobLicensePathService
.Setup(x => x.GetJobPathByFilters(It.IsAny<PathSearch>()))
.Returns(Task.FromResult(It.IsAny<IList<JobLicensePath>, PaginationModel>()>));
Using the generic method 'It.IsAny()' requires 1 type arguments
mockIJobLicensePathService
.Setup(x => x.GetJobPathByFilters(It.IsAny<PathSearch>()))
.Returns(Task.FromResult(It.IsAny<IList<JobLicensePath>>(), It.IsAny<PaginationModel>()));
No overload for method 'FromResult' takes 2 arguments