mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Can ExactMatcher (on Request) include IgnoreCase? #445
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 @mattisking on GitHub (Sep 15, 2022).
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).
@StefH commented on GitHub (Sep 15, 2022):
Can't you just use a
WildcardMatcherwith/lookup/12345and ignorecase = true?@mattisking commented on GitHub (Sep 15, 2022):
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 }
@StefH commented on GitHub (Sep 15, 2022):
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.
@mattisking commented on GitHub (Sep 15, 2022):
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
}
]
},
@StefH commented on GitHub (Sep 17, 2022):
@mattisking
I did update the ExactMather to support IgnoreCase.
please test preview version
1.5.6-ci-16453@StefH commented on GitHub (Sep 21, 2022):
@mattisking Can you test this?
@mattisking commented on GitHub (Sep 21, 2022):
I will test it today. Sorry, Business travel.
@StefH commented on GitHub (Sep 26, 2022):
@mattisking
Did you time to test?
@StefH commented on GitHub (Sep 29, 2022):
@mattisking ; can you please test this?
@StefH commented on GitHub (Oct 3, 2022):
@mattisking , if you have time, can you please test this?
(Then I can merge this to master)
@StefH commented on GitHub (Oct 12, 2022):
@mattisking
Did you have time yet to verify?
@StefH commented on GitHub (Oct 15, 2022):
https://github.com/WireMock-Net/WireMock.Net/pull/817
PR will be merged. A new NuGet will be released this weekend,