mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
FluentAssertions - Actual body is not displayed in error message when using Json Body #586
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @srollinet on GitHub (Mar 18, 2024).
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
IValueFormatterExample:
And to add it in the custom formatters
Formatter.AddFormatter(new JObjectFormatter());Note: the
IValueFormatterinterface 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
@StefH commented on GitHub (Mar 18, 2024):
@srollinet
Could it also be an option to just create a helper method in
WireMockAssertions.WithBody.cswhich formats all possible body values?@srollinet commented on GitHub (Mar 18, 2024):
It could also probably be an option. I can check that next day if you want.
@StefH commented on GitHub (Mar 18, 2024):
Sure. A PR is welcome.
@srollinet commented on GitHub (Mar 19, 2024):
Okay, doing something like this makes the message better
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
ToString()I wonder if the expected body should also be serialized as json, so both representations will be similar. What do you think?
@StefH commented on GitHub (Mar 19, 2024):
@srollinet
Can you take a look at my PR ?
@srollinet commented on GitHub (Mar 19, 2024):
@StefH Yes, it looks good to me