public Scenario ExtractScenario(global::Gherkin.Ast.Scenario scenario) { if (scenario == null) { throw new ArgumentNullException(nameof(scenario)); } var steps = ExtractSteps(scenario); return(new Scenario(steps)); }
public Scenario ExtractScenario(global::Gherkin.Ast.Scenario scenario, global::Gherkin.Ast.Background background) { if (scenario == null) { throw new ArgumentNullException(nameof(scenario)); } var steps = ExtractSteps(scenario); if (background != null) { steps = ExtractSteps(background).Concat(steps).ToList(); } return(new Scenario(scenario.Name, steps)); }
public Scenario ExtractScenario(global::Gherkin.Ast.Scenario gherkinScenario) { if (gherkinScenario == null) { throw new ArgumentNullException(nameof(gherkinScenario)); } var matchingStepMethods = gherkinScenario.Steps .Select(gherkingScenarioStep => { var matchingStepMethodInfo = _stepMethods.FirstOrDefault(stepMethodInfo => IsStepMethodInfoAMatch(gherkingScenarioStep, stepMethodInfo)); if (matchingStepMethodInfo == null) { throw new InvalidOperationException($"Cannot match any method with step `{gherkingScenarioStep.Keyword.Trim()} {gherkingScenarioStep.Text.Trim()}`. Scenario `{gherkinScenario.Name}`."); } var stepMethod = StepMethod.FromStepMethodInfo(matchingStepMethodInfo, gherkingScenarioStep); return(stepMethod); }) .ToList(); return(new Scenario(matchingStepMethods)); bool IsStepMethodInfoAMatch(global::Gherkin.Ast.Step gherkinScenarioStep, StepMethodInfo stepMethod) { var gherkinStepText = gherkinScenarioStep.Text.Trim(); foreach (var pattern in stepMethod.ScenarioStepPatterns) { if (!pattern.Kind.ToString().Equals(gherkinScenarioStep.Keyword.Trim(), StringComparison.OrdinalIgnoreCase)) { continue; } var match = Regex.Match(gherkinStepText, pattern.Pattern); if (!match.Success || !match.Value.Equals(gherkinStepText)) { continue; } return(true); } return(false); } }
public static global::Gherkin.Ast.Scenario ApplyBackground( this global::Gherkin.Ast.Scenario @this, global::Gherkin.Ast.Background background) { if (background == null) { throw new ArgumentNullException(nameof(background)); } var stepsWithBackground = background.Steps.Concat(@this.Steps).ToArray(); return(new global::Gherkin.Ast.Scenario( @this.Tags.ToArray(), @this.Location, @this.Keyword, @this.Name, @this.Description, stepsWithBackground)); }