Skip to content

Commit d305f1f

Browse files
authored
Migrate tests to Shouldly (#90)
1 parent fca7d07 commit d305f1f

File tree

6 files changed

+287
-291
lines changed

6 files changed

+287
-291
lines changed

src/Destructurama.Attributed.Tests/AttributedDestructuringTests.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using NUnit.Framework;
33
using Serilog;
44
using Serilog.Events;
5+
using Shouldly;
56

67
namespace Destructurama.Attributed.Tests;
78

@@ -37,17 +38,17 @@ public void AttributesAreConsultedWhenDestructuring()
3738
var sv = (StructureValue)evt.Properties["Customized"];
3839
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);
3940

40-
Assert.IsInstanceOf<ImmutableScalar>(props["ImmutableScalar"].LiteralValue());
41-
Assert.AreEqual(new MutableScalar().ToString(), props["MutableScalar"].LiteralValue());
42-
Assert.IsInstanceOf<StructureValue>(props["NotAScalar"]);
43-
Assert.IsFalse(props.ContainsKey("Ignored"));
44-
Assert.IsInstanceOf<NotAScalar>(props["ScalarAnyway"].LiteralValue());
45-
Assert.IsInstanceOf<Struct1>(props["Struct1"].LiteralValue());
46-
Assert.IsInstanceOf<Struct2>(props["Struct2"].LiteralValue());
41+
props["ImmutableScalar"].LiteralValue().ShouldBeOfType<ImmutableScalar>();
42+
props["MutableScalar"].LiteralValue().ShouldBe(new MutableScalar().ToString());
43+
props["NotAScalar"].ShouldBeOfType<StructureValue>();
44+
props.ContainsKey("Ignored").ShouldBeFalse();
45+
props["ScalarAnyway"].LiteralValue().ShouldBeOfType<NotAScalar>();
46+
props["Struct1"].LiteralValue().ShouldBeOfType<Struct1>();
47+
props["Struct2"].LiteralValue().ShouldBeOfType<Struct2>();
4748

4849
var str = sv.ToString();
49-
Assert.That(str.Contains("This is a username"));
50-
Assert.False(str.Contains("This is a password"));
50+
str.Contains("This is a username").ShouldBeTrue();
51+
str.Contains("This is a password").ShouldBeFalse();
5152
}
5253

5354
[LogAsScalar]

src/Destructurama.Attributed.Tests/IgnoreNullPropertiesTests.cs

Lines changed: 128 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using NUnit.Framework;
44
using Serilog;
55
using Serilog.Events;
6+
using Shouldly;
67

78
namespace Destructurama.Attributed.Tests;
89

@@ -162,17 +163,17 @@ public void NotLoggedIfNull_Uninitialized()
162163
var sv = (StructureValue)evt!.Properties["Customized"];
163164
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);
164165

165-
Assert.IsTrue(props.ContainsKey("Integer"));
166-
Assert.IsTrue(props.ContainsKey("DateTime"));
167-
Assert.IsTrue(props.ContainsKey("Struct"));
168-
Assert.IsTrue(props.ContainsKey("StructPartiallyInitialized"));
169-
170-
Assert.IsFalse(props.ContainsKey("String"));
171-
Assert.IsFalse(props.ContainsKey("NullableInteger"));
172-
Assert.IsFalse(props.ContainsKey("IntegerAsObject"));
173-
Assert.IsFalse(props.ContainsKey("Object"));
174-
Assert.IsFalse(props.ContainsKey("NullableDateTime"));
175-
Assert.IsFalse(props.ContainsKey("NullableStruct"));
166+
props.ContainsKey("Integer").ShouldBeTrue();
167+
props.ContainsKey("DateTime").ShouldBeTrue();
168+
props.ContainsKey("Struct").ShouldBeTrue();
169+
props.ContainsKey("StructPartiallyInitialized").ShouldBeTrue();
170+
171+
props.ContainsKey("String").ShouldBeFalse();
172+
props.ContainsKey("NullableInteger").ShouldBeFalse();
173+
props.ContainsKey("IntegerAsObject").ShouldBeFalse();
174+
props.ContainsKey("Object").ShouldBeFalse();
175+
props.ContainsKey("NullableDateTime").ShouldBeFalse();
176+
props.ContainsKey("NullableStruct").ShouldBeFalse();
176177
}
177178

