예제 #1
0
        public void NoTags()
        {
          var configuration = Container.Resolve<Configuration>();
          configuration.TestResultsFile = null;

          var scenario = new Scenario
          {
            Name = "A Scenario",
            Description = @"This scenario has no tags",
            Tags = { }
          };

          var htmlFeatureFormatter = Container.Resolve<HtmlScenarioFormatter>();
          XElement featureElement = htmlFeatureFormatter.Format(scenario, 1);
          XElement header = featureElement.Elements().FirstOrDefault(element => element.Name.LocalName == "div");

          Assert.NotNull(header);
          header.ShouldBeNamed("div");
          header.ShouldBeInInNamespace("http://www.w3.org/1999/xhtml");
          header.ShouldHaveAttribute("class", "scenario-heading");
          Assert.AreEqual(2, header.Elements().Count());

          header.Elements().ElementAt(0).ShouldBeNamed("h2");
          header.Elements().ElementAt(1).ShouldBeNamed("div");
        }
예제 #2
0
        public void Format(Body body, Scenario background)
        {
            var headerParagraph   = new Paragraph(new ParagraphProperties(new ParagraphStyleId { Val = "Heading2" }));
            var backgroundKeyword = GetLocalizedBackgroundKeyword();
            headerParagraph.Append(new Run(new RunProperties(new Bold()), new Text(backgroundKeyword)));

            var table = new Table();
            table.Append(GenerateTableProperties());
            var row = new TableRow();
            var cell = new TableCell();
            cell.Append(headerParagraph);

            foreach (var descriptionSentence in WordDescriptionFormatter.SplitDescription(background.Description))
            {
                cell.Append(CreateNormalParagraph(descriptionSentence));
            }

            foreach (var step in background.Steps)
            {
                cell.Append(WordStepFormatter.GenerateStepParagraph(step));
            }

            cell.Append(CreateNormalParagraph("")); // Is there a better way to generate a new empty line?
            row.Append(cell);
            table.Append(row);

            body.Append(table);
        }
예제 #3
0
 public TestResult GetScenarioResult(Scenario scenario)
 {
     XElement scenarioElement = this.GetScenarioElement(scenario);
     return scenarioElement != null 
         ? this.GetResultFromElement(scenarioElement)
         : new TestResult() { WasExecuted = false, WasSuccessful = false };
 }
예제 #4
0
        public void ThenCanRenderTags()
        {
            var configuration = Container.Resolve<Configuration>();
            configuration.TestResultsFile = null;

            var scenario = new Scenario
                              {
                                  Name = "A Scenario",
                                  Description = @"This scenario has tags",
                                  Tags = { "tag1", "tag2" }
                              };

            var htmlFeatureFormatter = Container.Resolve<HtmlScenarioFormatter>();
            XElement featureElement = htmlFeatureFormatter.Format(scenario, 1);
            XElement header = featureElement.Elements().FirstOrDefault(element => element.Name.LocalName == "div");

            Assert.NotNull(header);
            header.ShouldBeNamed("div");
            header.ShouldBeInInNamespace("http://www.w3.org/1999/xhtml");
            header.ShouldHaveAttribute("class", "scenario-heading");
            Assert.AreEqual(3, header.Elements().Count());

            header.Elements().ElementAt(0).ShouldBeNamed("h2");
            header.Elements().ElementAt(1).ShouldBeNamed("p");
            header.Elements().ElementAt(2).ShouldBeNamed("div");

            var tagsParagraph = header.Elements().ElementAt(1);

            Assert.AreEqual(
              @"<p class=""tags"" xmlns=""http://www.w3.org/1999/xhtml"">Tags: <span>tag1</span>, <span>tag2</span></p>",
              tagsParagraph.ToString());
        }
        public void ThenCanReadScenarioResultSuccessfully()
        {
            // 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<CucumberJsonResults>();

            var feature = new Feature { Name = "Test Feature" };

            var scenario1 = new Scenario { Name = "Passing", Feature = feature };
            TestResult result1 = results.GetScenarioResult(scenario1);

            result1.WasExecuted.ShouldBeTrue();
            result1.WasSuccessful.ShouldBeTrue();

            var scenario2 = new Scenario { Name = "Failing", Feature = feature };
            TestResult result2 = results.GetScenarioResult(scenario2);

            result2.WasExecuted.ShouldBeTrue();
            result2.WasSuccessful.ShouldBeFalse();
        }
예제 #6
0
        public void Format(XElement parentElement, Scenario scenario)
        {
            var section = new XElement("section",
                                       new XElement("title", scenario.Name));

            if (this.configuration.HasTestResults)
            {
                TestResult testResult = this.nunitResults.GetScenarioResult(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"));
                }
            }

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

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

            parentElement.Add(section);
        }
