forked from dillenmeister/Trello.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoPagingTests.cs
101 lines (80 loc) · 3.71 KB
/
AutoPagingTests.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.Collections.Generic;
using System.Linq;
using FakeItEasy;
using NUnit.Framework;
using TrelloNet.Extensions;
namespace TrelloNet.Tests
{
[TestFixture]
public class AutoPagingTests
{
private IActions _actions;
[SetUp]
public void Setup()
{
_actions = A.Fake<IActions>();
}
[Test]
public void ForBoard_WithPageSizeOf1AndTotalOf1ActionExists_ShouldMakeTwoCalls()
{
const int pageSize = 1;
SetupActionsForBoardToReturn(pageSize, 0, new[] { new Action() });
SetupActionsForBoardToReturn(pageSize, 1, Enumerable.Empty<Action>());
_actions.AutoPaged(pageSize).ForBoard(new BoardId("dummy")).ToList();
A.CallTo(() => _actions.ForBoard(A<IBoardId>._, A<IEnumerable<ActionType>>._, A<ISince>._, A<Paging>._)).MustHaveHappened(Repeated.Exactly.Twice);
}
[Test]
public void ForBoard_WithPageSizeOf1AndTotalOf2ActionsExists_ShouldMakeThreeCalls()
{
const int pageSize = 1;
SetupActionsForBoardToReturn(pageSize, 0, new[] { new Action() });
SetupActionsForBoardToReturn(pageSize, 1, new[] { new Action() });
SetupActionsForBoardToReturn(pageSize, 2, Enumerable.Empty<Action>());
_actions.AutoPaged(pageSize).ForBoard(new BoardId("dummy")).ToList();
A.CallTo(() => _actions.ForBoard(A<IBoardId>._, A<IEnumerable<ActionType>>._, A<ISince>._, A<Paging>._)).MustHaveHappened(Repeated.Exactly.Times(3));
}
[Test]
public void ForBoard_WithPageSizeOf2AndTotalOf1ActionExists_ShouldMakeOneCall()
{
const int pageSize = 2;
SetupActionsForBoardToReturn(pageSize, 0, new[] { new Action() });
SetupActionsForBoardToReturn(pageSize, 1, Enumerable.Empty<Action>());
_actions.AutoPaged(pageSize).ForBoard(new BoardId("dummy")).ToList();
A.CallTo(() => _actions.ForBoard(A<IBoardId>._, A<IEnumerable<ActionType>>._, A<ISince>._, A<Paging>._)).MustHaveHappened(Repeated.Exactly.Once);
}
[Test]
public void ForBoard_WithPageSizeOf2AndTotalOf2ActionExists_ShouldMakeTwoCalls()
{
const int pageSize = 2;
SetupActionsForBoardToReturn(pageSize, 0, new[] { new Action(), new Action() });
SetupActionsForBoardToReturn(pageSize, 1, Enumerable.Empty<Action>());
_actions.AutoPaged(2).ForBoard(new BoardId("dummy")).ToList();
A.CallTo(() => _actions.ForBoard(A<IBoardId>._, A<IEnumerable<ActionType>>._, A<ISince>._, A<Paging>._)).MustHaveHappened(Repeated.Exactly.Twice);
}
[Test]
public void ForBoard_WithPageSizeOf2AndTotalOf3ActionExists_ShouldMakeTwoCalls()
{
const int pageSize = 2;
SetupActionsForBoardToReturn(pageSize, 0, new[] { new Action(), new Action() });
SetupActionsForBoardToReturn(pageSize, 1, new[] { new Action() });
_actions.AutoPaged(2).ForBoard(new BoardId("dummy")).ToList();
A.CallTo(() => _actions.ForBoard(A<IBoardId>._, A<IEnumerable<ActionType>>._, A<ISince>._, A<Paging>._)).MustHaveHappened(Repeated.Exactly.Twice);
}
[Test]
public void ForBoard_WithPageSizeOf2AndTotalOf4ActionExists_ShouldMakeThreeCalls()
{
const int pageSize = 2;
SetupActionsForBoardToReturn(pageSize, 0, new[] { new Action(), new Action() });
SetupActionsForBoardToReturn(pageSize, 1, new[] { new Action(), new Action() });
SetupActionsForBoardToReturn(pageSize, 2, Enumerable.Empty<Action>());
_actions.AutoPaged(2).ForBoard(new BoardId("dummy")).ToList();
A.CallTo(() => _actions.ForBoard(A<IBoardId>._, A<IEnumerable<ActionType>>._, A<ISince>._, A<Paging>._)).MustHaveHappened(Repeated.Exactly.Times(3));
}
private void SetupActionsForBoardToReturn(int pageLimit, int pageSize, IEnumerable<Action> actionsToReturn)
{
A.CallTo(() => _actions.ForBoard(A<IBoardId>._, A<IEnumerable<ActionType>>._, A<ISince>._, A<Paging>
.That.Matches(p => p.Limit == pageLimit && p.Page == pageSize)))
.Returns(actionsToReturn);
}
}
}