mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
How to make Request mapping match only when it is a perfect match? #308
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 @tomatualus on GitHub (Oct 20, 2020).
Hello.
Lets say i have two request mappings. The
XPathMatchersare simplified.Request 1 has body matchers
XPathMatcherfor Value1 = 1 ANDXPathMatcherfor Value2 = 2.Request 2 has a body matcher
XPathMatcherfor Value1 = 1.How do i return the Request 1's response, when its matchers are a perfect fit, but return Request 2, when Value2 != 2?
Thanks in advance.
@StefH commented on GitHub (Oct 20, 2020):
Hello @tomatualus,
The current logic from WireMock.Net is that in case two mappings are a perfect fit, the one with the most matches is preferred.
Your second scenario return Request 2, when Value2 != 2 , I'm not completely sure that can be done right now. But I would would expect it to work correct, that is : return Request 2 because Request 1 does only only match for 50%.
See also https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/Owin/MappingMatcherTests.cs#L145
@tomatualus commented on GitHub (Oct 21, 2020):
Thanks for the reply @StefH
I will post my class setup down below. You can see that it doesn't work as expected, even though online XPath tools show that one of XPathMatchers should fail. Both of them return `Failed but no delay
Also the setup below has this scenario -
Request 1 has body matchers XPathMatcher for FirstForename = Failed AND XPathMatcher for Surname = Delay.
Request 2 has body matchers XPathMatcher for FirstForename = Failed AND XPathMatcher for Surname != Delay.
EDIT:
Interestingly enough, if i comment out
In both of the matchers, it correctly returns
Failed and delayandFailed but no delay@tomatualus commented on GitHub (Oct 21, 2020):
Just discovered the fix......
It seems like i can pass many strings into
XPathMatcher.. So when consolidated both XPathMatchers into one, it now works.But the question remains - why does the upper test not work?
@StefH commented on GitHub (Oct 21, 2020):
Maybe you need to use
notinstead of!=for strings?https://stackoverflow.com/questions/3418470/using-not-in-xpath