Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
benjamin-bader opened this issue Jun 28, 2018 · 6 comments
Closed

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

benjamin-bader opened this issue Jun 28, 2018 · 6 comments
Assignees
Labels

Comments

@benjamin-bader
Copy link

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"] = "[email protected]",
                ["results"] = new object[0]
            }));

The test issues an HTTP request like GET /api/incidents/[email protected]. 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", "[email protected]"), it works.

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

@StefH StefH self-assigned this Jun 28, 2018
@StefH StefH added the bug label Jun 28, 2018
@StefH
Copy link
Collaborator

StefH commented Jun 28, 2018

This seems like a bug, I'll investigate.

StefH added a commit that referenced this issue Jun 28, 2018
@StefH
Copy link
Collaborator

StefH commented 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

@benjamin-bader
Copy link
Author

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

@StefH
Copy link
Collaborator

StefH commented 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 StefH changed the title IRequestBuilder.WithParam broken for key-only matching? BUg: IRequestBuilder.WithParam broken for key-only matching Jun 29, 2018
@benjamin-bader
Copy link
Author

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

@StefH StefH changed the title BUg: IRequestBuilder.WithParam broken for key-only matching Bug: IRequestBuilder.WithParam broken for key-only matching Jun 29, 2018
@StefH
Copy link
Collaborator

StefH commented Jun 29, 2018

NuGet is created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants