Skip to content

Commit c341f45

Browse files
authored
CBL-7052: Completely remove FluentAssertions from testing (#1713)
On the way I was able to fix a few things: - Get rid of all WaitHandle.WaitAll calls so that the .NET 4.6.2 tests stop failing because xUnit runs on STAThread threads. - Turn off version vectors since this is 3.3.0 now
1 parent 8e2c04e commit c341f45

22 files changed

+1784
-1765
lines changed

src/Couchbase.Lite.Shared/API/Database/Database.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public sealed unsafe partial class Database : IChangeObservable<DatabaseChangedE
107107
#region Constants
108108

109109
private static readonly C4DatabaseConfig2 DBConfig = new C4DatabaseConfig2 {
110-
flags = C4DatabaseFlags.Create | C4DatabaseFlags.AutoCompact | C4DatabaseFlags.VersionVectors,
110+
flags = C4DatabaseFlags.Create | C4DatabaseFlags.AutoCompact
111111
};
112112

113113
private const string DBExtension = "cblite2";

src/Couchbase.Lite.Tests.NetCore/Couchbase.Lite.Tests.NetCore.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
</ItemGroup>
2626
<ItemGroup>
2727
<PackageReference Include="Couchbase.Lite.Enterprise" Version="3.2.0-b0014" />
28-
<PackageReference Include="FluentAssertions" Version="5.9.0" />
2928
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
3029
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
3130
<PackageReference Include="Shouldly" Version="4.3.0" />

src/Couchbase.Lite.Tests.Shared/DatabaseTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ private void WithActiveLiveQueries(bool isCloseNotDelete)
14991499
using (var otherDb = new Database("closeDB", Db.Config)) {
15001500
var otherDefaultColl = otherDb.GetDefaultCollection();
15011501
var query = QueryBuilder.Select(SelectResult.Expression(Meta.ID)).From(DataSource.Collection(otherDefaultColl));
1502-
var doc1Listener = new WaitAssert();
1502+
using var doc1Listener = new WaitAssert();
15031503
var token = query.AddChangeListener(null, (sender, args) => {
15041504
foreach (var row in args.Results) {
15051505
if (row.GetString("id") == "doc1") {

src/Couchbase.Lite.Tests.Shared/DocPerfTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
using System.IO;
2222
using System.Text;
2323
using Couchbase.Lite;
24-
using FluentAssertions;
2524
using Xunit;
2625
using Xunit.Abstractions;
26+
using Shouldly;
2727

2828
namespace Test
2929
{
@@ -59,7 +59,7 @@ protected override void Test()
5959
private void AddRevisions(uint count)
6060
{
6161
var doc = Db.GetDefaultCollection().GetDocument("doc")?.ToMutable();
62-
doc.Should().NotBeNull("because otherwise the save of the perf test failed");
62+
doc.ShouldNotBeNull("because otherwise the save of the perf test failed");
6363
Db.InBatch(() =>
6464
{
6565
for (int i = 0; i < count; i++) {

src/Couchbase.Lite.Tests.Shared/MmapTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//
1818

1919
using Couchbase.Lite;
20-
using FluentAssertions;
20+
using Shouldly;
2121
using LiteCore.Interop;
2222
using System.Runtime.InteropServices;
2323
using Xunit;
@@ -56,14 +56,14 @@ public unsafe void TestDefaultMMapConfig()
5656
throw new SkipException("Not supported on Mac Catalyst");
5757
#else
5858
var config = new DatabaseConfiguration();
59-
config.MmapEnabled.Should().BeTrue();
60-
config.MmapEnabled.Should().BeTrue("because the default should be true");
59+
config.MmapEnabled.ShouldBeTrue();
60+
config.MmapEnabled.ShouldBeTrue("because the default should be true");
6161

6262
config.MmapEnabled = false;
63-
config.MmapEnabled.Should().BeFalse("because C# properties should work...");
63+
config.MmapEnabled.ShouldBeFalse("because C# properties should work...");
6464

6565
config.MmapEnabled = true;
66-
config.MmapEnabled.Should().BeTrue("because C# properties should work...");
66+
config.MmapEnabled.ShouldBeTrue("because C# properties should work...");
6767
#endif
6868
}
6969

@@ -98,12 +98,12 @@ public unsafe void TestDatabaseWithConfiguredMMap(bool useMmap)
9898

9999
Database.Delete("test", null);
100100
using var db = new Database("test", config);
101-
db.Config.MmapEnabled.Should().Be(useMmap, "because otherwise MmapEnabled was not saved to the db's config");
101+
db.Config.MmapEnabled.ShouldBe(useMmap, "because otherwise MmapEnabled was not saved to the db's config");
102102
var c4db = db.c4db;
103-
c4db.Should().NotBeNull();
103+
c4db.ShouldNotBeNull();
104104
var nativeConfig = TestNative.c4db_getConfig2(c4db!.RawDatabase);
105105
var hasFlag = (nativeConfig->flags & C4DatabaseFlags.MmapDisabled) == C4DatabaseFlags.MmapDisabled;
106-
hasFlag.Should().Be(!useMmap, "because the flag in LiteCore should match MmapEnabled (but flipped)");
106+
hasFlag.ShouldBe(!useMmap, "because the flag in LiteCore should match MmapEnabled (but flipped)");
107107
}
108108
#endif
109109
}

src/Couchbase.Lite.Tests.Shared/NotificationTest.cs

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
using System.Threading;
2121
using System.Threading.Tasks;
2222
using Couchbase.Lite;
23-
using FluentAssertions;
23+
using Shouldly;
2424

2525
using Newtonsoft.Json;
2626
using 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

Comments
 (0)