コード例 #1
0
        public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline)
        {
            if (this.specRunFeatures == null)
            {
                return TestResult.Inconclusive;
            }

            var specRunFeature = this.FindSpecRunFeature(scenarioOutline.Feature);

            if (specRunFeature == null)
            {
                return TestResult.Inconclusive;
            }

            SpecRun.Scenario[] specRunScenarios = FindSpecRunScenarios(scenarioOutline, specRunFeature);

            if (specRunScenarios.Length == 0)
            {
                return TestResult.Inconclusive;
            }

            TestResult result = StringsToTestResult(specRunScenarios.Select(srs => srs.Result));

            return result;
        }
コード例 #2
0
        public void Format(XElement parentElement, ScenarioOutline scenario)
        {
            var section = new XElement("section",
                                       new XElement("title", scenario.Name));

            if (!string.IsNullOrEmpty(scenario.Description))
            {
                section.Add(new XElement("p", scenario.Description));
            }

            if (this.configuration.HasTestResults)
            {
                TestResult testResult = this.nunitResults.GetScenarioOutlineResult(scenario);
                if (testResult.WasExecuted && testResult.WasSuccessful)
                {
                    section.Add(new XElement("note", "This scenario passed"));
                }
                else if (testResult.WasExecuted && !testResult.WasSuccessful)
                {
                    section.Add(new XElement("note", "This scenario failed"));
                }
            }

            foreach (Step step in scenario.Steps)
            {
                this.ditaStepFormatter.Format(section, step);
            }

            parentElement.Add(section);
        }
コード例 #3
0
        public void Format(IXLWorksheet worksheet, ScenarioOutline scenarioOutline, ref int row)
        {
            int originalRow = row;
            worksheet.Cell(row++, "B").Value = scenarioOutline.Name;
            worksheet.Cell(row++, "C").Value = scenarioOutline.Description;

            var results = this.testResults.GetScenarioOutlineResult(scenarioOutline);
            if (this.configuration.HasTestResults && results.WasExecuted)
            {
                worksheet.Cell(originalRow, "B").Style.Fill.SetBackgroundColor(results.WasSuccessful
                                                                                   ? XLColor.AppleGreen
                                                                                   : XLColor.CandyAppleRed);
            }

            foreach (Step step in scenarioOutline.Steps)
            {
                this.excelStepFormatter.Format(worksheet, step, ref row);
            }

            row++;
			
			foreach (var example in scenarioOutline.Examples)
			{
	            worksheet.Cell(row++, "B").Value = "Examples";
				worksheet.Cell(row, "C").Value = example.Description;
	            this.excelTableFormatter.Format(worksheet, example.TableArgument, ref row);
			}
        }
コード例 #4
0
        public void ThenCanFormatScenarioOutlineWithMissingNameCorrectly()
        {
            var table = new Table
            {
                HeaderRow = new TableRow("Var1", "Var2", "Var3", "Var4"),
                DataRows =
                    new List<TableRow>(new[]
                                            {
                                                new TableRow("1", "2", "3", "4"),
                                                new TableRow("5", "6", "7", "8")
                                            })
            };

      var example = new Example { Name = "Some examples", Description = "An example", TableArgument = table };
      var examples = new List<Example>();
      examples.Add(example);

            var scenarioOutline = new ScenarioOutline
            {
                Description = "We need to make sure that scenario outlines work properly",
                Examples = examples
            };

            var htmlScenarioOutlineFormatter = Container.Resolve<HtmlScenarioOutlineFormatter>();
            var output = htmlScenarioOutlineFormatter.Format(scenarioOutline, 0);

            Check.That(output).ContainsGherkinScenario();
            Check.That(output).ContainsGherkinTable();
        }
コード例 #5
0
        public void ThenCanFormatScenarioOutlineWithMissingDescriptionCorrectly()
        {
            var table = new Table
            {
                HeaderRow = new TableRow("Var1", "Var2", "Var3", "Var4"),
                DataRows =
                    new List<TableRow>(new[]
                                            {
                                                new TableRow("1", "2", "3", "4"),
                                                new TableRow("5", "6", "7", "8")
                                            })
            };

            var example = new Example { Name = "Some examples", Description = "An example", TableArgument = table };
            var examples = new List<Example>();
            examples.Add(example);

            var scenarioOutline = new ScenarioOutline
            {
                Name = "Testing a scenario outline",
                Examples = examples
            };

            var htmlScenarioOutlineFormatter = Container.Resolve<HtmlScenarioOutlineFormatter>();
            var output = htmlScenarioOutlineFormatter.Format(scenarioOutline, 0);

            output.ShouldContainGherkinScenario();
            output.ShouldContainGherkinTable();
        }
