Unexpected behavior on multiple params matching #281

Closed
opened 2025-12-29 15:19:37 +01:00 by adam · 6 comments
Owner

Originally created by @devzaak on GitHub (Jul 13, 2020).

What is the expected purpose of

MockService
  .Given(Request.Create()
    .UsingGet()
    .WithPath($"/path*")
    .WithParam("limit", "1", "0", "2"))
  .RespondWith(Response.Create().WithCallback(request => GetData(limit)));

I expected that this setup would match on any of the provided values, but it rejects all of the requests with any of those values?
I know I can get this to match by providing linq or c# matcher as alternative, but just wanted to clarify purpose of the params?
Cheers

Originally created by @devzaak on GitHub (Jul 13, 2020). What is the expected purpose of ```csharp MockService .Given(Request.Create() .UsingGet() .WithPath($"/path*") .WithParam("limit", "1", "0", "2")) .RespondWith(Response.Create().WithCallback(request => GetData(limit))); ``` I expected that this setup would match on any of the provided values, but it rejects all of the requests with any of those values? I know I can get this to match by providing linq or c# matcher as alternative, but just wanted to clarify purpose of the params? Cheers
adam added the question label 2025-12-29 15:19:37 +01:00
adam closed this issue 2025-12-29 15:19:37 +01:00
Author
Owner

@StefH commented on GitHub (Jul 13, 2020):

Hello @aslezak,

The current intended behaviour from this logic is that you define that the limit parameter should be defined 3 times and have the values 0, 1 and 2. So it's basically an AND.

See this unit test which should explain it:
d971144426/test/WireMock.Net.Tests/RequestTests.cs (L126)

If you want to match on 0 or 1 or2, the best solution is to use a RegexMatcher.
So

.WithParam("limit", new RegexMatcher("^[012]$")
@StefH commented on GitHub (Jul 13, 2020): Hello @aslezak, The current intended behaviour from this logic is that you define that the `limit` parameter should be defined 3 times and have the values `0`, `1` and `2`. So it's basically an **AND**. See this unit test which should explain it: https://github.com/WireMock-Net/WireMock.Net/blob/d971144426bbf1761dcc4c24da5e3d9870267dd5/test/WireMock.Net.Tests/RequestTests.cs#L126 If you want to match on `0` or `1` or`2`, the best solution is to use a RegexMatcher. So ``` c# .WithParam("limit", new RegexMatcher("^[012]$") ```
Author
Owner

@StefH commented on GitHub (Jul 13, 2020):

A structural change could be to add another parameter which defines if the match result should be calculated using an AND or an OR. I'll think about this....

@StefH commented on GitHub (Jul 13, 2020): A structural change could be to add another parameter which defines if the match result should be calculated using an *AND* or an *OR*. I'll think about this....
Author
Owner

@devzaak commented on GitHub (Jul 13, 2020):

Thanks for the unit test and regex idea.
One thing I am curious about is in what cases does one want in url to have query param multiple times with different values. I know that some languages process multiple query string keys differently. PHP takes only the first one unless it is array, c# does array and so on.

ps. if match operator option is something that can be done, happy to make a PR for it.
Cheers

@devzaak commented on GitHub (Jul 13, 2020): Thanks for the unit test and regex idea. One thing I am curious about is in what cases does one want in url to have query param multiple times with different values. I know that some languages process multiple query string keys differently. PHP takes only the first one unless it is array, c# does array and so on. ps. if match operator option is something that can be done, happy to make a PR for it. Cheers
Author
Owner

@StefH commented on GitHub (Jul 13, 2020):

Multiple times the same param or single param with multiple values is the same.

So
?limit=1,2

Is same as
?limit=1&limit=2

You can try to make PR however this involves a lot if API changes and internal changes.

@StefH commented on GitHub (Jul 13, 2020): Multiple times the same param or single param with multiple values is the same. So ?limit=1,2 Is same as ?limit=1&limit=2 You can try to make PR however this involves a lot if API changes and internal changes.
Author
Owner

@devzaak commented on GitHub (Jul 13, 2020):

Thanks for the head up, haven't looked much into internals yet.
I think for now you can definitely close this issue, got the answers I was after, and will see when I have time how much changes the operator would involve.
Thanks for the quick reply!

@devzaak commented on GitHub (Jul 13, 2020): Thanks for the head up, haven't looked much into internals yet. I think for now you can definitely close this issue, got the answers I was after, and will see when I have time how much changes the operator would involve. Thanks for the quick reply!
Author
Owner

@StefH commented on GitHub (Jul 14, 2020):

I'll keep this open for now and see if I can add this somewhere in the documentation.
And I'll check the changes needed.

@StefH commented on GitHub (Jul 14, 2020): I'll keep this open for now and see if I can add this somewhere in the documentation. And I'll check the changes needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#281