Fix broken paging (#136)

* Add unit tests
* Use calculated page size instead of page

Co-authored-by: ITDancer139 <kevinitdancersommer@gmail.com>
This commit is contained in:
ITDancer13 2021-05-16 16:34:36 +02:00 committed by GitHub
parent 2c9d907764
commit aedbc1ed96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View File

@ -10,6 +10,7 @@
/// <summary>
/// Fallback value of no page size is specified in the request.
/// </summary>
/// <remarks>Values less or equal to 0 disable paging.</remarks>
public int DefaultPageSize { get; set; } = 0;
/// <summary>

View File

@ -389,7 +389,7 @@ namespace Sieve.Services
}
result = result.Skip((page - 1) * pageSize);
result = result.Take(page);
result = result.Take(pageSize);
return result;
}

View File

@ -613,5 +613,44 @@ namespace SieveUnitTests
Assert.Equal(1,posts[2].Id);
Assert.Equal(0,posts[3].Id);
}
[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
public void Paging_DifferentPages(int page)
{
var model = new SieveModel
{
Page = page,
PageSize = 1,
};
var result = _processor.Apply(model, _posts);
var posts = result.ToList();
Assert.Single(posts);
var expectedId = page - 1;
Assert.Equal(expectedId, posts.First().Id);
}
[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
public void Paging_DifferentPageSizes(int pageSize)
{
var model = new SieveModel
{
Page = 1,
PageSize = pageSize,
};
var result = _processor.Apply(model, _posts);
Assert.Equal(pageSize, result.Count());
}
}
}