Skip to content

Commit

Permalink
#23: BDD: Added private method.
Browse files Browse the repository at this point in the history
This simplifies XUnit test generation from Gherkin feature document.
  • Loading branch information
MarcinCelej committed Jan 18, 2024
1 parent 1e700a0 commit b33b6f3
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,7 @@ private void Generate(StringBuilder code, Scenario scenario, string? backgroundM
string displayName = scenarioOriginalTitle.Replace("\"", "\\\"");
if (scenario is ScenarioOutline)
{
Examples examples = ((ScenarioOutline) scenario).Examples;
arguments = "string " + string.Join(", string ", examples.Header.Values.Select(argument => Sentence.ToArgument(argument)));
code.AppendLine($" [Xunit.Theory(DisplayName = \"{displayName}\")]");

foreach (var row in examples.Rows)
{
code.AppendLine($" [Xunit.InlineData(\"{string.Join("\", \"", row.Values)}\")]");
}
arguments = GenerateScenarioOutlineAsXunitTheory();
}
else
{
Expand Down Expand Up @@ -151,6 +144,20 @@ private void Generate(StringBuilder code, Scenario scenario, string? backgroundM

code.AppendLine(" }");
code.AppendLine();

string GenerateScenarioOutlineAsXunitTheory()
{
Examples examples = ((ScenarioOutline) scenario).Examples;
arguments = "string " + string.Join(", string ", examples.Header.Values.Select(argument => Sentence.ToArgument(argument)));
code.AppendLine($" [Xunit.Theory(DisplayName = \"{displayName}\")]");

foreach (var row in examples.Rows)
{
code.AppendLine($" [Xunit.InlineData(\"{string.Join("\", \"", row.Values)}\")]");
}

return arguments;
}
}

private void GenerateSteps(StringBuilder code, List<Step> steps)
Expand Down

0 comments on commit b33b6f3

Please sign in to comment.