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 != TestResult.Inconclusive)) { worksheet.Cell(originalRow, "B").Style.Fill.SetBackgroundColor(results == TestResult.Passed ? 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); } }
public TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] exampleValues) { XElement featureElement = this.GetFeatureElement(scenarioOutline.Feature); XElement examplesElement = null; if (featureElement != null) { var signatureBuilder = this.ExampleSignatureBuilder; if (signatureBuilder == null) { throw new InvalidOperationException( "You need to set the ExampleSignatureBuilder before using GetExampleResult."); } Regex exampleSignature = signatureBuilder.Build(scenarioOutline, exampleValues); var parameterizedTestElement = featureElement .Descendants("test-suite") .FirstOrDefault(x => IsMatchingParameterizedTestElement(x, scenarioOutline)); if (parameterizedTestElement != null) { examplesElement = parameterizedTestElement.Descendants("test-case") .FirstOrDefault(x => IsMatchingTestCase(x, exampleSignature)); } } return this.GetResultFromElement(examplesElement); }
public void ThenCanFormatCompleteScenarioOutlineCorrectly() { 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", 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(); }
public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline) { if (this.specRunFeatures == null) { return TestResult.Inconclusive; } var specRunFeature = this.FindSpecRunFeature(scenarioOutline.Feature); if (specRunFeature == null) { return TestResult.Inconclusive; } Parser.SpecRun.Scenario[] specRunScenarios = FindSpecRunScenarios(scenarioOutline, specRunFeature); if (specRunScenarios.Length == 0) { return TestResult.Inconclusive; } TestResult result = StringsToTestResult(specRunScenarios.Select(srs => srs.Result)); return result; }
public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline) { IEnumerable<assembliesAssemblyCollectionTest> exampleElements = this.GetScenarioOutlineElements(scenarioOutline); int passedCount = 0; int failedCount = 0; int skippedCount = 0; foreach (var exampleElement in exampleElements) { TestResult result = this.GetResultFromElement(exampleElement); if (result == TestResult.Inconclusive) { skippedCount++; } if (result == TestResult.Passed) { passedCount++; } if (result == TestResult.Failed) { failedCount++; } } return GetAggregateResult(passedCount, failedCount, skippedCount); }
public void Format(Body body, ScenarioOutline scenarioOutline) { if (this.configuration.HasTestResults) { TestResult testResult = this.testResults.GetScenarioOutlineResult(scenarioOutline); if (testResult == TestResult.Passed) { body.GenerateParagraph("Passed", "Passed"); } else if (testResult == TestResult.Failed) { 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); } }
private XElement FormatHeading(ScenarioOutline scenarioOutline) { if (string.IsNullOrEmpty(scenarioOutline.Name)) { return null; } var result = new XElement( this.xmlns + "div", new XAttribute("class", "scenario-heading"), string.IsNullOrEmpty(scenarioOutline.Slug) ? null : new XAttribute("id", scenarioOutline.Slug), new XElement(this.xmlns + "h2", scenarioOutline.Name)); var tags = RetrieveTags(scenarioOutline); if (tags.Length > 0) { var paragraph = new XElement(this.xmlns + "p", HtmlScenarioFormatter.CreateTagElements(tags.OrderBy(t => t).ToArray(), this.xmlns)); paragraph.Add(new XAttribute("class", "tags")); result.Add(paragraph); } result.Add(this.htmlDescriptionFormatter.Format(scenarioOutline.Description)); return result; }
public XElement Format(Table table, ScenarioOutline scenarioOutline, bool includeResults) { if (table == null) return null; var headerCells = table.HeaderRow.ToArray(); if (includeResults) { headerCells = headerCells.Concat(new[] { " " }).ToArray(); } return new XElement(this.xmlns + "div", new XAttribute("class", "table_container"), new XElement(this.xmlns + "table", new XAttribute("class", "datatable"), new XElement(this.xmlns + "thead", new XElement(this.xmlns + "tr", headerCells.Select( cell => new XElement(this.xmlns + "th", cell)) ) ), new XElement(this.xmlns + "tbody", table.DataRows.Select(row => this.FormatRow(row, scenarioOutline, includeResults)) ) )); }
public bool IsMatch(ScenarioOutline scenarioOutline, string[] exampleValues, object scenarioElement) { var element = (XElement)scenarioElement; var valuesInScenario = element.DetermineValuesInScenario(); var isMatch = exampleValues.OrderBy(e => e).SequenceEqual(valuesInScenario.OrderBy(v => v)); return isMatch; }
public override TestResult GetExampleResult(ScenarioOutline scenario, string[] exampleValues) { var cucumberScenarios = this.GetCucumberScenarios(scenario); var query = cucumberScenarios.Where(cs => this.ScenarioHasStepsForAllExampleValues(cs.ScenarioBase, exampleValues)) .Select(cs => ToTestResult(cs.ScenarioBase, cs.Background)); return query.FirstOrDefault(); }
public Regex Build(ScenarioOutline scenarioOutline, string[] row) { var stringBuilder = new StringBuilder(); stringBuilder.Append(Regex.Escape(scenarioOutline.Name)); stringBuilder.Append("(, Examples (\\d*))?"); stringBuilder.Append(", " + Regex.Escape(row[0])); return new Regex(stringBuilder.ToString()); }
public void ThenCanSuccessfullyMatch() { var scenarioOutline = new ScenarioOutline {Name = "Adding several numbers"}; var exampleRow = new[] {"40", "50", "90"}; var signatureBuilder = Container.Resolve<xUnitExampleSignatureBuilder>(); Regex signature = signatureBuilder.Build(scenarioOutline, exampleRow); signature.IsMatch("Pickles.TestHarness.xUnit.AdditionFeature.AddingSeveralNumbers(firstNumber: \"40\", secondNumber: \"50\", result: \"90\", exampleTags: System.String[])".ToLowerInvariant()).ShouldBeTrue(); }
public void Map_NoSteps_ReturnsEmtpyListOfSteps() { var scenarioOutline = new ScenarioOutline { Steps = null }; var mapper = CreateMapper(); JsonScenarioOutline actual = mapper.Map(scenarioOutline); Check.That(actual.Steps.Count).IsEqualTo(0); }
public void Map_NoExamples_ReturnsEmptyListOfExamples() { var scenarioOutline = new ScenarioOutline { Examples = null }; var mapper = CreateMapper(); JsonScenarioOutline actual = mapper.Map(scenarioOutline); Check.That(actual.Examples.Count).IsEqualTo(0); }
public void Map_SomeScenarioOutline_ReturnsSomeJsonScenarioOutline() { var scenarioOutline = new ScenarioOutline(); var mapper = CreateMapper(); JsonScenarioOutline actual = mapper.Map(scenarioOutline); Check.That(actual).IsNotNull(); }
public XElement Format(ScenarioOutline scenarioOutline) { if (this.configuration.HasTestResults) { TestResult scenarioResult = this.results.GetScenarioOutlineResult(scenarioOutline); return this.BuildImageElement(scenarioResult); } return null; }
private XElement FormatSteps(ScenarioOutline scenarioOutline) { if (scenarioOutline.Steps == null) return null; return new XElement(this.xmlns + "div", new XAttribute("class", "steps"), new XElement(this.xmlns + "ul", scenarioOutline.Steps.Select( step => this.htmlStepFormatter.Format(step))) ); }
public void ThenCanSuccessfullyMatchSpecialCharacters() { var scenarioOutline = new ScenarioOutline { Name = "Adding several numbers (foo-bar, foo bar)" }; var exampleRow = new[] { "40", "50", "90" }; var signatureBuilder = new NUnit3ExampleSignatureBuilder(); Regex signature = signatureBuilder.Build(scenarioOutline, exampleRow); var isMatch = signature.IsMatch("AddingSeveralNumbersFoo_BarFooBar(\"40\",\"50\",\"90\",System.String[])".ToLowerInvariant()); Check.That(isMatch).IsTrue(); }
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); var isMatch = signature.IsMatch("Pickles.TestHarness.AdditionFeature.AddingSeveralNumbers(\"40\",\"50\",\"90\",System.String[])".ToLowerInvariant()); Check.That(isMatch).IsTrue(); }
public override TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] exampleValues) { IEnumerable<XElement> exampleElements = this.GetScenarioOutlineElements(scenarioOutline); foreach (XElement exampleElement in exampleElements) { if (this.ScenarioOutlineExampleMatcher.IsMatch(scenarioOutline, exampleValues, exampleElement)) { return this.GetResultFromElement(exampleElement); } } return TestResult.Inconclusive; }
public Regex Build(ScenarioOutline scenarioOutline, string[] row) { var stringBuilder = new StringBuilder(); stringBuilder.Append(scenarioOutline.Name.ToLowerInvariant().Replace(" ", string.Empty) + "\\("); foreach (string value in row) { stringBuilder.AppendFormat("\"{0}\",", value.ToLowerInvariant().Replace(@"\", string.Empty).Replace(@"$", @"\$")); } stringBuilder.Remove(stringBuilder.Length - 1, 1); return new Regex(stringBuilder.ToString()); }
public Regex Build(ScenarioOutline scenarioOutline, string[] row) { var stringBuilder = new StringBuilder(); var name = SpecFlowNameMapping.Build(scenarioOutline.Name.ToLowerInvariant()); stringBuilder.Append(name).Append("\\("); foreach (var value in row.Select(v => v.Length > MaxExampleValueLength ? new { Value = v.Substring(0, MaxExampleValueLength), Ellipsis = "..." } : new { Value = v, Ellipsis = "" })) stringBuilder.AppendFormat("(.*): \"{0}\"{1}, ", Regex.Escape(value.Value.ToLowerInvariant()), value.Ellipsis); stringBuilder.Remove(stringBuilder.Length - 2, 2); return new Regex(stringBuilder.ToString()); }
protected override XElement GetScenarioOutlineElement(ScenarioOutline scenarioOutline) { XElement featureElement = this.GetFeatureElement(scenarioOutline.Feature); XElement scenarioOutlineElement = null; if (featureElement != null) { scenarioOutlineElement = this.GetFeatureElement(scenarioOutline.Feature) .Descendants("test-suite") .Where(x => x.Attribute("description") != null) .FirstOrDefault(x => x.Attribute("description").Value == scenarioOutline.Name); } return scenarioOutlineElement; }
public void ThenCanSuccessfullyMatchExamplesWithLongValues() { var scenarioOutline = new ScenarioOutline { Name = "Deal correctly with overlong example values" }; var exampleRow = new[] { "Please enter a valid two letter country code (e.g. DE)!", "This is just a very very very veery long error message!" }; var signatureBuilder = new XUnitExampleSignatureBuilder(); var signature = signatureBuilder.Build(scenarioOutline, exampleRow); var isMatch = signature.IsMatch("Pickles.TestHarness.xunit2.ScenarioOutlinesFeature.DealCorrectlyWithOverlongExampleValues(value1: \"Please enter a valid two letter country code (e.g.\"..., value2: \"This is just a very very very veery long error mes\"..., exampleTags: [])".ToLowerInvariant()); Check.That(isMatch).IsTrue(); }
public void ThenCanSuccessfullyMatchExamplesWithLongValues() { var scenarioOutline = new ScenarioOutline { Name = "Deal correctly with overlong example values" }; var exampleRow = new[] { "Please enter a valid two letter country code (e.g. DE)!", "This is just a very very very veery long error message!" }; var signatureBuilder = new NUnit3ExampleSignatureBuilder(); var signature = signatureBuilder.Build(scenarioOutline, exampleRow); var isMatch = signature.IsMatch("DealCorrectlyWithOverlongExampleValues(\"Please enter a valid two letter count...\",\"This is just a very very very veery l...\",null)".ToLowerInvariant()); Check.That(isMatch).IsTrue(); }
public Regex Build(ScenarioOutline scenarioOutline, string[] row) { var stringBuilder = new StringBuilder(); var name = SpecFlowNameMapping.Build(scenarioOutline.Name.ToLowerInvariant()); stringBuilder.Append(name).Append("\\("); foreach (var value in row) { stringBuilder.AppendFormat("\"{0}\",", Regex.Escape(value.ToLowerInvariant())); } stringBuilder.Remove(stringBuilder.Length - 1, 1); return new Regex(stringBuilder.ToString()); }
private static bool MatchRegexSpecialChars(string expectedParameter) { var scenarioOutline = new ScenarioOutline { Name = "This scenario contains examples with Regex-special characters" }; var exampleRow = new[] { expectedParameter }; var signatureBuilder = new XUnitExampleSignatureBuilder(); var signature = signatureBuilder.Build(scenarioOutline, exampleRow); var matchEntry = string .Format( "Pickles.TestHarness.xunit2.ScenariosWithSpecialCharactersFeature.ThisScenarioContainsExamplesWithRegex_SpecialCharacters(regex: \"{0}\", exampleTags: System.String[])", expectedParameter) .ToLowerInvariant(); return signature.IsMatch(matchEntry); }
private XElement FormatExamples(ScenarioOutline scenarioOutline) { var exampleDiv = new XElement(this.xmlns + "div"); foreach (var example in scenarioOutline.Examples) { exampleDiv.Add(new XElement(this.xmlns + "div", new XAttribute("class", "examples"), new XElement(this.xmlns + "h3", "Examples: " + example.Name), this.htmlDescriptionFormatter.Format(example.Description), (example.TableArgument == null) ? null : this.htmlTableFormatter.Format(example.TableArgument, scenarioOutline, testResults.SupportsExampleResults) )); } return exampleDiv; }
public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline) { IEnumerable<XElement> exampleElements = this.GetScenarioOutlineElements(scenarioOutline); int passedCount = 0; int failedCount = 0; int skippedCount = 0; foreach (XElement exampleElement in exampleElements) { TestResult result = this.GetResultFromElement(exampleElement); if (result.WasExecuted == false) skippedCount++; if (result.WasExecuted && result.WasSuccessful) passedCount++; if (result.WasExecuted && !result.WasSuccessful) failedCount++; } return GetAggregateResult(passedCount, failedCount, skippedCount); }
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); Check.That(worksheet.Cell("B3").Value).IsEqualTo(scenarioOutline.Name); Check.That(worksheet.Cell("C4").Value).IsEqualTo(scenarioOutline.Description); Check.That(worksheet.Cell("B9").Value).IsEqualTo("Examples"); Check.That(worksheet.Cell("D10").Value).IsEqualTo("Var1"); Check.That(worksheet.Cell("E10").Value).IsEqualTo("Var2"); Check.That(worksheet.Cell("F10").Value).IsEqualTo("Var3"); Check.That(worksheet.Cell("G10").Value).IsEqualTo("Var4"); Check.That(worksheet.Cell("D11").Value).IsEqualTo(1.0); Check.That(worksheet.Cell("E11").Value).IsEqualTo(2.0); Check.That(worksheet.Cell("F11").Value).IsEqualTo(3.0); Check.That(worksheet.Cell("G11").Value).IsEqualTo(4.0); Check.That(worksheet.Cell("D12").Value).IsEqualTo(5.0); Check.That(worksheet.Cell("E12").Value).IsEqualTo(6.0); Check.That(worksheet.Cell("F12").Value).IsEqualTo(7.0); Check.That(worksheet.Cell("G12").Value).IsEqualTo(8.0); Check.That(row).IsEqualTo(13); } }