Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: json null formatting in assertion report #209

Merged
merged 16 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Arcus.Testing.Assert/AssertJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ private static JsonDifference CompareJsonNode(JsonNode expected, JsonNode actual
JsonArray actualArray => CompareJsonArray(expected, actualArray, options),
JsonObject actualObject => CompareJsonObject(expected, actualObject, options),
JsonValue actualValue => CompareJsonValue(expected, actualValue),
null => expected is null ? null : new JsonDifference(ActualIsNull, expected.GetPath()),
null => expected is null ? null : new JsonDifference(ActualIsNull, expected.GetPath())
{
ExpectedNodeDiff = expected.ToString(),
ActualNodeDiff = "null"
},
_ => null
};
}
Expand Down Expand Up @@ -470,8 +474,8 @@ internal class JsonDifference
internal JsonDifference(JsonDifferenceKind kind, JsonNode expected, JsonNode actual)
: this(kind, expected?.GetPath() ?? actual?.GetPath() ?? "<not-available>", expected: Describe(expected), actual: Describe(actual))
{
ExpectedNodeDiff = expected?.ToString();
ActualNodeDiff = actual?.ToString();
ExpectedNodeDiff = expected?.ToString() ?? "null";
ActualNodeDiff = actual?.ToString() ?? "null";
}

internal JsonDifference(JsonDifferenceKind kind, string path, object actual, object expected)
Expand Down
38 changes: 38 additions & 0 deletions src/Arcus.Testing.Tests.Unit/Assert_/AssertJsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,44 @@ [ [
""name"": ""post-metal""
}"
};
yield return new object[]
{
"{ \"this\": \"that\", \"options\": null }",
"{ \"this\": \"that\", \"options\": { \"and\": \"this\" } }",
@"Expected: Actual:
null {
""and"": ""this""
}"
};
yield return new object[]
{
"{ \"this\": \"that\", \"options\": { \"and\": \"this\" } }",
"{ \"this\": \"that\", \"options\": null }",
@"Expected: Actual:
{ null
""and"": ""this""
}"
};
yield return new object[]
{
"null",
"[ \"this\", \"that\" ]",
@"Expected: Actual:
null [
""this"",
""that""
]"
};
yield return new object[]
{
"[ \"this\", \"that\" ]",
"null",
@"Expected: Actual:
[ null
""this"",
""that""
] "
};
}
}

Expand Down
Loading