178179
[Test]
@@ -223,54 +224,52 @@ public void NotLoggedIfNull_Initialized()
223224
var sv = (StructureValue)evt!.Properties["Customized"];
224225
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);
225226

226-
Assert.IsTrue(props.ContainsKey("String"));
227-
Assert.IsTrue(props.ContainsKey("Integer"));
228-
Assert.IsTrue(props.ContainsKey("NullableInteger"));
229-
Assert.IsTrue(props.ContainsKey("Object"));
230-
Assert.IsTrue(props.ContainsKey("IntegerAsObject"));
231-
Assert.IsTrue(props.ContainsKey("DateTime"));
232-
Assert.IsTrue(props.ContainsKey("NullableDateTime"));
233-
Assert.IsTrue(props.ContainsKey("Struct"));
234-
Assert.IsTrue(props.ContainsKey("NullableStruct"));
235-
Assert.IsTrue(props.ContainsKey("StructPartiallyInitialized"));
236-
237-
Assert.AreEqual("Foo", props["String"].LiteralValue());
238-
Assert.AreEqual(10, props["Integer"].LiteralValue());
239-
Assert.AreEqual(5, props["NullableInteger"].LiteralValue());
240-
Assert.AreEqual("Bar", props["Object"].LiteralValue());
241-
Assert.AreEqual(0, props["IntegerAsObject"].LiteralValue());
242-
Assert.AreEqual(dateTime, props["DateTime"].LiteralValue());
243-
Assert.AreEqual(dateTime, props["NullableDateTime"].LiteralValue());
244-
Assert.IsInstanceOf<StructureValue>(props["Struct"]);
245-
Assert.IsInstanceOf<StructureValue>(props["NullableStruct"]);
246-
Assert.IsInstanceOf<StructureValue>(props["StructPartiallyInitialized"]);
247-
248-
var structProps = ((StructureValue)props["Struct"]).Properties
249-
.ToDictionary(p => p.Name, p => p.Value);
250-
251-
Assert.IsTrue(structProps.ContainsKey("Integer"));
252-
Assert.IsTrue(structProps.ContainsKey("NullableInteger"));
253-
Assert.IsTrue(structProps.ContainsKey("DateTime"));
254-
Assert.IsTrue(structProps.ContainsKey("NullableDateTime"));
255-
Assert.IsTrue(structProps.ContainsKey("Object"));
256-
Assert.AreEqual(20, structProps["Integer"].LiteralValue());
257-
Assert.AreEqual(15, structProps["NullableInteger"].LiteralValue());
258-
Assert.AreEqual(dateTime, structProps["DateTime"].LiteralValue());
259-
Assert.AreEqual(dateTime, structProps["NullableDateTime"].LiteralValue());
260-
Assert.AreEqual("Bar", structProps["Object"].LiteralValue());
261-
262-
var partiallyItitializedProps = ((StructureValue)props["StructPartiallyInitialized"]).Properties
263-
.ToDictionary(p => p.Name, p => p.Value);
264-
265-
Assert.IsTrue(partiallyItitializedProps.ContainsKey("Integer"));
266-
Assert.IsTrue(partiallyItitializedProps.ContainsKey("NullableInteger"));
267-
Assert.IsTrue(partiallyItitializedProps.ContainsKey("DateTime"));
268-
Assert.IsTrue(partiallyItitializedProps.ContainsKey("NullableDateTime"));
269-
Assert.IsFalse(partiallyItitializedProps.ContainsKey("Object"));
270-
Assert.AreEqual(20, partiallyItitializedProps["Integer"].LiteralValue());
271-
Assert.AreEqual(15, partiallyItitializedProps["NullableInteger"].LiteralValue());
272-
Assert.AreEqual(dateTime, partiallyItitializedProps["DateTime"].LiteralValue());
273-
Assert.AreEqual(dateTime, partiallyItitializedProps["NullableDateTime"].LiteralValue());
227+
props.ContainsKey("String").ShouldBeTrue();
228+
props.ContainsKey("Integer").ShouldBeTrue();
229+
props.ContainsKey("NullableInteger").ShouldBeTrue();
230+
props.ContainsKey("Object").ShouldBeTrue();
231+
props.ContainsKey("IntegerAsObject").ShouldBeTrue();
232+
props.ContainsKey("DateTime").ShouldBeTrue();
233+
props.ContainsKey("NullableDateTime").ShouldBeTrue();
234+
props.ContainsKey("Struct").ShouldBeTrue();
235+
props.ContainsKey("NullableStruct").ShouldBeTrue();
236+
props.ContainsKey("StructPartiallyInitialized").ShouldBeTrue();
237+
238+
props["String"].LiteralValue().ShouldBe("Foo");
239+
props["Integer"].LiteralValue().ShouldBe(10);
240+
props["NullableInteger"].LiteralValue().ShouldBe(5);
241+
props["Object"].LiteralValue().ShouldBe("Bar");
242+
props["IntegerAsObject"].LiteralValue().ShouldBe(0);
243+
props["DateTime"].LiteralValue().ShouldBe(dateTime);
244+
props["NullableDateTime"].LiteralValue().ShouldBe(dateTime);
245+
props["Struct"].ShouldBeOfType<StructureValue>();
246+
props["NullableStruct"].ShouldBeOfType<StructureValue>();
247+
props["StructPartiallyInitialized"].ShouldBeOfType<StructureValue>();
248+
249+
var structProps = ((StructureValue)props["Struct"]).Properties.ToDictionary(p => p.Name, p => p.Value);
250+
251+
structProps.ContainsKey("Integer").ShouldBeTrue();
252+
structProps.ContainsKey("NullableInteger").ShouldBeTrue();
253+
structProps.ContainsKey("DateTime").ShouldBeTrue();
254+
structProps.ContainsKey("NullableDateTime").ShouldBeTrue();
255+
structProps.ContainsKey("Object").ShouldBeTrue();
256+
structProps["Integer"].LiteralValue().ShouldBe(20);
257+
structProps["NullableInteger"].LiteralValue().ShouldBe(15);
258+
structProps["DateTime"].LiteralValue().ShouldBe(dateTime);
259+
structProps["NullableDateTime"].LiteralValue().ShouldBe(dateTime);
260+
structProps["Object"].LiteralValue().ShouldBe("Bar");
261+
262+
var partiallyItitializedProps = ((StructureValue)props["StructPartiallyInitialized"]).Properties.ToDictionary(p => p.Name, p => p.Value);
263+
264+
partiallyItitializedProps.ContainsKey("Integer").ShouldBeTrue();
265+
partiallyItitializedProps.ContainsKey("NullableInteger").ShouldBeTrue();
266+
partiallyItitializedProps.ContainsKey("DateTime").ShouldBeTrue();
267+
partiallyItitializedProps.ContainsKey("NullableDateTime").ShouldBeTrue();
268+
partiallyItitializedProps.ContainsKey("Object").ShouldBeFalse();
269+
partiallyItitializedProps["Integer"].LiteralValue().ShouldBe(20);
270+
partiallyItitializedProps["NullableInteger"].LiteralValue().ShouldBe(15);
271+
partiallyItitializedProps["DateTime"].LiteralValue().ShouldBe(dateTime);
272+
partiallyItitializedProps["NullableDateTime"].LiteralValue().ShouldBe(dateTime);
274273
}
275274

