diff --git a/src/Destructurama.Attributed.Tests/AttributedDestructuringTests.cs b/src/Destructurama.Attributed.Tests/AttributedDestructuringTests.cs index 12e49a4..9c89554 100644 --- a/src/Destructurama.Attributed.Tests/AttributedDestructuringTests.cs +++ b/src/Destructurama.Attributed.Tests/AttributedDestructuringTests.cs @@ -2,6 +2,7 @@ using NUnit.Framework; using Serilog; using Serilog.Events; +using Shouldly; namespace Destructurama.Attributed.Tests; @@ -37,17 +38,17 @@ public void AttributesAreConsultedWhenDestructuring() var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsInstanceOf(props["ImmutableScalar"].LiteralValue()); - Assert.AreEqual(new MutableScalar().ToString(), props["MutableScalar"].LiteralValue()); - Assert.IsInstanceOf(props["NotAScalar"]); - Assert.IsFalse(props.ContainsKey("Ignored")); - Assert.IsInstanceOf(props["ScalarAnyway"].LiteralValue()); - Assert.IsInstanceOf(props["Struct1"].LiteralValue()); - Assert.IsInstanceOf(props["Struct2"].LiteralValue()); + props["ImmutableScalar"].LiteralValue().ShouldBeOfType(); + props["MutableScalar"].LiteralValue().ShouldBe(new MutableScalar().ToString()); + props["NotAScalar"].ShouldBeOfType(); + props.ContainsKey("Ignored").ShouldBeFalse(); + props["ScalarAnyway"].LiteralValue().ShouldBeOfType(); + props["Struct1"].LiteralValue().ShouldBeOfType(); + props["Struct2"].LiteralValue().ShouldBeOfType(); var str = sv.ToString(); - Assert.That(str.Contains("This is a username")); - Assert.False(str.Contains("This is a password")); + str.Contains("This is a username").ShouldBeTrue(); + str.Contains("This is a password").ShouldBeFalse(); } [LogAsScalar] diff --git a/src/Destructurama.Attributed.Tests/IgnoreNullPropertiesTests.cs b/src/Destructurama.Attributed.Tests/IgnoreNullPropertiesTests.cs index 36c31d9..fc9f2d0 100644 --- a/src/Destructurama.Attributed.Tests/IgnoreNullPropertiesTests.cs +++ b/src/Destructurama.Attributed.Tests/IgnoreNullPropertiesTests.cs @@ -3,6 +3,7 @@ using NUnit.Framework; using Serilog; using Serilog.Events; +using Shouldly; namespace Destructurama.Attributed.Tests; @@ -162,17 +163,17 @@ public void NotLoggedIfNull_Uninitialized() var sv = (StructureValue)evt!.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("Integer")); - Assert.IsTrue(props.ContainsKey("DateTime")); - Assert.IsTrue(props.ContainsKey("Struct")); - Assert.IsTrue(props.ContainsKey("StructPartiallyInitialized")); - - Assert.IsFalse(props.ContainsKey("String")); - Assert.IsFalse(props.ContainsKey("NullableInteger")); - Assert.IsFalse(props.ContainsKey("IntegerAsObject")); - Assert.IsFalse(props.ContainsKey("Object")); - Assert.IsFalse(props.ContainsKey("NullableDateTime")); - Assert.IsFalse(props.ContainsKey("NullableStruct")); + props.ContainsKey("Integer").ShouldBeTrue(); + props.ContainsKey("DateTime").ShouldBeTrue(); + props.ContainsKey("Struct").ShouldBeTrue(); + props.ContainsKey("StructPartiallyInitialized").ShouldBeTrue(); + + props.ContainsKey("String").ShouldBeFalse(); + props.ContainsKey("NullableInteger").ShouldBeFalse(); + props.ContainsKey("IntegerAsObject").ShouldBeFalse(); + props.ContainsKey("Object").ShouldBeFalse(); + props.ContainsKey("NullableDateTime").ShouldBeFalse(); + props.ContainsKey("NullableStruct").ShouldBeFalse(); } [Test] @@ -223,54 +224,52 @@ public void NotLoggedIfNull_Initialized() var sv = (StructureValue)evt!.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("String")); - Assert.IsTrue(props.ContainsKey("Integer")); - Assert.IsTrue(props.ContainsKey("NullableInteger")); - Assert.IsTrue(props.ContainsKey("Object")); - Assert.IsTrue(props.ContainsKey("IntegerAsObject")); - Assert.IsTrue(props.ContainsKey("DateTime")); - Assert.IsTrue(props.ContainsKey("NullableDateTime")); - Assert.IsTrue(props.ContainsKey("Struct")); - Assert.IsTrue(props.ContainsKey("NullableStruct")); - Assert.IsTrue(props.ContainsKey("StructPartiallyInitialized")); - - Assert.AreEqual("Foo", props["String"].LiteralValue()); - Assert.AreEqual(10, props["Integer"].LiteralValue()); - Assert.AreEqual(5, props["NullableInteger"].LiteralValue()); - Assert.AreEqual("Bar", props["Object"].LiteralValue()); - Assert.AreEqual(0, props["IntegerAsObject"].LiteralValue()); - Assert.AreEqual(dateTime, props["DateTime"].LiteralValue()); - Assert.AreEqual(dateTime, props["NullableDateTime"].LiteralValue()); - Assert.IsInstanceOf(props["Struct"]); - Assert.IsInstanceOf(props["NullableStruct"]); - Assert.IsInstanceOf(props["StructPartiallyInitialized"]); - - var structProps = ((StructureValue)props["Struct"]).Properties - .ToDictionary(p => p.Name, p => p.Value); - - Assert.IsTrue(structProps.ContainsKey("Integer")); - Assert.IsTrue(structProps.ContainsKey("NullableInteger")); - Assert.IsTrue(structProps.ContainsKey("DateTime")); - Assert.IsTrue(structProps.ContainsKey("NullableDateTime")); - Assert.IsTrue(structProps.ContainsKey("Object")); - Assert.AreEqual(20, structProps["Integer"].LiteralValue()); - Assert.AreEqual(15, structProps["NullableInteger"].LiteralValue()); - Assert.AreEqual(dateTime, structProps["DateTime"].LiteralValue()); - Assert.AreEqual(dateTime, structProps["NullableDateTime"].LiteralValue()); - Assert.AreEqual("Bar", structProps["Object"].LiteralValue()); - - var partiallyItitializedProps = ((StructureValue)props["StructPartiallyInitialized"]).Properties - .ToDictionary(p => p.Name, p => p.Value); - - Assert.IsTrue(partiallyItitializedProps.ContainsKey("Integer")); - Assert.IsTrue(partiallyItitializedProps.ContainsKey("NullableInteger")); - Assert.IsTrue(partiallyItitializedProps.ContainsKey("DateTime")); - Assert.IsTrue(partiallyItitializedProps.ContainsKey("NullableDateTime")); - Assert.IsFalse(partiallyItitializedProps.ContainsKey("Object")); - Assert.AreEqual(20, partiallyItitializedProps["Integer"].LiteralValue()); - Assert.AreEqual(15, partiallyItitializedProps["NullableInteger"].LiteralValue()); - Assert.AreEqual(dateTime, partiallyItitializedProps["DateTime"].LiteralValue()); - Assert.AreEqual(dateTime, partiallyItitializedProps["NullableDateTime"].LiteralValue()); + props.ContainsKey("String").ShouldBeTrue(); + props.ContainsKey("Integer").ShouldBeTrue(); + props.ContainsKey("NullableInteger").ShouldBeTrue(); + props.ContainsKey("Object").ShouldBeTrue(); + props.ContainsKey("IntegerAsObject").ShouldBeTrue(); + props.ContainsKey("DateTime").ShouldBeTrue(); + props.ContainsKey("NullableDateTime").ShouldBeTrue(); + props.ContainsKey("Struct").ShouldBeTrue(); + props.ContainsKey("NullableStruct").ShouldBeTrue(); + props.ContainsKey("StructPartiallyInitialized").ShouldBeTrue(); + + props["String"].LiteralValue().ShouldBe("Foo"); + props["Integer"].LiteralValue().ShouldBe(10); + props["NullableInteger"].LiteralValue().ShouldBe(5); + props["Object"].LiteralValue().ShouldBe("Bar"); + props["IntegerAsObject"].LiteralValue().ShouldBe(0); + props["DateTime"].LiteralValue().ShouldBe(dateTime); + props["NullableDateTime"].LiteralValue().ShouldBe(dateTime); + props["Struct"].ShouldBeOfType(); + props["NullableStruct"].ShouldBeOfType(); + props["StructPartiallyInitialized"].ShouldBeOfType(); + + var structProps = ((StructureValue)props["Struct"]).Properties.ToDictionary(p => p.Name, p => p.Value); + + structProps.ContainsKey("Integer").ShouldBeTrue(); + structProps.ContainsKey("NullableInteger").ShouldBeTrue(); + structProps.ContainsKey("DateTime").ShouldBeTrue(); + structProps.ContainsKey("NullableDateTime").ShouldBeTrue(); + structProps.ContainsKey("Object").ShouldBeTrue(); + structProps["Integer"].LiteralValue().ShouldBe(20); + structProps["NullableInteger"].LiteralValue().ShouldBe(15); + structProps["DateTime"].LiteralValue().ShouldBe(dateTime); + structProps["NullableDateTime"].LiteralValue().ShouldBe(dateTime); + structProps["Object"].LiteralValue().ShouldBe("Bar"); + + var partiallyItitializedProps = ((StructureValue)props["StructPartiallyInitialized"]).Properties.ToDictionary(p => p.Name, p => p.Value); + + partiallyItitializedProps.ContainsKey("Integer").ShouldBeTrue(); + partiallyItitializedProps.ContainsKey("NullableInteger").ShouldBeTrue(); + partiallyItitializedProps.ContainsKey("DateTime").ShouldBeTrue(); + partiallyItitializedProps.ContainsKey("NullableDateTime").ShouldBeTrue(); + partiallyItitializedProps.ContainsKey("Object").ShouldBeFalse(); + partiallyItitializedProps["Integer"].LiteralValue().ShouldBe(20); + partiallyItitializedProps["NullableInteger"].LiteralValue().ShouldBe(15); + partiallyItitializedProps["DateTime"].LiteralValue().ShouldBe(dateTime); + partiallyItitializedProps["NullableDateTime"].LiteralValue().ShouldBe(dateTime); } [Test] @@ -290,8 +289,8 @@ public void WithMask_NotLoggedIfNull_Uninitialized() var sv = (StructureValue)evt!.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsFalse(props.ContainsKey("String")); - Assert.IsFalse(props.ContainsKey("Object")); + props.ContainsKey("String").ShouldBeFalse(); + props.ContainsKey("Object").ShouldBeFalse(); } [Test] @@ -316,11 +315,11 @@ public void WithMask_NotLoggedIfNull_Initialized() var sv = (StructureValue)evt!.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("String")); - Assert.IsTrue(props.ContainsKey("Object")); + props.ContainsKey("String").ShouldBeTrue(); + props.ContainsKey("Object").ShouldBeTrue(); - Assert.AreEqual("Foo***", props["String"].LiteralValue()); - Assert.AreEqual("Bar***", props["Object"].LiteralValue()); + props["String"].LiteralValue().ShouldBe("Foo***"); + props["Object"].LiteralValue().ShouldBe("Bar***"); } [Test] @@ -345,7 +344,7 @@ public void EnumerableIgnored() log.Information("Here is {@Customized}", customized); var sv = evt!.Properties["Customized"]; - Assert.IsInstanceOf(sv); + sv.ShouldBeOfType(); } [Test] @@ -373,15 +372,14 @@ public void EnumerableDestructedAsStruct() var sv = (StructureValue)evt!.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("Integer")); - Assert.IsFalse(props.ContainsKey("NullableInteger")); - Assert.IsTrue(props.ContainsKey("Dependency")); + props.ContainsKey("Integer").ShouldBeTrue(); + props.ContainsKey("NullableInteger").ShouldBeFalse(); + props.ContainsKey("Dependency").ShouldBeTrue(); - var dependencyProps = ((StructureValue)props["Dependency"]).Properties - .ToDictionary(p => p.Name, p => p.Value); + var dependencyProps = ((StructureValue)props["Dependency"]).Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(dependencyProps.ContainsKey("Integer")); - Assert.IsFalse(dependencyProps.ContainsKey("NullableInteger")); + dependencyProps.ContainsKey("Integer").ShouldBeTrue(); + dependencyProps.ContainsKey("NullableInteger").ShouldBeFalse(); } [Test] @@ -401,17 +399,17 @@ public void NotLoggedIfNullAttribute_Uninitialized() var sv = (StructureValue)evt!.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("Integer")); - Assert.IsTrue(props.ContainsKey("DateTime")); - Assert.IsTrue(props.ContainsKey("Struct")); - Assert.IsTrue(props.ContainsKey("StructPartiallyInitialized")); - - Assert.IsFalse(props.ContainsKey("String")); - Assert.IsFalse(props.ContainsKey("NullableInteger")); - Assert.IsFalse(props.ContainsKey("IntegerAsObject")); - Assert.IsFalse(props.ContainsKey("Object")); - Assert.IsFalse(props.ContainsKey("NullableDateTime")); - Assert.IsFalse(props.ContainsKey("NullableStruct")); + props.ContainsKey("Integer").ShouldBeTrue(); + props.ContainsKey("DateTime").ShouldBeTrue(); + props.ContainsKey("Struct").ShouldBeTrue(); + props.ContainsKey("StructPartiallyInitialized").ShouldBeTrue(); + + props.ContainsKey("String").ShouldBeFalse(); + props.ContainsKey("NullableInteger").ShouldBeFalse(); + props.ContainsKey("IntegerAsObject").ShouldBeFalse(); + props.ContainsKey("Object").ShouldBeFalse(); + props.ContainsKey("NullableDateTime").ShouldBeFalse(); + props.ContainsKey("NullableStruct").ShouldBeFalse(); } [Test] @@ -462,57 +460,53 @@ public void NotLoggedIfNullAttribute_Initialized() var sv = (StructureValue)evt!.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("String")); - Assert.IsTrue(props.ContainsKey("Integer")); - Assert.IsTrue(props.ContainsKey("NullableInteger")); - Assert.IsTrue(props.ContainsKey("Object")); - Assert.IsTrue(props.ContainsKey("IntegerAsObject")); - Assert.IsTrue(props.ContainsKey("DateTime")); - Assert.IsTrue(props.ContainsKey("NullableDateTime")); - Assert.IsTrue(props.ContainsKey("Struct")); - Assert.IsTrue(props.ContainsKey("NullableStruct")); - Assert.IsTrue(props.ContainsKey("StructPartiallyInitialized")); - - Assert.AreEqual("Foo", props["String"].LiteralValue()); - Assert.AreEqual(10, props["Integer"].LiteralValue()); - Assert.AreEqual(5, props["NullableInteger"].LiteralValue()); - Assert.AreEqual("Bar", props["Object"].LiteralValue()); - Assert.AreEqual(0, props["IntegerAsObject"].LiteralValue()); - Assert.AreEqual(dateTime, props["DateTime"].LiteralValue()); - Assert.AreEqual(dateTime, props["NullableDateTime"].LiteralValue()); - Assert.IsInstanceOf(props["Struct"]); - Assert.IsInstanceOf(props["NullableStruct"]); - Assert.IsInstanceOf(props["StructPartiallyInitialized"]); - - var structProps = ((StructureValue)props["Struct"]).Properties - .ToDictionary(p => p.Name, p => p.Value); - - Assert.IsTrue(structProps.ContainsKey("Integer")); - Assert.IsTrue(structProps.ContainsKey("NullableInteger")); - Assert.IsTrue(structProps.ContainsKey("DateTime")); - Assert.IsTrue(structProps.ContainsKey("NullableDateTime")); - Assert.IsTrue(structProps.ContainsKey("Object")); - Assert.AreEqual(20, structProps["Integer"].LiteralValue()); - Assert.AreEqual(15, structProps["NullableInteger"].LiteralValue()); - Assert.AreEqual(dateTime, structProps["DateTime"].LiteralValue()); - Assert.AreEqual(dateTime, structProps["NullableDateTime"].LiteralValue()); - Assert.AreEqual("Bar", structProps["Object"].LiteralValue()); - - var partiallyItitializedProps = ((StructureValue)props["StructPartiallyInitialized"]).Properties - .ToDictionary(p => p.Name, p => p.Value); - - Assert.IsTrue(partiallyItitializedProps.ContainsKey("Integer")); - Assert.IsTrue(partiallyItitializedProps.ContainsKey("NullableInteger")); - Assert.IsTrue(partiallyItitializedProps.ContainsKey("DateTime")); - Assert.IsTrue(partiallyItitializedProps.ContainsKey("NullableDateTime")); - Assert.IsTrue(partiallyItitializedProps.ContainsKey("Object")); - Assert.AreEqual(20, partiallyItitializedProps["Integer"].LiteralValue()); - Assert.AreEqual(15, partiallyItitializedProps["NullableInteger"].LiteralValue()); - Assert.AreEqual(dateTime, partiallyItitializedProps["DateTime"].LiteralValue()); - Assert.AreEqual(dateTime, partiallyItitializedProps["NullableDateTime"].LiteralValue()); - + props.ContainsKey("String").ShouldBeTrue(); + props.ContainsKey("Integer").ShouldBeTrue(); + props.ContainsKey("NullableInteger").ShouldBeTrue(); + props.ContainsKey("Object").ShouldBeTrue(); + props.ContainsKey("IntegerAsObject").ShouldBeTrue(); + props.ContainsKey("DateTime").ShouldBeTrue(); + props.ContainsKey("NullableDateTime").ShouldBeTrue(); + props.ContainsKey("Struct").ShouldBeTrue(); + props.ContainsKey("NullableStruct").ShouldBeTrue(); + props.ContainsKey("StructPartiallyInitialized").ShouldBeTrue(); + + props["String"].LiteralValue().ShouldBe("Foo"); + props["Integer"].LiteralValue().ShouldBe(10); + props["NullableInteger"].LiteralValue().ShouldBe(5); + props["Object"].LiteralValue().ShouldBe("Bar"); + props["IntegerAsObject"].LiteralValue().ShouldBe(0); + props["DateTime"].LiteralValue().ShouldBe(dateTime); + props["NullableDateTime"].LiteralValue().ShouldBe(dateTime); + props["Struct"].ShouldBeOfType(); + props["NullableStruct"].ShouldBeOfType(); + props["StructPartiallyInitialized"].ShouldBeOfType(); + + var structProps = ((StructureValue)props["Struct"]).Properties.ToDictionary(p => p.Name, p => p.Value); + + structProps.ContainsKey("Integer").ShouldBeTrue(); + structProps.ContainsKey("NullableInteger").ShouldBeTrue(); + structProps.ContainsKey("DateTime").ShouldBeTrue(); + structProps.ContainsKey("NullableDateTime").ShouldBeTrue(); + structProps.ContainsKey("Object").ShouldBeTrue(); + structProps["Integer"].LiteralValue().ShouldBe(20); + structProps["NullableInteger"].LiteralValue().ShouldBe(15); + structProps["DateTime"].LiteralValue().ShouldBe(dateTime); + structProps["NullableDateTime"].LiteralValue().ShouldBe(dateTime); + structProps["Object"].LiteralValue().ShouldBe("Bar"); + + var partiallyItitializedProps = ((StructureValue)props["StructPartiallyInitialized"]).Properties.ToDictionary(p => p.Name, p => p.Value); + + partiallyItitializedProps.ContainsKey("Integer").ShouldBeTrue(); + partiallyItitializedProps.ContainsKey("NullableInteger").ShouldBeTrue(); + partiallyItitializedProps.ContainsKey("DateTime").ShouldBeTrue(); + partiallyItitializedProps.ContainsKey("NullableDateTime").ShouldBeTrue(); + partiallyItitializedProps.ContainsKey("Object").ShouldBeTrue(); + partiallyItitializedProps["Integer"].LiteralValue().ShouldBe(20); + partiallyItitializedProps["NullableInteger"].LiteralValue().ShouldBe(15); + partiallyItitializedProps["DateTime"].LiteralValue().ShouldBe(dateTime); + partiallyItitializedProps["NullableDateTime"].LiteralValue().ShouldBe(dateTime); } - } diff --git a/src/Destructurama.Attributed.Tests/LogWithNameAttributedTests.cs b/src/Destructurama.Attributed.Tests/LogWithNameAttributedTests.cs index b3a0059..b334770 100644 --- a/src/Destructurama.Attributed.Tests/LogWithNameAttributedTests.cs +++ b/src/Destructurama.Attributed.Tests/LogWithNameAttributedTests.cs @@ -2,13 +2,13 @@ using NUnit.Framework; using Serilog; using Serilog.Events; +using Shouldly; namespace Destructurama.Attributed.Tests; [TestFixture] public class LogWithNameAttributedTests { - [Test] public void AttributesAreConsultedWhenDestructuring() { @@ -30,7 +30,7 @@ public void AttributesAreConsultedWhenDestructuring() var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); var literalValue = props["FullName"].LiteralValue(); - Assert.AreEqual("John Doe", literalValue); + literalValue.ShouldBe("John Doe"); } #region LogWithName diff --git a/src/Destructurama.Attributed.Tests/MaskedAttributeTests.cs b/src/Destructurama.Attributed.Tests/MaskedAttributeTests.cs index 6209247..fc3b910 100644 --- a/src/Destructurama.Attributed.Tests/MaskedAttributeTests.cs +++ b/src/Destructurama.Attributed.Tests/MaskedAttributeTests.cs @@ -2,6 +2,7 @@ using NUnit.Framework; using Serilog; using Serilog.Events; +using Shouldly; namespace Destructurama.Attributed.Tests; @@ -152,8 +153,8 @@ public void LogMaskedAttribute_Replaces_Value_With_DefaultStars_Mask() var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("DefaultMasked")); - Assert.AreEqual("***", props["DefaultMasked"].LiteralValue()); + props.ContainsKey("DefaultMasked").ShouldBeTrue(); + props["DefaultMasked"].LiteralValue().ShouldBe("***"); } [Test] @@ -171,7 +172,7 @@ public void LogMaskedAttribute_Replaces_Array_Value_With_DefaultStars_Mask() var customized = new CustomizedMaskedLogs { - DefaultMaskedArray = new[] { "123456789", "123456789", "123456789" } + DefaultMaskedArray = ["123456789", "123456789", "123456789"] }; log.Information("Here is {@Customized}", customized); @@ -179,10 +180,10 @@ public void LogMaskedAttribute_Replaces_Array_Value_With_DefaultStars_Mask() var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("DefaultMaskedArray")); + props.ContainsKey("DefaultMaskedArray").ShouldBeTrue(); var seq = props["DefaultMaskedArray"] as SequenceValue; foreach (var elem in seq!.Elements) - Assert.AreEqual("***", elem.LiteralValue()); + elem.LiteralValue().ShouldBe("***"); } [Test] @@ -208,8 +209,8 @@ public void LogMaskedAttribute_Replaces_Value_With_DefaultStars_Mask_And_Preserv var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("DefaultMaskedPreserved")); - Assert.AreEqual("*********", props["DefaultMaskedPreserved"].LiteralValue()); + props.ContainsKey("DefaultMaskedPreserved").ShouldBeTrue(); + props["DefaultMaskedPreserved"].LiteralValue().ShouldBe("*********"); } [Test] @@ -235,8 +236,8 @@ public void LogMaskedAttribute_Replaces_Value_With_DefaultStars_Mask_And_Not_Pre var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("DefaultMaskedNotPreservedOnEmptyString")); - Assert.AreEqual("***", props["DefaultMaskedNotPreservedOnEmptyString"].LiteralValue()); + props.ContainsKey("DefaultMaskedNotPreservedOnEmptyString").ShouldBeTrue(); + props["DefaultMaskedNotPreservedOnEmptyString"].LiteralValue().ShouldBe("***"); } [Test] @@ -262,8 +263,8 @@ public void LogMaskedAttribute_Replaces_Value_With_Provided_Mask() var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("CustomMasked")); - Assert.AreEqual("_REMOVED_", props["CustomMasked"].LiteralValue()); + props.ContainsKey("CustomMasked").ShouldBeTrue(); + props["CustomMasked"].LiteralValue().ShouldBe("_REMOVED_"); } [Test] @@ -289,8 +290,8 @@ public void LogMaskedAttribute_Replaces_Value_With_Provided_Empty_Mask() var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("CustomMasked")); - Assert.AreEqual("", props["CustomMaskedWithEmptyString"].LiteralValue()); + props.ContainsKey("CustomMasked").ShouldBeTrue(); + props["CustomMaskedWithEmptyString"].LiteralValue().ShouldBe(""); } [Test] @@ -316,8 +317,8 @@ public void LogMaskedAttribute_Replaces_Value_With_Provided_Mask_And_PreservedLe var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("CustomMaskedPreservedLength")); - Assert.AreEqual("#########", props["CustomMaskedPreservedLength"].LiteralValue()); + props.ContainsKey("CustomMaskedPreservedLength").ShouldBeTrue(); + props["CustomMaskedPreservedLength"].LiteralValue().ShouldBe("#########"); } [Test] @@ -343,8 +344,8 @@ public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_With_Custom_ var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstThreeThenCustomMask")); - Assert.AreEqual("123_REMOVED_", props["ShowFirstThreeThenCustomMask"].LiteralValue()); + props.ContainsKey("ShowFirstThreeThenCustomMask").ShouldBeTrue(); + props["ShowFirstThreeThenCustomMask"].LiteralValue().ShouldBe("123_REMOVED_"); } [Test] @@ -370,8 +371,8 @@ public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_With_Custom_ var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstThreeThenCustomMaskPreservedLengthIgnored")); - Assert.AreEqual("123_REMOVED_", props["ShowFirstThreeThenCustomMaskPreservedLengthIgnored"].LiteralValue()); + props.ContainsKey("ShowFirstThreeThenCustomMaskPreservedLengthIgnored").ShouldBeTrue(); + props["ShowFirstThreeThenCustomMaskPreservedLengthIgnored"].LiteralValue().ShouldBe("123_REMOVED_"); } [Test] @@ -397,8 +398,8 @@ public void LogMaskedAttribute_Shows_First_NChars_And_Last_NChars_Replaces_Value var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstAndLastThreeAndDefaultMaskInTheMiddle")); - Assert.AreEqual("123***321", props["ShowFirstAndLastThreeAndDefaultMaskInTheMiddle"].LiteralValue()); + props.ContainsKey("ShowFirstAndLastThreeAndDefaultMaskInTheMiddle").ShouldBeTrue(); + props["ShowFirstAndLastThreeAndDefaultMaskInTheMiddle"].LiteralValue().ShouldBe("123***321"); } [Test] @@ -424,8 +425,8 @@ public void LogMaskedAttribute_Shows_First_NChars_And_Last_NChars_Replaces_Value var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstAndLastThreeAndDefaultMaskInTheMiddlePreservedLength")); - Assert.AreEqual("123***********321", props["ShowFirstAndLastThreeAndDefaultMaskInTheMiddlePreservedLength"].LiteralValue()); + props.ContainsKey("ShowFirstAndLastThreeAndDefaultMaskInTheMiddlePreservedLength").ShouldBeTrue(); + props["ShowFirstAndLastThreeAndDefaultMaskInTheMiddlePreservedLength"].LiteralValue().ShouldBe("123***********321"); } [Test] @@ -451,8 +452,8 @@ public void LogMaskedAttribute_Shows_First_NChars_And_Last_NChars_Replaces_Value var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstAndLastThreeAndDefaultMaskInTheMiddlePreservedLength")); - Assert.AreEqual("123*456", props["ShowFirstAndLastThreeAndDefaultMaskInTheMiddlePreservedLength"].LiteralValue()); + props.ContainsKey("ShowFirstAndLastThreeAndDefaultMaskInTheMiddlePreservedLength").ShouldBeTrue(); + props["ShowFirstAndLastThreeAndDefaultMaskInTheMiddlePreservedLength"].LiteralValue().ShouldBe("123*456"); } [Test] @@ -478,8 +479,8 @@ public void LogMaskedAttribute_Shows_First_NChars_And_Last_NChars_Then_Replaces_ var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstAndLastThreeAndCustomMaskInTheMiddle")); - Assert.AreEqual("123_REMOVED_321", props["ShowFirstAndLastThreeAndCustomMaskInTheMiddle"].LiteralValue()); + props.ContainsKey("ShowFirstAndLastThreeAndCustomMaskInTheMiddle").ShouldBeTrue(); + props["ShowFirstAndLastThreeAndCustomMaskInTheMiddle"].LiteralValue().ShouldBe("123_REMOVED_321"); } [Test] @@ -505,8 +506,8 @@ public void LogMaskedAttribute_Shows_First_NChars_And_Last_NChars_Then_Replaces_ var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstAndLastThreeAndCustomMaskInTheMiddle")); - Assert.AreEqual("123_REMOVED_321", props["ShowFirstAndLastThreeAndCustomMaskInTheMiddle"].LiteralValue()); + props.ContainsKey("ShowFirstAndLastThreeAndCustomMaskInTheMiddle").ShouldBeTrue(); + props["ShowFirstAndLastThreeAndCustomMaskInTheMiddle"].LiteralValue().ShouldBe("123_REMOVED_321"); } [Test] @@ -532,8 +533,8 @@ public void LogMaskedAttribute_Shows_First_NChars_And_Last_NChars_Then_Replaces_ var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstAndLastThreeAndCustomMaskInTheMiddle")); - Assert.AreEqual("12", props["ShowFirstAndLastThreeAndCustomMaskInTheMiddle"].LiteralValue()); + props.ContainsKey("ShowFirstAndLastThreeAndCustomMaskInTheMiddle").ShouldBeTrue(); + props["ShowFirstAndLastThreeAndCustomMaskInTheMiddle"].LiteralValue().ShouldBe("12"); } [Test] @@ -559,8 +560,8 @@ public void LogMaskedAttribute_Shows_First_NChars_And_Last_NChars_Then_Replaces_ var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstAndLastThreeAndCustomMaskInTheMiddle")); - Assert.AreEqual("1234", props["ShowFirstAndLastThreeAndCustomMaskInTheMiddle"].LiteralValue()); + props.ContainsKey("ShowFirstAndLastThreeAndCustomMaskInTheMiddle").ShouldBeTrue(); + props["ShowFirstAndLastThreeAndCustomMaskInTheMiddle"].LiteralValue().ShouldBe("1234"); } [Test] @@ -586,8 +587,8 @@ public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_Other_Chars_ var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstThreeThenDefaultMasked")); - Assert.AreEqual("123***", props["ShowFirstThreeThenDefaultMasked"].LiteralValue()); + props.ContainsKey("ShowFirstThreeThenDefaultMasked").ShouldBeTrue(); + props["ShowFirstThreeThenDefaultMasked"].LiteralValue().ShouldBe("123***"); } [Test] @@ -613,8 +614,8 @@ public void LogMaskedAttribute_Shows_Last_NChars_Then_Replaces_All_Other_Chars_W var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowLastThreeThenCustomMask")); - Assert.AreEqual("_REMOVED_789", props["ShowLastThreeThenCustomMask"].LiteralValue()); + props.ContainsKey("ShowLastThreeThenCustomMask").ShouldBeTrue(); + props["ShowLastThreeThenCustomMask"].LiteralValue().ShouldBe("_REMOVED_789"); } [Test] @@ -640,8 +641,8 @@ public void LogMaskedAttribute_Shows_Last_NChars_Then_Replaces_All_Other_Chars_W var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowLastThreeThenCustomMaskPreservedLengthIgnored")); - Assert.AreEqual("_REMOVED_789", props["ShowLastThreeThenCustomMaskPreservedLengthIgnored"].LiteralValue()); + props.ContainsKey("ShowLastThreeThenCustomMaskPreservedLengthIgnored").ShouldBeTrue(); + props["ShowLastThreeThenCustomMaskPreservedLengthIgnored"].LiteralValue().ShouldBe("_REMOVED_789"); } [Test] @@ -667,8 +668,8 @@ public void LogMaskedAttribute_Shows_Last_NChars_Then_Replaces_All_Other_Chars_W var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowLastThreeThenDefaultMasked")); - Assert.AreEqual("***789", props["ShowLastThreeThenDefaultMasked"].LiteralValue()); + props.ContainsKey("ShowLastThreeThenDefaultMasked").ShouldBeTrue(); + props["ShowLastThreeThenDefaultMasked"].LiteralValue().ShouldBe("***789"); } [Test] @@ -694,8 +695,8 @@ public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_Other_Chars_ var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstThreeThenDefaultMaskedPreservedLength")); - Assert.AreEqual("123******", props["ShowFirstThreeThenDefaultMaskedPreservedLength"].LiteralValue()); + props.ContainsKey("ShowFirstThreeThenDefaultMaskedPreservedLength").ShouldBeTrue(); + props["ShowFirstThreeThenDefaultMaskedPreservedLength"].LiteralValue().ShouldBe("123******"); } [Test] @@ -722,8 +723,8 @@ public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_Other_Chars_ var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstThreeThenDefaultMaskedPreservedLength")); - Assert.AreEqual("", props["ShowFirstThreeThenDefaultMaskedPreservedLength"].LiteralValue()); + props.ContainsKey("ShowFirstThreeThenDefaultMaskedPreservedLength").ShouldBeTrue(); + props["ShowFirstThreeThenDefaultMaskedPreservedLength"].LiteralValue().ShouldBe(""); } [Test] @@ -750,8 +751,8 @@ public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_Other_Chars_ var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstThreeThenDefaultMaskedPreservedLength")); - Assert.AreEqual("123", props["ShowFirstThreeThenDefaultMaskedPreservedLength"].LiteralValue()); + props.ContainsKey("ShowFirstThreeThenDefaultMaskedPreservedLength").ShouldBeTrue(); + props["ShowFirstThreeThenDefaultMaskedPreservedLength"].LiteralValue().ShouldBe("123"); } [Test] @@ -778,8 +779,8 @@ public void LogMaskedAttribute_Shows_First_NChars_Then_Replaces_All_Other_Chars_ var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstThreeThenDefaultMaskedPreservedLength")); - Assert.AreEqual("12", props["ShowFirstThreeThenDefaultMaskedPreservedLength"].LiteralValue()); + props.ContainsKey("ShowFirstThreeThenDefaultMaskedPreservedLength").ShouldBeTrue(); + props["ShowFirstThreeThenDefaultMaskedPreservedLength"].LiteralValue().ShouldBe("12"); } [Test] @@ -805,8 +806,8 @@ public void LogMaskedAttribute_Shows_Last_NChars_Then_Replaces_All_Other_Chars_W var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowLastThreeThenDefaultMaskedPreservedLength")); - Assert.AreEqual("******789", props["ShowLastThreeThenDefaultMaskedPreservedLength"].LiteralValue()); + props.ContainsKey("ShowLastThreeThenDefaultMaskedPreservedLength").ShouldBeTrue(); + props["ShowLastThreeThenDefaultMaskedPreservedLength"].LiteralValue().ShouldBe("******789"); } [Test] @@ -832,8 +833,8 @@ public void LogMaskedAttribute_Shows_Last_NChars_Then_Replaces_All_Other_Chars_W var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowLastThreeThenDefaultMaskedPreservedLength")); - Assert.AreEqual("123", props["ShowLastThreeThenDefaultMaskedPreservedLength"].LiteralValue()); + props.ContainsKey("ShowLastThreeThenDefaultMaskedPreservedLength").ShouldBeTrue(); + props["ShowLastThreeThenDefaultMaskedPreservedLength"].LiteralValue().ShouldBe("123"); } [Test] @@ -859,8 +860,8 @@ public void LogMaskedAttribute_Shows_Last_NChars_Then_Replaces_All_Other_Chars_W var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowLastThreeThenDefaultMaskedPreservedLength")); - Assert.AreEqual("12", props["ShowLastThreeThenDefaultMaskedPreservedLength"].LiteralValue()); + props.ContainsKey("ShowLastThreeThenDefaultMaskedPreservedLength").ShouldBeTrue(); + props["ShowLastThreeThenDefaultMaskedPreservedLength"].LiteralValue().ShouldBe("12"); } [Test] @@ -886,7 +887,7 @@ public void LogMaskedAttribute_Shows_First_NChars_And_Last_NChars_Then_Replaces_ var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("ShowFirstAndLastThreeAndCustomMaskInTheMiddlePreservedLengthIgnored")); - Assert.AreEqual("123_REMOVED_321", props["ShowFirstAndLastThreeAndCustomMaskInTheMiddlePreservedLengthIgnored"].LiteralValue()); + props.ContainsKey("ShowFirstAndLastThreeAndCustomMaskInTheMiddlePreservedLengthIgnored").ShouldBeTrue(); + props["ShowFirstAndLastThreeAndCustomMaskInTheMiddlePreservedLengthIgnored"].LiteralValue().ShouldBe("123_REMOVED_321"); } } diff --git a/src/Destructurama.Attributed.Tests/NotLoggedIfDefaultAttributeTests.cs b/src/Destructurama.Attributed.Tests/NotLoggedIfDefaultAttributeTests.cs index dba97e5..0fc07b4 100644 --- a/src/Destructurama.Attributed.Tests/NotLoggedIfDefaultAttributeTests.cs +++ b/src/Destructurama.Attributed.Tests/NotLoggedIfDefaultAttributeTests.cs @@ -2,6 +2,7 @@ using NUnit.Framework; using Serilog; using Serilog.Events; +using Shouldly; namespace Destructurama.Attributed.Tests; @@ -85,39 +86,38 @@ public void NotLoggedIfDefault_Uninitialized() var sv = (StructureValue)evt!.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsFalse(props.ContainsKey("String")); - Assert.IsFalse(props.ContainsKey("Integer")); - Assert.IsFalse(props.ContainsKey("NullableInteger")); - Assert.IsFalse(props.ContainsKey("Object")); - Assert.IsFalse(props.ContainsKey("DateTime")); - Assert.IsFalse(props.ContainsKey("Struct")); - - Assert.IsTrue(props.ContainsKey("StringLogged")); - Assert.IsTrue(props.ContainsKey("IntegerLogged")); - Assert.IsTrue(props.ContainsKey("NullableIntegerLogged")); - Assert.IsTrue(props.ContainsKey("ObjectLogged")); - Assert.IsTrue(props.ContainsKey("DateTimeLogged")); - Assert.IsTrue(props.ContainsKey("StructLogged")); - - Assert.AreEqual(default(string), props["StringLogged"].LiteralValue()); - Assert.AreEqual(default(int), props["IntegerLogged"].LiteralValue()); - Assert.AreEqual(default(int?), props["NullableIntegerLogged"].LiteralValue()); - Assert.AreEqual(default, props["ObjectLogged"].LiteralValue()); - Assert.AreEqual(default(DateTime), props["DateTimeLogged"].LiteralValue()); - Assert.AreEqual(default(NotLoggedIfDefaultStruct), props["StructLogged"].LiteralValue()); - - Assert.IsTrue(props.ContainsKey("StructWithAttributes")); - Assert.IsTrue(props["StructWithAttributes"] is StructureValue); - - var structProps = ((StructureValue)props["StructWithAttributes"]).Properties - .ToDictionary(p => p.Name, p => p.Value); - - Assert.IsFalse(structProps.ContainsKey("Integer")); - Assert.IsFalse(structProps.ContainsKey("DateTime")); - Assert.IsTrue(structProps.ContainsKey("IntegerLogged")); - Assert.IsTrue(structProps.ContainsKey("DateTimeLogged")); - Assert.AreEqual(default(int), structProps["IntegerLogged"].LiteralValue()); - Assert.AreEqual(default(DateTime), structProps["DateTimeLogged"].LiteralValue()); + props.ContainsKey("String").ShouldBeFalse(); + props.ContainsKey("Integer").ShouldBeFalse(); + props.ContainsKey("NullableInteger").ShouldBeFalse(); + props.ContainsKey("Object").ShouldBeFalse(); + props.ContainsKey("DateTime").ShouldBeFalse(); + props.ContainsKey("Struct").ShouldBeFalse(); + + props.ContainsKey("StringLogged").ShouldBeTrue(); + props.ContainsKey("IntegerLogged").ShouldBeTrue(); + props.ContainsKey("NullableIntegerLogged").ShouldBeTrue(); + props.ContainsKey("ObjectLogged").ShouldBeTrue(); + props.ContainsKey("DateTimeLogged").ShouldBeTrue(); + props.ContainsKey("StructLogged").ShouldBeTrue(); + + props["StringLogged"].LiteralValue().ShouldBe(default(string)); + props["IntegerLogged"].LiteralValue().ShouldBe(default(int)); + props["NullableIntegerLogged"].LiteralValue().ShouldBe(default(int?)); + props["ObjectLogged"].LiteralValue().ShouldBe(default); + props["DateTimeLogged"].LiteralValue().ShouldBe(default(DateTime)); + props["StructLogged"].LiteralValue().ShouldBe(default(NotLoggedIfDefaultStruct)); + + props.ContainsKey("StructWithAttributes").ShouldBeTrue(); + props["StructWithAttributes"].ShouldBeOfType(); + + var structProps = ((StructureValue)props["StructWithAttributes"]).Properties.ToDictionary(p => p.Name, p => p.Value); + + structProps.ContainsKey("Integer").ShouldBeFalse(); + structProps.ContainsKey("DateTime").ShouldBeFalse(); + structProps.ContainsKey("IntegerLogged").ShouldBeTrue(); + structProps.ContainsKey("DateTimeLogged").ShouldBeTrue(); + structProps["IntegerLogged"].LiteralValue().ShouldBe(default(int)); + structProps["DateTimeLogged"].LiteralValue().ShouldBe(default(DateTime)); } [Test] @@ -160,50 +160,49 @@ public void NotLoggedIfDefault_Initialized() var sv = (StructureValue)evt!.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("String")); - Assert.IsTrue(props.ContainsKey("Integer")); - Assert.IsTrue(props.ContainsKey("NullableInteger")); - Assert.IsTrue(props.ContainsKey("Object")); - Assert.IsTrue(props.ContainsKey("DateTime")); - Assert.IsTrue(props.ContainsKey("Struct")); - Assert.IsTrue(props.ContainsKey("IntegerAsObject")); - - Assert.IsTrue(props.ContainsKey("StringLogged")); - Assert.IsTrue(props.ContainsKey("IntegerLogged")); - Assert.IsTrue(props.ContainsKey("NullableIntegerLogged")); - Assert.IsTrue(props.ContainsKey("ObjectLogged")); - Assert.IsTrue(props.ContainsKey("DateTimeLogged")); - Assert.IsTrue(props.ContainsKey("StructLogged")); - - Assert.AreEqual("Foo", props["String"].LiteralValue()); - Assert.AreEqual(10, props["Integer"].LiteralValue()); - Assert.AreEqual(5, props["NullableInteger"].LiteralValue()); - Assert.AreEqual("Bar", props["Object"].LiteralValue()); - Assert.AreEqual(dateTime, props["DateTime"].LiteralValue()); - Assert.IsInstanceOf(props["Struct"]); - Assert.AreEqual(0, props["IntegerAsObject"].LiteralValue()); - - Assert.AreEqual(default(string), props["StringLogged"].LiteralValue()); - Assert.AreEqual(default(int), props["IntegerLogged"].LiteralValue()); - Assert.AreEqual(default(int?), props["NullableIntegerLogged"].LiteralValue()); - Assert.AreEqual(default, props["ObjectLogged"].LiteralValue()); - Assert.AreEqual(default(DateTime), props["DateTimeLogged"].LiteralValue()); - Assert.AreEqual(default(NotLoggedIfDefaultStruct), props["StructLogged"].LiteralValue()); - - Assert.IsTrue(props.ContainsKey("StructWithAttributes")); - Assert.IsTrue(props["StructWithAttributes"] is StructureValue); - - var structProps = ((StructureValue)props["StructWithAttributes"]).Properties - .ToDictionary(p => p.Name, p => p.Value); - - Assert.IsTrue(structProps.ContainsKey("Integer")); - Assert.IsTrue(structProps.ContainsKey("DateTime")); - Assert.IsTrue(structProps.ContainsKey("IntegerLogged")); - Assert.IsTrue(structProps.ContainsKey("DateTimeLogged")); - Assert.AreEqual(20, structProps["Integer"].LiteralValue()); - Assert.AreEqual(dateTime, structProps["DateTime"].LiteralValue()); - Assert.AreEqual(default(int), structProps["IntegerLogged"].LiteralValue()); - Assert.AreEqual(default(DateTime), structProps["DateTimeLogged"].LiteralValue()); + props.ContainsKey("String").ShouldBeTrue(); + props.ContainsKey("Integer").ShouldBeTrue(); + props.ContainsKey("NullableInteger").ShouldBeTrue(); + props.ContainsKey("Object").ShouldBeTrue(); + props.ContainsKey("DateTime").ShouldBeTrue(); + props.ContainsKey("Struct").ShouldBeTrue(); + props.ContainsKey("IntegerAsObject").ShouldBeTrue(); + + props.ContainsKey("StringLogged").ShouldBeTrue(); + props.ContainsKey("IntegerLogged").ShouldBeTrue(); + props.ContainsKey("NullableIntegerLogged").ShouldBeTrue(); + props.ContainsKey("ObjectLogged").ShouldBeTrue(); + props.ContainsKey("DateTimeLogged").ShouldBeTrue(); + props.ContainsKey("StructLogged").ShouldBeTrue(); + + props["String"].LiteralValue().ShouldBe("Foo"); + props["Integer"].LiteralValue().ShouldBe(10); + props["NullableInteger"].LiteralValue().ShouldBe(5); + props["Object"].LiteralValue().ShouldBe("Bar"); + props["DateTime"].LiteralValue().ShouldBe(dateTime); + props["Struct"].ShouldBeOfType(); + props["IntegerAsObject"].LiteralValue().ShouldBe(0); + + props["StringLogged"].LiteralValue().ShouldBe(default(string)); + props["IntegerLogged"].LiteralValue().ShouldBe(default(int)); + props["NullableIntegerLogged"].LiteralValue().ShouldBe(default(int?)); + props["ObjectLogged"].LiteralValue().ShouldBe(default); + props["DateTimeLogged"].LiteralValue().ShouldBe(default(DateTime)); + props["StructLogged"].LiteralValue().ShouldBe(default(NotLoggedIfDefaultStruct)); + + props.ContainsKey("StructWithAttributes").ShouldBeTrue(); + props["StructWithAttributes"].ShouldBeOfType(); + + var structProps = ((StructureValue)props["StructWithAttributes"]).Properties.ToDictionary(p => p.Name, p => p.Value); + + structProps.ContainsKey("Integer").ShouldBeTrue(); + structProps.ContainsKey("DateTime").ShouldBeTrue(); + structProps.ContainsKey("IntegerLogged").ShouldBeTrue(); + structProps.ContainsKey("DateTimeLogged").ShouldBeTrue(); + structProps["Integer"].LiteralValue().ShouldBe(20); + structProps["DateTime"].LiteralValue().ShouldBe(dateTime); + structProps["IntegerLogged"].LiteralValue().ShouldBe(default(int)); + structProps["DateTimeLogged"].LiteralValue().ShouldBe(default(DateTime)); } } diff --git a/src/Destructurama.Attributed.Tests/ReplacedAttributeTests.cs b/src/Destructurama.Attributed.Tests/ReplacedAttributeTests.cs index aa2ba2e..7ce482c 100644 --- a/src/Destructurama.Attributed.Tests/ReplacedAttributeTests.cs +++ b/src/Destructurama.Attributed.Tests/ReplacedAttributeTests.cs @@ -2,6 +2,7 @@ using NUnit.Framework; using Serilog; using Serilog.Events; +using Shouldly; namespace Destructurama.Attributed.Tests; @@ -60,8 +61,8 @@ public void LogReplacedAttribute_Replaces_First() var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("RegexReplaceFirst")); - Assert.AreEqual("***|456|789", props["RegexReplaceFirst"].LiteralValue()); + props.ContainsKey("RegexReplaceFirst").ShouldBeTrue(); + props["RegexReplaceFirst"].LiteralValue().ShouldBe("***|456|789"); } [Test] @@ -87,8 +88,8 @@ public void LogReplacedAttribute_Replaces_Second() var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("RegexReplaceSecond")); - Assert.AreEqual("123|***|789", props["RegexReplaceSecond"].LiteralValue()); + props.ContainsKey("RegexReplaceSecond").ShouldBeTrue(); + props["RegexReplaceSecond"].LiteralValue().ShouldBe("123|***|789"); } [Test] @@ -114,8 +115,8 @@ public void LogReplacedAttribute_Replaces_Third() var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("RegexReplaceThird")); - Assert.AreEqual("123|456|***", props["RegexReplaceThird"].LiteralValue()); + props.ContainsKey("RegexReplaceThird").ShouldBeTrue(); + props["RegexReplaceThird"].LiteralValue().ShouldBe("123|456|***"); } [Test] @@ -141,8 +142,8 @@ public void LogReplacedAttribute_Replaces_FirstThird() var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("RegexReplaceFirstThird")); - Assert.AreEqual("***|456|****", props["RegexReplaceFirstThird"].LiteralValue()); + props.ContainsKey("RegexReplaceFirstThird").ShouldBeTrue(); + props["RegexReplaceFirstThird"].LiteralValue().ShouldBe("***|456|****"); } [Test] @@ -169,9 +170,9 @@ public void LogReplacedAttribute_Replaces_First_And_Third() var sv = (StructureValue)evt.Properties["Customized"]; var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value); - Assert.IsTrue(props.ContainsKey("RegexReplaceFirst")); - Assert.AreEqual("***|456|789", props["RegexReplaceFirst"].LiteralValue()); - Assert.IsTrue(props.ContainsKey("RegexReplaceThird")); - Assert.AreEqual("123|456|***", props["RegexReplaceThird"].LiteralValue()); + props.ContainsKey("RegexReplaceFirst").ShouldBeTrue(); + props["RegexReplaceFirst"].LiteralValue().ShouldBe("***|456|789"); + props.ContainsKey("RegexReplaceThird").ShouldBeTrue(); + props["RegexReplaceThird"].LiteralValue().ShouldBe("123|456|***"); } }