Exemplo n.º 1
0
        public void ApplyExampleRow_Throws_Error_When_Example_Not_Found(
            string exampleName,
            int exampleRowIndex
            )
        {
            //arrange.
            var sut = new Gherkin.Ast.ScenarioOutline(
                null,
                null,
                null,
                "outline123",
                null,
                new Gherkin.Ast.Step[] { },
                new Gherkin.Ast.Examples[]
            {
                new Gherkin.Ast.Examples(
                    null,
                    null,
                    null,
                    "existing example",
                    null,
                    new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[] { }),
                    new Gherkin.Ast.TableRow[]
                {
                    new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[] { })
                })
            });

            //act / assert.
            Assert.Throws <InvalidOperationException>(() => sut.ApplyExampleRow(exampleName, exampleRowIndex));
        }
Exemplo n.º 2
0
        public static SpecFlowFeature CreateFeatureWithScenarioOutline(string[] tags = null, string[] scenarioOutlineTags = null, string[] examplesTags = null)
        {
            tags = tags ?? new string[0];

            var scenario1 = new ScenarioOutline(GetTags(scenarioOutlineTags), null, "Scenario Outline", "scenario outline1 title", "", new Step[0], new []
            {
                new Examples(GetTags(examplesTags), null, "Examples", "examples name", "", new Gherkin.Ast.TableRow(null, new []{ new TableCell(null, "col1"), }), new Gherkin.Ast.TableRow[0])
            });

            return new SpecFlowFeature(GetTags(tags), null, "en", "feature", "title", "desc", null, new ScenarioDefinition[] {scenario1}, new Comment[0], null);
        }
Exemplo n.º 3
0
 internal G.ScenarioOutline CreateScenarioOutline(string[] tags, string name, string description, G.Step[] steps, G.Examples[] examples)
 {
     G.ScenarioOutline scenarioOutline = new G.ScenarioOutline(
         tags.Select(this.CreateTag).ToArray(),
         AnyLocation,
         "Scenario",
         name,
         description,
         steps,
         examples);
     return(scenarioOutline);
 }
Exemplo n.º 4
0
        public ScenarioOutline MapToScenarioOutline(G.ScenarioOutline scenarioOutline)
        {
            if (scenarioOutline == null)
            {
                return(null);
            }

            return(new ScenarioOutline
            {
                Description = scenarioOutline.Description ?? string.Empty,
                Examples = (scenarioOutline.Examples ?? new G.Examples[0]).Select(this.MapToExample).ToList(),
                Location = this.MapToLocation(scenarioOutline.Location),
                Name = scenarioOutline.Name,
                Slug = scenarioOutline.Name.ToSlug(),
                Steps = scenarioOutline.Steps.Select(this.MapToStep).ToList(),
                Tags = scenarioOutline.Tags.Select(this.MapToString).ToList()
            });
        }
Exemplo n.º 5
0
        public ScenarioOutline MapToScenarioOutline(G.ScenarioOutline scenarioOutline, params string[] tagsToHide)
        {
            if (scenarioOutline == null)
            {
                return(null);
            }

            var visibleTags = RetrieveOnlyVisibleTags(scenarioOutline.Tags, tagsToHide);

            return(new ScenarioOutline
            {
                Description = scenarioOutline.Description ?? string.Empty,
                Examples = (scenarioOutline.Examples ?? new G.Examples[0]).Select(this.MapToExample).ToList(),
                Location = this.MapToLocation(scenarioOutline.Location),
                Name = scenarioOutline.Name,
                Slug = scenarioOutline.Name.ToSlug(),
                Steps = scenarioOutline.Steps.Select(this.MapToStep).ToList(),
                Tags = visibleTags
            });
        }
Exemplo n.º 6
0
 public ScenarioOutline MapToScenarioOutline(G.ScenarioOutline scenarioOutline)
 {
     return(this.mapper.Map <ScenarioOutline>(scenarioOutline));
 }
Exemplo n.º 7
0
 internal G.ScenarioOutline CreateScenarioOutline(string[] tags, string name, string description, G.Step[] steps, G.Examples[] examples)
 {
     G.ScenarioOutline scenarioOutline = new G.ScenarioOutline(
         tags.Select(this.CreateTag).ToArray(),
         AnyLocation,
         "Scenario",
         name,
         description,
         steps,
         examples);
     return scenarioOutline;
 }
        private IEnumerable<SpecFlowStep> CreateScenarioSteps(ScenarioOutline scenarioOutline, Dictionary<string, string> paramSubst)
        {
            var result = new List<SpecFlowStep>();
            foreach (var scenarioStep in scenarioOutline.Steps)
            {
                var specflowStep = (SpecFlowStep) scenarioStep;

                var stepArgument = specflowStep.Argument;
                if (specflowStep.Argument is DataTable)
                {
                    stepArgument = Clone((DataTable)specflowStep.Argument, (c) => GetReplacedText(c.Value, paramSubst));
                }

                var newStep = Clone(specflowStep, stepArgument);

                result.Add(newStep);
            }
            return result;
        }
        private IEnumerable<SpecFlowStep> CreateFirstExampleScenarioSteps(ScenarioOutline scenarioOutline)
        {
            foreach (var exampleSet in scenarioOutline.Examples)
            {
                foreach (var example in exampleSet.TableBody)
                {
                    Dictionary<string, string> paramSubst = new Dictionary<string, string>();
                    for (int i = 0; i < exampleSet.TableHeader.Cells.Count(); i++)
                    {
                        paramSubst.Add(exampleSet.TableHeader.Cells.ElementAt(i).Value, example.Cells.ElementAt(i).Value);
                    }

                    return CreateScenarioSteps(scenarioOutline, paramSubst);
                }
            }
            return new List<SpecFlowStep>();
        }
