Skip to content

Commit 71a9700

Browse files
author
Bart Koelman
committed
Fixed broken tests in cibuild due to different line endings
1 parent b1598e6 commit 71a9700

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

test/TestBuildingBlocks/ObjectAssertionsExtensions.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public static class ObjectAssertionsExtensions
1313
{
1414
private const decimal NumericPrecision = 0.00000000001M;
1515

16-
private static readonly JsonSerializerOptions SerializerOptions = new()
16+
private static readonly JsonWriterOptions JsonWriterOptions = new()
1717
{
18-
WriteIndented = true,
18+
Indented = true,
1919
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
2020
};
2121

@@ -70,13 +70,23 @@ public static AndConstraint<NullableNumericAssertions<decimal>> BeApproximately(
7070
[CustomAssertion]
7171
public static void BeJson(this StringAssertions source, string expected, string because = "", params object[] becauseArgs)
7272
{
73-
var sourceToken = JsonSerializer.Deserialize<JsonElement>(source.Subject, SerializerOptions);
74-
var expectedToken = JsonSerializer.Deserialize<JsonElement>(expected, SerializerOptions);
73+
using JsonDocument sourceJson = JsonDocument.Parse(source.Subject);
74+
using JsonDocument expectedJson = JsonDocument.Parse(expected);
7575

76-
string sourceText = sourceToken.ToString();
77-
string expectedText = expectedToken.ToString();
76+
string sourceText = ToJsonString(sourceJson);
77+
string expectedText = ToJsonString(expectedJson);
7878

7979
sourceText.Should().Be(expectedText, because, becauseArgs);
8080
}
81+
82+
private static string ToJsonString(JsonDocument document)
83+
{
84+
using var stream = new MemoryStream();
85+
var writer = new Utf8JsonWriter(stream, JsonWriterOptions);
86+
87+
document.WriteTo(writer);
88+
writer.Flush();
89+
return Encoding.UTF8.GetString(stream.ToArray());
90+
}
8191
}
8292
}

0 commit comments

Comments
 (0)