コード例 #1
0
        public Scenario ExtractScenario(global::Gherkin.Ast.Scenario scenario)
        {
            if (scenario == null)
            {
                throw new ArgumentNullException(nameof(scenario));
            }

            var steps = ExtractSteps(scenario);

            return(new Scenario(steps));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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));
        }