mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Feature: Negate a matcher #96
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 (Apr 25, 2018).
Originally assigned to: @StefH on GitHub.
Is there any way to negate a matcher, so i could match on the absense of a match. For example what if i want to stub for all requests that do not have an API key header? Or all requests with query param A but missing query param B?
@StefH commented on GitHub (Apr 26, 2018):
Good question. I thought the
RegexMatchercould be solution, but that can only check/not-check on the value from a header, you cannot define a match where the complete api-header is absent...@StefH commented on GitHub (Apr 26, 2018):
Another option could be (in code):
As mapping, a solution would be:
or
or
@alastairtree commented on GitHub (Apr 26, 2018):
It would also be nice if we could apply it elsewhere also - for example on query params. I think I prefer something in the matcher that reverses the match, so that every matcher could be inverted if you wanted. But it could be easily confusing. Perhaps an Enum and a sensible default to make it really explicit?
and then in json perhaps:
@StefH commented on GitHub (Apr 27, 2018):
When looking at the original WireMock : http://wiremock.org/docs/request-matching/ (see text
It is also possible to perform a negative match)I think that this would also be an option:
code
or instead of
Reject(...), we could useRejectMatch(...)/RejectOnMatch(...)/Not(...)/NoMatch(...)/RejectPattern(...)json
Your proposal (looks good I think)
or
option 1 (add a new list : the
RejectMatchers)or
option 2 (looks like the WireMock.org solution, however the
IgnoreCaseis a bit strange because it's used in the matching, but now it seems that only the pattern is rejected...)Maybe some more?
@StefH commented on GitHub (May 1, 2018):
@alastairtree Did you have time to take a look at my last comment?
@alastairtree commented on GitHub (May 1, 2018):
I don't feel that passionately about the syntax, but having reviewed the various options i think i still prefer my proosal of
.WithHeader("Accept", "text/html*", MatchBehaviour.RejectOnMatch)and the"RejectOnMatch": true,json flavour, but happy to be overruled!@StefH commented on GitHub (May 1, 2018):
I'll keep your proposal and I will update the code. Probably I'll send a PR review to you when it's ready.
@alastairtree commented on GitHub (May 1, 2018):
Thats very kind! It is a good feature I think, but I am not urgently in need at the moment as I found a work around using priorities, so by all means put other issues ahead of this one. Very happy to code review anything though.
@alastairtree commented on GitHub (May 4, 2018):
Had a look at that branch and its looking good.
@StefH commented on GitHub (May 4, 2018):
I'm not done yet. Have to write more unit tests and do some real testing.
@StefH commented on GitHub (May 6, 2018):
Hello @alastairtree.
Now I think I've updated and tested all the code, can you now please do a review and if possible also run some real tests to see if the behaviour is correct?
@StefH commented on GitHub (May 11, 2018):
@alastairtree, can you do a code-review please?
@alastairtree commented on GitHub (May 12, 2018):
Looking good @StefH - added some little bits in #134
@alastairtree commented on GitHub (May 16, 2018):
All looking good @StefH. I have added a bit of docs to https://github.com/WireMock-Net/WireMock.Net/wiki/Stubbing-and-Request-Matching#reversing-the-match-behaviour-with-matchbehaviourrejectonmatch
@StefH commented on GitHub (May 16, 2018):
Very cool !!! Thank you very much.