diff --git a/Tests/DynamicSerializerTests.cs b/Tests/DynamicSerializerTests.cs index 91ed005..d5eea4d 100644 --- a/Tests/DynamicSerializerTests.cs +++ b/Tests/DynamicSerializerTests.cs @@ -2,6 +2,7 @@ using FluentAssertions; using System; using System.Linq; +using Tests.Utilities; using Xunit; namespace Tests { @@ -27,7 +28,7 @@ public void NullValuesAreSerializedToEmptyColumn() { DateTime = null }; string csv = CsvSerializer.Serialize(new[] { obj }, withHeaders: true); - csv.Should().Be(""" + csv.Should().BeSimilarTo(""" "Bool","Byte","SByte","Short","UShort","Int","UInt","Long","ULong","Float","Double","Decimal","String","DateTime" ,,,,,,,,,,,,, """); @@ -49,7 +50,7 @@ public void NullValuesAreSerializedToEmptyColumn() { DateTime = new DateTime(2019, 8, 23) }; csv = CsvSerializer.Serialize(new[] { obj }, withHeaders: true); - csv.Should().Be(""" + csv.Should().BeSimilarTo(""" "Bool","Byte","SByte","Short","UShort","Int","UInt","Long","ULong","Float","Double","Decimal","String","DateTime" True,102,-100,-200,200,-3000,3000,-40000,40000,1E+14,1.7837193718273812E+19,989898989898,"CSV Serializer","8/23/2019 12:00:00 AM" """); diff --git a/Tests/NaiveSerializerTests.cs b/Tests/NaiveSerializerTests.cs index 843c6c3..7a599ff 100644 --- a/Tests/NaiveSerializerTests.cs +++ b/Tests/NaiveSerializerTests.cs @@ -2,6 +2,7 @@ using FluentAssertions; using System; using System.Linq; +using Tests.Utilities; using Xunit; namespace Tests { @@ -27,7 +28,7 @@ public void NullValuesAreSerializedIntoEmptyColumn() { DateTime = null }; string csv = CsvSerializer.Serialize(new[] { obj }, withHeaders: true); - csv.Should().Be(""" + csv.Should().BeSimilarTo(""" "Bool","Byte","SByte","Short","UShort","Int","UInt","Long","ULong","Float","Double","Decimal","String","DateTime" ,,,,,,,,,,,,, """); @@ -49,7 +50,7 @@ public void NullValuesAreSerializedIntoEmptyColumn() { DateTime = new DateTime(2019, 8, 23) }; csv = CsvSerializer.Serialize(new[] { obj }, withHeaders: true); - csv.Should().Be(""" + csv.Should().BeSimilarTo(""" "Bool","Byte","SByte","Short","UShort","Int","UInt","Long","ULong","Float","Double","Decimal","String","DateTime" True,102,-100,-200,200,-3000,3000,-40000,40000,1E+14,1.7837193718273812E+19,989898989898,"CSV Serializer","8/23/2019 12:00:00 AM" """); diff --git a/Tests/SerializerTests.cs b/Tests/SerializerTests.cs index 1961628..ea01103 100644 --- a/Tests/SerializerTests.cs +++ b/Tests/SerializerTests.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.Linq; using System.Net; +using Tests.Utilities; using Xunit; namespace Tests { @@ -30,7 +31,7 @@ public void AnonymousTypesAreSerializedUsingNaiveSerializer() { }; string csv = CsvSerializer.Serialize(new[] { item }, withHeaders: true); - csv.Should().Be(""" + csv.Should().BeSimilarTo(""" "Bool","Byte","SByte","Short","UShort","Int","UInt","Long","ULong","Float","Double","Decimal","String","DateTime","Uri","StatusCode" True,102,-100,-200,200,-3000,3000,-40000,40000,1E+14,1.7837193718273812E+19,989898989898,"CSV Serializer","8/23/2019 12:00:00 AM","http://localhost:5000/",OK """); @@ -57,7 +58,7 @@ public void PublicTypesAreSerializedUsingDynamicSerializer() { StatusCode = HttpStatusCode.OK }; string csv = CsvSerializer.Serialize(new[] { item }, withHeaders: true); - csv.Should().Be(""" + csv.Should().BeSimilarTo(""" "Bool","Byte","SByte","Short","UShort","Int","UInt","Long","ULong","Float","Double","Decimal","String","DateTime","Uri","StatusCode" True,102,-100,-200,200,-3000,3000,-40000,40000,1E+14,1.7837193718273812E+19,989898989898,"CSV Serializer","8/23/2019 12:00:00 AM","http://localhost:5000/",OK """); @@ -69,7 +70,7 @@ public void PrivateTypesAreSerializedUsingNaiveSerializer() { Name = "CSV Serializer" }; string csv = CsvSerializer.Serialize(new[] { item }, withHeaders: true); - csv.Should().Be(""" + csv.Should().BeSimilarTo(""" "Name" "CSV Serializer" """); diff --git a/Tests/Utilities/FluentAssertionsExtensions.cs b/Tests/Utilities/FluentAssertionsExtensions.cs new file mode 100644 index 0000000..2846cf1 --- /dev/null +++ b/Tests/Utilities/FluentAssertionsExtensions.cs @@ -0,0 +1,11 @@ +using FluentAssertions; +using FluentAssertions.Primitives; + +namespace Tests.Utilities { + internal static class FluentAssertionsExtensions { + public static AndConstraint BeSimilarTo(this StringAssertions assertions, string expected, string? because = null, params object[] becauseArgs) { + return assertions.Subject.Replace("\r\n", "\n").Replace("\r", "\n") + .Should().Be(expected.Replace("\r\n", "\n").Replace("\r", "\n"), because, becauseArgs); + } + } +}