Пример #1
0
    public void ThenCanFormatMarkdownTableExtensions()
    {
      var feature = new Feature
      {
        Name = "A feature",
        Description =
@"In order to see the description as nice HTML
As a Pickles user
I want to see the descriptions written in markdown rendered with tables

| Table Header 1 | Table Header 2 |
| -------------- | -------------- |
| Cell value 1   | Cell value 2   |
| Cell value 3   |                |
| Cell value 4   | Cell value 5   |
"
      };

      var htmlFeatureFormatter = Container.Resolve<HtmlFeatureFormatter>();
      XElement featureElement = htmlFeatureFormatter.Format(feature);
      XElement description = featureElement.Elements().FirstOrDefault(element => element.Name.LocalName == "div");

      Check.That(description).IsNotNull();
      Check.That(description).IsNamed("div");
      Check.That(description).IsInNamespace("http://www.w3.org/1999/xhtml");
      Check.That(description).HasAttribute("class", "description");

      XElement table = description.Descendants().FirstOrDefault(el => el.Name.LocalName == "table");

      Check.That(table).IsNotNull();
    }
        public void Then_feature_without_background_adds_first_scenario_on_correct_row()
        {
            var excelFeatureFormatter = Container.Resolve<ExcelFeatureFormatter>();

            var feature = new Feature
                              {
                                  Name = "Test Feature",
                                  Description =
                                      "In order to test this feature,\nAs a developer\nI want to test this feature",
                              };
            var scenario = new Scenario
            {
                Name = "Test Scenario",
                Description =
                    "In order to test this scenario,\nAs a developer\nI want to test this scenario"
            };
            var given = new Step { NativeKeyword = "Given", Name = "a precondition" };
            scenario.Steps = new List<Step>(new[] { given });
            feature.AddFeatureElement(scenario);

            using (var workbook = new XLWorkbook())
            {
                IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
                excelFeatureFormatter.Format(worksheet, feature);

                Check.That(worksheet.Cell("B4").Value).IsEqualTo(scenario.Name);
                Check.That(worksheet.Cell("C5").Value).IsEqualTo(scenario.Description);
                Check.That(worksheet.Cell("D6").Value).IsEqualTo(given.Name);
            }
        }
Пример #3
0
 public FeatureNode(FileSystemInfoBase location, string relativePathFromRoot, Feature feature)
 {
     this.OriginalLocation = location;
     this.OriginalLocationUrl = location.ToUri();
     this.RelativePathFromRoot = relativePathFromRoot;
     this.Feature = feature;
 }
Пример #4
0
        public JsonFeature Map(Feature feature)
        {
            if (feature == null)
            {
                return null;
            }

            var result = new JsonFeature
            {
                Name = feature.Name,
                Description = feature.Description,
                Result = this.resultMapper.Map(feature.Result),
                Tags = feature.Tags.ToArray().ToList(),
            };

            result.FeatureElements.AddRange(feature.FeatureElements.Select(this.MapFeatureElement).ToList());
            result.Background = this.scenarioMapper.Map(feature.Background);

            if (result.Background != null)
            {
                result.Background.Feature = result;
            }

            foreach (var featureElement in result.FeatureElements)
            {
                featureElement.Feature = result;
            }

            return result;
        }
        public void Then_feature_with_background_is_added_successfully()
        {
            var excelFeatureFormatter = Container.Resolve<ExcelFeatureFormatter>();

            var feature = new Feature
            {
                Name = "Test Feature",
                Description =
                    "In order to test this feature,\nAs a developer\nI want to test this feature",
            };
            var background = new Scenario
            {
                Name = "Test Background Scenario",
                Description =
                    "In order to test this background,\nAs a developer\nI want to test this background"
            };
            var given = new Step { NativeKeyword = "Given", Name = "a precondition" };
            background.Steps = new List<Step>(new[] { given });
            feature.AddBackground(background);

            using (var workbook = new XLWorkbook())
            {
                IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
                excelFeatureFormatter.Format(worksheet, feature);

                Check.That(worksheet.Cell("B4").Value).IsEqualTo(background.Name);
                Check.That(worksheet.Cell("C5").Value).IsEqualTo(background.Description);
                Check.That(worksheet.Cell("D6").Value).IsEqualTo(given.Name);
            }
        }
