public async Task <ActionResult <IEnumerable <AuthorDTO> > > GetAuthors([FromQuery] AuthorSpecificationParams authorParams) { var spec = new AuthorsWithBooksSpecification(authorParams); // get any overall count of items (after filtering has been applied) var countSpec = new AuthorsWithFiltersForCountSpecification(authorParams); var totalItems = await _authorRepository.CountAsync(countSpec); // add pagination response headers to help client applications _httpContextAccessor.HttpContext.AddPaginationResponseHeaders(totalItems, authorParams.PageSize, authorParams.PageIndex); var authors = await _authorRepository.ListAsync(spec); return(Ok(_mapper.Map <IEnumerable <Author>, IEnumerable <AuthorDTO> >(authors))); }
public async Task GetAuthors_ReturnsOkResult() { // Arrange var httpContext = new DefaultHttpContext(); _httpContextAccessorMock.Setup(_ => _.HttpContext).Returns(httpContext); var controller = new AuthorsController(_authorRepositoryMock.Object, _mapperMock.Object, _httpContextAccessorMock.Object); var authorParams = new AuthorSpecificationParams() { PageIndex = 1, PageSize = 5 }; // Act var response = await controller.GetAuthors(authorParams); // Assert Assert.IsType <OkObjectResult>(response.Result); }