public PagedSearchResponseDto <List <PersonSearchResultDto> > SearchPeople(PagedSearchDto dto) { using (MyDbContext context = new MyDbContext()) { SqlParameter pageSize = new SqlParameter("@PageSize", dto.PageSize ?? (object)DBNull.Value) { DbType = System.Data.DbType.Int32 }; SqlParameter pageNumber = new SqlParameter("@PageNumber", dto.PageNumber ?? (object)DBNull.Value) { DbType = System.Data.DbType.Int32 }; SqlParameter orderBy = new SqlParameter("@OrderBy", string.IsNullOrEmpty(dto.OrderByColumn) ? (object)DBNull.Value : dto.OrderByColumn); SqlParameter orderAsc = new SqlParameter("@OrderAsc", dto.OrderAscending ?? (object)DBNull.Value); SqlParameter totalRows = new SqlParameter("@TotalRows", 0) { DbType = System.Data.DbType.Int32, Direction = System.Data.ParameterDirection.Output }; List <PersonSearchResultDto> results = context.Database.SqlQuery <PersonSearchResultDto>("EXEC dbo.GetPeople @PageSize, @PageNumber, @OrderBy, @OrderAsc, @TotalRows OUTPUT", pageSize, pageNumber, orderBy, orderAsc, totalRows).ToList(); PagedSearchResponseDto <List <PersonSearchResultDto> > response = new PagedSearchResponseDto <List <PersonSearchResultDto> > { PageSize = dto.PageSize, PageNumber = dto.PageNumber, OrderByColumn = dto.OrderByColumn, OrderAscending = dto.OrderAscending, TotalRows = (int?)totalRows.Value, Result = results }; return(response); } }
public async Task MyTestMethod() { PagedSearchDto dto = new PagedSearchDto(); dto.PageSize = 25; dto.PageNumber = 2; dto.OrderByColumn = "FirstName"; dto.OrderAscending = true; dto.TotalRows = 0; ApiResponse response = await _Client.GetPeople(dto); PagedSearchResponseDto <List <PersonSearchResultDto> > data = response.GetTypedContent <PagedSearchResponseDto <List <PersonSearchResultDto> > >(); Assert.AreEqual(dto.PageSize, data.Result.Count); }
public void TestGetPeopleWithDefaults() { using (ApiSampleRepository repository = new ApiSampleRepository()) { PagedSearchDto dto = new PagedSearchDto(); dto.PageSize = 25; dto.PageNumber = 2; dto.OrderByColumn = "PersonId"; dto.OrderAscending = true; dto.TotalRows = 0; PagedSearchResponseDto <List <PersonSearchResultDto> > response = repository.SearchPeople(dto); Assert.IsTrue(response.Result.Count == 25); Assert.IsTrue(response.Result.First().PersonId == 26); } }