Пример #6
0
 protected override XElement GetFeatureElement(Feature feature)
 {
     return this.resultsDocument
         .Descendants("test-suite")
         .Where(x => x.Attribute("description") != null)
         .FirstOrDefault(x => x.Attribute("description").Value == feature.Name);
 }
        public void Setup()
        {
            this.testFeature = new Feature { Name = "Test" };
            this.featureFileInfo = this.FileSystem.FileInfo.FromFileName(FileSystem.Path.Combine(RootPath, FeaturePath));
            this.featureDirectoryNode = new FeatureNode(this.featureFileInfo, RelativePath, this.testFeature);

            this.featureWithMeta = new JsonFeatureWithMetaInfo(this.featureDirectoryNode);
        }
        public void Setup()
        {
            this._testFeature = new Feature { Name = "Test" };
            this._featureFileInfo = this.FileSystem.FileInfo.FromFileName(FileSystem.Path.Combine(ROOT_PATH, FEATURE_PATH));
            this._featureDirectoryNode = new FeatureNode(this._featureFileInfo, RELATIVE_PATH, this._testFeature);

            this._featureWithMeta = new FeatureWithMetaInfo(this._featureDirectoryNode);
        }
Пример #9
0
        /// <summary>
        /// Retrieves all UnitTest XElements that belong to the specified feature.
        /// </summary>
        /// <param name="feature">The feature for which to retrieve the unit tests.</param>
        /// <returns>A sequence of <see cref="XElement" /> instances that are called "UnitTest"
        /// that belong to the specified feature.</returns>
        private IEnumerable<XElement> GetScenariosForFeature(Feature feature)
        {
            var scenarios = from scenario in this.resultsDocument.AllScenarios()
                            where scenario.HasPropertyFeatureTitle(feature.Name)
                            select scenario;

            return scenarios;
        }
Пример #10
0
        public TestResult GetFeatureResult(Feature feature)
        {
            var featureElement = this.GetFeatureElement(feature);
            int passedCount = featureElement.passed;
            int failedCount = featureElement.failed;
            int skippedCount = featureElement.skipped;

            return GetAggregateResult(passedCount, failedCount, skippedCount);
        }
Пример #11
0
        public TestResult GetFeatureResult(Feature feature)
        {
            XElement featureElement = this.GetFeatureElement(feature);
            int passedCount = int.Parse(featureElement.Attribute("passed").Value);
            int failedCount = int.Parse(featureElement.Attribute("failed").Value);
            int skippedCount = int.Parse(featureElement.Attribute("skipped").Value);

            return GetAggregateResult(passedCount, failedCount, skippedCount);
        }
        public void Map_FeatureWithDescription_ReturnsDescription()
        {
            var feature = new Feature { Description = "As a math idiot" };

            var mapper = CreateMapper();

            var actual = mapper.Map(feature);

            Check.That(actual.Description).IsEqualTo("As a math idiot");
        }
Пример #13
0
        public override TestResult GetFeatureResult(Feature feature)
        {
            var scenarios = this.GetScenariosForFeature(feature);

            var featureExecutionIds = scenarios.ExecutionIdElements();

            TestResult result = this.GetExecutionResult(featureExecutionIds);

            return result;
        }
        public void Map_FeatureWithName_ReturnsName()
        {
            var feature = new Feature { Name = "Name of the Feature" };

            var mapper = CreateMapper();

            var actual = mapper.Map(feature);

            Check.That(actual.Name).IsEqualTo("Name of the Feature");
        }
        public void Map_SomeFeature_ReturnsJsonFeature()
        {
            var feature = new Feature();

            var mapper = CreateMapper();

            var actual = mapper.Map(feature);

            Check.That(actual).IsNotNull();
        }
Пример #16
0
        public XElement Format(Feature feature)
        {
            if (this.configuration.HasTestResults)
            {
                TestResult scenarioResult = this.results.GetFeatureResult(feature);

                return this.BuildImageElement(scenarioResult);
            }

            return null;
        }
Пример #17
0
      private XElement GetFeatureElement(Feature feature)
        {
            IEnumerable<XElement> featureQuery =
                from clazz in this.resultsDocument.Root.Descendants("class")
                from test in clazz.Descendants("test")
                from trait in clazz.Descendants("traits").Descendants("trait")
                where trait.Attribute("name").Value == "FeatureTitle" && trait.Attribute("value").Value == feature.Name
                select clazz;

            return featureQuery.FirstOrDefault();
        }