Exemplo n.º 10
0
        public void ApplyExampleRow_Digests_Row_Values_Into_Scenario()
        {
            //arrange.
            var sut = new Gherkin.Ast.ScenarioOutline(
                null,
                null,
                null,
                "outline123",
                null,
                new Gherkin.Ast.Step[]
            {
                new Gherkin.Ast.Step(null, "Given", "I chose <a> as first number", null),
                new Gherkin.Ast.Step(null, "And", "I chose <b> as second number", null),
                new Gherkin.Ast.Step(null, "When", "I press add", null),
                new Gherkin.Ast.Step(null, "Then", "the result should be <sum> on the screen", null),
            },
                new Gherkin.Ast.Examples[]
            {
                new Gherkin.Ast.Examples(
                    null,
                    null,
                    null,
                    "existing example",
                    null,
                    new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]
                {
                    new Gherkin.Ast.TableCell(null, "a"),
                    new Gherkin.Ast.TableCell(null, "b"),
                    new Gherkin.Ast.TableCell(null, "sum")
                }),
                    new Gherkin.Ast.TableRow[]
                {
                    new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]
                    {
                        new Gherkin.Ast.TableCell(null, "1"),
                        new Gherkin.Ast.TableCell(null, "2"),
                        new Gherkin.Ast.TableCell(null, "3")
                    })
                })
            });

            //act.
            var scenario = sut.ApplyExampleRow("existing example", 0);

            //assert.
            Assert.NotNull(scenario);
            Assert.Equal(sut.Name, scenario.Name);
            Assert.Equal(sut.Steps.Count(), scenario.Steps.Count());
            Assert.Equal(4, scenario.Steps.Count());

            var sutSteps      = sut.Steps.ToList();
            var scenarioSteps = scenario.Steps.ToList();

            ValidateStep(scenarioSteps[0], "Given", "I chose 1 as first number", sutSteps[0]);
            ValidateStep(scenarioSteps[1], "And", "I chose 2 as second number", sutSteps[1]);
            ValidateStep(scenarioSteps[2], "When", "I press add", sutSteps[2]);
            ValidateStep(scenarioSteps[3], "Then", "the result should be 3 on the screen", sutSteps[3]);

            void ValidateStep(Gherkin.Ast.Step step, string keyword, string text,
                              Gherkin.Ast.Step other)
            {
                Assert.NotSame(other, step);
                Assert.Equal(keyword, step.Keyword);
                Assert.Equal(text, step.Text);
            }
        }
Exemplo n.º 11
0
        public void ApplyExampleRow_Digests_Row_Values_Into_Scenario_With_DataTable_In_Step()
        {
            //arrange.
            var sut = new Gherkin.Ast.ScenarioOutline(
                null,
                null,
                null,
                "outline123",
                null,
                new Gherkin.Ast.Step[]
            {
                new Gherkin.Ast.Step(null, "Given", "I pass a datatable with tokens", new DataTable(new []
                {
                    new TableRow(null, new[] { new TableCell(null, "Column1"), new TableCell(null, "Column2") }),
                    new TableRow(null, new[] { new TableCell(null, "<a>"), new TableCell(null, "data with <b> in the middle") }),
                    new TableRow(null, new[] { new TableCell(null, "<b>"), new TableCell(null, "<a>") })
                })),
                new Gherkin.Ast.Step(null, "When", "I apply a sample row", null),
                new Gherkin.Ast.Step(null, "Then", "the data table should be populated", null),
            },
                new Gherkin.Ast.Examples[]
            {
                new Gherkin.Ast.Examples(
                    null,
                    null,
                    null,
                    "existing example",
                    null,
                    new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]
                {
                    new Gherkin.Ast.TableCell(null, "a"),
                    new Gherkin.Ast.TableCell(null, "b"),
                }),
                    new Gherkin.Ast.TableRow[]
                {
                    new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]
                    {
                        new Gherkin.Ast.TableCell(null, "1"),
                        new Gherkin.Ast.TableCell(null, "2")
                    })
                })
            });

            //act.
            var scenario = sut.ApplyExampleRow("existing example", 0);

            //assert.
            Assert.NotNull(scenario);
            Assert.Equal(sut.Name, scenario.Name);
            Assert.Equal(sut.Steps.Count(), scenario.Steps.Count());
            Assert.Equal(3, scenario.Steps.Count());

            var scenarioSteps = scenario.Steps.ToList();

            Assert.IsType <DataTable>(scenarioSteps[0].Argument);
            var dataTable = (DataTable)scenarioSteps[0].Argument;
            var rows      = dataTable.Rows.ToList();

            ValidateRow(rows[0], "Column1", "Column2");
            ValidateRow(rows[1], "1", "data with 2 in the middle");
            ValidateRow(rows[2], "2", "1");

            void ValidateRow(TableRow row, string expectedColumn0Value, string expectedColumn1Value)
            {
                var cells = row.Cells.ToArray();

                Assert.Equal(cells[0].Value, expectedColumn0Value);
                Assert.Equal(cells[1].Value, expectedColumn1Value);
            }
        }