WireMock.Net icon indicating copy to clipboard operation
WireMock.Net copied to clipboard

Can ExactMatcher (on Request) include IgnoreCase?

Open mattisking opened this issue 3 years ago • 7 comments

I've got an API I've mocked, a nice and simple one, which is nothing but a kind of lookup service so just simple restful gets. An example might look like: [HttpGet] /lookup/{id}

The Request part of my mapping: "Request": { "Path": { "Matchers": [ { "Name": "ExactMatcher", "Pattern": "/lookup/12345" } ] },

This gives me the ability to set a bunch of specific responses for various values. In order to have a "catchall", I've also got this other mapping: "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/lookup/*", "IgnoreCase": true } ] }, This serves me well as I can define a bunch of custom cases, but also have a catch all for other values where I want to return a default response.

The problem is that the ExactMatcher doesn't appear to support IgnoreCase which to a degree I understand... it's an exact match, but in truth, casing in a URL's route is generally going to work fine regardless of case: /lookup/12345 and /Lookup/1235

are going to work the same for the vast majority of API calls and I'd argue remain an "exact match" in most cases (most cases, so the IgnoreCase option remains a good choice).

mattisking avatar Sep 15 '22 19:09 mattisking

Can't you just use a WildcardMatcher with /lookup/12345 and ignorecase = true?

StefH avatar Sep 15 '22 19:09 StefH

If I do that, then my WildCard one I setup now catches everything if the path case is different.

Example: ExactMatcher: /lookup/12345 return: { "id": 1 }

WildcardMatcher: /lookup/* IgnoreCase: true return: { "id": 2 }

Test cases: /lookup/12345 will return { "id": 1 }

/Lookup/12345 will return { "id": 2 }, but I want { "id": 1 }

mattisking avatar Sep 15 '22 19:09 mattisking

Ah.

In that case I think regexmatcher will be the best choice for you: https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#regular-expression-matching-regexmatcher

Which is powerfull because it's regex, and also supports ignore case.

StefH avatar Sep 15 '22 19:09 StefH

It’s not ideal for my use case but I can make it work in conjunction with Priority:

“Priority”: 1 “Request": { "Path": { "Matchers": [ { "Name": "RegexMatcher", "Pattern": "/lookup/12345$", “IgnoreCase”: true } ] },

“Priority”: 2, "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/lookup/*", "IgnoreCase": true } ] },

mattisking avatar Sep 15 '22 20:09 mattisking

@mattisking I did update the ExactMather to support IgnoreCase.

please test preview version 1.5.6-ci-16453

StefH avatar Sep 17 '22 08:09 StefH

@mattisking Can you test this?

StefH avatar Sep 21 '22 12:09 StefH

I will test it today. Sorry, Business travel.

mattisking avatar Sep 21 '22 13:09 mattisking

@mattisking Did you time to test?

StefH avatar Sep 26 '22 11:09 StefH

@mattisking ; can you please test this?

StefH avatar Sep 29 '22 13:09 StefH

@mattisking , if you have time, can you please test this?

(Then I can merge this to master)

StefH avatar Oct 03 '22 17:10 StefH

@mattisking Did you have time yet to verify?

StefH avatar Oct 12 '22 10:10 StefH

https://github.com/WireMock-Net/WireMock.Net/pull/817

PR will be merged. A new NuGet will be released this weekend,

StefH avatar Oct 15 '22 06:10 StefH