コード例 #6
0
        public void Format(Body body, ScenarioOutline scenarioOutline)
        {
            if (this.configuration.HasTestResults)
            {
                TestResult testResult = this.testResults.GetScenarioOutlineResult(scenarioOutline);
                if (testResult.WasExecuted && testResult.WasSuccessful)
                {
                    body.GenerateParagraph("Passed", "Passed");
                }
                else if (testResult.WasExecuted && !testResult.WasSuccessful)
                {
                    body.GenerateParagraph("Failed", "Failed");
                }
            }

            body.GenerateParagraph(scenarioOutline.Name, "Heading2");
            if (!string.IsNullOrEmpty(scenarioOutline.Description))
                body.GenerateParagraph(scenarioOutline.Description, "Normal");

            foreach (Step step in scenarioOutline.Steps)
            {
                this.wordStepFormatter.Format(body, step);
            }
			
			foreach (var example in scenarioOutline.Examples)
			{
	            body.GenerateParagraph("Examples: " + example.Description, "Heading3");
	            this.wordTableFormatter.Format(body, example.TableArgument);
			}
        }
        public void ThenCanSuccessfullyMatch()
        {
            var scenarioOutline = new ScenarioOutline {Name = "Adding several numbers"};
            var exampleRow = new[] {"40", "50", "90"};

            var signatureBuilder = Container.Resolve<NUnitExampleSignatureBuilder>();
            Regex signature = signatureBuilder.Build(scenarioOutline, exampleRow);

            signature.IsMatch("Pickles.TestHarness.AdditionFeature.AddingSeveralNumbers(\"40\",\"50\",\"90\",System.String[])".ToLowerInvariant()).ShouldBeTrue();
        }
コード例 #8
0
        public void ThenSingleScenarioOutlineWithStepsAddedSuccessfully()
        {
            var excelScenarioFormatter = Container.Resolve<ExcelScenarioOutlineFormatter>();
            var exampleTable = new Table();
            exampleTable.HeaderRow = new TableRow("Var1", "Var2", "Var3", "Var4");
            exampleTable.DataRows =
                new List<TableRow>(new[] {new TableRow("1", "2", "3", "4"), new TableRow("5", "6", "7", "8")});
            var example = new Example {Name = "Examples", Description = string.Empty, TableArgument = exampleTable};
            var examples = new List<Example>();
            examples.Add(example);
            var scenarioOutline = new ScenarioOutline
                                      {
                                          Name = "Test Feature",
                                          Description =
                                              "In order to test this feature,\nAs a developer\nI want to test this feature",
                                          Examples = examples
                                      };
            var given = new Step {NativeKeyword = "Given", Name = "a precondition"};
            var when = new Step {NativeKeyword = "When", Name = "an event occurs"};
            var then = new Step {NativeKeyword = "Then", Name = "a postcondition"};
            scenarioOutline.Steps = new List<Step>(new[] {given, when, then});

            using (var workbook = new XLWorkbook())
            {
                IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
                int row = 3;
                excelScenarioFormatter.Format(worksheet, scenarioOutline, ref row);

                worksheet.Cell("B3").Value.ShouldEqual(scenarioOutline.Name);
                worksheet.Cell("C4").Value.ShouldEqual(scenarioOutline.Description);
                worksheet.Cell("B9").Value.ShouldEqual("Examples");
                worksheet.Cell("D10").Value.ShouldEqual("Var1");
                worksheet.Cell("E10").Value.ShouldEqual("Var2");
                worksheet.Cell("F10").Value.ShouldEqual("Var3");
                worksheet.Cell("G10").Value.ShouldEqual("Var4");
                worksheet.Cell("D11").Value.ShouldEqual(1.0);
                worksheet.Cell("E11").Value.ShouldEqual(2.0);
                worksheet.Cell("F11").Value.ShouldEqual(3.0);
                worksheet.Cell("G11").Value.ShouldEqual(4.0);
                worksheet.Cell("D12").Value.ShouldEqual(5.0);
                worksheet.Cell("E12").Value.ShouldEqual(6.0);
                worksheet.Cell("F12").Value.ShouldEqual(7.0);
                worksheet.Cell("G12").Value.ShouldEqual(8.0);
                row.ShouldEqual(13);
            }
        }
コード例 #9
0
        public void ThenSingleScenarioOutlineAddedSuccessfully()
        {
            var excelScenarioFormatter = Container.Resolve<ExcelScenarioOutlineFormatter>();
            var exampleTable = new Table();
            exampleTable.HeaderRow = new TableRow("Var1", "Var2", "Var3", "Var4");
            exampleTable.DataRows =
                new List<TableRow>(new[] {new TableRow("1", "2", "3", "4"), new TableRow("5", "6", "7", "8")});
            var example = new Example {Name = "Examples", Description = string.Empty, TableArgument = exampleTable};
            var examples = new List<Example>();
            examples.Add(example);
            var scenarioOutline = new ScenarioOutline
                                      {
                                          Name = "Test Feature",
                                          Description =
                                              "In order to test this feature,\nAs a developer\nI want to test this feature",
                                          Examples = examples
                                      };

            using (var workbook = new XLWorkbook())
            {
                IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
                int row = 3;
                excelScenarioFormatter.Format(worksheet, scenarioOutline, ref row);

                worksheet.Cell("B3").Value.ShouldEqual(scenarioOutline.Name);
                worksheet.Cell("C4").Value.ShouldEqual(scenarioOutline.Description);
                worksheet.Cell("B6").Value.ShouldEqual("Examples");
                worksheet.Cell("D7").Value.ShouldEqual("Var1");
                worksheet.Cell("E7").Value.ShouldEqual("Var2");
                worksheet.Cell("F7").Value.ShouldEqual("Var3");
                worksheet.Cell("G7").Value.ShouldEqual("Var4");
                worksheet.Cell("D8").Value.ShouldEqual(1.0);
                worksheet.Cell("E8").Value.ShouldEqual(2.0);
                worksheet.Cell("F8").Value.ShouldEqual(3.0);
                worksheet.Cell("G8").Value.ShouldEqual(4.0);
                worksheet.Cell("D9").Value.ShouldEqual(5.0);
                worksheet.Cell("E9").Value.ShouldEqual(6.0);
                worksheet.Cell("F9").Value.ShouldEqual(7.0);
                worksheet.Cell("G9").Value.ShouldEqual(8.0);
                row.ShouldEqual(10);
            }
        }
