-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
FluentAssertions - Actual body is not displayed in error message when using Json Body #1084
Comments
@srollinet |
It could also probably be an option. I can check that next day if you want. |
Sure. A PR is welcome. |
Okay, doing something like this makes the message better public AndConstraint<WireMockAssertions> WithBodyAsJson(IObjectMatcher matcher, string because = "", params object[] becauseArgs)
{
var (filter, condition) = BuildFilterAndCondition(r => r.BodyAsJson, matcher);
return ExecuteAssertionWithBodyAsIObjectMatcher(matcher, because, becauseArgs, condition, filter, r => FormatBody(r.BodyAsJson));
}
private static object? FormatBody(object? body)
{
if (body is JToken jToken)
{
return jToken.ToString(Formatting.None);
}
//TODO Add other types here
return body;
}
But it is still different between the expected body and the actual body And it is worse if the Matcher is created by using a named type, or even worse if the type overrides
I wonder if the expected body should also be serialized as json, so both representations will be similar. What do you think? |
@srollinet |
@StefH Yes, it looks good to me |
Describe the bug
When using a Json Body, Fluent assertion cannot format the actual body in the error message
Expected behavior:
The json body is correctly formatted
Test to reproduce
You can reproduce the message with this unit test (proper assertion is not done, the test fails with the unformatted message)
Other related info
One solution is to implement a custom
IValueFormatter
Example:
And to add it in the custom formatters
Formatter.AddFormatter(new JObjectFormatter());
Note: the
IValueFormatter
interface varies based on the target framework, so it must be multiple implementationsLet me know if I can help or if I can make a PR for this issue
The text was updated successfully, but these errors were encountered: