7
7
8
8
namespace MvcPaging . Tests
9
9
{
10
- [ TestFixture ]
11
- public class PagerTests
12
- {
13
-
14
- internal class PagionationComparer : IComparer
15
- {
16
-
17
- public int Compare ( object x , object y )
18
- {
19
- PaginationModel first = ( PaginationModel ) x ;
20
- PaginationModel second = ( PaginationModel ) y ;
21
-
22
- var displayTextResult = first . DisplayText . CompareTo ( second . DisplayText ) ;
23
- if ( displayTextResult != 0 ) return displayTextResult ;
24
-
25
- if ( ! first . PageIndex . HasValue && second . PageIndex . HasValue ) return - 1 ;
26
- if ( first . PageIndex . HasValue && ! second . PageIndex . HasValue ) return 1 ;
27
- if ( first . PageIndex . HasValue && second . PageIndex . HasValue )
28
- {
29
- var pageIndexResult = first . PageIndex . Value . CompareTo ( second . PageIndex . Value ) ;
30
- if ( pageIndexResult != 0 ) return pageIndexResult ;
31
- }
32
- var activeResult = first . Active . CompareTo ( second . Active ) ;
33
- if ( activeResult != 0 ) return activeResult ;
34
- var isCurrentResult = first . IsCurrent . CompareTo ( second . IsCurrent ) ;
35
- if ( isCurrentResult != 0 ) return isCurrentResult ;
36
-
37
- return 0 ;
38
- }
39
- }
40
-
41
- [ Test ]
42
- public void Can_Build_Correct_Model_For_5_Items_With_2_Item_Per_Page ( )
43
- {
44
- // Assemble
45
- var pager = new Pager ( null , 2 , 1 , 5 , null , null ) ;
46
- var expectedPagination = new List < PaginationModel > ( )
10
+ [ TestFixture ]
11
+ public class PagerTests
12
+ {
13
+
14
+ internal class PaginationComparer : IComparer
15
+ {
16
+
17
+ public int Compare ( object x , object y )
18
+ {
19
+ PaginationModel first = ( PaginationModel ) x ;
20
+ PaginationModel second = ( PaginationModel ) y ;
21
+
22
+ var displayTextResult = first . DisplayText . CompareTo ( second . DisplayText ) ;
23
+ if ( displayTextResult != 0 ) return displayTextResult ;
24
+
25
+ if ( ! first . PageIndex . HasValue && second . PageIndex . HasValue ) return - 1 ;
26
+ if ( first . PageIndex . HasValue && ! second . PageIndex . HasValue ) return 1 ;
27
+ if ( first . PageIndex . HasValue && second . PageIndex . HasValue )
28
+ {
29
+ var pageIndexResult = first . PageIndex . Value . CompareTo ( second . PageIndex . Value ) ;
30
+ if ( pageIndexResult != 0 ) return pageIndexResult ;
31
+ }
32
+ var activeResult = first . Active . CompareTo ( second . Active ) ;
33
+ if ( activeResult != 0 ) return activeResult ;
34
+ var isCurrentResult = first . IsCurrent . CompareTo ( second . IsCurrent ) ;
35
+ if ( isCurrentResult != 0 ) return isCurrentResult ;
36
+
37
+ return 0 ;
38
+ }
39
+ }
40
+
41
+ [ Test ]
42
+ public void Can_Build_Correct_Model_For_5_Items_With_2_Item_Per_Page ( )
43
+ {
44
+ // Assemble
45
+ var pager = new Pager ( null , 2 , 1 , 5 ) ;
46
+ var expectedPagination = new List < PaginationModel > ( )
47
47
{
48
48
new PaginationModel { Active = false , DisplayText = "«" } ,
49
49
new PaginationModel { Active = true , DisplayText = "1" , PageIndex = 1 , IsCurrent = true } ,
@@ -52,21 +52,20 @@ public void Can_Build_Correct_Model_For_5_Items_With_2_Item_Per_Page()
52
52
new PaginationModel { Active = true , DisplayText = "»" , PageIndex = 2 }
53
53
} ;
54
54
55
- // Act
56
- var result = pager . BuildPaginationModel ( ) ;
57
-
58
- // Assert
59
-
60
- Assert . AreEqual ( expectedPagination . Count , result . Count ) ;
61
- CollectionAssert . AreEqual ( expectedPagination , result , new PagionationComparer ( ) ) ;
62
- }
63
-
64
- [ Test ]
65
- public void Can_Build_Correct_Model_For_10_Items_With_2_Item_Per_Page ( )
66
- {
67
- // Assemble
68
- var pager = new Pager ( null , 2 , 3 , 10 , null , null ) ;
69
- var expectedPagination = new List < PaginationModel > ( )
55
+ // Act
56
+ var result = pager . BuildPaginationModel ( ) ;
57
+
58
+ // Assert
59
+ Assert . AreEqual ( expectedPagination . Count , result . Count ( ) ) ;
60
+ CollectionAssert . AreEqual ( expectedPagination , result , new PaginationComparer ( ) ) ;
61
+ }
62
+
63
+ [ Test ]
64
+ public void Can_Build_Correct_Model_For_10_Items_With_2_Item_Per_Page ( )
65
+ {
66
+ // Assemble
67
+ var pager = new Pager ( null , 2 , 3 , 10 ) ;
68
+ var expectedPagination = new List < PaginationModel > ( )
70
69
{
71
70
new PaginationModel { Active = true , DisplayText = "«" , PageIndex = 2 } ,
72
71
new PaginationModel { Active = true , DisplayText = "1" , PageIndex = 1 } ,
@@ -77,22 +76,22 @@ public void Can_Build_Correct_Model_For_10_Items_With_2_Item_Per_Page()
77
76
new PaginationModel { Active = true , DisplayText = "»" , PageIndex = 4 }
78
77
} ;
79
78
80
- // Act
81
- var result = pager . BuildPaginationModel ( ) ;
79
+ // Act
80
+ var result = pager . BuildPaginationModel ( ) ;
82
81
83
- // Assert
82
+ // Assert
84
83
85
- Assert . AreEqual ( expectedPagination . Count , result . Count ) ;
86
- CollectionAssert . AreEqual ( expectedPagination , result , new PagionationComparer ( ) ) ;
87
- }
84
+ Assert . AreEqual ( expectedPagination . Count , result . Count ( ) ) ;
85
+ CollectionAssert . AreEqual ( expectedPagination , result , new PaginationComparer ( ) ) ;
86
+ }
88
87
89
88
90
- [ Test ]
91
- public void Can_Build_Correct_Model_For_33_Items_With_2_Item_Per_Page ( )
92
- {
93
- // Assemble
94
- var pager = new Pager ( null , 2 , 13 , 33 , null , null ) ;
95
- var expectedPagination = new List < PaginationModel > ( )
89
+ [ Test ]
90
+ public void Can_Build_Correct_Model_For_33_Items_With_2_Item_Per_Page ( )
91
+ {
92
+ // Assemble
93
+ var pager = new Pager ( null , 2 , 13 , 33 ) ;
94
+ var expectedPagination = new List < PaginationModel > ( )
96
95
{
97
96
new PaginationModel { Active = true , DisplayText = "«" , PageIndex = 12 } ,
98
97
new PaginationModel { Active = true , DisplayText = "1" , PageIndex = 1 } ,
@@ -111,14 +110,39 @@ public void Can_Build_Correct_Model_For_33_Items_With_2_Item_Per_Page()
111
110
new PaginationModel { Active = true , DisplayText = "»" , PageIndex = 14 }
112
111
} ;
113
112
114
- // Act
115
- var result = pager . BuildPaginationModel ( ) ;
113
+ // Act
114
+ var result = pager . BuildPaginationModel ( ) ;
115
+
116
+ // Assert
117
+ Assert . AreEqual ( expectedPagination . Count , result . Count ( ) ) ;
118
+ CollectionAssert . AreEqual ( expectedPagination , result , new PaginationComparer ( ) ) ;
119
+ }
116
120
117
- // Assert
121
+ [ Test ]
122
+ public void Can_Build_Correct_Model_For_33_Items_With_2_Item_Per_Page_And_Max_5_Pages ( )
123
+ {
124
+ // Assemble
125
+ var pager = new Pager ( null , 2 , 1 , 33 ) . Options ( o => o . MaxNrOfPages ( 5 ) ) ;
126
+ var expectedPagination = new List < PaginationModel > ( )
127
+ {
128
+ new PaginationModel { Active = false , DisplayText = "«" } ,
129
+ new PaginationModel { Active = true , DisplayText = "1" , PageIndex = 1 , IsCurrent = true } ,
130
+ new PaginationModel { Active = true , DisplayText = "2" , PageIndex = 2 } ,
131
+ new PaginationModel { Active = true , DisplayText = "3" , PageIndex = 3 } ,
132
+ new PaginationModel { Active = true , DisplayText = "4" , PageIndex = 4 } ,
133
+ new PaginationModel { Active = true , DisplayText = "5" , PageIndex = 5 } ,
134
+ new PaginationModel { Active = true , DisplayText = "..." } ,
135
+ new PaginationModel { Active = true , DisplayText = "16" , PageIndex = 16 } ,
136
+ new PaginationModel { Active = true , DisplayText = "17" , PageIndex = 17 } ,
137
+ new PaginationModel { Active = true , DisplayText = "»" , PageIndex = 2 }
138
+ } ;
118
139
119
- Assert . AreEqual ( expectedPagination . Count , result . Count ) ;
120
- CollectionAssert . AreEqual ( expectedPagination , result , new PagionationComparer ( ) ) ;
121
- }
140
+ // Act
141
+ var result = pager . BuildPaginationModel ( ) ;
122
142
123
- }
143
+ // Assert
144
+ Assert . AreEqual ( expectedPagination . Count , result . Count ( ) ) ;
145
+ CollectionAssert . AreEqual ( expectedPagination , result , new PaginationComparer ( ) ) ;
146
+ }
147
+ }
124
148
}
0 commit comments