コード例 #10
0
 public TestResult GetExampleResult(ScenarioOutline scenario, string[] exampleValues)
 {
     throw new NotSupportedException();
 }
コード例 #11
0
        public override TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline)
        {
            IEnumerable <TestResult> exampleElements = this.GetScenarioOutlineElements(scenarioOutline).Select(this.GetResultFromElement);

            return(this.DetermineAggregateResult(exampleElements));
        }
コード例 #12
0
        public void ThenCanFormatScenarioOutlineWithMissingTableFromExampleCorrectly()
        {
            var example = new Example { Name = "Some examples", Description = "An example" };
      var examples = new List<Example>();
      examples.Add(example);

      var scenarioOutline = new ScenarioOutline
            {
                Name = "Testing a scenario outline",
                Description = "We need to make sure that scenario outlines work properly",
                Examples = examples
            };

            var htmlScenarioOutlineFormatter = Container.Resolve<HtmlScenarioOutlineFormatter>();
            var output = htmlScenarioOutlineFormatter.Format(scenarioOutline, 0);

            Check.That(output).ContainsGherkinScenario();
            Check.That(output).Not.ContainsGherkinTable();
        }
コード例 #13
0
        public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline)
        {
            var results = this.TestResults.Select(tr => tr.GetScenarioOutlineResult(scenarioOutline)).ToArray();

            return(EvaluateTestResults(results));
        }
コード例 #14
0
        public void ThenCanFormatScenarioOutlineWithMissingExampleCorrectly()
        {
            var scenarioOutline = new ScenarioOutline
            {
                Name = "Testing a scenario outline",
                Description = "We need to make sure that scenario outlines work properly",
                Examples = new List<Example>()
            };

            var htmlScenarioOutlineFormatter = Container.Resolve<HtmlScenarioOutlineFormatter>();
            var output = htmlScenarioOutlineFormatter.Format(scenarioOutline, 0);

            output.ShouldContainGherkinScenario();
            output.ShouldNotContainGherkinTable();
        }
コード例 #15
0
ファイル: NullTestResults.cs プロジェクト: Jaykul/pickles
 public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline)
 {
     return new TestResult();
 }
コード例 #16
0
 protected abstract XElement GetExamplesElement(ScenarioOutline scenarioOutline, string[] values);
コード例 #17
0
        private CodeMemberMethod CreateScenatioOutlineTestMethod(TestClassGenerationContext generationContext, ScenarioOutline scenarioOutline, ParameterSubstitution paramToIdentifier)
        {
            CodeMemberMethod testMethod = CreateMethod(generationContext.TestClass);

            testMethod.Attributes = MemberAttributes.Public;
            testMethod.Name       = string.Format(TEST_NAME_FORMAT, scenarioOutline.Name.ToIdentifier());

            foreach (var pair in paramToIdentifier)
            {
                testMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), pair.Value));
            }

            testMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string[]), SCENARIO_OUTLINE_EXAMPLE_TAGS_PARAMETER));
            return(testMethod);
        }
コード例 #18
0
        public XElement Format(ScenarioOutline scenarioOutline, params string[] exampleValues)
        {
          if (this.configuration.HasTestResults && this.results.SupportsExampleResults)
          {
            TestResult exampleResult = this.results.GetExampleResult(scenarioOutline, exampleValues);

            return this.BuildImageElement(exampleResult);
          }

          return null;
        }
コード例 #19
0
ファイル: MultipleTestResults.cs プロジェクト: Jaykul/pickles
 public abstract TestResult GetExampleResult(ScenarioOutline scenario, string[] exampleValues);
コード例 #20
0
        public XElement Format(ScenarioOutline scenarioOutline)
        {
          if (this.configuration.HasTestResults)
          {
            TestResult scenarioResult = this.results.GetScenarioOutlineResult(scenarioOutline);

            return this.BuildImageElement(scenarioResult);
          }

          return null;
        }
コード例 #21
0
ファイル: NullTestResults.cs プロジェクト: Jaykul/pickles
 public TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] exampleValues)
 {
     return new TestResult();
 }
コード例 #22
0
        public void GetScenarioOutlineResult_TwoInconclusive_ReturnsInconclusive()
        {
            var scenarioOutline = new ScenarioOutline();

              var testResults1 = SetupStubForGetScenarioOutlineResult(TestResult.Inconclusive);
              var testResults2 = SetupStubForGetScenarioOutlineResult(TestResult.Inconclusive);

              ITestResults multipleTestResults = CreateMultipleTestResults(testResults1.Object, testResults2.Object);

              var result = multipleTestResults.GetScenarioOutlineResult(scenarioOutline);

              result.ShouldEqual(TestResult.Inconclusive);
        }
