When using C# code generation WithBody() matcher is not generated for POST Request #593

Closed
opened 2025-12-29 08:30:42 +01:00 by adam · 3 comments
Owner

Originally created by @asos-alexhaigh on GitHub (May 1, 2024).

Originally assigned to: @StefH on GitHub.

Describe the bug

When you generate C# code using MappingConverterType=Builder the created code doesn't contains .WithBody for the request.

Expected behavior:

A clear and concise description of what you expected to happen.

Test to reproduce

  • 1 Record a POST request with a JSON body
  • 2 In __admin\mappings Observer the JSON file generated has a Body Matcher defined
  "Request": {
    "Path": {
      "Matchers": [
        {
          "Name": "WildcardMatcher",
          "Pattern": "/rest/v4/users",
          "IgnoreCase": false
        }
      ]
    },
    "Methods": [
      "POST"
    ],
    "Body": {
      "Matcher": {
        "Name": "JsonMatcher",
        "Pattern": {
          "addressLine1": "123 Main Street",
          "city": "New York",
          "clientUserId": "integration-test-user-1",
          "country": "US",
          "dateOfBirth": "1980-01-01",
          "email": "integrationtestuser1@company.com",
          "firstName": "Alex",
          "lastName": "Test",
          "postalCode": "10016",
          "profileType": "BUSINESS",
          "businessName": "Integration Test 1",
          "programToken": "prg-3f63490c-e249-46e7-97f5-31c725d51f3a",
          "stateProvince": "NY"
        },
        "IgnoreCase": true,
        "Regex": false
      }
    }
  },
  • 3 Make a GET request to http://localhost:9095/__admin/mappings/code?MappingConverterType=Builder
  • 4 Observe C# code doesn't have Body match on Request
        builder
            .Given(Request.Create()
                .UsingMethod("POST")
                .WithPath("/rest/v4/users")
                .WithHeader("Accept", "*/*", true)
                .WithHeader("Connection", "keep-alive", true)
                .WithHeader("User-Agent", "PostmanRuntime/7.37.3", true)
                .WithHeader("Accept-Encoding", "gzip, deflate, br", true)
                .WithHeader("Content-Type", "application/json", true)
                .WithHeader("Content-Length", "443", true)
                .WithHttpVersion("1.1")
            )
            .WithGuid("66cb85f5-6a2c-4f67-b685-3fcb9275e17a");
Originally created by @asos-alexhaigh on GitHub (May 1, 2024). Originally assigned to: @StefH on GitHub. ### Describe the bug When you generate C# code using `MappingConverterType=Builder` the created code doesn't contains `.WithBody` for the request. ### Expected behavior: A clear and concise description of what you expected to happen. ### Test to reproduce - 1 Record a POST request with a JSON body - 2 In `__admin\mappings` Observer the JSON file generated has a Body Matcher defined ``` json "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/rest/v4/users", "IgnoreCase": false } ] }, "Methods": [ "POST" ], "Body": { "Matcher": { "Name": "JsonMatcher", "Pattern": { "addressLine1": "123 Main Street", "city": "New York", "clientUserId": "integration-test-user-1", "country": "US", "dateOfBirth": "1980-01-01", "email": "integrationtestuser1@company.com", "firstName": "Alex", "lastName": "Test", "postalCode": "10016", "profileType": "BUSINESS", "businessName": "Integration Test 1", "programToken": "prg-3f63490c-e249-46e7-97f5-31c725d51f3a", "stateProvince": "NY" }, "IgnoreCase": true, "Regex": false } } }, ``` - 3 Make a GET request to `http://localhost:9095/__admin/mappings/code?MappingConverterType=Builder` - 4 Observe C# code doesn't have Body match on Request ``` c# builder .Given(Request.Create() .UsingMethod("POST") .WithPath("/rest/v4/users") .WithHeader("Accept", "*/*", true) .WithHeader("Connection", "keep-alive", true) .WithHeader("User-Agent", "PostmanRuntime/7.37.3", true) .WithHeader("Accept-Encoding", "gzip, deflate, br", true) .WithHeader("Content-Type", "application/json", true) .WithHeader("Content-Length", "443", true) .WithHttpVersion("1.1") ) .WithGuid("66cb85f5-6a2c-4f67-b685-3fcb9275e17a"); ```
adam added the bug label 2025-12-29 08:30:42 +01:00
adam closed this issue 2025-12-29 08:30:42 +01:00
Author
Owner

@StefH commented on GitHub (May 3, 2024):

Thanks for the detailed description, I'll take look.

@StefH commented on GitHub (May 3, 2024): Thanks for the detailed description, I'll take look.
Author
Owner

@StefH commented on GitHub (May 8, 2024):

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

@StefH commented on GitHub (May 8, 2024): https://github.com/WireMock-Net/WireMock.Net/pull/1101
Author
Owner

@StefH commented on GitHub (May 8, 2024):

Solved

@StefH commented on GitHub (May 8, 2024): Solved
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#593