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

MappingsToCSharpCode should use RegexMatcher when specified #1151

Closed
carlin-q-scott opened this issue Aug 5, 2024 · 3 comments
Closed

MappingsToCSharpCode should use RegexMatcher when specified #1151

carlin-q-scott opened this issue Aug 5, 2024 · 3 comments
Assignees
Labels

Comments

@carlin-q-scott
Copy link

Is your feature request related to a problem? Please describe.
I used the MappingsToCSharpCode on the WiremockServer class to get C# mappings for my json mocks and it did not respect the matchers. It assumed everything was an exact match.

My json defined mock:

{
  "Request": {
    "Methods": [
      "POST"
    ],
    "Path": "/auth",
    "Params": [
      {
        "Name": "clientId",
        "Matchers": [
          {
            "Name": "RegexMatcher",
            "Pattern": "^scenario_(.+)$"
          }
        ]
      }
    ]
  }
}

The resulting CSharpCode:

builder
    .Given(Request.Create()
        .UsingMethod("POST")
        .WithPath("/auth")
        .WithParam("clientId", $"^scenario_(.+)$")
    )

Describe the solution you'd like
If the Matcher.Name is RegexMatcher, then create a RegexMatcher instead of directly passing the pattern to the RequestBuilder method.

builder
    .Given(Request.Create()
        .UsingMethod("POST")
        .WithPath("/auth")
        .WithParam("clientId", new RegexMatcher($"^scenario_(.+)$"))
    )

Describe alternatives you've considered
Manually fixing the generated code.

Is your feature request supported by WireMock (java version)? Please provide details.
I don't think this relevant.

Additional context
Add any other context or screenshots about the feature request here.

@StefH
Copy link
Collaborator

StefH commented Aug 5, 2024

@carlin-q-scott
This is indeed invalid.
(ExactMatcher and LinqMatcher are also not correctly transformed)

However fixing this needs a complete rewrite from the generating logic...
(Currently the logic is defined in 1 class, but the knowledge about the parameters should be moved to the matcher itself...)

@StefH StefH added bug and removed feature labels Aug 5, 2024
@StefH StefH self-assigned this Aug 5, 2024
@StefH
Copy link
Collaborator

StefH commented Aug 6, 2024

#1152

@StefH
Copy link
Collaborator

StefH commented Aug 6, 2024

@carlin-q-scott
If you want, you can use preview 1.5.62-ci-19075 to test.

@StefH StefH closed this as completed Aug 27, 2024
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