276275
[Test]
@@ -290,8 +289,8 @@ public void WithMask_NotLoggedIfNull_Uninitialized()
290289
var sv = (StructureValue)evt!.Properties["Customized"];
291290
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);
292291

293-
Assert.IsFalse(props.ContainsKey("String"));
294-
Assert.IsFalse(props.ContainsKey("Object"));
292+
props.ContainsKey("String").ShouldBeFalse();
293+
props.ContainsKey("Object").ShouldBeFalse();
295294
}
296295

297296
[Test]
@@ -316,11 +315,11 @@ public void WithMask_NotLoggedIfNull_Initialized()
316315
var sv = (StructureValue)evt!.Properties["Customized"];
317316
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);
318317

319-
Assert.IsTrue(props.ContainsKey("String"));
320-
Assert.IsTrue(props.ContainsKey("Object"));
318+
props.ContainsKey("String").ShouldBeTrue();
319+
props.ContainsKey("Object").ShouldBeTrue();
321320

322-
Assert.AreEqual("Foo***", props["String"].LiteralValue());
323-
Assert.AreEqual("Bar***", props["Object"].LiteralValue());
321+
props["String"].LiteralValue().ShouldBe("Foo***");
322+
props["Object"].LiteralValue().ShouldBe("Bar***");
324323
}
325324

