-
Notifications
You must be signed in to change notification settings - Fork 758
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
Assert.Equivalent and System.Text.Json #2696
Comments
The problem is three-fold:
Unless and until You should be wary about using [Fact]
public void XunitBug()
{
var o1 = new JsonObject();
var o2 = new JsonObject();
o1.Add("field1", JsonValue.Create("1"));
o1.Add("field2", JsonValue.Create("2"));
o2.Add("field2", JsonValue.Create("2"));
o2.Add("field1", JsonValue.Create("1"));
Assert.Equal(o1.ToJsonString(), o2.ToJsonString());
}
The best generalized solution I can think of is to implement (or find) an |
Thanks, I didn't want to use strings for the very reason you mentioned. I was just making sure they were equal in this simple case. FluentAssertions has ComparingByMembers that looks like it may work or maybe I just implement a simple non-recursive comparer which should meet our needs. Thanks again. |
The problem with a generalized "comparing by members" is that that's exactly what we do. 😁 |
Hi @jasonj333 there is Xunit assertion json extension package which can assert json data as "json way". For your example, just write similar as: string actualJson = """
{
"field1": "1",
"field2": "2"
}
""";
string expectedJson = """
{
"field2": "2",
"field1": "1"
}
""";
JsonAssertion.Equivalent(expectedJson, actualJson);
the library considered all recursive cases for json. |
Using .NET 7, we recently switched from JSON.Net to System.Text.Json and a few of our tests failed. Previously, we were using Assert.Equivalent to compare 2 JSON objects, now we are getting an exception within xUnit:
Simple repo:
We are using Visual Studio 17.4.4 and xUnit 2.4.2
The text was updated successfully, but these errors were encountered: