2020using System . Threading ;
2121using System . Threading . Tasks ;
2222using Couchbase . Lite ;
23- using FluentAssertions ;
23+ using Shouldly ;
2424
2525using Newtonsoft . Json ;
2626using Xunit ;
@@ -40,17 +40,24 @@ public NotificationTest(ITestOutputHelper output) : base(output)
4040
4141 }
4242
43+ protected override void Dispose ( bool disposing )
44+ {
45+ base . Dispose ( disposing ) ;
46+
47+ _wa ? . Dispose ( ) ;
48+ }
49+
4350 [ Fact ]
4451 public void TestDatabaseChange ( )
4552 {
46- var wa = new WaitAssert ( ) ;
53+ using var wa = new WaitAssert ( ) ;
4754 DefaultCollection . AddChangeListener ( null , ( sender , args ) =>
4855 {
4956 var docIDs = args . DocumentIDs ;
5057 wa . RunAssert ( ( ) =>
5158 {
52- args . Database . Should ( ) . Be ( Db ) ;
53- docIDs . Should ( ) . HaveCount ( 10 , "because that is the number of expected rows" ) ;
59+ args . Database . ShouldBe ( Db ) ;
60+ docIDs . Count . ShouldBe ( 10 , "because that is the number of expected rows" ) ;
5461 } ) ;
5562 } ) ;
5663
@@ -69,16 +76,16 @@ public void TestDatabaseChange()
6976 [ Fact ]
7077 public void TestCollectionChange ( )
7178 {
72- var wa = new WaitAssert ( ) ;
79+ using var wa = new WaitAssert ( ) ;
7380 var colA = Db . CreateCollection ( "colA" , "scopeA" ) ;
7481
7582 colA . AddChangeListener ( null , ( sender , args ) =>
7683 {
7784 var docIDs = args . DocumentIDs ;
7885 wa . RunAssert ( ( ) =>
7986 {
80- args . Collection . Should ( ) . Be ( colA ) ;
81- docIDs . Should ( ) . HaveCount ( 10 , "because that is the number of expected rows" ) ;
87+ args . Collection . ShouldBe ( colA ) ;
88+ docIDs . Count . ShouldBe ( 10 , "because that is the number of expected rows" ) ;
8289 } ) ;
8390 } ) ;
8491
@@ -158,7 +165,7 @@ public void TestCollectionDocumentChange()
158165 colB . Save ( doc4 ) ;
159166
160167 _wa . WaitForResult ( TimeSpan . FromSeconds ( 5 ) ) ;
161- _expectedDocumentChanges . Count . Should ( ) . Be ( 0 ) ;
168+ _expectedDocumentChanges . Count . ShouldBe ( 0 ) ;
162169
163170 _wa = new WaitAssert ( ) ;
164171
@@ -170,15 +177,15 @@ public void TestCollectionDocumentChange()
170177 colB . Save ( doc4 ) ;
171178
172179 _wa . WaitForResult ( TimeSpan . FromSeconds ( 5 ) ) ;
173- _expectedDocumentChanges . Count . Should ( ) . Be ( 0 ) ;
180+ _expectedDocumentChanges . Count . ShouldBe ( 0 ) ;
174181
175182 _wa = new WaitAssert ( ) ;
176183
177184 _expectedDocumentChanges . Add ( "doc2" ) ;
178185 colA . Delete ( doc2 ) ;
179186
180187 _wa . WaitForResult ( TimeSpan . FromSeconds ( 5 ) ) ;
181- _expectedDocumentChanges . Count . Should ( ) . Be ( 0 ) ;
188+ _expectedDocumentChanges . Count . ShouldBe ( 0 ) ;
182189
183190 _expectedDocumentChanges . Add ( "doc3" ) ;
184191 var doc3 = new MutableDocument ( "doc3" ) ;
@@ -187,8 +194,8 @@ public void TestCollectionDocumentChange()
187194
188195 Thread . Sleep ( 1000 ) ;
189196
190- _expectedDocumentChanges . Count . Should ( ) . Be ( 1 , "Because there is no listener to observe doc3 change." ) ;
191- _wa . CaughtExceptions . Should ( ) . BeEmpty ( "because otherwise too many callbacks happened" ) ;
197+ _expectedDocumentChanges . Count . ShouldBe ( 1 , "Because there is no listener to observe doc3 change." ) ;
198+ _wa . CaughtExceptions . ShouldBeEmpty ( "because otherwise too many callbacks happened" ) ;
192199 _expectedDocumentChanges . Clear ( ) ;
193200 }
194201 }
@@ -215,7 +222,7 @@ public async Task TestAddSameChangeListeners()
215222 DefaultCollection . Save ( doc1 ) ;
216223
217224 await Task . Delay ( 500 ) ;
218- _wa . CaughtExceptions . Should ( ) . BeEmpty ( "because otherwise too many callbacks happened" ) ;
225+ _wa . CaughtExceptions . ShouldBeEmpty ( "because otherwise too many callbacks happened" ) ;
219226 }
220227
221228 [ Fact ]
@@ -241,7 +248,7 @@ public async Task TestCollectionAddSameChangeListeners()
241248 colA . Save ( doc1 ) ;
242249
243250 await Task . Delay ( 500 ) ;
244- _wa . CaughtExceptions . Should ( ) . BeEmpty ( "because otherwise too many callbacks happened" ) ;
251+ _wa . CaughtExceptions . ShouldBeEmpty ( "because otherwise too many callbacks happened" ) ;
245252 }
246253
247254 [ Fact ]
@@ -269,7 +276,7 @@ public async Task TestRemoveDocumentChangeListener()
269276 DefaultCollection . Save ( doc1 ) ;
270277
271278 await Task . Delay ( 500 ) ;
272- _wa . CaughtExceptions . Should ( ) . BeEmpty ( "because otherwise too many callbacks happened" ) ;
279+ _wa . CaughtExceptions . ShouldBeEmpty ( "because otherwise too many callbacks happened" ) ;
273280
274281 // Remove again
275282 DefaultCollection . RemoveChangeListener ( token ) ;
@@ -301,7 +308,7 @@ public async Task TestCollectionRemoveDocumentChangeListener()
301308 colA . Save ( doc1 ) ;
302309
303310 await Task . Delay ( 500 ) ;
304- _wa . CaughtExceptions . Should ( ) . BeEmpty ( "because otherwise too many callbacks happened" ) ;
311+ _wa . CaughtExceptions . ShouldBeEmpty ( "because otherwise too many callbacks happened" ) ;
305312
306313 // Remove again
307314 token . Remove ( ) ;
@@ -314,21 +321,21 @@ public void TestExternalChanges()
314321 var countdownDB = new CountdownEvent ( 1 ) ;
315322 db2 . GetDefaultCollection ( ) . AddChangeListener ( ( sender , args ) =>
316323 {
317- args . Should ( ) . NotBeNull ( ) ;
318- args . DocumentIDs . Count . Should ( ) . Be ( 10 ) ;
319- countdownDB . CurrentCount . Should ( ) . Be ( 1 ) ;
324+ args . ShouldNotBeNull ( ) ;
325+ args . DocumentIDs . Count . ShouldBe ( 10 ) ;
326+ countdownDB . CurrentCount . ShouldBe ( 1 ) ;
320327 countdownDB . Signal ( ) ;
321328 } ) ;
322329
323330 var countdownDoc = new CountdownEvent ( 1 ) ;
324331 db2 . GetDefaultCollection ( ) . AddDocumentChangeListener ( "doc-6" , ( sender , args ) =>
325332 {
326- args . Should ( ) . NotBeNull ( ) ;
327- args . DocumentID . Should ( ) . Be ( "doc-6" ) ;
333+ args . ShouldNotBeNull ( ) ;
334+ args . DocumentID . ShouldBe ( "doc-6" ) ;
328335 using ( var doc = db2 . GetDefaultCollection ( ) . GetDocument ( args . DocumentID ) ) {
329- doc . Should ( ) . NotBeNull ( "because otherwise the save of '{doc }' failed" , args . DocumentID ) ;
330- doc ! . GetString ( "type" ) . Should ( ) . Be ( "demo" ) ;
331- countdownDoc . CurrentCount . Should ( ) . Be ( 1 ) ;
336+ doc . ShouldNotBeNull ( $ "because otherwise the save of '{ args . DocumentID } ' failed") ;
337+ doc ! . GetString ( "type" ) . ShouldBe ( "demo" ) ;
338+ countdownDoc . CurrentCount . ShouldBe ( 1 ) ;
332339 countdownDoc . Signal ( ) ;
333340 }
334341 } ) ;
@@ -343,8 +350,8 @@ public void TestExternalChanges()
343350 }
344351 } ) ;
345352
346- countdownDB . Wait ( TimeSpan . FromSeconds ( 5 ) ) . Should ( ) . BeTrue ( ) ;
347- countdownDoc . Wait ( TimeSpan . FromSeconds ( 5 ) ) . Should ( ) . BeTrue ( ) ;
353+ countdownDB . Wait ( TimeSpan . FromSeconds ( 5 ) ) . ShouldBeTrue ( ) ;
354+ countdownDoc . Wait ( TimeSpan . FromSeconds ( 5 ) ) . ShouldBeTrue ( ) ;
348355 }
349356 }
350357
@@ -356,21 +363,21 @@ public void TestCollectionExternalChanges()
356363 var countdownDB = new CountdownEvent ( 1 ) ;
357364 colB . AddChangeListener ( ( sender , args ) =>
358365 {
359- args . Should ( ) . NotBeNull ( ) ;
360- args . DocumentIDs . Count . Should ( ) . Be ( 10 ) ;
361- countdownDB . CurrentCount . Should ( ) . Be ( 1 ) ;
366+ args . ShouldNotBeNull ( ) ;
367+ args . DocumentIDs . Count . ShouldBe ( 10 ) ;
368+ countdownDB . CurrentCount . ShouldBe ( 1 ) ;
362369 countdownDB . Signal ( ) ;
363370 } ) ;
364371
365372 var countdownDoc = new CountdownEvent ( 1 ) ;
366373 colB . AddDocumentChangeListener ( "doc-6" , ( sender , args ) =>
367374 {
368- args . Should ( ) . NotBeNull ( ) ;
369- args . DocumentID . Should ( ) . Be ( "doc-6" ) ;
375+ args . ShouldNotBeNull ( ) ;
376+ args . DocumentID . ShouldBe ( "doc-6" ) ;
370377 using ( var doc = colB . GetDocument ( args . DocumentID ) ) {
371- doc . Should ( ) . NotBeNull ( "because otherwise the save of '{doc }' failed" , args . DocumentID ) ;
372- doc ! . GetString ( "type" ) . Should ( ) . Be ( "demo" ) ;
373- countdownDoc . CurrentCount . Should ( ) . Be ( 1 ) ;
378+ doc . ShouldNotBeNull ( $ "because otherwise the save of '{ args . DocumentID } ' failed") ;
379+ doc ! . GetString ( "type" ) . ShouldBe ( "demo" ) ;
380+ countdownDoc . CurrentCount . ShouldBe ( 1 ) ;
374381 countdownDoc . Signal ( ) ;
375382 }
376383 } ) ;
@@ -385,8 +392,8 @@ public void TestCollectionExternalChanges()
385392 }
386393 } ) ;
387394
388- countdownDB . Wait ( TimeSpan . FromSeconds ( 5 ) ) . Should ( ) . BeTrue ( ) ;
389- countdownDoc . Wait ( TimeSpan . FromSeconds ( 5 ) ) . Should ( ) . BeTrue ( ) ;
395+ countdownDB . Wait ( TimeSpan . FromSeconds ( 5 ) ) . ShouldBeTrue ( ) ;
396+ countdownDoc . Wait ( TimeSpan . FromSeconds ( 5 ) ) . ShouldBeTrue ( ) ;
390397 }
391398 }
392399
@@ -434,8 +441,8 @@ public async Task TestCollectionChangeListener()
434441 colB . Save ( doc3b ) ;
435442
436443 await Task . Delay ( 800 ) ;
437- _expectedDocumentChanges . Count . Should ( ) . Be ( 0 ) ;
438- _unexpectedDocumentChanges . Count . Should ( ) . Be ( 3 ) ;
444+ _expectedDocumentChanges . Count . ShouldBe ( 0 ) ;
445+ _unexpectedDocumentChanges . Count . ShouldBe ( 3 ) ;
439446
440447 //will notify 2 times since there are 2 observers
441448 _expectedDocumentChanges . Add ( "doc6" ) ;
@@ -444,7 +451,7 @@ public async Task TestCollectionChangeListener()
444451 doc6 . SetString ( "name" , "Jack" ) ;
445452 colA . Save ( doc6 ) ;
446453 await Task . Delay ( 500 ) ;
447- _expectedDocumentChanges . Count . Should ( ) . Be ( 0 ) ;
454+ _expectedDocumentChanges . Count . ShouldBe ( 0 ) ;
448455
449456 t1 . Remove ( ) ;
450457
@@ -454,7 +461,7 @@ public async Task TestCollectionChangeListener()
454461 doc4 . SetString ( "name" , "Jack" ) ;
455462 colA . Save ( doc4 ) ;
456463 await Task . Delay ( 500 ) ;
457- _expectedDocumentChanges . Count . Should ( ) . Be ( 0 ) ;
464+ _expectedDocumentChanges . Count . ShouldBe ( 0 ) ;
458465
459466 t2 . Remove ( ) ;
460467
@@ -465,9 +472,9 @@ public async Task TestCollectionChangeListener()
465472 colA . Save ( doc5 ) ;
466473 await Task . Delay ( 500 ) ;
467474
468- _wa . CaughtExceptions . Should ( ) . BeEmpty ( "because otherwise too many callbacks happened" ) ;
469- _expectedDocumentChanges . Count . Should ( ) . Be ( 1 ) ;
470- _unexpectedDocumentChanges . Count . Should ( ) . Be ( 3 ) ;
475+ _wa . CaughtExceptions . ShouldBeEmpty ( "because otherwise too many callbacks happened" ) ;
476+ _expectedDocumentChanges . Count . ShouldBe ( 1 ) ;
477+ _unexpectedDocumentChanges . Count . ShouldBe ( 3 ) ;
471478 }
472479 }
473480#endif
@@ -482,10 +489,10 @@ private void CollectionChanged(object? sender, CollectionChangedEventArgs args)
482489 {
483490 lock ( _expectedDocumentChanges ! ) {
484491 foreach ( var docId in args . DocumentIDs ) {
485- _expectedDocumentChanges . Should ( )
486- . Contain ( docId , "because otherwise a rogue notification came" ) ;
487- _unexpectedDocumentChanges . Should ( )
488- . NotContain ( docId , "because otherwise a rogue notification came" ) ;
492+ _expectedDocumentChanges
493+ . ShouldContain ( docId , "because otherwise a rogue notification came" ) ;
494+ _unexpectedDocumentChanges !
495+ . ShouldNotContain ( docId , "because otherwise a rogue notification came" ) ;
489496 _expectedDocumentChanges . Remove ( docId ) ;
490497 }
491498
@@ -506,8 +513,8 @@ private void DocumentChanged(object? sender, DocumentChangedEventArgs args)
506513 _wa ! . RunConditionalAssert ( ( ) =>
507514 {
508515 lock ( _expectedDocumentChanges ! ) {
509- _expectedDocumentChanges . Should ( )
510- . Contain ( args . DocumentID , "because otherwise a rogue notification came" ) ;
516+ _expectedDocumentChanges
517+ . ShouldContain ( args . DocumentID , "because otherwise a rogue notification came" ) ;
511518 _expectedDocumentChanges . Remove ( args . DocumentID ) ;
512519
513520 WriteLine (
0 commit comments