-
-
Notifications
You must be signed in to change notification settings - Fork 526
Expand file tree
/
Copy pathPaginationResultTests.cs
More file actions
75 lines (64 loc) · 2 KB
/
Copy pathPaginationResultTests.cs
File metadata and controls
75 lines (64 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System.Linq;
using SqlKata.Execution;
using Xunit;
namespace SqlKata.Tests
{
public class PaginationResultTests
{
[Fact]
public void ReportsPageStateFromCountAndPageSize()
{
var result = new PaginationResult<int>
{
Count = 25,
Page = 2,
PerPage = 10,
};
Assert.Equal(3, result.TotalPages);
Assert.False(result.IsFirst);
Assert.False(result.IsLast);
Assert.True(result.HasNext);
Assert.True(result.HasPrevious);
}
[Fact]
public void BuildsQueriesForAdjacentPages()
{
var nextResult = new PaginationResult<int>
{
Query = new Query("Posts"),
Page = 2,
PerPage = 10,
};
var nextQuery = nextResult.NextQuery();
Assert.Same(nextResult.Query, nextQuery);
Assert.Equal(20, nextQuery.GetOffset());
Assert.Equal(10, nextQuery.GetLimit());
var previousResult = new PaginationResult<int>
{
Query = new Query("Posts"),
Page = 2,
PerPage = 10,
};
var previousQuery = previousResult.PreviousQuery();
Assert.Same(previousResult.Query, previousQuery);
Assert.Equal(0, previousQuery.GetOffset());
Assert.Equal(10, previousQuery.GetLimit());
}
[Fact]
public void EachYieldsTheCurrentPageWhenThereIsNoNextPage()
{
var result = new PaginationResult<int>
{
Count = 2,
List = new[] { 1, 2 },
Page = 1,
PerPage = 10,
};
var iterator = result.Each;
var pages = iterator.ToList();
Assert.Single(pages);
Assert.Same(result, pages[0]);
Assert.Same(result, iterator.CurrentPage);
}
}
}