Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgDangl committed Jan 31, 2019
2 parents fa006f4 + fd60708 commit 8c7900f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to **LightQuery** are documented here.

## v1.5.2:
- Bugfix: Empty results now report the `page` as `1` instead of `0`. Thanks to GitHub user @erdembas for the pull request!

## v1.5.1:
- When a `page` is requested that is higher than the last available one, the last available one will be returned instead. Thanks to GitHub user @erdembas for the pull request!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private async Task<PaginationResult<object>> GetPaginationResult(QueryContainer
if (totalCount <= ((queryOptions.Page - 1) * queryOptions.PageSize))
{
queryOptions.Page = (int)System.Math.Ceiling((decimal)totalCount / queryOptions.PageSize);
queryOptions.Page = queryOptions.Page == 0 ? 1 : queryOptions.Page;
}

return new PaginationResult<object>
Expand Down
1 change: 1 addition & 0 deletions src/LightQuery/LightQueryAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private PaginationResult<object> GetPaginationResult(QueryContainer queryContain
if (totalCount <= ((queryOptions.Page - 1) * queryOptions.PageSize))
{
queryOptions.Page = (int)System.Math.Ceiling((decimal)totalCount / queryOptions.PageSize);
queryOptions.Page = queryOptions.Page == 0 ? 1 : queryOptions.Page;
}

return new PaginationResult<object>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ public async Task IfPageAndPageSizeExceedTotalCountReturnsLastValidPageAndRecord
Assert.Equal(5, pagedResult.Data.Count);
}

[Fact]
public async Task ReturnsEmptyResultWithPageSetToOneIfNoRecordsPresent()
{
var url = "AsyncPaginatedLightQuery?returnEmptyList=true&pageSize=5";
var pagedResult = await GetResponse<PaginationResult<User>>(url);
Assert.Equal(0, pagedResult.TotalCount);

Assert.Equal(1, pagedResult.Page);
Assert.Equal(5, pagedResult.PageSize);
Assert.Empty(pagedResult.Data);
}

[Fact]
public async Task AppliesDefaultSortWithoutClientSortParameter()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ public AsyncPaginatedLightQueryController(LightQueryContext context)
private readonly LightQueryContext _context;

[LightQuery(forcePagination: true, defaultPageSize: 3)]
public IActionResult GetValues()
public IActionResult GetValues(bool returnEmptyList = false)
{
var users = _context.Users.OrderBy(u => Guid.NewGuid());
if (returnEmptyList)
{
users = users.Where(u => false).AsQueryable().OrderBy(u => Guid.NewGuid());
}
return Ok(users);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ public PaginatedLightQueryController(LightQueryContext context)
private readonly LightQueryContext _context;

[LightQuery(forcePagination: true, defaultPageSize: 3)]
public IActionResult GetValues()
public IActionResult GetValues(bool returnEmptyList = false)
{
var users = _context.Users.OrderBy(u => Guid.NewGuid());
if (returnEmptyList)
{
users = users.Where(u => false).AsQueryable().OrderBy(u => Guid.NewGuid());
}
return Ok(users);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ public async Task IfPageAndPageSizeExceedTotalCountReturnsLastValidPageAndRecord
Assert.Equal(5, pagedResult.Data.Count);
}

[Fact]
public async Task ReturnsEmptyResultWithPageSetToOneIfNoRecordsPresent()
{
var url = "PaginatedLightQuery?returnEmptyList=true&pageSize=5";
var pagedResult = await GetResponse<PaginationResult<User>>(url);
Assert.Equal(0, pagedResult.TotalCount);

Assert.Equal(1, pagedResult.Page);
Assert.Equal(5, pagedResult.PageSize);
Assert.Empty(pagedResult.Data);
}

[Fact]
public async Task AppliesDefaultSortWithoutClientSortParameter()
{
Expand Down

0 comments on commit 8c7900f

Please sign in to comment.