You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generated C# code for stateful (Scenario) mappings does not compile and drops the WhenStateIs condition #1501
The C# code generator exposed via GET /__admin/mappings/code produces incorrect code for any mapping that uses a Scenario/State.
For a mapping configured with .WhenStateIs(...) and/or .WillSetStateTo(...), the generator emits:
.WhenStateIs("<NextState>",<TimesInSameState>)
This is wrong in two ways:
It does not compile. There is no WhenStateIs(string, int) overload, only WhenStateIs(string) and WhenStateIs(int) exist. So the generated code cannot be pasted back into a project and built.
It silently drops the execution condition. The mapping's actual WhenStateIs value is never emitted at all, so the condition disappears from the generated code.
Steps to reproduce
varserver=WireMockServer.StartWithAdminInterface();// A stateful (Scenario) mapping:// - only eligible when the scenario "checkout" is in state "StepA"// - moves the scenario to state "StepB" after it has matched twiceserver.Given(Request.Create().WithPath("/order").UsingGet()).InScenario("checkout").WhenStateIs("StepA").WillSetStateTo("StepB",2).RespondWith(Response.Create().WithSuccess());// Generate the equivalent C# code for the mappings.usingvarhttp=newHttpClient();varcode=awaithttp.GetStringAsync($"{server.Url}/__admin/mappings/code");Console.WriteLine(code);
The generated output contains:
server.Given(Request.Create().UsingMethod("GET").WithPath(...)).WithGuid("...").InScenario("checkout").WhenStateIs("StepB",2)// does not compile; wrong value; "StepA" is lost.RespondWith(Response.Create().WithStatusCode(200));
Trying to compile the generated snippet fails, e.g.:
error CS1501: No overload for method 'WhenStateIs' takes 2 arguments
Expected behavior
The generated code should reconstruct the original mapping and compile as-is:
Activity
StefH commentedon Aug 17, 2026
Thanks.
I noted that there is also error in WithPath using WildcardMatcher
Fix wiremock#1501: Generate WhenStateIs/WillSetStateTo correctly in T…