コード例 #23
0
        private void GenerateScenarioOutlineTestVariant(CodeTypeDeclaration testType, ScenarioOutline scenarioOutline, string testMethodName, List <KeyValuePair <string, string> > paramToIdentifier, string exampleSetTitle, Row row, Tags exampleSetTags, string variantName, ExampleSet exampleSet)
        {
            CodeMemberMethod testMethod = GetTestMethodDeclaration(testType, scenarioOutline, exampleSetTags);

            testMethod.Name = string.IsNullOrEmpty(exampleSetTitle)
                ? string.Format("{0}_{1}", testMethod.Name, variantName)
                : string.Format("{0}_{1}_{2}", testMethod.Name, exampleSetTitle, variantName);

            //call test implementation with the params
            List <CodeExpression> argumentExpressions = new List <CodeExpression>();

            foreach (var paramCell in row.Cells)
            {
                argumentExpressions.Add(new CodePrimitiveExpression(paramCell.Value));
            }

            argumentExpressions.Add(GetStringArrayExpression(exampleSetTags));

            testMethod.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeThisReferenceExpression(),
                    testMethodName,
                    argumentExpressions.ToArray()));

            List <KeyValuePair <string, string> > arguments = new List <KeyValuePair <string, string> >();

            for (int rowIndex = 0; rowIndex < exampleSet.Table.Body.Length; rowIndex++)
            {
                arguments.Add(new KeyValuePair <string, string>(exampleSet.Table.Header.Cells[rowIndex].Value, row.Cells[rowIndex].Value));
            }

            testGeneratorProvider.SetTestVariant(testMethod, scenarioOutline.Title, exampleSetTitle, arguments);
        }
コード例 #24
0
        public override TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] exampleValues)
        {
            var examplesElement = this.GetExamplesElement(scenarioOutline, exampleValues);

            return(this.GetResultFromElement(examplesElement));
        }
コード例 #25
0
        private void GenerateScenarioOutlineTest(TestClassGenerationContext generationContext, ScenarioOutline scenarioOutline)
        {
            ValidateExampleSetConsistency(scenarioOutline);

            ParameterSubstitution paramToIdentifier = CreateParamToIdentifierMapping(scenarioOutline);

            var scenatioOutlineTestMethod = CreateScenatioOutlineTestMethod(generationContext, scenarioOutline, paramToIdentifier);
            var exampleTagsParam          = new CodeVariableReferenceExpression(SCENARIO_OUTLINE_EXAMPLE_TAGS_PARAMETER);

            if (generationContext.GenerateRowTests)
            {
                GenerateScenarioOutlineExamplesAsRowTests(generationContext, scenarioOutline, scenatioOutlineTestMethod);
            }
            else
            {
                GenerateScenarioOutlineExamplesAsIndividualMethods(scenarioOutline, generationContext, scenatioOutlineTestMethod, paramToIdentifier);
            }
            GenerateTestBody(generationContext, scenarioOutline, scenatioOutlineTestMethod, exampleTagsParam, paramToIdentifier);
        }
コード例 #26
0
 public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline)
 {
     // Not applicable
     return(new TestResult());
 }
コード例 #27
0
ファイル: NUnitResults.cs プロジェクト: seanfitzg/pickles
        public override TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] arguments)
        {
            var results = TestResults.OfType <NUnitSingleResults>().Select(tr => tr.GetExampleResult(scenarioOutline, arguments)).ToArray();

            return(EvaluateTestResults(results));
        }
コード例 #28
0
        public void GetScenarioOutlineResult_OnePassingOneFailing_ReturnsFailed()
        {
            var scenarioOutline = new ScenarioOutline();

              var testResults1 = SetupStubForGetScenarioOutlineResult(TestResult.Passed);
              var testResults2 = SetupStubForGetScenarioOutlineResult(TestResult.Failed);

              ITestResults multipleTestResults = CreateMultipleTestResults(testResults1.Object, testResults2.Object);

              var result = multipleTestResults.GetScenarioOutlineResult(scenarioOutline);

              result.ShouldEqual(TestResult.Failed);
        }
コード例 #29
0
 protected abstract XElement GetScenarioOutlineElement(ScenarioOutline scenarioOutline);
コード例 #30
0
 public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline)
 {
   //Not applicable
   return new TestResult();
 }
コード例 #31
0
        public override TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline)
        {
            var scenarioOutlineElement = this.GetScenarioOutlineElement(scenarioOutline);

            return(this.DetermineScenarioOutlineResult(scenarioOutlineElement));
        }
コード例 #32
0
ファイル: NUnitResults.cs プロジェクト: Jaykul/pickles
    public override TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] arguments)
    {
      var results = TestResults.OfType<NUnitSingleResults>().Select(tr => tr.GetExampleResult(scenarioOutline, arguments)).ToArray();

      return EvaluateTestResults(results);
    }
コード例 #33
0
 private void Add(ScenarioOutline scenarioOutline)
 => activeScenarioOutlinesList.Add(scenarioOutline);
コード例 #34
0
 private static SpecRun.Scenario[] FindSpecRunScenarios(ScenarioOutline scenarioOutline, SpecRun.Feature specRunFeature)
 {
     return specRunFeature.Scenarios.Where(d => d.Title.StartsWith(scenarioOutline.Name + ", ")).ToArray();
 }