Пример #18
0
        public void Format(IXLWorksheet worksheet, Feature feature)
        {
            worksheet.Cell("A1").Style.Font.SetBold();
            worksheet.Cell("A1").Value = feature.Name;

            if (feature.Description.Length <= short.MaxValue)
            {
                worksheet.Cell("B2").Value = feature.Description;
            }
            else
            {
                var description = feature.Description.Substring(0, short.MaxValue);
                Log.Warn("The description of feature {0} was truncated because of cell size limitations in Excel.", feature.Name);
                worksheet.Cell("B2").Value = description;
            }

            worksheet.Cell("B2").Style.Alignment.WrapText = false;

            var results = this.testResults.GetFeatureResult(feature);

            if (this.configuration.HasTestResults && results != TestResult.Inconclusive)
            {
                worksheet.Cell("A1").Style.Fill.SetBackgroundColor(results == TestResult.Passed
                    ? XLColor.AppleGreen
                    : XLColor.CandyAppleRed);
            }

            var featureElementsToRender = new List<IFeatureElement>();
            if (feature.Background != null)
            {
                featureElementsToRender.Add(feature.Background);
            }

            featureElementsToRender.AddRange(feature.FeatureElements);

            var row = 4;
            foreach (var featureElement in featureElementsToRender)
            {
                var scenario = featureElement as Scenario;
                if (scenario != null)
                {
                    this.excelScenarioFormatter.Format(worksheet, scenario, ref row);
                }

                var scenarioOutline = featureElement as ScenarioOutline;
                if (scenarioOutline != null)
                {
                    this.excelScenarioOutlineFormatter.Format(worksheet, scenarioOutline, ref row);
                }

                row++;
            }
        }
