Bug: IRequestBuilder.WithParam broken for key-only matching #117

Closed
opened 2025-12-29 08:22:29 +01:00 by adam · 6 comments
Owner

Originally created by @benjamin-bader on GitHub (Jun 28, 2018).

Originally assigned to: @StefH on GitHub.

I just upgraded our wiremock-net from 1.0.2.3 to 1.0.4.2 and noticed that a few tests that were working have broken. This request matcher no longer works:

server.Given(Request.Create()
            .WithPath("/api/incidents/search")
            .WithParam("q")
            .UsingGet())
        .RespondWith(Response.Create()
            .WithStatusCode(200)
            .WithBodyAsJson(new Dictionary<string, object>
            {
                ["text"] = "frank@contoso.com",
                ["results"] = new object[0]
            }));

The test issues an HTTP request like GET /api/incidents/search?q=frank@contoso.com. In 1.0.2.3, this request was matched by the server, but not in 1.0.4.2. If I change the builder such that I call .WithParam("q", "frank@contoso.com"), it works.

This seems like a regression, given that the API hasn't changed as far as I can tell.

Originally created by @benjamin-bader on GitHub (Jun 28, 2018). Originally assigned to: @StefH on GitHub. I just upgraded our wiremock-net from `1.0.2.3` to `1.0.4.2` and noticed that a few tests that were working have broken. This request matcher no longer works: ``` server.Given(Request.Create() .WithPath("/api/incidents/search") .WithParam("q") .UsingGet()) .RespondWith(Response.Create() .WithStatusCode(200) .WithBodyAsJson(new Dictionary<string, object> { ["text"] = "frank@contoso.com", ["results"] = new object[0] })); ``` The test issues an HTTP request like `GET /api/incidents/search?q=frank@contoso.com`. In `1.0.2.3`, this request was matched by the server, but not in `1.0.4.2`. If I change the builder such that I call `.WithParam("q", "frank@contoso.com")`, it works. This seems like a regression, given that the API hasn't changed as far as I can tell.
adam added the bug label 2025-12-29 08:22:29 +01:00
adam closed this issue 2025-12-29 08:22:29 +01:00
Author
Owner

@StefH commented on GitHub (Jun 28, 2018):

This seems like a bug, I'll investigate.

@StefH commented on GitHub (Jun 28, 2018): This seems like a bug, I'll investigate.
Author
Owner

@StefH commented on GitHub (Jun 28, 2018):

New code can be used like:

server
	.Given(Request
		.Create()
		.WithPath(new WildcardMatcher("/param2", true))
		.WithParam("key", "test")
		.UsingGet())
	.RespondWith(Response.Create()
		.WithHeader("Content-Type", "application/json")
		.WithBodyAsJson(new { result = "param2" }));

server
	.Given(Request
		.Create()
		.WithPath(new WildcardMatcher("/param3", true))
		.WithParam("key", new WildcardMatcher("t*"))
		.UsingGet())
	.RespondWith(Response.Create()
		.WithHeader("Content-Type", "application/json")
		.WithBodyAsJson(new { result = "param3" }));

See also linked code or branch : https://github.com/WireMock-Net/WireMock.Net/tree/Fix_IRequestBuilder.WithParam

@StefH commented on GitHub (Jun 28, 2018): New code can be used like: ``` c# server .Given(Request .Create() .WithPath(new WildcardMatcher("/param2", true)) .WithParam("key", "test") .UsingGet()) .RespondWith(Response.Create() .WithHeader("Content-Type", "application/json") .WithBodyAsJson(new { result = "param2" })); server .Given(Request .Create() .WithPath(new WildcardMatcher("/param3", true)) .WithParam("key", new WildcardMatcher("t*")) .UsingGet()) .RespondWith(Response.Create() .WithHeader("Content-Type", "application/json") .WithBodyAsJson(new { result = "param3" })); ``` See also linked code or branch : https://github.com/WireMock-Net/WireMock.Net/tree/Fix_IRequestBuilder.WithParam
Author
Owner

@benjamin-bader commented on GitHub (Jun 29, 2018):

Cool, thanks. Looks like the original usage will work in the next release - is that correct?

@benjamin-bader commented on GitHub (Jun 29, 2018): Cool, thanks. Looks like the original usage will work in the next release - is that correct?
Author
Owner

@StefH commented on GitHub (Jun 29, 2018):

Correct the C# code will be backwards compatible.

However the mapping JSON be changed and looks like:

{
    "Guid": "63f84226-8c13-483f-946c-9008cca9555e",
    "Priority": 0,
    "Request": {
        "Path": {
            "Matchers": [
                {
                    "Name": "WildcardMatcher",
                    "Pattern": "/param3",
                    "IgnoreCase": true
                }
            ]
        },
        "Methods": [
            "get"
        ],
        "Params": [
            {
                "Name": "key",
                "Matchers": [
                    {
                        "Name": "WildcardMatcher",
                        "Pattern": "t*",
                        "IgnoreCase": false
                    }
                ]
            }
        ]
}

(You can use a WildcardMatcher, RegExMatcher, ExactMatcher or whatever.)

@StefH commented on GitHub (Jun 29, 2018): Correct the C# code will be backwards compatible. However the mapping JSON be changed and looks like: ``` js { "Guid": "63f84226-8c13-483f-946c-9008cca9555e", "Priority": 0, "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/param3", "IgnoreCase": true } ] }, "Methods": [ "get" ], "Params": [ { "Name": "key", "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "t*", "IgnoreCase": false } ] } ] } ``` (You can use a WildcardMatcher, RegExMatcher, ExactMatcher or whatever.)
Author
Owner

@benjamin-bader commented on GitHub (Jun 29, 2018):

Awesome - thanks for the advice and for the quick fix!

@benjamin-bader commented on GitHub (Jun 29, 2018): Awesome - thanks for the advice and for the quick fix!
Author
Owner

@StefH commented on GitHub (Jun 30, 2018):

NuGet is created

@StefH commented on GitHub (Jun 30, 2018): NuGet is created
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#117