mirror of
https://github.com/Biarity/Sieve.git
synced 2024-12-05 03:26:22 +01:00
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:
parent
2c9d907764
commit
aedbc1ed96
@ -10,6 +10,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fallback value of no page size is specified in the request.
|
/// Fallback value of no page size is specified in the request.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>Values less or equal to 0 disable paging.</remarks>
|
||||||
public int DefaultPageSize { get; set; } = 0;
|
public int DefaultPageSize { get; set; } = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -389,7 +389,7 @@ namespace Sieve.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = result.Skip((page - 1) * pageSize);
|
result = result.Skip((page - 1) * pageSize);
|
||||||
result = result.Take(page);
|
result = result.Take(pageSize);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -613,5 +613,44 @@ namespace SieveUnitTests
|
|||||||
Assert.Equal(1,posts[2].Id);
|
Assert.Equal(1,posts[2].Id);
|
||||||
Assert.Equal(0,posts[3].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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user