Пример #19
0
        public void ThenCanFormatDescriptionAsMarkdown()
        {
            var feature = new Feature
            {
                Name = "A feature",
                Description =
                    @"In order to see the description as nice HTML
As a Pickles user
I want to see the descriptions written in markdown rendered as HTML

Introduction
============

This feature should have some markdown elements that get displayed properly

Context
-------

> I really like blockquotes to describe
> to describe text

I also enjoy using lists as well, here are the reasons

- Lists are easy to read
- Lists make my life easier

I also enjoy ordering things

1. This is the first reason
2. This is the second reason"
            };

            var htmlFeatureFormatter = Container.Resolve<HtmlFeatureFormatter>();
            XElement featureElement = htmlFeatureFormatter.Format(feature);
            XElement description = featureElement.Elements().FirstOrDefault(element => element.Name.LocalName == "div");

            Check.That(description).IsNotNull();
            Check.That(description).IsNamed("div");
            Check.That(description).IsInNamespace("http://www.w3.org/1999/xhtml");
            Check.That(description).HasAttribute("class", "description");
            Check.That(description.Elements().Count()).IsEqualTo(9);

            Check.That(description.Elements().ElementAt(0)).IsNamed("p");
            Check.That(description.Elements().ElementAt(1)).IsNamed("h1");
            Check.That(description.Elements().ElementAt(2)).IsNamed("p");
            Check.That(description.Elements().ElementAt(3)).IsNamed("h2");
            Check.That(description.Elements().ElementAt(4)).IsNamed("blockquote");
            Check.That(description.Elements().ElementAt(5)).IsNamed("p");
            Check.That(description.Elements().ElementAt(6)).IsNamed("ul");
            Check.That(description.Elements().ElementAt(7)).IsNamed("p");
            Check.That(description.Elements().ElementAt(8)).IsNamed("ol");
        }
        public void ThenCanShortenLongNameSuccessfully()
        {
            var excelSheetNameGenerator = Container.Resolve<ExcelSheetNameGenerator>();
            var feature = new Feature {Name = "This is a really really long feature name that needs to be shortened"};

            string name;
            using (var wb = new XLWorkbook())
            {
                name = excelSheetNameGenerator.GenerateSheetName(wb, feature);
            }

            Check.That(name).IsEqualTo("THISISAREALLYREALLYLONGFEATUREN");
        }
 private static string RemoveUnnecessaryAndIllegalCharacters(Feature feature)
 {
     return feature.Name
         .Replace(" ", string.Empty)
         .Replace("\t", string.Empty)
         .Replace(":", string.Empty)
         .Replace(@"\", string.Empty)
         .Replace("/", string.Empty)
         .Replace("?", string.Empty)
         .Replace("*", string.Empty)
         .Replace("[", string.Empty)
         .Replace("]", string.Empty);
 }
Пример #22
0
    public TestResult GetFeatureResult(Feature feature)
    {
      var featureElement = this.GetFeatureElement(feature);

      if (featureElement == null)
      {
        return TestResult.Inconclusive;
      }
      var results = featureElement.Descendants("test-case")
        .Select(GetResultFromElement);

      return results.Merge();
    }
        public void ThenCanCreateSimpleNameSuccessfully()
        {
            var excelSheetNameGenerator = Container.Resolve<ExcelSheetNameGenerator>();
            var feature = new Feature { Name = "A short feature name" };

            string name;
            using (var wb = new XLWorkbook())
            {
                name = excelSheetNameGenerator.GenerateSheetName(wb, feature);
            }

            Check.That(name).IsEqualTo("ASHORTFEATURENAME");
        }
        public void GetFeatureResult_TwoInconclusive_ReturnsInconclusive()
        {
            var feature = new Feature();

              var testResults1 = SetupStubForGetFeatureResult(feature, TestResult.Inconclusive);
              var testResults2 = SetupStubForGetFeatureResult(feature, TestResult.Inconclusive);

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

              var result = multipleTestResults.GetFeatureResult(feature);

              result.ShouldEqual(TestResult.Inconclusive);
        }
Пример #25
0
    public TestResult GetFeatureResult(Feature feature)
    {
      var featureExecutionIds =
        from scenario in this.AllScenariosInResultFile()
        let properties = PropertiesOf(scenario)
        where properties != null
        where FeatureNamePropertyExistsWith(feature.Name, among: properties)
        select ScenarioExecutionIdOf(scenario);

      TestResult result = featureExecutionIds.Select(this.GetExecutionResult).Merge();

      return result;
    }
        public void GetFeatureResult_OnePassingOneFailed_ReturnsPassed()
        {
            var feature = new Feature();

              var testResults1 = SetupStubForGetFeatureResult(feature, TestResult.Passed);
              var testResults2 = SetupStubForGetFeatureResult(feature, TestResult.Failed);

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

              var result = multipleTestResults.GetFeatureResult(feature);

              result.ShouldEqual(TestResult.Failed);
        }
        public void GetFeatureResult_OnePassingOneInconclusive_ReturnsPassed()
        {
            var feature = new Feature();

            var testResults1 = SetupStubForGetFeatureResult(feature, TestResult.Passed);
            var testResults2 = SetupStubForGetFeatureResult(feature, TestResult.Inconclusive);

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

            var result = multipleTestResults.GetFeatureResult(feature);

            Check.That(result).IsEqualTo(TestResult.Passed);
        }
        public void TestResultsFileIsMessingElementsForAFeature_ShouldReturnInconclusive()
        {
            var results = ParseResultsFile();
            var feature = new Feature {
                Name = "Feature That Has No Scenarios In The Test Run"
            };
            var scenarioWithoutElements = new Scenario {
                Name = "Ignored scenario", Feature = feature
            };

            var result = results.GetScenarioResult(scenarioWithoutElements);

            Check.That(result).IsEqualTo(TestResult.Inconclusive);
        }
Пример #29
0
        public void Process(Feature feature)
        {
            feature.Description = Process(feature.Description);

            foreach (var featureElement in feature.FeatureElements)
            {
                featureElement.Description = Process(featureElement.Description);
            }

            if (feature.Background != null)
            {
                feature.Background.Description = Process(feature.Background.Description);
            }
        }
Пример #30
0
        public override TestResult GetFeatureResult(Feature feature)
        {
            var specRunFeature = this.FindSpecRunFeature(feature);

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

            TestResult result =
                specRunFeature.Scenarios.Select(specRunScenario => StringToTestResult(specRunScenario.Result)).Merge();

            return result;
        }
Пример #31
0
        public override TestResult GetFeatureResult(Feature feature)
        {
            XElement featureElement = this.GetFeatureElement(feature);

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

            int passedCount = int.Parse(featureElement.Attribute("passed").Value);
            int failedCount = int.Parse(featureElement.Attribute("failed").Value);
            int skippedCount = int.Parse(featureElement.Attribute("skipped").Value);

            return this.GetAggregateResult(passedCount, failedCount, skippedCount);
        }