コード例 #35
0
        public void CreateScenarios(BusinessFlow BF)
        {
            string FileName = string.Empty;

            if (BF.ExternalID != null)
            {
                FileName = BF.ExternalID.Replace(@"~", WorkSpace.Instance.Solution.Folder);
            }

            if (!System.IO.File.Exists(FileName))
            {
                // General
                Reporter.ToUser(eUserMsgKey.GherkinFileNotFound, FileName);
                return;
            }

            Parser          parser          = new Parser();
            GherkinDocument gherkinDocument = parser.Parse(FileName);

            mBizFlow = BF;

            ClearGeneretedActivites(mBizFlow);
            ClearOptimizedScenariosVariables(mBizFlow);

            //Add Tags to BF
            foreach (var t in gherkinDocument.Feature.Tags)
            {
                Guid TagGuid = GetOrCreateTagInSolution(t.Name);
                mBizFlow.Tags.Add(TagGuid);
            }

            foreach (Gherkin.Ast.ScenarioDefinition sc in gherkinDocument.Feature.Children)
            {
                IEnumerable <Examples> examples = null;
                // In case of Scenario Outline we need to generate new BF per each line in the table of examples
                if (sc.Keyword == "Scenario Outline")
                {
                    ScenarioOutline so = (ScenarioOutline)sc;
                    examples = so.Examples;
                }

                // Create new BF per each scenario

                if (examples == null)
                {
                    CreateScenario(sc);
                }
                else
                {
                    int i = 0;
                    ValuesDict = new Dictionary <string, List <OptionalValue> >();

                    //TODO: handle case of more than one example table - check what is Gherking expected todo: all combinations!!??
                    foreach (Examples x in examples)
                    {
                        foreach (Gherkin.Ast.TableRow tr in x.TableBody)
                        {
                            i++;
                            ActivitiesGroup AG = CreateScenario(sc, i);
                            // Now the we have the flow created with activities, we update the activities var replacing <param> with value from table
                            var activities = from z in BF.Activities where z.ActivitiesGroupID == AG.Name select z;

                            foreach (Activity a in activities)
                            {
                                while (true)
                                {
                                    string ColName = General.GetStringBetween(a.ActivityName, "<", ">");
                                    if (string.IsNullOrEmpty(ColName))
                                    {
                                        break;
                                    }

                                    string val = GetExampleValue(x.TableHeader, tr, ColName);
                                    a.ActivityName = a.ActivityName.Replace("<" + ColName + ">", "\"" + val + "\"");

                                    VariableBase v = a.Variables.Where(y => y.Name == ColName).FirstOrDefault();

                                    OptionalValue ov = new OptionalValue(val);
                                    if (ValuesDict.ContainsKey(ColName))
                                    {
                                        ValuesDict[ColName].Add(ov);
                                    }
                                    else
                                    {
                                        List <OptionalValue> newList = new List <OptionalValue>();
                                        newList.Add(ov);
                                        ValuesDict.Add(ColName, newList);
                                    }
                                    ((VariableSelectionList)v).OptionalValuesList.Add(ov);
                                    ((VariableSelectionList)v).SelectedValue = val;
                                }
                            }
                        }
                    }

                    foreach (Activity a in BF.Activities)
                    {
                        foreach (VariableBase vb in a.Variables)
                        {
                            if (vb is VariableSelectionList)
                            {
                                if (ValuesDict.ContainsKey(vb.Name))
                                {
                                    foreach (OptionalValue ov in ValuesDict[vb.Name])
                                    {
                                        OptionalValue ExistedOV = ((VariableSelectionList)vb).OptionalValuesList.Where(y => y.Value == ov.Value).FirstOrDefault();
                                        if (ExistedOV == null)
                                        {
                                            ((VariableSelectionList)vb).OptionalValuesList.Add(ov);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(NotFoundItems))
            {
                Reporter.ToUser(eUserMsgKey.GherkinColumnNotExist, NotFoundItems);
            }
        }
コード例 #36
0
 public ScenarioTestCase(SpecFlowFeatureTestClass featureTestClass, ScenarioOutline scenario, string[] featureTags, Dictionary <string, string> scenarioOutlineParameters, string exampleId, Location exampleLocation)
     : this(featureTestClass, scenario, featureTags, exampleLocation)
 {
     ScenarioOutlineParameters = scenarioOutlineParameters;
     ExampleId = exampleId;
 }
コード例 #37
0
        protected virtual void CompileScenarioOutline(List <Pickle> pickles, IEnumerable <PickleStep> backgroundSteps, ScenarioOutline 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);
                }
            }
        }
コード例 #38
0
ファイル: MultipleTestResults.cs プロジェクト: Jaykul/pickles
    public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline)
    {
      var results = this.TestResults.Select(tr => tr.GetScenarioOutlineResult(scenarioOutline)).ToArray();

      return EvaluateTestResults(results);
    }
コード例 #39
0
 public bool IsMatch(ScenarioOutline scenarioOutline, string[] exampleValues, object scenarioElement)
 {
     return(false);
 }
コード例 #40
0
 void AssertThatExamplesAreGiven(ScenarioOutline outline, string fileName)
 {
     if (outline.Examples.Count == 0)
     {
         throw new GherkinParseException(fileName, "In a scenario outline, a table of examples should be given");
     }
 }
コード例 #41
0
 public abstract TestResult GetExampleResult(ScenarioOutline scenario, string[] exampleValues);
コード例 #42
0
        void AssertThatPlaceholdersCanBeResolvedWithThisTable(ScenarioOutline scenario, string fileName)
        {
            var placeholderMatcher = new Regex("<(.)*>");

            var matches = scenario.Steps.SelectMany(s => placeholderMatcher.Matches(s.Text).Cast<Match>());

            foreach(var match in matches.Select(m => m.Value.Substring(1, m.Value.Length - 2)))
            {
                var key = match;

                if (!scenario.Examples.Any(d => d.ContainsKey(key)))
                {
                    throw new GherkinParseException(fileName, "The placeholder '{0}' has no matching column in the table of examples", key);
                }
            }
        }
コード例 #43
0
 private static SpecRun.Scenario[] FindSpecRunScenarios(ScenarioOutline scenarioOutline, SpecRun.Feature specRunFeature)
 {
     return(specRunFeature.Scenarios.Where(d => d.Title.StartsWith(scenarioOutline.Name + ", ")).ToArray());
 }
コード例 #44
0
        ///<summary>
        /// Call this function to parse a piece of text, specifying its file origin (which will generate better error messages).
        ///</summary>
        ///<param name="fileName">Name of file origin of the Gherkin-text</param>
        ///<param name="text">Gherkin-text to parse</param>
        ///<returns>A parse result including the AST</returns>
        public ParseResult Parse(string fileName, string text)
        {
            var features = new List<Feature>();

            using (var reader = new StringReader(text))
            {
                var accumulatedTags = new List<string>();

                string line;

                Feature currentFeature = null;
                Scenario currentScenario = null;
                StepType? mostRecentStepType = null;
                var tableColumnNames = new List<string>();
                var parsingExamples = false;
                var parsingBackground = false;

                var lineNumber = 0;

                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Trim();
                    lineNumber++;

                    if (ShouldBeIgnored(line))
                    {
                        continue;
                    }

                    if (line.StartsWith("@"))
                    {
                        var tokens = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        var invalidTag = tokens.FirstOrDefault(t => !t.StartsWith("@"));

                        if (invalidTag != null)
                        {
                            throw new GherkinParseException(fileName, lineNumber, line,
                                                            "'{0}' is not a valid tag - tags must begin with '@', e.g. '@important'",
                                                            invalidTag);
                        }

                        var tags = tokens.Select(t => t.TrimStart('@'));

                        accumulatedTags.AddRange(tags);

                        continue;
                    }

                    if (line.StartsWith(FeatureIntroduction, Comparison))
                    {
                        var featureText = line.Substring(FeatureIntroduction.Length).Trim();
                        currentFeature = new Feature(featureText, accumulatedTags);
                        accumulatedTags.Clear();
                        features.Add(currentFeature);
                        currentScenario = null;
                        mostRecentStepType = null;
                        continue;
                    }

                    if (currentFeature == null)
                    {
                        currentFeature = Feature.NewAnonymousFeature(accumulatedTags);
                        accumulatedTags.Clear();
                        features.Add(currentFeature);
                    }

                    if (line.StartsWith("Background:", Comparison) )
                    {
                        parsingBackground = true;
                        continue;
                    }

                    if (line.StartsWith(ScenarioIntroduction, Comparison))
                    {
                        var scenarioText = line.Substring(line.IndexOf(":") + 1).Trim();
                        currentScenario = new ExecutableScenario(scenarioText, accumulatedTags.Concat(currentFeature.Tags));
                        accumulatedTags.Clear();
                        tableColumnNames.Clear();
                        currentFeature.Scenarios.Add(currentScenario);
                        mostRecentStepType = null;
                        parsingExamples = parsingBackground = false;
                        continue;
                    }

                    if (line.StartsWith(ScenarioOutlineIntroduction, Comparison))
                    {
                        var scenarioText = line.Substring(line.IndexOf(":") + 1).Trim();
                        currentScenario = new ScenarioOutline(scenarioText, accumulatedTags.Concat(currentFeature.Tags));
                        accumulatedTags.Clear();
                        tableColumnNames.Clear();
                        currentFeature.Scenarios.Add(currentScenario);
                        mostRecentStepType = null;
                        parsingExamples = parsingBackground = false;
                        continue;
                    }

                    if (line.StartsWith(ExamplesIntroduction, Comparison))
                    {
                        if (!(currentScenario is ScenarioOutline))
                        {
                            throw new GherkinParseException(fileName, lineNumber, line, "Cannot specify examples in an ordinary scenario. Please use the 'Scenario outline:' introduction if you mean to specify examples");
                        }

                        parsingExamples = true;

                        continue;
                    }

                    if (parsingBackground)
                    {
                        if (string.IsNullOrEmpty(line))
                        {
                            continue;
                        }

                        if (line.StartsWith("and", Comparison))
                        {
                            if (mostRecentStepType == null)
                            {
                                throw new GherkinParseException(fileName, lineNumber, line,
                                                                @"Lines can only be introduced with ""and"" when it's preceded by either ""given"", ""when"", or ""then"".");
                            }

                            currentFeature.BackgroundSteps.Add(Step.And(line.Substring("and".Length).Trim(),
                                                               mostRecentStepType.Value));
                        }
                        else if (line.StartsWith("given", Comparison))
                        {
                            currentFeature.BackgroundSteps.Add(Step.Given(line.Substring("given".Length).Trim()));
                            mostRecentStepType = StepType.Given;
                            tableColumnNames.Clear();
                        }
                        else if (line.StartsWith("|"))
                        {
                            var tokens = line.Split('|').Select(s => s.Trim()).ToArray();

                            if (!tableColumnNames.Any())
                            {
                                tableColumnNames.AddRange(tokens);
                            }
                            else
                            {
                                var dict = new Dictionary<string, string>();

                                for (var index = 0; index < tokens.Length; index++)
                                {
                                    var key = tableColumnNames[index];
                                    if (string.IsNullOrEmpty(key)) continue;

                                    dict[key] = tokens[index];
                                }

                                currentFeature.BackgroundSteps.Last().Parameters.Add(dict);
                            }
                        }
                        else
                        {
                            throw new GherkinParseException(fileName, lineNumber, line,
                                                            @"Expected line to start with either ""given"", or ""|"". Please note that ""when"" or ""then"" steps may not appear inside the background element.");
                        }

                        continue;
                    }

                    if (currentScenario != null)
                    {
                        if (string.IsNullOrEmpty(line))
                        {
                            continue;
                        }

                        if (line.StartsWith("and", Comparison))
                        {
                            if (mostRecentStepType == null)
                            {
                                throw new GherkinParseException(fileName, lineNumber, line,
                                                                @"Lines can only be introduced with ""and"" when it's preceded by either ""given"", ""when"", ""then"", or ""|"".");
                            }

                            currentScenario.Steps.Add(Step.And(line.Substring("and".Length).Trim(),
                                                               mostRecentStepType.Value));
                            tableColumnNames.Clear();
                        }
                        else if (line.StartsWith("given", Comparison))
                        {
                            currentScenario.Steps.Add(Step.Given(line.Substring("given".Length).Trim()));
                            mostRecentStepType = StepType.Given;
                            tableColumnNames.Clear();
                        }
                        else if (line.StartsWith("when", Comparison))
                        {
                            currentScenario.Steps.Add(Step.When(line.Substring("when".Length).Trim()));
                            mostRecentStepType = StepType.When;
                            tableColumnNames.Clear();
                        }
                        else if (line.StartsWith("then", Comparison))
                        {
                            currentScenario.Steps.Add(Step.Then(line.Substring("then".Length).Trim()));
                            mostRecentStepType = StepType.Then;
                            tableColumnNames.Clear();
                        }
                        else if (line.StartsWith("|"))
                        {
                            var tokens = line.Split('|').Select(s => s.Trim()).ToArray();

                            if (!tableColumnNames.Any())
                            {
                                tableColumnNames.AddRange(tokens);
                            }
                            else
                            {
                                var dict = new Dictionary<string, string>();

                                for(var index = 0; index < tokens.Length; index++)
                                {
                                    var key = tableColumnNames[index];
                                    if (string.IsNullOrEmpty(key)) continue;

                                    dict[key] = tokens[index];
                                }

                                if (parsingExamples)
                                {
                                    ((ScenarioOutline)currentScenario).Examples.Add(dict);
                                }
                                else
                                {
                                    currentScenario.Steps.Last().Parameters.Add(dict);
                                }
                            }
                        }
                        else
                        {
                            throw new GherkinParseException(fileName, lineNumber, line,
                                                            @"Expected line to start with either ""given"", ""when"", or ""then"".");
                        }

                        continue;
                    }

                    currentFeature.AddText(line);
                    continue;
                }
            }

            features.ForEach(feature => AssertConsistency(feature, fileName));

            return new ParseResult(features);
        }
コード例 #45
0
        private IEnumerable <assembliesAssemblyCollectionTest> GetScenarioOutlineElements(ScenarioOutline scenario)
        {
            var featureElement = this.GetFeatureElement(scenario.Feature);

            if (featureElement == null)
            {
                return(Enumerable.Empty <assembliesAssemblyCollectionTest>());
            }
            var query = from test in featureElement.test
                        where HasDescriptionTrait(test, scenario.Name)
                        select test;

            return(query);
        }
コード例 #46
0
        private void GenerateScenarioOutlineTestVariant(CodeTypeDeclaration testType, ScenarioOutline scenarioOutline, string testMethodName,
                                                        IEnumerable <KeyValuePair <string, string> > paramToIdentifier, string exampleSetTitle, string exampleSetIdentifier,
                                                        Row row, Tags exampleSetTags, string variantName)
        {
            var variantNameIdentifier = variantName.ToIdentifier().TrimStart('_');

            CodeMemberMethod testMethod = GetTestMethodDeclaration(testType, scenarioOutline, exampleSetTags);

            testMethod.Name = string.IsNullOrEmpty(exampleSetIdentifier)
                ? string.Format("{0}_{1}", testMethod.Name, variantNameIdentifier)
                : string.Format("{0}_{1}_{2}", testMethod.Name, exampleSetIdentifier, variantNameIdentifier);

            //call test implementation with the params
            List <CodeExpression> argumentExpressions = row.Cells.Select(paramCell => new CodePrimitiveExpression(paramCell.Value)).Cast <CodeExpression>().ToList();

            argumentExpressions.Add(GetStringArrayExpression(exampleSetTags));

            testMethod.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeThisReferenceExpression(),
                    testMethodName,
                    argumentExpressions.ToArray()));

            var arguments = paramToIdentifier.Select((p2i, paramIndex) => new KeyValuePair <string, string>(p2i.Key, row.Cells[paramIndex].Value)).ToList();

            testGeneratorProvider.SetTestVariant(testMethod, scenarioOutline.Title, exampleSetTitle, variantName, arguments);
        }