예제 #7
0
        public XElement Format(Scenario scenario, int id)
        {
          var header = new XElement(
            this.xmlns + "div", 
            new XAttribute("class", "scenario-heading"), 
            new XElement(this.xmlns + "h2", scenario.Name));

          var tags = RetrieveTags(scenario);
          if (tags.Length > 0)
          {
            var paragraph = new XElement(this.xmlns + "p", CreateTagElements(tags.OrderBy(t => t).ToArray(), this.xmlns));
            paragraph.Add(new XAttribute("class", "tags"));
            header.Add(paragraph);
          }

          header.Add(this.htmlDescriptionFormatter.Format(scenario.Description));

          return new XElement(
            this.xmlns + "li",
            new XAttribute("class", "scenario"),
            this.htmlImageResultFormatter.Format(scenario),
            header,
            new XElement(
              this.xmlns + "div",
              new XAttribute("class", "steps"),
              new XElement(
                this.xmlns + "ul",
                scenario.Steps.Select(step => this.htmlStepFormatter.Format(step))))
            );
        }
 public TestResult GetScenarioResult(Scenario scenario)
 {
     Parser.JsonResult.Element cucumberScenario  = null;
       var cucumberFeature = this.GetFeatureElement(scenario.Feature);
       if(cucumberFeature != null)
     cucumberScenario = cucumberFeature.elements.FirstOrDefault(x => x.name == scenario.Name);
       return this.GetResultFromScenario(cucumberScenario);
 }
        public void ThenCanReadBackgroundResultSuccessfully()
        {
            var background = new Scenario {Name = "Background", Feature = this._feature};
            this._feature.AddBackground(background);

            TestResult result = this._results.GetScenarioResult(background);

            result.WasExecuted.ShouldBeFalse();
            result.WasSuccessful.ShouldBeFalse();
        }
예제 #10
0
 public TestResult GetScenarioResult(Scenario scenario)
 {
     XElement featureElement = this.GetFeatureElement(scenario.Feature);
     XElement scenarioElement = null;
     if (featureElement != null)
     {
         scenarioElement = featureElement
             .Descendants("test-case")
             .Where(x => x.Attribute("description") != null)
             .FirstOrDefault(x => x.Attribute("description").Value == scenario.Name);
     }
     return this.GetResultFromElement(scenarioElement);
 }
        public void ThenCanReadScenarioResultSuccessfully()
        {
            var scenario1 = new Scenario {Name = "Add two numbers", Feature = this._feature};
            TestResult result1 = this._results.GetScenarioResult(scenario1);

            result1.WasExecuted.ShouldBeTrue();
            result1.WasSuccessful.ShouldBeTrue();

            var scenario2 = new Scenario {Name = "Fail to add two numbers", Feature = this._feature};
            TestResult result2 = this._results.GetScenarioResult(scenario2);

            result2.WasExecuted.ShouldBeTrue();
            result2.WasSuccessful.ShouldBeFalse();
        }
예제 #12
0
        private Guid GetScenarioExecutionId(Scenario scenario)
        {
            var idString =
                (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 == scenario.Feature.Name
                 let description = unitTest.Element(ns + "Description")
                 where description.Value == scenario.Name
                 let id = unitTest.Element(ns + "Execution").Attribute("id").Value
                 select id).FirstOrDefault();

            return !string.IsNullOrEmpty(idString) ? new Guid(idString) : Guid.Empty;
        }
        public void ThenSingleScenarioAddedSuccessfully()
        {
            var excelScenarioFormatter = Container.Resolve<ExcelScenarioFormatter>();
            var scenario = new Scenario
                               {
                                   Name = "Test Feature",
                                   Description =
                                       "In order to test this feature,\nAs a developer\nI want to test this feature"
                               };

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

                worksheet.Cell("B3").Value.ShouldEqual(scenario.Name);
                worksheet.Cell("C4").Value.ShouldEqual(scenario.Description);
                row.ShouldEqual(5);
            }
        }
예제 #14
0
        public void Format(IXLWorksheet worksheet, Scenario scenario, ref int row)
        {
            int originalRow = row;
            worksheet.Cell(row, "B").Style.Font.SetBold();
            worksheet.Cell(row++, "B").Value = scenario.Name;
            worksheet.Cell(row++, "C").Value = scenario.Description;

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


            foreach (Step step in scenario.Steps)
            {
                this.excelStepFormatter.Format(worksheet, step, ref row);
            }
        }
