コード例 #1
0
        private List <StepMethod> ExtractSteps(global::Gherkin.Ast.ScenarioDefinition gherkinScenario)
        {
            if (gherkinScenario == null)
            {
                throw new ArgumentNullException(nameof(gherkinScenario));
            }

            return(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());

            bool IsStepMethodInfoAMatch(global::Gherkin.Ast.Step gherkinScenarioStep, StepMethodInfo stepMethod)
            {
                var gherkinStepText = gherkinScenarioStep.Text.Trim();
                var gherkinKeyword  = gherkinScenarioStep.Keyword.Trim();

                if (gherkinKeyword == "*")
                {
                    gherkinKeyword = "Star";
                }

                foreach (var pattern in stepMethod.ScenarioStepPatterns)
                {
                    if (!pattern.Kind.ToString().Equals(gherkinKeyword, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    var match = Regex.Match(gherkinStepText, pattern.Pattern);
                    if (!match.Success || !match.Value.Equals(gherkinStepText))
                    {
                        continue;
                    }

                    return(true);
                }

                return(false);
            }
        }
コード例 #2
0
        private List <StepMethod> ExtractSteps(global::Gherkin.Ast.ScenarioDefinition gherkinScenario)
        {
            if (gherkinScenario == null)
            {
                throw new ArgumentNullException(nameof(gherkinScenario));
            }

            return(gherkinScenario.Steps
                   .Select(gherkingScenarioStep =>
            {
                var matchingStepMethodInfo = _stepMethods.FirstOrDefault(stepMethodInfo => stepMethodInfo.Matches(gherkingScenarioStep));
                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());
        }