コード例 #47
0
        private void GenerateScenarioOutlineTest(CodeTypeDeclaration testType, CodeMemberMethod testSetup, ScenarioOutline scenarioOutline, Feature feature)
        {
            string testMethodName = string.Format(TEST_FORMAT, scenarioOutline.Title.ToIdentifier());

            ParameterSubstitution paramToIdentifier = new ParameterSubstitution();

            foreach (var param in scenarioOutline.Examples.ExampleSets[0].Table.Header.Cells)
            {
                paramToIdentifier.Add(param.Value, param.Value.ToIdentifierCamelCase());
            }

            if (scenarioOutline.Examples.ExampleSets.Length > 1)
            {
                //TODO: check params
            }

            var testMethod = GenerateScenarioOutlineBody(feature, scenarioOutline, paramToIdentifier, testType, testMethodName, testSetup);

            if (testGeneratorProvider.SupportsRowTests && this.allowRowTests)
            {
                SetTestMethodDeclaration(testMethod, scenarioOutline, null, rowTest: true);

                foreach (var exampleSet in scenarioOutline.Examples.ExampleSets)
                {
                    for (int rowIndex = 0; rowIndex < exampleSet.Table.Body.Length; rowIndex++)
                    {
                        IEnumerable <string> arguments = exampleSet.Table.Body[rowIndex].Cells.Select(c => c.Value);
                        testGeneratorProvider.SetRow(testMethod, arguments, GetNonIgnoreTags(exampleSet.Tags), HasIgnoreTag(exampleSet.Tags));
                    }
                }
            }
            else
            {
                int exampleSetIndex = 0;
                foreach (var exampleSet in scenarioOutline.Examples.ExampleSets)
                {
                    string exampleSetTitle = exampleSet.Title == null
                        ? string.Format("Scenarios{0}", exampleSetIndex + 1)
                        : exampleSet.Title.ToIdentifier();

                    bool useFirstColumnAsName = CanUseFirstColumnAsName(exampleSet.Table);

                    for (int rowIndex = 0; rowIndex < exampleSet.Table.Body.Length; rowIndex++)
                    {
                        string variantName = useFirstColumnAsName ? exampleSet.Table.Body[rowIndex].Cells[0].Value.ToIdentifierPart() :
                                             string.Format("Variant{0}", rowIndex);
                        GenerateScenarioOutlineTestVariant(testType, scenarioOutline, testMethodName, paramToIdentifier, exampleSetTitle, exampleSet.Table.Body[rowIndex], exampleSet.Tags, variantName, exampleSet);
                    }
                    exampleSetIndex++;
                }
            }
        }
