Exemplo n.º 1
0
        public List <Pickle> Compile(GherkinDocument gherkinDocument)
        {
            var     pickles = new List <Pickle>();
            Feature feature = gherkinDocument.Feature;

            if (feature == null)
            {
                return(pickles);
            }

            var featureTags     = feature.Tags;
            var backgroundSteps = new PickleStep[0];

            foreach (var scenarioDefinition in feature.Children)
            {
                if (scenarioDefinition is Background)
                {
                    backgroundSteps = PickleSteps(scenarioDefinition);
                }
                else if (scenarioDefinition is Scenario)
                {
                    CompileScenario(pickles, backgroundSteps, (Scenario)scenarioDefinition, featureTags, feature.Language);
                }
                else
                {
                    CompileScenarioOutline(pickles, backgroundSteps, (ScenarioOutline)scenarioDefinition, featureTags, feature.Language);
                }
            }
            return(pickles);
        }
Exemplo n.º 2
0
        public List <Pickle> Compile(GherkinDocument gherkinDocument)
        {
            var     pickles = new List <Pickle>();
            Feature feature = gherkinDocument.Feature;

            if (feature == null)
            {
                return(pickles);
            }

            var featureTags     = feature.Tags;
            var backgroundSteps = new PickleStep[0];

            foreach (var stepsContainer in feature.Children)
            {
                if (stepsContainer is Background)
                {
                    backgroundSteps = PickleSteps(stepsContainer);
                }
                else
                {
                    var scenario = (Scenario)stepsContainer;
                    if (!scenario.Examples.Any())
                    {
                        CompileScenario(pickles, backgroundSteps, scenario, featureTags, feature.Language);
                    }
                    else
                    {
                        CompileScenarioOutline(pickles, backgroundSteps, scenario, featureTags, feature.Language);
                    }
                }
            }
            return(pickles);
        }
Exemplo n.º 3
0
        protected virtual void CompileScenarioOutline(List <Pickle> pickles, IEnumerable <PickleStep> backgroundSteps, Scenario scenarioOutline, IEnumerable <Tag> featureTags, string language)
        {
            foreach (var examples in scenarioOutline.Examples)
            {
                if (examples.TableHeader == null)
                {
                    continue;
                }
                var variableCells = examples.TableHeader.Cells;
                foreach (var values in examples.TableBody)
                {
                    var valueCells = values.Cells;

                    var steps = new List <PickleStep>();
                    if (scenarioOutline.Steps.Any())
                    {
                        steps.AddRange(backgroundSteps);
                    }

                    var tags = new List <Tag>();
                    tags.AddRange(featureTags);
                    tags.AddRange(scenarioOutline.Tags);
                    tags.AddRange(examples.Tags);

                    foreach (var scenarioOutlineStep in scenarioOutline.Steps)
                    {
                        string stepText = Interpolate(scenarioOutlineStep.Text, variableCells, valueCells);

                        // TODO: Use an Array of location in DataTable/DocString as well.
                        // If the Gherkin AST classes supported
                        // a list of locations, we could just reuse the same classes

                        PickleStep pickleStep = CreatePickleStep(
                            scenarioOutlineStep,
                            stepText,
                            CreatePickleArguments(scenarioOutlineStep.Argument, variableCells, valueCells),
                            new[] {
                            PickleLocation(values.Location),
                            PickleStepLocation(scenarioOutlineStep)
                        }
                            );
                        steps.Add(pickleStep);
                    }

                    Pickle pickle = new Pickle(
                        Interpolate(scenarioOutline.Name, variableCells, valueCells),
                        language,
                        steps,
                        PickleTags(tags),
                        new[] {
                        PickleLocation(values.Location),
                        PickleLocation(scenarioOutline.Location)
                    }
                        );

                    pickles.Add(pickle);
                }
            }
        }
Exemplo n.º 4
0
        public List <Pickle> Compile(GherkinDocument gherkinDocument)
        {
            var     pickles = new List <Pickle>();
            Feature feature = gherkinDocument.Feature;

            if (feature == null)
            {
                return(pickles);
            }

            var language        = feature.Language;
            var tags            = feature.Tags;
            var backgroundSteps = new PickleStep[0];

            Build(pickles, language, tags, backgroundSteps, feature);

            return(pickles);
        }