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); output.ShouldContainGherkinScenario(); output.ShouldContainGherkinTable(); }
public void ThenCanReadScenarioOutlineResultSuccessfully() { // Write out the embedded test results file using (var input = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("PicklesDoc.Pickles.Test." + RESULTS_FILE_NAME))) using (var output = new StreamWriter(RESULTS_FILE_NAME)) { output.Write(input.ReadToEnd()); } var configuration = Container.Resolve<Configuration>(); configuration.TestResultsFile = new FileInfo(RESULTS_FILE_NAME); var results = Container.Resolve<NUnitResults>(); 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(); }
public TestResult GetScenarioOutlineResult(Gherkin.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); }
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); } }
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); }
public void ThenCanReadScenarioOutlineResultSuccessfully() { var scenarioOutline = new ScenarioOutline {Name = "Adding several numbers", Feature = this._feature}; TestResult result = this._results.GetScenarioOutlineResult(scenarioOutline); result.WasExecuted.ShouldBeTrue(); result.WasSuccessful.ShouldBeTrue(); }
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(); }
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 TestResult GetScenarioOutlineResult(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 this.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 - 2, 2); return new Regex(stringBuilder.ToString()); }
public TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] row) { IEnumerable<XElement> exampleElements = this.GetScenarioOutlineElements(scenarioOutline); var result = new TestResult(); foreach (XElement exampleElement in exampleElements) { Regex signature = this.exampleSignatureBuilder.Build(scenarioOutline, row); if (signature.IsMatch(exampleElement.Attribute("name").Value.ToLowerInvariant())) { return this.GetResultFromElement(exampleElement); } } return result; }
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) )); } 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); 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 TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] row) { XElement featureElement = this.GetFeatureElement(scenarioOutline.Feature); XElement examplesElement = null; if (featureElement != null) { Regex 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 this.GetResultFromElement(examplesElement); }
private static ScenarioOutline BuildMinimalScenarioOutline() { var examples = new List<Example>(); examples.Add(new Example { Description = "My Example Description", TableArgument = new Table { HeaderRow = new TableRow("Cell1"), DataRows = new List<TableRow>(new[] { new TableRow ("Value1") }) }, }); var scenarioOutline = new ScenarioOutline { Description = "My Outline Description", Examples = examples, 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; }
private XElement FormatHeading(ScenarioOutline scenarioOutline) { if (string.IsNullOrEmpty(scenarioOutline.Name)) return null; var result = new XElement(this.xmlns + "div", new XAttribute("class", "scenario-heading"), 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 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); } }
public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline) { var queriedFeatureName = scenarioOutline.Feature.Name; var queriedScenarioOutlineName = scenarioOutline.Name; var allScenariosForAFeature = from scenario in AllScenariosInResultFile() let scenarioProperties = PropertiesOf(scenario) where scenarioProperties != null where FeatureNamePropertyExistsWith(queriedFeatureName, among: scenarioProperties) select scenario; var scenarioOutlineExecutionIds = from scenario in allScenariosForAFeature where NameOf(scenario) == queriedScenarioOutlineName select ScenarioExecutionIdOf(scenario); TestResult result = scenarioOutlineExecutionIds.Select(this.GetExecutionResult).Merge(); return result; }
public TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] row) { IEnumerable<XElement> exampleElements = this.GetScenarioOutlineElements(scenarioOutline); var result = new TestResult(); var signatureBuilder = this.ExampleSignatureBuilder; if (signatureBuilder == null) { throw new InvalidOperationException("You need to set the ExampleSignatureBuilder before using GetExampleResult."); } foreach (XElement exampleElement in exampleElements) { Regex signature = signatureBuilder.Build(scenarioOutline, row); if (signature.IsMatch(exampleElement.Attribute("name").Value.ToLowerInvariant())) { return this.GetResultFromElement(exampleElement); } } return result; }
public TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] row) { 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, 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 this.GetResultFromElement(examplesElement); }
private static string[] RetrieveTags(ScenarioOutline scenarioOutline) { if (scenarioOutline == null) return new string[0]; if (scenarioOutline.Feature == null) return scenarioOutline.Tags.ToArray(); return scenarioOutline.Feature.Tags.Concat(scenarioOutline.Tags).ToArray(); }
public TestResult GetExampleResult(ScenarioOutline scenarioOutline, string[] row) { return new TestResult(); }
public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline) { return new TestResult(); }
public XElement Format(ScenarioOutline scenarioOutline, int id) { return new XElement(this.xmlns + "li", new XAttribute("class", "scenario"), this.htmlImageResultFormatter.Format(scenarioOutline), this.FormatHeading(scenarioOutline), this.FormatSteps(scenarioOutline), (scenarioOutline.Examples == null || !scenarioOutline.Examples.Any()) ? null : this.FormatExamples(scenarioOutline) ); }
private static SpecRun.Scenario[] FindSpecRunScenarios(Gherkin.ScenarioOutline scenarioOutline, SpecRun.Feature specRunFeature) { return(specRunFeature.Scenarios.Where(d => d.Title.StartsWith(scenarioOutline.Name + ", ")).ToArray()); }
public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline) { //Not applicable return new TestResult(); }
public TestResult GetScenarioOutlineResult(ScenarioOutline scenarioOutline) { var results = this.TestResults.Select(tr => tr.GetScenarioOutlineResult(scenarioOutline)).ToArray(); return EvaluateTestResults(results); }
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); TestResult result = scenarioOutlineExecutionIds.Select(this.GetExecutionResult).Merge(); return result; }
private IEnumerable<XElement> GetScenarioOutlineElements(ScenarioOutline scenario) { XElement featureElement = this.GetFeatureElement(scenario.Feature); IEnumerable<XElement> 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 GetExampleResult(ScenarioOutline scenarioOutline, string[] arguments) { var results = TestResults.OfType<NUnitSingleResults>().Select(tr => tr.GetExampleResult(scenarioOutline, arguments)).ToArray(); return EvaluateTestResults(results); }
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); output.ShouldContainGherkinScenario(); output.ShouldNotContainGherkinTable(); }