Beispiel #1
0
        public void DigestScenarioStepValues_Sets_DataTable_Value()
        {
            //arrange.
            var featureInstance = new FeatureWithDataTableScenarioStep();
            var sut             = StepMethodInfo.FromMethodInfo(
                featureInstance.GetType().GetMethod(nameof(FeatureWithDataTableScenarioStep.When_DataTable_Is_Expected)),
                featureInstance
                );

            var step = CreateGherkinDocument("some scenario 1212",
                                             "When " + FeatureWithDataTableScenarioStep.Steptext + Environment.NewLine +
                                             @"  | First argument | Second argument | Result |
    | 1              |       2         |       3|
    | a              |   b             | c      |
"
                                             ).Feature.Children.First().Steps.First();

            //act.
            sut.DigestScenarioStepValues(step);

            //assert.
            var digestedText = sut.GetDigestedStepText();

            Assert.Equal(FeatureWithDataTableScenarioStep.Steptext, digestedText);
        }
        public void FromMethodInfo_Creates_StepMethodInfo_With_DataTable()
        {
            //arrange.
            var featureInstance = new FeatureWithDataTableScenarioStep();

            //act.
            var sut = StepMethodInfo.FromMethodInfo(
                featureInstance.GetType().GetMethod(nameof(FeatureWithDataTableScenarioStep.When_DataTable_Is_Expected)),
                featureInstance
                );

            //assert.
            Assert.NotNull(sut);
        }
        public async Task ExecuteScenario_Executes_ScenarioStep_With_DataTable()
        {
            //arrange.
            var scenarioName    = "scenario123";
            var featureInstance = new FeatureWithDataTableScenarioStep();
            var output          = new Mock <ITestOutputHelper>();

            featureInstance.Output = output.Object;

            _featureFileRepository.Setup(r => r.GetByFilePath($"{nameof(FeatureWithDataTableScenarioStep)}.feature"))
            .Returns(new FeatureFile(CreateGherkinDocument(scenarioName,
                                                           "When " + FeatureWithDataTableScenarioStep.Steptext + Environment.NewLine +
                                                           @"  | First argument | Second argument | Result |
    | 1              |       2         |       3|
    | a              |   b             | c      |
"
                                                           )))
            .Verifiable();

            //act.
            await _sut.ExecuteScenarioAsync(featureInstance, scenarioName);

            //assert.
            _featureFileRepository.Verify();

            Assert.NotNull(featureInstance.ReceivedDataTable);
            Assert.Equal(3, featureInstance.ReceivedDataTable.Rows.Count());

            AssertDataTableCell(0, 0, "First argument");
            AssertDataTableCell(0, 1, "Second argument");
            AssertDataTableCell(0, 2, "Result");

            AssertDataTableCell(1, 0, "1");
            AssertDataTableCell(1, 1, "2");
            AssertDataTableCell(1, 2, "3");

            AssertDataTableCell(2, 0, "a");
            AssertDataTableCell(2, 1, "b");
            AssertDataTableCell(2, 2, "c");

            void AssertDataTableCell(int rowIndex, int cellIndex, string value)
            {
                Assert.True(featureInstance.ReceivedDataTable.Rows.Count() > rowIndex);
                Assert.NotNull(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex));
                Assert.True(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex).Cells.Count() > cellIndex);
                Assert.NotNull(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex).Cells.ElementAt(cellIndex));
                Assert.Equal("First argument", featureInstance.ReceivedDataTable.Rows.ElementAt(0).Cells.ElementAt(0).Value);
            }
        }
        public void DigestScenarioStepValues_Sets_DataTable_Value()
        {
            //arrange.
            var featureInstance = new FeatureWithDataTableScenarioStep();
            var sut             = StepMethodInfo.FromMethodInfo(
                featureInstance.GetType().GetMethod(nameof(FeatureWithDataTableScenarioStep.When_DataTable_Is_Expected)),
                featureInstance
                );

            var step = new Gherkin.Ast.Step(
                null,
                "When",
                FeatureWithDataTableScenarioStep.Steptext,
                new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]
            {
                new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]
                {
                    new Gherkin.Ast.TableCell(null, "First argument"),
                    new Gherkin.Ast.TableCell(null, "Second argument"),
                    new Gherkin.Ast.TableCell(null, "Result"),
                }),
                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"),
                }),
                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, "c"),
                })
            }));

            //act.
            sut.DigestScenarioStepValues(step);

            //assert.
            var digestedText = sut.GetDigestedStepText();

            Assert.Equal(FeatureWithDataTableScenarioStep.Steptext, digestedText);
        }
        public void ExtractScnario_Extracts_Scenario_With_DataTable()
        {
            //arrange.
            var scenarioName    = "scenario213";
            var featureInstance = new FeatureWithDataTableScenarioStep();
            var sut             = FeatureClass.FromFeatureInstance(featureInstance);

            var featureFile = new FeatureFile(CreateGherkinDocument(scenarioName,
                                                                    "When " + FeatureWithDataTableScenarioStep.Steptext + Environment.NewLine +
                                                                    @"  | First argument | Second argument | Result |
    | 1              |       2         |       3|
    | a              |   b             | c      |
"
                                                                    ));

            //act.
            var scenario = sut.ExtractScenario(scenarioName, featureFile);

            //assert.
            Assert.NotNull(scenario);
        }
