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 scenarioOutline = new ScenarioOutline { Name = "Testing a scenario outline", Example = new Example { Name = "Some examples", Description = "An example", TableArgument = table } }; var htmlScenarioOutlineFormatter = Kernel.Get<HtmlScenarioOutlineFormatter>(); var output = htmlScenarioOutlineFormatter.Format(scenarioOutline, 0); output.ShouldContainGherkinScenario(); output.ShouldContainGherkinTable(); }
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) { var 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 (var step in scenario.Steps) { this.ditaStepFormatter.Format(section, step); } parentElement.Add(section); }
public void ThenCanReadScenarioOutlineResultSuccessfully() { // Write out the embedded test results file using (var input = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Pickles.Test." + RESULTS_FILE_NAME))) using (var output = new StreamWriter(RESULTS_FILE_NAME)) { output.Write(input.ReadToEnd()); } var configuration = Kernel.Get<Configuration>(); configuration.TestResultsFile = new FileInfo(RESULTS_FILE_NAME); var results = Kernel.Get<XUnitResults>(); var feature = new Feature {Name = "Addition"}; var scenarioOutline = new ScenarioOutline {Name = "Adding several numbers", Feature = feature}; TestResult result = results.GetScenarioOutlineResult(scenarioOutline); result.WasExecuted.ShouldBeTrue(); result.WasSuccessful.ShouldBeTrue(); TestResult exampleResult1 = results.GetExampleResult(scenarioOutline, new[] {"40", "50", "90"}); exampleResult1.WasExecuted.ShouldBeTrue(); exampleResult1.WasSuccessful.ShouldBeTrue(); TestResult exampleResult2 = results.GetExampleResult(scenarioOutline, new[] {"60", "70", "130"}); exampleResult2.WasExecuted.ShouldBeTrue(); exampleResult2.WasSuccessful.ShouldBeTrue(); }
private static ScenarioOutline BuildMinimalScenarioOutline() { var scenarioOutline = new ScenarioOutline { Description = "My Outline Description", Example = new Example { Description = "My Example Description", TableArgument = new Table { HeaderRow = new TableRow("Cell1"), DataRows = new List<TableRow>(new[] { new TableRow("Value1") }) }, }, Steps = new List<Step> { new Step { NativeKeyword = "Given", Name = "My Step Name", TableArgument = new Table { HeaderRow = new TableRow("Cell1"), DataRows = new List<TableRow>(new[] { new TableRow("Value1") }) }, } } }; return scenarioOutline; }
public void Format(Body body, ScenarioOutline scenarioOutline) { if (configuration.HasTestResults) { TestResult testResult = 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) { wordStepFormatter.Format(body, step); } body.GenerateParagraph("Examples:", "Heading3"); wordTableFormatter.Format(body, scenarioOutline.Example.TableArgument); }
public void ThenCanReadScenarioOutlineResultSuccessfully() { var scenarioOutline = new ScenarioOutline {Name = "Adding several numbers", Feature = _feature}; TestResult result = _results.GetScenarioOutlineResult(scenarioOutline); result.WasExecuted.ShouldBeTrue(); result.WasSuccessful.ShouldBeTrue(); }
private XElement FormatExamples(ScenarioOutline scenarioOutline) { return new XElement(xmlns + "div", new XAttribute("class", "examples"), new XElement(xmlns + "h3", "Examples"), htmlDescriptionFormatter.Format(scenarioOutline.Example.Description), (scenarioOutline.Example.TableArgument == null) ? null : htmlTableFormatter.Format(scenarioOutline.Example.TableArgument) ); }
public XElement Format(ScenarioOutline scenarioOutline, int id) { return new XElement(xmlns + "li", new XAttribute("class", "scenario"), htmlImageResultFormatter.Format(scenarioOutline), FormatHeading(scenarioOutline), FormatSteps(scenarioOutline), scenarioOutline.Example == null ? null : FormatExamples(scenarioOutline) ); }
private XElement FormatHeading(ScenarioOutline scenarioOutline) { if (string.IsNullOrEmpty(scenarioOutline.Name)) return null; return new XElement(xmlns + "div", new XAttribute("class", "scenario-heading"), new XElement(xmlns + "h2", scenarioOutline.Name), htmlDescriptionFormatter.Format(scenarioOutline.Description) ); }
public void ThenCanSuccessfullyMatch() { var scenarioOutline = new ScenarioOutline { Name = "Adding several numbers" }; var exampleRow = new string[] { "40", "50", "90" }; var signatureBuilder = Kernel.Get<xUnitExampleSignatureBuilder>(); var signature = signatureBuilder.Build(scenarioOutline, exampleRow); signature.IsMatch("Pickles.TestHarness.xUnit.AdditionFeature.AddingSeveralNumbers(firstNumber: \"40\", secondNumber: \"50\", result: \"90\", exampleTags: System.String[])".ToLowerInvariant()).ShouldBeTrue(); }
private XElement FormatSteps(ScenarioOutline scenarioOutline) { if (scenarioOutline.Steps == null) return null; return new XElement(xmlns + "div", new XAttribute("class", "steps"), new XElement(xmlns + "ul", scenarioOutline.Steps.Select( step => htmlStepFormatter.Format(step))) ); }
public XElement Format(ScenarioOutline scenarioOutline) { if (configuration.HasTestFrameworkResults) { TestResult scenarioResult = this.results.GetScenarioOutlineResult(scenarioOutline); if (!scenarioResult.WasExecuted || !scenarioResult.IsSuccessful) return null; return BuildImageElement(scenarioResult); } return null; }
private IEnumerable<XElement> GetScenarioOutlineElements(ScenarioOutline scenario) { var featureElement = GetFeatureElement(scenario.Feature); var scenarioQuery = from test in featureElement.Descendants("test") from trait in test.Descendants("traits").Descendants("trait") where trait.Attribute("name").Value == "Description" && trait.Attribute("value").Value == scenario.Name select test; return scenarioQuery; }
public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline) { XElement featureElement = GetFeatureElement(scenarioOutline.Feature); XElement scenarioOutlineElement = null; if (featureElement != null) { scenarioOutlineElement = GetFeatureElement(scenarioOutline.Feature) .Descendants("test-suite") .Where(x => x.Attribute("description") != null) .FirstOrDefault(x => x.Attribute("description").Value == scenarioOutline.Name); } return GetResultFromElement(scenarioOutlineElement); }
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); } stringBuilder.Remove(stringBuilder.Length - 1, 1); return new Regex(stringBuilder.ToString()); }
public TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] row) { var featureElement = GetFeatureElement(scenarioOutline.Feature); XElement examplesElement = null; if (featureElement != null) { examplesElement = GetFeatureElement(scenarioOutline.Feature) .Descendants("test-suite") .Where(x => x.Attribute("description") != null) .FirstOrDefault(x => x.Attribute("description").Value == scenarioOutline.Name) .Descendants("test-case") .Where(x => x.Attribute("description") != null) .FirstOrDefault(x => IsRowMatched(ExtractRowValuesFromName(x.Attribute("description").Value), row)); } return GetResultFromElement(examplesElement); }
public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline) { IEnumerable<XElement> exampleElements = GetScenarioOutlineElements(scenarioOutline); int passedCount = 0; int failedCount = 0; int skippedCount = 0; foreach (XElement exampleElement in exampleElements) { TestResult result = 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 = Kernel.Get<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 scenarioOutline = new ScenarioOutline { Name = "Test Feature", Description = "In order to test this feature,\nAs a developer\nI want to test this feature", Example = example }; 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); } }
public void ThenSingleScenarioOutlineAddedSuccessfully() { var excelScenarioFormatter = Kernel.Get<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 scenarioOutline = new ScenarioOutline { Name = "Test Feature", Description = "In order to test this feature,\nAs a developer\nI want to test this feature", Example = example }; 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); } }
public XElement Format(ScenarioOutline scenarioOutline, int id) { return new XElement(xmlns + "li", new XAttribute("class", "scenario"), this.htmlImageResultFormatter.Format(scenarioOutline), new XElement(xmlns + "div", new XAttribute("class", "scenario-heading"), new XElement(xmlns + "h2", scenarioOutline.Name), this.htmlDescriptionFormatter.Format(scenarioOutline.Description) ), new XElement(xmlns + "div", new XAttribute("class", "steps"), new XElement(xmlns + "ul", scenarioOutline.Steps.Select(step => this.htmlStepFormatter.Format(step))) ), new XElement(xmlns + "div", new XAttribute("class", "examples"), new XElement(xmlns + "h3", "Examples"), this.htmlDescriptionFormatter.Format(scenarioOutline.Example.Description), this.htmlTableFormatter.Format(scenarioOutline.Example.TableArgument) ) ); }
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 = testResults.GetScenarioOutlineResult(scenarioOutline); if (configuration.HasTestResults && results.WasExecuted) { worksheet.Cell(originalRow, "B").Style.Fill.SetBackgroundColor(results.WasSuccessful ? XLColor.AppleGreen : XLColor.CandyAppleRed); } foreach (Step step in scenarioOutline.Steps) { excelStepFormatter.Format(worksheet, step, ref row); } row++; worksheet.Cell(row++, "B").Value = "Examples"; excelTableFormatter.Format(worksheet, scenarioOutline.Example.TableArgument, ref row); }
public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline) { var scenarioOutlineExecutionIds = from unitTest in this.resultsDocument.Root.Descendants(ns + "UnitTest") let properties = unitTest.Element(ns + "Properties") where properties != null let property = properties.Element(ns + "Property") let key = property.Element(ns + "Key") let value = property.Element(ns + "Value") where key.Value == "FeatureTitle" && value.Value == scenarioOutline.Feature.Name let description = unitTest.Element(ns + "Description") where description.Value == scenarioOutline.Name select new Guid(unitTest.Element(ns + "Execution").Attribute("id").Value); bool wasExecuted = true; bool wasSuccessful = true; foreach (Guid scenarioOutlineExecutionId in scenarioOutlineExecutionIds) { TestResult result = GetExecutionResult(scenarioOutlineExecutionId); if (!result.WasExecuted) wasExecuted = false; if (!result.WasSuccessful) wasSuccessful = false; } return new TestResult {WasExecuted = wasExecuted, WasSuccessful = wasSuccessful}; }
public string GetScenarioOutlineKey(ScenarioOutline scenarioOutline) { return GetScenarioOutlineKey(scenarioOutline.Feature.Name, scenarioOutline.Name); }
public TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] row) { return new TestResult(); }
public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline) { return new TestResult(); }
public TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] row) { var featureElement = GetFeatureElement(scenarioOutline.Feature); XElement examplesElement = null; if (featureElement != null) { var exampleSignature = this.exampleSignatureBuilder.Build(scenarioOutline, row); examplesElement = featureElement .Descendants("test-suite") .Where(x => x.Attribute("description") != null) .FirstOrDefault(x => x.Attribute("description").Value == scenarioOutline.Name) .Descendants("test-case") .Where(x => x.Attribute("name") != null) .FirstOrDefault(x => exampleSignature.IsMatch(x.Attribute("name").Value.ToLowerInvariant())); } return GetResultFromElement(examplesElement); }
public TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] row) { IEnumerable<XElement> exampleElements = GetScenarioOutlineElements(scenarioOutline); var result = new TestResult(); foreach (XElement exampleElement in exampleElements) { Regex signature = exampleSignatureBuilder.Build(scenarioOutline, row); if (signature.IsMatch(exampleElement.Attribute("name").Value.ToLowerInvariant())) { return GetResultFromElement(exampleElement); } } return result; }
public void AddScenarioOutline(ScenarioOutline scenarioOutline) { scenarioOutline.Feature = this; this.ScenarioOutlines.Add(scenarioOutline); }
public XElement Format(ScenarioOutline scenarioOutline) { if (configuration.HasTestResults) { TestResult scenarioResult = results.GetScenarioOutlineResult(scenarioOutline); return scenarioResult.WasExecuted ? BuildImageElement(scenarioResult) : null; } return null; }
public void ThenCanFormatScenarioOutlineWithMissingExampleCorrectly() { var scenarioOutline = new ScenarioOutline { Name = "Testing a scenario outline", Description = "We need to make sure that scenario outlines work properly", Example = null }; var htmlScenarioOutlineFormatter = Kernel.Get<HtmlScenarioOutlineFormatter>(); var output = htmlScenarioOutlineFormatter.Format(scenarioOutline, 0); output.ShouldContainGherkinScenario(); output.ShouldNotContainGherkinTable(); }