Is it possible using post method with query parameters request matching? #261

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

Originally created by @shockliang on GitHub (Mar 22, 2020).

var name = "myGroup";
mockServer
    .Given(Request.Create()
        .WithPath("/api/v4/groups")
        .WithHeader("PRIVATE-TOKEN", token)
        .WithParam("name", name)
        .UsingPost())
    .RespondWith(Response.Create()
        .WithHeader("Content-Type", "application/json")
        .WithStatusCode(HttpStatusCode.Created)
        .WithBody(json));

I'm implementing create group for gitlab server [doc] and trying write tests to verify some cases.
Above simple code that doesn't work when using WithParam as request matching .
So... Any way to verify post with query parameters?

Originally created by @shockliang on GitHub (Mar 22, 2020). ``` c# var name = "myGroup"; mockServer .Given(Request.Create() .WithPath("/api/v4/groups") .WithHeader("PRIVATE-TOKEN", token) .WithParam("name", name) .UsingPost()) .RespondWith(Response.Create() .WithHeader("Content-Type", "application/json") .WithStatusCode(HttpStatusCode.Created) .WithBody(json)); ``` I'm implementing create group for gitlab server [[doc](https://docs.gitlab.com/ee/api/groups.html#new-group)] and trying write tests to verify some cases. Above simple code that doesn't work when using `WithParam` as request matching . So... Any way to verify post with query parameters?
adam added the question label 2025-12-29 08:25:00 +01:00
adam closed this issue 2025-12-29 08:25:00 +01:00
Author
Owner

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

This should be possible, see https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs#L496

Result:
image

@StefH commented on GitHub (Mar 22, 2020): This should be possible, see https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs#L496 Result: ![image](https://user-images.githubusercontent.com/249938/77247840-32d35a80-6c35-11ea-85c1-2460cb19fc9c.png)
Author
Owner

@shockliang commented on GitHub (Mar 22, 2020):

My environment:
OS: mac os 10.14.6
dotnet version: dotnet core 3.0.

I got the response with Not Found and content {"Status":"No matching mapping found"}

@shockliang commented on GitHub (Mar 22, 2020): My environment: OS: mac os 10.14.6 dotnet version: dotnet core 3.0. I got the response with `Not Found` and content `{"Status":"No matching mapping found"}`
Author
Owner

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

What you can do to debug, is set AllowPartialMapping to true in the WireMockServerSettings
https://github.com/WireMock-Net/WireMock.Net/wiki/Settings#allowpartialmapping

When you look at the logging from the running application, you can see which elements have a score from 1.0 (=100% match)
image

(I just added a netcore3.1 example to this repository, that one also does work fine.)

@StefH commented on GitHub (Mar 22, 2020): What you can do to debug, is set `AllowPartialMapping` to true in the WireMockServerSettings https://github.com/WireMock-Net/WireMock.Net/wiki/Settings#allowpartialmapping When you look at the logging from the running application, you can see which elements have a score from 1.0 (=100% match) ![image](https://user-images.githubusercontent.com/249938/77250074-b5fcac80-6c45-11ea-8830-6903e0ff79ad.png) (I just added a netcore3.1 example to this repository, that one also does work fine.)
Author
Owner

@shockliang commented on GitHub (Mar 22, 2020):

It's work after setting AllowPartialMapping to be true.
But the request matching doesn't work. The match details show me the score of RequestMessageParamMatcher still zero.
Is it normally when setting AllowPartialMapping to be true?

MatchDetails
@shockliang commented on GitHub (Mar 22, 2020): It's work after setting `AllowPartialMapping` to be true. But the request matching doesn't work. The match details show me the score of `RequestMessageParamMatcher` still zero. Is it normally when setting `AllowPartialMapping` to be true? <img width="775" alt="MatchDetails" src="https://user-images.githubusercontent.com/4479699/77254005-2c76ca00-6c99-11ea-8811-4b3b2fd27586.png">
Author
Owner

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

Can you please provide details on the complete request you send? Because from the logging it seems you provide multiple parameters?

@StefH commented on GitHub (Mar 22, 2020): Can you please provide details on the complete request you send? Because from the logging it seems you provide multiple parameters?
Author
Owner

@shockliang commented on GitHub (Mar 23, 2020):

Yes, the actual code I'm using 4 parameters. I'm sorry about that.
I'm using RestSharp as http client.
This is my actual code.

        public async Task<Group> CreateSubGroup(
            string name,
            string path,
            int parentId,
            Uri host,
            string visibility = Visibility.Private)
        {
            var client = new RestClient(new Uri(host, "api/v4"));
            var request = new RestRequest($"groups", Method.POST, DataFormat.Json);
            request
                .AddHeader("PRIVATE-TOKEN", token)
                .AddParameter("name", name)
                .AddParameter("path", path)
                .AddParameter("visibility", visibility)
                .AddParameter("parent_id", parentId);

            return await client.PostAsync<Group>(request);
        }
@shockliang commented on GitHub (Mar 23, 2020): Yes, the actual code I'm using 4 parameters. I'm sorry about that. I'm using [RestSharp](https://github.com/restsharp/RestSharp) as http client. This is my actual code. ``` public async Task<Group> CreateSubGroup( string name, string path, int parentId, Uri host, string visibility = Visibility.Private) { var client = new RestClient(new Uri(host, "api/v4")); var request = new RestRequest($"groups", Method.POST, DataFormat.Json); request .AddHeader("PRIVATE-TOKEN", token) .AddParameter("name", name) .AddParameter("path", path) .AddParameter("visibility", visibility) .AddParameter("parent_id", parentId); return await client.PostAsync<Group>(request); } ```
Author
Owner

@StefH commented on GitHub (Mar 23, 2020):

When using 4 params (see updated code https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs#L496)
And using postman, this works fine:
image

@StefH commented on GitHub (Mar 23, 2020): When using 4 params (see updated code https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs#L496) And using postman, this works fine: ![image](https://user-images.githubusercontent.com/249938/77294331-628d6b80-6ce4-11ea-9fc9-33915d39b423.png)
Author
Owner

@shockliang commented on GitHub (Mar 24, 2020):

OK! I will keeping investigate my cases. Thank for your helping! 👍

@shockliang commented on GitHub (Mar 24, 2020): OK! I will keeping investigate my cases. Thank for your helping! 👍
Author
Owner

@StefH commented on GitHub (Apr 1, 2020):

Closing this issue.
If you still have problems, just reply here or create a new issue.

@StefH commented on GitHub (Apr 1, 2020): Closing this issue. If you still have problems, just reply here or create a new issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#261