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

* Fix #1501: Generate WhenStateIs/WillSetStateTo correctly in ToCSharpCode

* Fix matcher to code converters. Refactor changes.

* Adjust test artifacts.

* Return fully qualified class names for matchers
This commit is contained in:
Dmytro Nikitin
2026-08-19 19:58:47 +02:00
committed by GitHub
parent 42353f035e
commit 2b165eb6a1
40 changed files with 334 additions and 113 deletions
@@ -146,7 +146,7 @@ internal class MappingConverter(MatcherMapper mapper)
case JsonMatcher jsonMatcher:
{
var matcherType = jsonMatcher.GetType().Name;
var matcherType = jsonMatcher.GetType().FullName;
sb.AppendLine($" .WithBody(new {matcherType}(");
sb.AppendLine($" value: {ConvertToAnonymousObjectDefinition(jsonMatcher.Value, 3)},");
sb.AppendLine($" ignoreCase: {ToCSharpBooleanLiteral(jsonMatcher.IgnoreCase)},");
@@ -162,14 +162,18 @@ internal class MappingConverter(MatcherMapper mapper)
// Guid
sb.AppendLine($" .WithGuid(\"{mapping.Guid}\")");
// Scenario + State
// Scenario, ExecutionConditionState, NextState and StateTimes
if (!string.IsNullOrEmpty(mapping.Scenario))
{
sb.AppendLine($" .InScenario({ToCSharpStringLiteral(mapping.Scenario)})");
}
if (!string.IsNullOrEmpty(mapping.ExecutionConditionState))
{
sb.AppendLine($" .WhenStateIs({ToCSharpStringLiteral(mapping.ExecutionConditionState)})");
}
if (!string.IsNullOrEmpty(mapping.NextState))
{
sb.AppendLine($" .WhenStateIs({ToCSharpStringLiteral(mapping.NextState)}, {ToCSharpIntLiteral(mapping.TimesInSameState)})");
sb.AppendLine($" .WillSetStateTo({ToCSharpStringLiteral(mapping.NextState)}, {ToCSharpIntLiteral(mapping.TimesInSameState)})");
}
if (mapping.Probability != null)