WithParam not working. #629

Closed
opened 2025-12-29 08:31:26 +01:00 by adam · 4 comments
Owner

Originally created by @hmiguel on GitHub (Sep 2, 2024).

Hello,

I'm trying to do a mock with 'WithParam', but seems like it's not working.

using WireMock.Matchers;
using WireMock.Server;

var client = new HttpClient();
var server = WireMockServer.Start();

server.Given(
    WireMock.RequestBuilders.Request.Create()
    .WithPath("/test")
        .UsingGet()
        .WithParam("filters", new ExactMatcher("a:b,c:d"))
    )
    .RespondWith(
        WireMock.ResponseBuilders.Response.Create()
           .WithHeader("Content-Type", "application/json")
           .WithStatusCode(200)
           .WithDelay(TimeSpan.FromMilliseconds(50))
    );

var response = await client.GetAsync($"http://localhost:{server.Port}/test?filters=a:b,c:d");

Console.WriteLine("Response: " + response.StatusCode);

Result

Mock not found.

Expected Result

Mock found.

Originally created by @hmiguel on GitHub (Sep 2, 2024). Hello, I'm trying to do a mock with 'WithParam', but seems like it's not working. ```csharp using WireMock.Matchers; using WireMock.Server; var client = new HttpClient(); var server = WireMockServer.Start(); server.Given( WireMock.RequestBuilders.Request.Create() .WithPath("/test") .UsingGet() .WithParam("filters", new ExactMatcher("a:b,c:d")) ) .RespondWith( WireMock.ResponseBuilders.Response.Create() .WithHeader("Content-Type", "application/json") .WithStatusCode(200) .WithDelay(TimeSpan.FromMilliseconds(50)) ); var response = await client.GetAsync($"http://localhost:{server.Port}/test?filters=a:b,c:d"); Console.WriteLine("Response: " + response.StatusCode); ``` ### Result Mock not found. ### Expected Result Mock found.
adam added the bug label 2025-12-29 08:31:26 +01:00
adam closed this issue 2025-12-29 08:31:27 +01:00
Author
Owner

@StefH commented on GitHub (Sep 4, 2024):

In that case, you should use:

var settings = new WireMockServerSettings
        {
            QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma
        };
        var server = WireMockServer.Start(settings);
@StefH commented on GitHub (Sep 4, 2024): In that case, you should use: ``` c# var settings = new WireMockServerSettings { QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma }; var server = WireMockServer.Start(settings); ```
Author
Owner

@hmiguel commented on GitHub (Sep 4, 2024):

Ok, that setting works with Wiremock.Server, but seems like it's not working with container.

var container = await WiremockContainer.Launch();  //  sheyenrath/wiremock.net:latest
var api = RestClient.For<IWireMockAdminApi>($"http://localhost:2080");
await api.PostSettingsAsync(new WireMock.Admin.Settings.SettingsModel
{
    QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma
});

var filter = "a:b,c:d";
var builder = api.GetMappingBuilder();

var paramModel = new ParamModel
{
    Name = "filters",
    Matchers = [ new MatcherModel { Name = "ExactMatcher", Pattern = filter } ]

};

builder.Given(m=>
{
    m.WithRequest(r =>
    {
        r.WithPath("/test");
        r.UsingGet();
        r.WithParams(x => x.Add(paramModel));
    });

    m.WithResponse(r =>
    {
        r.WithStatusCode(200);
        r.WithDelay(TimeSpan.FromMilliseconds(50));
    });
});

var result = await builder.BuildAndPostAsync().ConfigureAwait(false);

var client = new HttpClient();
var response = await client.GetAsync($"http://localhost:2080/test?filters={filter}");

Console.WriteLine("Response: " + response.StatusCode);

await container.StopAsync();
@hmiguel commented on GitHub (Sep 4, 2024): Ok, that setting works with Wiremock.Server, but seems like it's not working with container. ```csharp var container = await WiremockContainer.Launch(); // sheyenrath/wiremock.net:latest var api = RestClient.For<IWireMockAdminApi>($"http://localhost:2080"); await api.PostSettingsAsync(new WireMock.Admin.Settings.SettingsModel { QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma }); var filter = "a:b,c:d"; var builder = api.GetMappingBuilder(); var paramModel = new ParamModel { Name = "filters", Matchers = [ new MatcherModel { Name = "ExactMatcher", Pattern = filter } ] }; builder.Given(m=> { m.WithRequest(r => { r.WithPath("/test"); r.UsingGet(); r.WithParams(x => x.Add(paramModel)); }); m.WithResponse(r => { r.WithStatusCode(200); r.WithDelay(TimeSpan.FromMilliseconds(50)); }); }); var result = await builder.BuildAndPostAsync().ConfigureAwait(false); var client = new HttpClient(); var response = await client.GetAsync($"http://localhost:2080/test?filters={filter}"); Console.WriteLine("Response: " + response.StatusCode); await container.StopAsync(); ```
Author
Owner

@StefH commented on GitHub (Sep 4, 2024):

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

@StefH commented on GitHub (Sep 4, 2024): https://github.com/WireMock-Net/WireMock.Net/pull/1166
Author
Owner

@StefH commented on GitHub (Sep 4, 2024):

A new version will be released soon.

@StefH commented on GitHub (Sep 4, 2024): A new version will be released soon.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#629