Skip to content

Commit

Permalink
Fix failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnygunawan committed Nov 13, 2023
1 parent 051603f commit 8c1ce7b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Tests/DynamicSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FluentAssertions;
using System;
using System.Linq;
using Tests.Utilities;
using Xunit;

namespace Tests {
Expand All @@ -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"
,,,,,,,,,,,,,
""");
Expand All @@ -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"
""");
Expand Down
5 changes: 3 additions & 2 deletions Tests/NaiveSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FluentAssertions;
using System;
using System.Linq;
using Tests.Utilities;
using Xunit;

namespace Tests {
Expand All @@ -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"
,,,,,,,,,,,,,
""");
Expand All @@ -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"
""");
Expand Down
7 changes: 4 additions & 3 deletions Tests/SerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Globalization;
using System.Linq;
using System.Net;
using Tests.Utilities;
using Xunit;

namespace Tests {
Expand All @@ -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
""");
Expand All @@ -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
""");
Expand All @@ -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"
""");
Expand Down
11 changes: 11 additions & 0 deletions Tests/Utilities/FluentAssertionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using FluentAssertions;
using FluentAssertions.Primitives;

namespace Tests.Utilities {
internal static class FluentAssertionsExtensions {
public static AndConstraint<StringAssertions> 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);
}
}
}

0 comments on commit 8c1ce7b

Please sign in to comment.