Skip to content

Fix #1501: Generate WhenStateIs/WillSetStateTo correctly in ToCSharpCode - #1502

Merged
StefH merged 4 commits into
wiremock:masterfrom
Bafyn:fix/mappings-code-scenario-state
Aug 19, 2026
Merged

Fix #1501: Generate WhenStateIs/WillSetStateTo correctly in ToCSharpCode#1502
StefH merged 4 commits into
wiremock:masterfrom
Bafyn:fix/mappings-code-scenario-state

Conversation

@Bafyn

@Bafyn Bafyn commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

MappingConverter.ToCSharpCode generated broken code for stateful (Scenario) mappings: it emitted .WhenStateIs(NextState, TimesInSameState), which has no matching overload (does not compile), used NextState under WhenStateIs, and never emitted the actual ExecutionConditionState.

References

Fixes #1501

Submitter checklist

  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected

Tests

  • Added two MappingConverterTests.ToCSharpCode cases;
  • Corrected two MappingBuilderTests.ToCSharpCode verified snapshots.

@StefH

StefH commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

I just started also on this....

@StefH

StefH commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

@Bafyn
Can you also update the Wildcardmatcher code to:

public override string GetCSharpCodeArguments()
{
    return
        $"new {Name}" +
        $"(" +
        $"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
        $"new AnyOf<string, StringPattern>[] {{ {MappingConverterUtils.ToCSharpCodeArguments(_patterns)} }}, " +
        $"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
        $"{MatchOperator.GetFullyQualifiedEnumValue()}" +
        $")";
}

@Bafyn

Bafyn commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@StefH I realized you did when I noticed you assigned the issue to yourself 🙃
I can also look into this thing you mentioned #1501 (comment)

UPD: yes, checking

Comment thread src/WireMock.Net.Minimal/Serialization/MappingConverter.cs
Comment thread src/WireMock.Net.Minimal/Serialization/MappingConverter.cs Outdated
@Bafyn

Bafyn commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

FYI @StefH the other matchers had the same issues. Fixed them in scope of the latest update

@Bafyn
Bafyn force-pushed the fix/mappings-code-scenario-state branch from c804ec4 to 5cc3d42 Compare August 18, 2026 14:53
@Bafyn
Bafyn force-pushed the fix/mappings-code-scenario-state branch from 5cc3d42 to e9deb0b Compare August 18, 2026 15:16
Comment thread src/WireMock.Net.Minimal/Matchers/ContentTypeMatcher.cs Outdated
@StefH

StefH commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Added comment.

And if you have fixed an issue, you can "resolve conversation" here in the github.

@Bafyn
Bafyn marked this pull request as draft August 18, 2026 20:28
@Bafyn
Bafyn marked this pull request as ready for review August 18, 2026 20:28
@StefH
StefH merged commit 2b165eb into wiremock:master Aug 19, 2026
7 of 8 checks passed
@Bafyn
Bafyn deleted the fix/mappings-code-scenario-state branch August 19, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated C# code for stateful (Scenario) mappings does not compile and drops the WhenStateIs condition

2 participants