Fluent API for RequestMessagePathMatcher with IgnoreCase flag #308

Closed
opened 2025-12-29 15:20:20 +01:00 by adam · 2 comments
Owner

Originally created by @devzaak on GitHub (Oct 22, 2020).

While writing tests with out of bounds client libraries I ran into an issue of the requests not matching due to being case sensitive. I know it is possible to configure this via JSON for the server. But I have not found a way to do that in fluent api:
Example:

MockService.Given(Request.Create().WithPath("/somePath").UsingGet()).RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK));

This will not match a request to .../somepath

Current workaround for this involves using a bit more code:

MockService.Given(Request.Create()
                         .WithPath(path => path.Equals($"/somePath", StringComparison.InvariantCultureIgnoreCase))
                         .UsingGet())
           .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK));

Solution would be to add behavior modification flag in the IRequestBuilder WithPath([NotNull] params string[] paths); as bool parameter IgnoreCase or alternatively StringComparison enum parameter.

If this would be an acceptable solution I can provide a PR for this feature.
Thanks!

Originally created by @devzaak on GitHub (Oct 22, 2020). While writing tests with out of bounds client libraries I ran into an issue of the requests not matching due to being case sensitive. I know it is possible to configure this via JSON for the server. But I have not found a way to do that in fluent api: Example: ```csharp MockService.Given(Request.Create().WithPath("/somePath").UsingGet()).RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); ``` This will not match a request to `.../somepath` Current workaround for this involves using a bit more code: ```csharp MockService.Given(Request.Create() .WithPath(path => path.Equals($"/somePath", StringComparison.InvariantCultureIgnoreCase)) .UsingGet()) .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); ``` Solution would be to add behavior modification flag in the `IRequestBuilder WithPath([NotNull] params string[] paths);` as `bool` parameter `IgnoreCase` or alternatively `StringComparison` enum parameter. If this would be an acceptable solution I can provide a PR for this feature. Thanks!
adam added the question label 2025-12-29 15:20:20 +01:00
adam closed this issue 2025-12-29 15:20:20 +01:00
Author
Owner

@StefH commented on GitHub (Oct 22, 2020):

Hello @aslezak,

As workaround you can use:

.WithPath(new WildcardMatcher("/somePath", true))

Would that be good enough for you?

@StefH commented on GitHub (Oct 22, 2020): Hello @aslezak, As workaround you can use: ``` c# .WithPath(new WildcardMatcher("/somePath", true)) ``` Would that be good enough for you?
Author
Owner

@devzaak commented on GitHub (Oct 22, 2020):

Ah, yes, didn't spot that overload,
That'll do, thanks!

@devzaak commented on GitHub (Oct 22, 2020): Ah, yes, didn't spot that overload, That'll do, thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#308