コード例 #48
0
        public bool IsMatch(ScenarioOutline scenarioOutline, string[] exampleValues, object scenarioElement)
        {
            var build = this.signatureBuilder.Build(scenarioOutline, exampleValues);

            return(ScenarioOutlineExampleIsMatch((assembliesAssemblyCollectionTest)scenarioElement, build));
        }
コード例 #49
0
 public Regex Build(ScenarioOutline scenarioOutline, string[] row)
 {
     // We don't actually need this regex-based thing for VsTest results.
     // It sucks that we have to provide one.
     return(new Regex(string.Empty));
 }
コード例 #50
0
        public TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] arguments)
        {
            var results = TestResults.Select(tr => tr.GetExampleResult(scenarioOutline, arguments)).ToArray();

            return(EvaluateTestResults(results));
        }
コード例 #51
0
        private void GenerateScenarioOutlineExamplesAsRowTests(TestClassGenerationContext generationContext, ScenarioOutline scenarioOutline, CodeMemberMethod scenatioOutlineTestMethod)
        {
            SetupTestMethod(generationContext, scenatioOutlineTestMethod, scenarioOutline, null, null, null, rowTest: true);

            foreach (var examples in scenarioOutline.Examples)
            {
                foreach (var row in examples.TableBody)
                {
                    var arguments = row.Cells.Select(c => c.Value);
                    testGeneratorProvider.SetRow(generationContext, scenatioOutlineTestMethod, arguments, GetNonIgnoreTags(examples.Tags), HasIgnoreTag(examples.Tags));
                }
            }
        }