Beispiel #6
0
        public void ExtractScnario_Extracts_Scenario_With_DataTable()
        {
            //arrange.
            var scenarioName    = "scenario213";
            var featureInstance = new FeatureWithDataTableScenarioStep();
            var sut             = FeatureClass.FromFeatureInstance(featureInstance);

            var gherknScenario = CreateGherkinDocument(scenarioName,
                                                       new string[]
            {
                "When " + FeatureWithDataTableScenarioStep.Steptext
            },
                                                       new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]
            {
                new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]
                {
                    new Gherkin.Ast.TableCell(null, "First argument"),
                    new Gherkin.Ast.TableCell(null, "Second argument"),
                    new Gherkin.Ast.TableCell(null, "Result"),
                }),
                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"),
                }),
                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, "c"),
                })
            })).Feature.Children.First() as Gherkin.Ast.Scenario;

            //act.
            var scenario = sut.ExtractScenario(gherknScenario);

            //assert.
            Assert.NotNull(scenario);
        }
        public async Task ExecuteScenarioOutlineAsync_Executes_ScenarioStep_With_DataTable(
            string exampleName,
            int exampleRowIndex)
        {
            //arrange.
            var scenarioName    = "scenario123";
            var featureInstance = new FeatureWithDataTableScenarioStep();
            var output          = new Mock <ITestOutputHelper>();

            featureInstance.InternalOutput = output.Object;

            _featureFileRepository.Setup(r => r.GetByFilePath($"{nameof(FeatureWithDataTableScenarioStep)}.feature"))
            .Returns(new FeatureFile(FeatureWithDataTableScenarioStep.CreateGherkinDocument(scenarioName,
                                                                                            new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]
            {
                new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]
                {
                    new Gherkin.Ast.TableCell(null, "First argument"),
                    new Gherkin.Ast.TableCell(null, "Second argument"),
                    new Gherkin.Ast.TableCell(null, "Result"),
                }),
                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"),
                }),
                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, "c"),
                })
            }))))
            .Verifiable();

            //act.
            await _sut.ExecuteScenarioOutlineAsync(featureInstance, scenarioName, exampleName, exampleRowIndex);

            //assert.
            _featureFileRepository.Verify();

            Assert.NotNull(featureInstance.ReceivedDataTable);
            Assert.Equal(3, featureInstance.ReceivedDataTable.Rows.Count());

            AssertDataTableCell(0, 0, "First argument");
            AssertDataTableCell(0, 1, "Second argument");
            AssertDataTableCell(0, 2, "Result");

            AssertDataTableCell(1, 0, "1");
            AssertDataTableCell(1, 1, "2");
            AssertDataTableCell(1, 2, "3");

            AssertDataTableCell(2, 0, "a");
            AssertDataTableCell(2, 1, "b");
            AssertDataTableCell(2, 2, "c");

            void AssertDataTableCell(int rowIndex, int cellIndex, string value)
            {
                Assert.True(featureInstance.ReceivedDataTable.Rows.Count() > rowIndex);
                Assert.NotNull(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex));
                Assert.True(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex).Cells.Count() > cellIndex);
                Assert.NotNull(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex).Cells.ElementAt(cellIndex));
                Assert.Equal("First argument", featureInstance.ReceivedDataTable.Rows.ElementAt(0).Cells.ElementAt(0).Value);
            }
        }