326325
[Test]
@@ -345,7 +344,7 @@ public void EnumerableIgnored()
345344
log.Information("Here is {@Customized}", customized);
346345

347346
var sv = evt!.Properties["Customized"];
348-
Assert.IsInstanceOf<SequenceValue>(sv);
347+
sv.ShouldBeOfType<SequenceValue>();
349348
}
350349

351350
[Test]
@@ -373,15 +372,14 @@ public void EnumerableDestructedAsStruct()
373372
var sv = (StructureValue)evt!.Properties["Customized"];
374373
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);
375374

376-
Assert.IsTrue(props.ContainsKey("Integer"));
377-
Assert.IsFalse(props.ContainsKey("NullableInteger"));
378-
Assert.IsTrue(props.ContainsKey("Dependency"));
375+
props.ContainsKey("Integer").ShouldBeTrue();
376+
props.ContainsKey("NullableInteger").ShouldBeFalse();
377+
props.ContainsKey("Dependency").ShouldBeTrue();
379378

380-
var dependencyProps = ((StructureValue)props["Dependency"]).Properties
381-
.ToDictionary(p => p.Name, p => p.Value);
379+
var dependencyProps = ((StructureValue)props["Dependency"]).Properties.ToDictionary(p => p.Name, p => p.Value);
382380

383-
Assert.IsTrue(dependencyProps.ContainsKey("Integer"));
384-
Assert.IsFalse(dependencyProps.ContainsKey("NullableInteger"));
381+
dependencyProps.ContainsKey("Integer").ShouldBeTrue();
382+
dependencyProps.ContainsKey("NullableInteger").ShouldBeFalse();
385383
}
386384

387385
[Test]
@@ -401,17 +399,17 @@ public void NotLoggedIfNullAttribute_Uninitialized()
401399
var sv = (StructureValue)evt!.Properties["Customized"];
402400
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);
403401

404-
Assert.IsTrue(props.ContainsKey("Integer"));
405-
Assert.IsTrue(props.ContainsKey("DateTime"));
406-
Assert.IsTrue(props.ContainsKey("Struct"));
407-
Assert.IsTrue(props.ContainsKey("StructPartiallyInitialized"));
408-
409-
Assert.IsFalse(props.ContainsKey("String"));
410-
Assert.IsFalse(props.ContainsKey("NullableInteger"));
411-
Assert.IsFalse(props.ContainsKey("IntegerAsObject"));
412-
Assert.IsFalse(props.ContainsKey("Object"));
413-
Assert.IsFalse(props.ContainsKey("NullableDateTime"));
414-
Assert.IsFalse(props.ContainsKey("NullableStruct"));
402+
props.ContainsKey("Integer").ShouldBeTrue();
403+
props.ContainsKey("DateTime").ShouldBeTrue();
404+
props.ContainsKey("Struct").ShouldBeTrue();
405+
props.ContainsKey("StructPartiallyInitialized").ShouldBeTrue();
406+
407+
props.ContainsKey("String").ShouldBeFalse();
408+
props.ContainsKey("NullableInteger").ShouldBeFalse();
409+
props.ContainsKey("IntegerAsObject").ShouldBeFalse();
410+
props.ContainsKey("Object").ShouldBeFalse();
411+
props.ContainsKey("NullableDateTime").ShouldBeFalse();
412+
props.ContainsKey("NullableStruct").ShouldBeFalse();
415413
}
416414