コード例 #52
0
 public static IList <TableRow> GetExamplesTableBody(this ScenarioOutline scenario)
 {
     return(scenario.Examples.First().TableBody.ToList());
 }
コード例 #53
0
        private void GenerateScenarioOutlineTestVariant(TestClassGenerationContext generationContext, ScenarioOutline scenarioOutline, CodeMemberMethod scenatioOutlineTestMethod,
                                                        IEnumerable <KeyValuePair <string, string> > paramToIdentifier, string exampleSetTitle, string exampleSetIdentifier,
                                                        Gherkin.Ast.TableRow row, IEnumerable <Tag> exampleSetTags, string variantName)
        {
            CodeMemberMethod testMethod = CreateTestMethod(generationContext, scenarioOutline, exampleSetTags, variantName, exampleSetIdentifier);

            AddLineDirective(testMethod.Statements, scenarioOutline);

            //call test implementation with the params
            List <CodeExpression> argumentExpressions = row.Cells.Select(paramCell => new CodePrimitiveExpression(paramCell.Value)).Cast <CodeExpression>().ToList();

            argumentExpressions.Add(GetStringArrayExpression(exampleSetTags));

            testMethod.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeThisReferenceExpression(),
                    scenatioOutlineTestMethod.Name,
                    argumentExpressions.ToArray()));

            AddLineDirectiveHidden(testMethod.Statements);
            var arguments = paramToIdentifier.Select((p2i, paramIndex) => new KeyValuePair <string, string>(p2i.Key, row.Cells.ElementAt(paramIndex).Value)).ToList();

            testGeneratorProvider.SetTestMethodAsRow(generationContext, testMethod, scenarioOutline.Name, exampleSetTitle, variantName, arguments);
        }
コード例 #54
0
 public static IList <TableCell> GetExamplesTableHeaders(this ScenarioOutline scenario)
 {
     return(scenario.Examples.First().TableHeader.Cells.ToList());
 }
コード例 #55
0
ファイル: MsTestResults.cs プロジェクト: Jaykul/pickles
 public override TestResult GetExampleResult(ScenarioOutline scenario, string[] exampleValues)
 {
   throw new NotSupportedException();
 }
コード例 #56
0
 internal static bool BelongsToScenarioOutline(this XElement xmlScenario, ScenarioOutline scenarioOutline)
 {
     return(xmlScenario.Name().ToUpperInvariant().StartsWith(TransformName(scenarioOutline.Name)));
 }