@@ -135,4 +135,71 @@ public async Task SearchTags()
135135 Assert . That ( tags . Count ( ) , Is . EqualTo ( expectedCount ) , $ "Expected search expression '{ searchExpression } ' to return { expectedCount } results.") ;
136136 }
137137 }
138+
139+ [ Test ]
140+ public async Task EnumerateTags_FivePerPageAndWithStartPageSpecified ( )
141+ {
142+ // Arrange
143+ using var server = new GitLabConfig ( )
144+ . WithUser ( "user1" , isDefault : true )
145+ . WithProject ( "test-project" , id : 1 , addDefaultUserAsMaintainer : true , configure : project =>
146+ {
147+ project . WithCommit ( "Commit with tags" , tags : Enumerable . Range ( 0 , 20 ) . Select ( i => $ "1.{ i } .0") . ToArray ( ) ) ;
148+ } )
149+ . BuildServer ( ) ;
150+
151+ var client = server . CreateClient ( ) ;
152+ var tagClient = client . GetRepository ( 1 ) . Tags ;
153+
154+ var perPage = 5 ;
155+
156+ ( int ? StartPage , string [ ] ExpectedTags ) [ ] testCases =
157+ [
158+ ( null , [ "1.19.0" , "1.18.0" , "1.17.0" , "1.16.0" , "1.15.0" ] ) ,
159+ ( 1 , [ "1.19.0" , "1.18.0" , "1.17.0" , "1.16.0" , "1.15.0" ] ) ,
160+ ( 2 , [ "1.14.0" , "1.13.0" , "1.12.0" , "1.11.0" , "1.10.0" ] ) ,
161+ ( 4 , [ "1.4.0" , "1.3.0" , "1.2.0" , "1.1.0" , "1.0.0" ] ) ,
162+ ( 5 , [ ] ) ,
163+ ] ;
164+
165+ foreach ( var ( startPage , expectedTags ) in testCases )
166+ {
167+ // Act
168+ var tags = tagClient . GetAsync ( new TagQuery { OrderBy = "version" , PerPage = perPage , Page = startPage } ) . AsEnumerable ( ) . Take ( perPage ) . ToArray ( ) ;
169+
170+ // Assert
171+ Assert . That ( tags . Select ( t => t . Name ) , Is . EqualTo ( expectedTags ) ) ;
172+ }
173+ }
174+
175+ [ Test ]
176+ public async Task EnumerateTags_WithPreviousTagSpecified ( )
177+ {
178+ // Arrange
179+ using var server = new GitLabConfig ( )
180+ . WithUser ( "user1" , isDefault : true )
181+ . WithProject ( "test-project" , id : 1 , addDefaultUserAsMaintainer : true , configure : project =>
182+ {
183+ project . WithCommit ( "Commit with tags" , tags : Enumerable . Range ( 0 , 10 ) . Select ( i => $ "1.{ i } .0") . ToArray ( ) ) ;
184+ } )
185+ . BuildServer ( ) ;
186+
187+ var client = server . CreateClient ( ) ;
188+ var tagClient = client . GetRepository ( 1 ) . Tags ;
189+
190+ ( string PreviousTag , string [ ] ExpectedTags ) [ ] testCases =
191+ [
192+ ( null , [ "1.9.0" , "1.8.0" , "1.7.0" , "1.6.0" , "1.5.0" , "1.4.0" , "1.3.0" , "1.2.0" , "1.1.0" , "1.0.0" ] ) ,
193+ ( "1.3.0" , [ "1.2.0" , "1.1.0" , "1.0.0" ] ) ,
194+ ] ;
195+
196+ foreach ( var ( previousTag , expectedTags ) in testCases )
197+ {
198+ // Act
199+ var tags = tagClient . GetAsync ( new TagQuery { OrderBy = "version" , PageToken = previousTag } ) . AsEnumerable ( ) . ToArray ( ) ;
200+
201+ // Assert
202+ Assert . That ( tags . Select ( t => t . Name ) , Is . EqualTo ( expectedTags ) ) ;
203+ }
204+ }
138205}
0 commit comments