417415
[Test]
@@ -462,57 +460,53 @@ public void NotLoggedIfNullAttribute_Initialized()
462460
var sv = (StructureValue)evt!.Properties["Customized"];
463461
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);
464462

465-
Assert.IsTrue(props.ContainsKey("String"));
466-
Assert.IsTrue(props.ContainsKey("Integer"));
467-
Assert.IsTrue(props.ContainsKey("NullableInteger"));
468-
Assert.IsTrue(props.ContainsKey("Object"));
469-
Assert.IsTrue(props.ContainsKey("IntegerAsObject"));
470-
Assert.IsTrue(props.ContainsKey("DateTime"));
471-
Assert.IsTrue(props.ContainsKey("NullableDateTime"));
472-
Assert.IsTrue(props.ContainsKey("Struct"));
473-
Assert.IsTrue(props.ContainsKey("NullableStruct"));
474-
Assert.IsTrue(props.ContainsKey("StructPartiallyInitialized"));
475-
476-
Assert.AreEqual("Foo", props["String"].LiteralValue());
477-
Assert.AreEqual(10, props["Integer"].LiteralValue());
478-
Assert.AreEqual(5, props["NullableInteger"].LiteralValue());
479-
Assert.AreEqual("Bar", props["Object"].LiteralValue());
480-
Assert.AreEqual(0, props["IntegerAsObject"].LiteralValue());
481-
Assert.AreEqual(dateTime, props["DateTime"].LiteralValue());
482-
Assert.AreEqual(dateTime, props["NullableDateTime"].LiteralValue());
483-
Assert.IsInstanceOf<StructureValue>(props["Struct"]);
484-
Assert.IsInstanceOf<StructureValue>(props["NullableStruct"]);
485-
Assert.IsInstanceOf<StructureValue>(props["StructPartiallyInitialized"]);
486-
487-
var structProps = ((StructureValue)props["Struct"]).Properties
488-
.ToDictionary(p => p.Name, p => p.Value);
489-
490-
Assert.IsTrue(structProps.ContainsKey("Integer"));
491-
Assert.IsTrue(structProps.ContainsKey("NullableInteger"));
492-
Assert.IsTrue(structProps.ContainsKey("DateTime"));
493-
Assert.IsTrue(structProps.ContainsKey("NullableDateTime"));
494-
Assert.IsTrue(structProps.ContainsKey("Object"));
495-
Assert.AreEqual(20, structProps["Integer"].LiteralValue());
496-
Assert.AreEqual(15, structProps["NullableInteger"].LiteralValue());
497-
Assert.AreEqual(dateTime, structProps["DateTime"].LiteralValue());
498-
Assert.AreEqual(dateTime, structProps["NullableDateTime"].LiteralValue());
499-
Assert.AreEqual("Bar", structProps["Object"].LiteralValue());
500-
501-
var partiallyItitializedProps = ((StructureValue)props["StructPartiallyInitialized"]).Properties
502-
.ToDictionary(p => p.Name, p => p.Value);
503-
504-
Assert.IsTrue(partiallyItitializedProps.ContainsKey("Integer"));
505-
Assert.IsTrue(partiallyItitializedProps.ContainsKey("NullableInteger"));
506-
Assert.IsTrue(partiallyItitializedProps.ContainsKey("DateTime"));
507-
Assert.IsTrue(partiallyItitializedProps.ContainsKey("NullableDateTime"));
508-
Assert.IsTrue(partiallyItitializedProps.ContainsKey("Object"));
509-
Assert.AreEqual(20, partiallyItitializedProps["Integer"].LiteralValue());
510-
Assert.AreEqual(15, partiallyItitializedProps["NullableInteger"].LiteralValue());
511-
Assert.AreEqual(dateTime, partiallyItitializedProps["DateTime"].LiteralValue());
512-
Assert.AreEqual(dateTime, partiallyItitializedProps["NullableDateTime"].LiteralValue());
513-
463+
props.ContainsKey("String").ShouldBeTrue();
464+
props.ContainsKey("Integer").ShouldBeTrue();
465+
props.ContainsKey("NullableInteger").ShouldBeTrue();
466+
props.ContainsKey("Object").ShouldBeTrue();
467+
props.ContainsKey("IntegerAsObject").ShouldBeTrue();
468+
props.ContainsKey("DateTime").ShouldBeTrue();
469+
props.ContainsKey("NullableDateTime").ShouldBeTrue();
470+
props.ContainsKey("Struct").ShouldBeTrue();
471+
props.ContainsKey("NullableStruct").ShouldBeTrue();
472+
props.ContainsKey("StructPartiallyInitialized").ShouldBeTrue();
473+
474+
props["String"].LiteralValue().ShouldBe("Foo");
475+
props["Integer"].LiteralValue().ShouldBe(10);
476+
props["NullableInteger"].LiteralValue().ShouldBe(5);
477+
props["Object"].LiteralValue().ShouldBe("Bar");
478+
props["IntegerAsObject"].LiteralValue().ShouldBe(0);
479+
props["DateTime"].LiteralValue().ShouldBe(dateTime);
480+
props["NullableDateTime"].LiteralValue().ShouldBe(dateTime);
481+
props["Struct"].ShouldBeOfType<StructureValue>();
482+
props["NullableStruct"].ShouldBeOfType<StructureValue>();
483+
props["StructPartiallyInitialized"].ShouldBeOfType<StructureValue>();
484+
485+
var structProps = ((StructureValue)props["Struct"]).Properties.ToDictionary(p => p.Name, p => p.Value);
486+
487+
structProps.ContainsKey("Integer").ShouldBeTrue();
488+
structProps.ContainsKey("NullableInteger").ShouldBeTrue();
489+
structProps.ContainsKey("DateTime").ShouldBeTrue();
490+
structProps.ContainsKey("NullableDateTime").ShouldBeTrue();
491+
structProps.ContainsKey("Object").ShouldBeTrue();
492+
structProps["Integer"].LiteralValue().ShouldBe(20);
493+
structProps["NullableInteger"].LiteralValue().ShouldBe(15);
494+
structProps["DateTime"].LiteralValue().ShouldBe(dateTime);
495+
structProps["NullableDateTime"].LiteralValue().ShouldBe(dateTime);
496+
structProps["Object"].LiteralValue().ShouldBe("Bar");
497+
498+
var partiallyItitializedProps = ((StructureValue)props["StructPartiallyInitialized"]).Properties.ToDictionary(p => p.Name, p => p.Value);
499+
500+
partiallyItitializedProps.ContainsKey("Integer").ShouldBeTrue();
501+
partiallyItitializedProps.ContainsKey("NullableInteger").ShouldBeTrue();
502+
partiallyItitializedProps.ContainsKey("DateTime").ShouldBeTrue();
503+
partiallyItitializedProps.ContainsKey("NullableDateTime").ShouldBeTrue();
504+
partiallyItitializedProps.ContainsKey("Object").ShouldBeTrue();
505+
partiallyItitializedProps["Integer"].LiteralValue().ShouldBe(20);
506+
partiallyItitializedProps["NullableInteger"].LiteralValue().ShouldBe(15);
507+
partiallyItitializedProps["DateTime"].LiteralValue().ShouldBe(dateTime);
508+
partiallyItitializedProps["NullableDateTime"].LiteralValue().ShouldBe(dateTime);
514509
}
515-
516510
}
517511

518512

src/Destructurama.Attributed.Tests/LogWithNameAttributedTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
using NUnit.Framework;
33
using Serilog;
44
using Serilog.Events;
5+
using Shouldly;
56

67
namespace Destructurama.Attributed.Tests;
78

89
[TestFixture]
910
public class LogWithNameAttributedTests
1011
{
11-
1212
[Test]
1313
public void AttributesAreConsultedWhenDestructuring()
1414
{
@@ -30,7 +30,7 @@ public void AttributesAreConsultedWhenDestructuring()
3030
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);
3131

3232
var literalValue = props["FullName"].LiteralValue();
33-
Assert.AreEqual("John Doe", literalValue);
33+
literalValue.ShouldBe("John Doe");
3434
}
3535

3636
#region LogWithName

0 commit comments

Comments
 (0)