예제 #15
0
        public TestResult GetScenarioResult(Gherkin.Scenario scenario)
        {
            if (this.specRunFeatures == null)
            {
                return(TestResult.Inconclusive);
            }

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

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

            var specRunScenario = FindSpecRunScenario(scenario, specRunFeature);

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

            return(StringToTestResult(specRunScenario.Result));
        }
예제 #16
0
        public void Format(Body body, Scenario scenario)
        {
            if (this.configuration.HasTestResults)
            {
                TestResult testResult = this.nunitResults.GetScenarioResult(scenario);
                if (testResult.WasExecuted && testResult.WasSuccessful)
                {
                    body.GenerateParagraph("Passed", "Passed");
                }
                else if (testResult.WasExecuted && !testResult.WasSuccessful)
                {
                    body.GenerateParagraph("Failed", "Failed");
                }
            }

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

            foreach (Step step in scenario.Steps)
            {
                this.wordStepFormatter.Format(body, step);
            }
        }
예제 #17
0
 public TestResult GetScenarioResult(Scenario scenario)
 {
     Guid scenarioExecutionId = this.GetScenarioExecutionId(scenario);
     return this.GetExecutionResult(scenarioExecutionId);
 }
예제 #18
0
        private Guid GetScenarioExecutionId(Scenario queriedScenario)
        {
            var idString =
                (from scenario in AllScenariosInResultFile()
                 let properties = PropertiesOf(scenario)
                 where properties != null
                 where FeatureNamePropertyExistsWith(queriedScenario.Feature.Name, among: properties)
                 where NameOf(scenario) == queriedScenario.Name
                 select ScenarioExecutionIdStringOf(scenario)).FirstOrDefault();

            return !string.IsNullOrEmpty(idString) ? new Guid(idString) : Guid.Empty;
        }
예제 #19
0
        public TestResult GetScenarioResult(Scenario scenario)
        {
            var results = this.TestResults.Select(tr => tr.GetScenarioResult(scenario)).ToArray();

              return EvaluateTestResults(results);
        }
예제 #20
0
        private static SpecRun.Scenario FindSpecRunScenario(Gherkin.Scenario scenario, SpecRun.Feature specRunFeature)
        {
            SpecRun.Scenario result = specRunFeature.Scenarios.FirstOrDefault(d => d.Title.Equals(scenario.Name));

            return(result);
        }
예제 #21
0
 public void AddBackground(Scenario background)
 {
     background.Feature = this;
     this.Background = background;
 }
예제 #22
0
        public XElement Format(Scenario scenario)
        {
          if (this.configuration.HasTestResults)
          {
            TestResult scenarioResult = this.results.GetScenarioResult(scenario);

            return this.BuildImageElement(scenarioResult);
          }

          return null;
        }
예제 #23
0
 public TestResult GetScenarioResult(Scenario scenario)
 {
     return new TestResult();
 }
예제 #24
0
 public TestResult GetScenarioResult(Scenario scenario)
 {
     XElement scenarioElement = this.GetScenarioElement(scenario);
     return scenarioElement != null
         ? this.GetResultFromElement(scenarioElement)
         : TestResult.Inconclusive;
 }
        public void GetScenarioResult_OnePassingOneFailing_ReturnsFailed()
        {
            var scenario = new Scenario();

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

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

              var result = multipleTestResults.GetScenarioResult(scenario);

              result.ShouldEqual(TestResult.Failed);
        }
예제 #26
0
        private XElement GetScenarioElement(Scenario 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.FirstOrDefault();
        }
예제 #27
0
      private static string[] RetrieveTags(Scenario scenario)
      {
        if (scenario == null) return new string[0];

        if (scenario.Feature == null) return scenario.Tags.ToArray();

        return scenario.Feature.Tags.Concat(scenario.Tags).ToArray();
      }
        public void GetScenarioResult_TwoInconclusive_ReturnsInconclusive()
        {
            var scenario = new Scenario();

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

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

              var result = multipleTestResults.GetScenarioResult(scenario);

              result.ShouldEqual(TestResult.Inconclusive);
        }
        public void ThenSingleScenarioWithStepsAddedSuccessfully()
        {
            var excelScenarioFormatter = Container.Resolve<ExcelScenarioFormatter>();
            var scenario = new Scenario
                               {
                                   Name = "Test Feature",
                                   Description =
                                       "In order to test this feature,\nAs a developer\nI want to test this feature"
                               };
            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"};
            scenario.Steps = new List<Step>(new[] {given, when, then});

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

                worksheet.Cell("B3").Value.ShouldEqual(scenario.Name);
                worksheet.Cell("C4").Value.ShouldEqual(scenario.Description);
                row.ShouldEqual(8);
            }
        }