mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Issue: Wildcard matching a json body does not work? #98
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 @alastairtree on GitHub (May 11, 2018).
Originally assigned to: @StefH on GitHub.
Hello @StefH,
I have noticed that if I try to match request bodies containing json, I am restricted to using the JsonPathMatcher. Sometimes it is quicker and easier to use wildcard or regex matchers (say) but these matchers just get ignored if the content type header is set as application/json. This is not exactly intuitive - that a request header affects which of the matchers are applied or silently ignored. I assume this was a deliberate decision? Is there a reason you do not want to support the other matcher types on json? (and I assume the same is in place with xml.)
Sample failing test:
@StefH commented on GitHub (May 11, 2018):
It was not a 100% deliberate decision, this seemed logical at the time I built this piece of code.
I'll see if I can extend the matching logic to support this scenario, and not break others ;-)
@StefH commented on GitHub (May 11, 2018):
@alastairtree
Please do a code-review on my
stef_133branch.See specifically the changes in
RequestMessageBodyMatcher.cs.@alastairtree commented on GitHub (May 12, 2018):
@StefH I have reviewed and added a couple more tests. I was wondering if it would be tidier to put the string version of the json in the BodyAsString property rather than adding a third? Other than that it looks good to me.
@StefH commented on GitHub (May 12, 2018):
Thanks for tour tests, and
[Theory]is cool option which I should more in my unit-tests in general.If I remove the
BodyAsStringOriginalproperty, I think I need to switch the code into this:Else the logic will not work? Correct ?
@alastairtree commented on GitHub (May 13, 2018):
Yeah that looks good to me, and those tests should make sure the basics are not broken. How should it behave of there are more than one body matcher? Do we have tests covering that?
@StefH commented on GitHub (May 13, 2018):
The
RequestMessageBodyMatcherdo only allow for 1 matcher, as opposed to e.g.RequestMessageHeaderMatcherwhich does allow multiple.I'll make a PR and add you as reviewer. And when all is fine, I can merge and create a new version.