@@ -150,117 +150,115 @@ public async Task SimpleExampleOfOffsetPagingThroughDatasetUsingQueryApiWithWher
150150 [ TestMethod ]
151151 public async Task TestCursorPagingQueryApiSyntaxAsync ( )
152152 {
153- using ( var sqlConnection = await CreateSqlConnectionAsync ( ) . ConfigureAwait ( false ) )
153+ using var sqlConnection = await CreateSqlConnectionAsync ( ) . ConfigureAwait ( false ) ;
154+
155+ const int pageSize = 2 ;
156+ int ? totalCount = null ;
157+ int runningTotal = 0 ;
158+ ICursorPageResults < CharacterDbModel > page = null ;
159+
160+ do
154161 {
155- const int pageSize = 2 ;
156- int ? totalCount = null ;
157- int runningTotal = 0 ;
158- ICursorPageResults < CharacterDbModel > page = null ;
162+ page = await sqlConnection . PagingCursorQueryAsync < CharacterDbModel > (
163+ orderBy : new [ ] { OrderField . Descending < CharacterDbModel > ( c => c . Id ) } ,
164+ pagingParams : CursorPagingParams . ForCursors (
165+ first : pageSize ,
166+ afterCursor : page ? . EndCursor ,
167+ retrieveTotalCount : totalCount is null
168+ )
169+ ) ;
170+
171+ page . Should ( ) . NotBeNull ( ) ;
172+
173+ var resultsList = page . CursorResults . ToList ( ) ;
174+ resultsList . Should ( ) . HaveCount ( pageSize ) ;
159175
160- do
176+ //Validate that we get Total Count only once, and on all following pages it is skipped and Null is returned as expected!
177+ if ( totalCount is null )
161178 {
162- page = await sqlConnection . PagingCursorQueryAsync < CharacterDbModel > (
163- orderBy : new [ ] { OrderField . Descending < CharacterDbModel > ( c => c . Id ) } ,
164- pagingParams : CursorPagingParams . ForCursors (
165- first : pageSize ,
166- afterCursor : page ? . EndCursor ,
167- retrieveTotalCount : totalCount is null
168- )
169- ) ;
170-
171- page . Should ( ) . NotBeNull ( ) ;
172-
173- var resultsList = page . CursorResults . ToList ( ) ;
174- resultsList . Should ( ) . HaveCount ( pageSize ) ;
175-
176- //Validate that we get Total Count only once, and on all following pages it is skipped and Null is returned as expected!
177- if ( totalCount is null )
178- {
179- page . TotalCount . Should ( ) . BePositive ( ) ;
180- totalCount = page . TotalCount ;
181- TestContext . WriteLine ( "*********************************************************" ) ;
182- TestContext . WriteLine ( $ "[{ totalCount } ] Total Results to be processed...") ;
183- TestContext . WriteLine ( "*********************************************************" ) ;
184- }
185- else
186- {
187- page . TotalCount . Should ( ) . BeNull ( ) ;
188- }
179+ page . TotalCount . Should ( ) . BePositive ( ) ;
180+ totalCount = page . TotalCount ;
181+ TestContext . WriteLine ( "*********************************************************" ) ;
182+ TestContext . WriteLine ( $ "[{ totalCount } ] Total Results to be processed...") ;
183+ TestContext . WriteLine ( "*********************************************************" ) ;
184+ }
185+ else
186+ {
187+ page . TotalCount . Should ( ) . BeNull ( ) ;
188+ }
189189
190- runningTotal += resultsList . Count ;
191-
192- TestContext . WriteLine ( "" ) ;
193- TestContext . WriteLine ( $ "[{ resultsList . Count } ] Page Results:") ;
194- TestContext . WriteLine ( "----------------------------------------" ) ;
195- foreach ( var result in resultsList )
196- {
197- var entity = result . Entity ;
198- TestContext . WriteLine ( $ "[{ result . Cursor } ] ==> ({ entity . Id } ) { entity . Name } ") ;
199- AssertCharacterDbModelIsValid ( entity ) ;
200- }
201-
202- } while ( page . HasNextPage ) ;
203-
204- Assert . AreEqual ( totalCount , runningTotal , "Total Count doesn't Match the final running total tally!" ) ;
205- }
190+ runningTotal += resultsList . Count ;
191+
192+ TestContext . WriteLine ( "" ) ;
193+ TestContext . WriteLine ( $ "[{ resultsList . Count } ] Page Results:") ;
194+ TestContext . WriteLine ( "----------------------------------------" ) ;
195+ foreach ( var result in resultsList )
196+ {
197+ var entity = result . Entity ;
198+ TestContext . WriteLine ( $ "[{ result . Cursor } ] ==> ({ entity . Id } ) { entity . Name } ") ;
199+ AssertCharacterDbModelIsValid ( entity ) ;
200+ }
201+
202+ } while ( page . HasNextPage ) ;
203+
204+ Assert . AreEqual ( totalCount , runningTotal , "Total Count doesn't Match the final running total tally!" ) ;
206205 }
207206
208207 [ TestMethod ]
209208 public async Task TestOffsetPagingQueryApiSyntaxAsync ( )
210209 {
211- using ( var sqlConnection = await CreateSqlConnectionAsync ( ) . ConfigureAwait ( false ) )
210+ using var sqlConnection = await CreateSqlConnectionAsync ( ) . ConfigureAwait ( false ) ;
211+
212+ const int pageSize = 2 ;
213+ int ? totalCount = null ;
214+ int runningTotal = 0 ;
215+ IOffsetPageResults < CharacterDbModel > page = null ;
216+
217+ do
212218 {
213- const int pageSize = 2 ;
214- int ? totalCount = null ;
215- int runningTotal = 0 ;
216- IOffsetPageResults < CharacterDbModel > page = null ;
219+ page = await sqlConnection . PagingOffsetQueryAsync < CharacterDbModel > (
220+ orderBy : new [ ] { OrderField . Descending < CharacterDbModel > ( c => c . Id ) } ,
221+ pagingParams : OffsetPagingParams . ForSkipTake (
222+ take : pageSize ,
223+ skip : page ? . EndIndex ,
224+ retrieveTotalCount : totalCount is null
225+ )
226+ ) ;
217227
218- do
228+ page . Should ( ) . NotBeNull ( ) ;
229+
230+ var resultsList = page . Results . ToList ( ) ;
231+ resultsList . Should ( ) . HaveCount ( pageSize ) ;
232+
233+ //Validate that we get Total Count only once, and on all following pages it is skipped and Null is returned as expected!
234+ if ( totalCount is null )
219235 {
220- page = await sqlConnection . PagingOffsetQueryAsync < CharacterDbModel > (
221- orderBy : new [ ] { OrderField . Descending < CharacterDbModel > ( c => c . Id ) } ,
222- pagingParams : OffsetPagingParams . ForSkipTake (
223- take : pageSize ,
224- skip : page ? . EndIndex ,
225- retrieveTotalCount : totalCount is null
226- )
227- ) ;
228-
229- page . Should ( ) . NotBeNull ( ) ;
230-
231- var resultsList = page . Results . ToList ( ) ;
232- resultsList . Should ( ) . HaveCount ( pageSize ) ;
233-
234- //Validate that we get Total Count only once, and on all following pages it is skipped and Null is returned as expected!
235- if ( totalCount is null )
236- {
237- page . TotalCount . Should ( ) . BePositive ( ) ;
238- totalCount = page . TotalCount ;
239- TestContext . WriteLine ( "*********************************************************" ) ;
240- TestContext . WriteLine ( $ "[{ totalCount } ] Total Results to be processed...") ;
241- TestContext . WriteLine ( "*********************************************************" ) ;
242- }
243- else
244- {
245- page . TotalCount . Should ( ) . BeNull ( ) ;
246- }
247-
248- runningTotal += resultsList . Count ;
249-
250- TestContext . WriteLine ( "" ) ;
251- TestContext . WriteLine ( $ "[{ resultsList . Count } ] Page Results:") ;
252- TestContext . WriteLine ( "----------------------------------------" ) ;
253- int counter = 0 ;
254- foreach ( var entity in resultsList )
255- {
256- TestContext . WriteLine ( $ "[{ ++ counter } ] ==> ({ entity . Id } ) { entity . Name } ") ;
257- AssertCharacterDbModelIsValid ( entity ) ;
258- }
259-
260- } while ( page . HasNextPage ) ;
261-
262- Assert . AreEqual ( totalCount , runningTotal , "Total Count doesn't Match the final running total tally!" ) ;
263- }
236+ page . TotalCount . Should ( ) . BePositive ( ) ;
237+ totalCount = page . TotalCount ;
238+ TestContext . WriteLine ( "*********************************************************" ) ;
239+ TestContext . WriteLine ( $ "[{ totalCount } ] Total Results to be processed...") ;
240+ TestContext . WriteLine ( "*********************************************************" ) ;
241+ }
242+ else
243+ {
244+ page . TotalCount . Should ( ) . BeNull ( ) ;
245+ }
246+
247+ runningTotal += resultsList . Count ;
248+
249+ TestContext . WriteLine ( "" ) ;
250+ TestContext . WriteLine ( $ "[{ resultsList . Count } ] Page Results:") ;
251+ TestContext . WriteLine ( "----------------------------------------" ) ;
252+ int counter = 0 ;
253+ foreach ( var entity in resultsList )
254+ {
255+ TestContext . WriteLine ( $ "[{ ++ counter } ] ==> ({ entity . Id } ) { entity . Name } ") ;
256+ AssertCharacterDbModelIsValid ( entity ) ;
257+ }
258+
259+ } while ( page . HasNextPage ) ;
260+
261+ Assert . AreEqual ( totalCount , runningTotal , "Total Count doesn't Match the final running total tally!" ) ;
264262 }
265263
266264 private void AssertCharacterDbModelIsValid ( CharacterDbModel entity )
@@ -282,8 +280,6 @@ private void AssertCharacterDbModelIsValid(CharacterDbModel entity)
282280 ? "Protocol"
283281 : "Astromech"
284282 ) ;
285-
286-
287283 }
288284 }
289285}
0 commit comments