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);

                Check.That(worksheet.Cell("B3").Value).IsEqualTo(scenario.Name);
                Check.That(worksheet.Cell("C4").Value).IsEqualTo(scenario.Description);
                Check.That(row).IsEqualTo(8);
            }
        }
        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);
            }
        }
        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);
            }
        }
Beispiel #4
0
        public static Paragraph GenerateStepParagraph(Step step)
        {
            // HACK - We need to generate a custom paragraph here because 2 Run objects are needed to allow for the bolded keyword
            var paragraph = new Paragraph(new ParagraphProperties(new ParagraphStyleId { Val = "Normal" }));

            // Add comments before step
            if (step.Comments.Any(o => o.Type == CommentType.StepComment))
            {
                foreach (var comment in step.Comments.Where(o => o.Type == CommentType.StepComment))
                {
                    paragraph.Append(new Run(new RunProperties(new Italic()), new Text(comment.Text)));
                    paragraph.Append(new Break());
                }
            }

            // Add step
            paragraph.Append(new Run(new RunProperties(new Bold()), new Text(step.NativeKeyword)));
            var nameText = new Text { Space = SpaceProcessingModeValues.Preserve };
            nameText.Text = " " + step.Name;
            paragraph.Append(new Run(nameText));

            // Add comments after step
            if (step.Comments.Any(o => o.Type == CommentType.AfterLastStepComment))
            {
                paragraph.Append(new Break());

                foreach (var comment in step.Comments.Where(o => o.Type == CommentType.AfterLastStepComment))
                {
                    paragraph.Append(new Run(new RunProperties(new Italic()), new Text(comment.Text)));
                    paragraph.Append(new Break());
                }
            }

            return paragraph;
        }
        public void ThenStepCommentsAreAddedSuccessfully()
        {
            var excelStepFormatter = Container.Resolve<ExcelStepFormatter>();
            var step = new Step
            {
                NativeKeyword = "Given",
                Name = "I have some precondition",
                Comments = new List<Comment>()
                {
                    new Comment()
                    {
                        Text = "# A comment",
                        Type = CommentType.StepComment
                    }
                }
            };

            using (var workbook = new XLWorkbook())
            {
                IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
                int row = 5;
                excelStepFormatter.Format(worksheet, step, ref row);

                Check.That(worksheet.Cell("C5").Value).IsEqualTo(step.Comments.First().Text);
                Check.That(worksheet.Cell("C6").Value).IsEqualTo(step.NativeKeyword);
                Check.That(worksheet.Cell("D6").Value).IsEqualTo(step.Name);
            }
        }
        public void Multiline_strings_are_formatted_as_list_items_with_pre_elements_formatted_as_code_internal()
        {
            var step = new Step
            {
                Keyword = Keyword.Given,
                NativeKeyword = "Given ",
                Name = "a simple step",
                TableArgument = null,
                DocStringArgument = "this is a\nmultiline table\nargument",
            };

            var formatter = Container.Resolve<HtmlStepFormatter>();
            XElement actual = formatter.Format(step);

            XNamespace xmlns = XNamespace.Get("http://www.w3.org/1999/xhtml");
            var expected = new XElement(
                xmlns + "li",
                new XAttribute("class", "step"),
                new XElement(xmlns + "span", new XAttribute("class", "keyword"), ExpectedGivenHtml),
                new XText("a simple step"),
                new XElement(
                    xmlns + "div",
                    new XAttribute("class", "pre"),
                    new XElement(
                        xmlns + "pre",
                        new XElement(
                            xmlns + "code",
                            new XAttribute("class", "no-highlight"),
                            new XText(
                                "this is a\nmultiline table\nargument")))));

            Check.That(expected).IsDeeplyEqualTo(actual);
        }
Beispiel #7
0
        public XElement Format(Step step)
        {
            XElement li;

            XElement beforeStepComments = null;
            XElement afterStepComments = null;
            if (step.Comments.Any(o => o.Type == CommentType.StepComment))
            {
                beforeStepComments = this.FormatComments(step, CommentType.StepComment);
            }
            if (step.Comments.Any(o => o.Type == CommentType.AfterLastStepComment))
            {
                afterStepComments = this.FormatComments(step, CommentType.AfterLastStepComment);
            }

            li = new XElement(
                    this.xmlns + "li",
                    new XAttribute("class", "step"),
                    beforeStepComments,
                    new XElement(this.xmlns + "span", new XAttribute("class", "keyword"), step.NativeKeyword),
                    step.Name,
                    afterStepComments);

            if (step.TableArgument != null)
            {
                li.Add(this.htmlTableFormatter.Format(step.TableArgument));
            }

            if (!string.IsNullOrEmpty(step.DocStringArgument))
            {
                li.Add(this.htmlMultilineStringFormatter.Format(step.DocStringArgument));
            }

            return li;
        }
        public void Map_WithKeyword_ReturnsCorrectKeyword()
        {
            var step = new Step { Keyword = Keyword.But };

            var mapper = CreateMapper();

            var actual = mapper.Map(step);

            Check.That(actual.Keyword).IsEqualTo(JsonKeyword.But);
        }
        public void Map_WithNativeKeyword_ReturnsNativeKeyword()
        {
            var step = new Step { NativeKeyword = "But" };

            var mapper = CreateMapper();

            var actual = mapper.Map(step);

            Check.That(actual.NativeKeyword).IsEqualTo("But");
        }
 public static Paragraph GenerateStepParagraph(Step step)
 {
     // HACK - We need to generate a custom paragraph here because 2 Run objects are needed to allow for the bolded keyword
     var paragraph = new Paragraph(new ParagraphProperties(new ParagraphStyleId { Val = "Normal" }));
     paragraph.Append(new Run(new RunProperties(new Bold()), new Text(step.NativeKeyword)));
     var nameText = new Text { Space = SpaceProcessingModeValues.Preserve };
     nameText.Text = " " + step.Name;
     paragraph.Append(new Run(nameText));
     return paragraph;
 }
        public void Map_NonNullStep_ReturnsJsonStep()
        {
            var step = new Step();

            var mapper = CreateMapper();

            var actual = mapper.Map(step);

            Check.That(actual).IsNotNull();
        }
Beispiel #12
0
        protected XElement FormatComments(Step step, CommentType type)
        {
            XElement comment = new XElement(this.xmlns + "span", new XAttribute("class", "comment"));

            foreach (var stepComment in step.Comments.Where(o => o.Type == type))
            {
                comment.Add(stepComment.Text.Trim());
                comment.Add(new XElement(this.xmlns + "br"));
            }
            comment.LastNode.Remove();

            return comment;
        }
        public void ThenStepAddedSuccessfully()
        {
            var excelStepFormatter = Container.Resolve<ExcelStepFormatter>();
            var step = new Step { NativeKeyword = "Given", Name = "I have some precondition" };

            using (var workbook = new XLWorkbook())
            {
                IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
                int row = 5;
                excelStepFormatter.Format(worksheet, step, ref row);

                Check.That(worksheet.Cell("C5").Value).IsEqualTo(step.NativeKeyword);
                Check.That(worksheet.Cell("D5").Value).IsEqualTo(step.Name);
            }
        }
        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);
            }
        }
        public void Format(IXLWorksheet worksheet, Step step, ref int row)
        {
            worksheet.Cell(row, "C").Style.Font.SetBold();
            worksheet.Cell(row, "C").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Right);
            worksheet.Cell(row, "C").Value = step.NativeKeyword;
            worksheet.Cell(row++, "D").Value = step.Name;

            if (step.TableArgument != null)
            {
                this.excelTableFormatter.Format(worksheet, step.TableArgument, ref row);
            }

            if (!string.IsNullOrEmpty(step.DocStringArgument))
            {
                this.excelDocumentStringFormatter.Format(worksheet, step.DocStringArgument, ref row);
            }
        }
        public XElement Format(Step step)
        {
            var li = new XElement(
                this.xmlns + "li",
                new XAttribute("class", "step"),
                new XElement(this.xmlns + "span", new XAttribute("class", "keyword"), step.NativeKeyword),
                step.Name);

            if (step.TableArgument != null)
            {
                li.Add(this.htmlTableFormatter.Format(step.TableArgument));
            }

            if (!string.IsNullOrEmpty(step.DocStringArgument))
            {
                li.Add(this.htmlMultilineStringFormatter.Format(step.DocStringArgument));
            }

            return li;
        }
        public void Format(IXLWorksheet worksheet, Step step, ref int row)
        {
            // Add comments
            if (step.Comments.Any(o => o.Type == CommentType.StepComment))
            {
                foreach (var comment in step.Comments.Where(o => o.Type == CommentType.StepComment))
                {
                    worksheet.Cell(row, "C").Style.Font.SetItalic();
                    worksheet.Cell(row, "C").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left);
                    worksheet.Cell(row, "C").Value = comment.Text;
                    row++;
                }
            }

            worksheet.Cell(row, "C").Style.Font.SetBold();
            worksheet.Cell(row, "C").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Right);
            worksheet.Cell(row, "C").Value = step.NativeKeyword;
            worksheet.Cell(row++, "D").Value = step.Name;

            if (step.Comments.Any(o => o.Type == CommentType.AfterLastStepComment))
            {
                foreach (var comment in step.Comments.Where(o => o.Type == CommentType.AfterLastStepComment))
                {
                    worksheet.Cell(row, "C").Style.Font.SetItalic();
                    worksheet.Cell(row, "C").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left);
                    worksheet.Cell(row, "C").Value = comment.Text;
                    row++;
                }
            }
            

            if (step.TableArgument != null)
            {
                this.excelTableFormatter.Format(worksheet, step.TableArgument, ref row);
            }

            if (!string.IsNullOrEmpty(step.DocStringArgument))
            {
                this.excelDocumentStringFormatter.Format(worksheet, step.DocStringArgument, ref row);
            }
        }
Beispiel #18
0
        public void Format(Body body, Step step)
        {
            var paragraph = GenerateStepParagraph(step);
            body.Append(paragraph);

            if (!string.IsNullOrEmpty(step.DocStringArgument))
            {
                string[] lines = step.DocStringArgument.Split(
                    new[] { Environment.NewLine },
                    StringSplitOptions.RemoveEmptyEntries);
                foreach (string line in lines)
                {
                    body.GenerateParagraph(line, "Quote");
                }
            }

            if (step.TableArgument != null)
            {
                this.wordTableFormatter.Format(body, step.TableArgument);
            }
        }
        public void Simple_steps_are_formatted_as_list_items()
        {
            var step = new Step
            {
                Keyword = Keyword.Given,
                Name = "a simple step",
                NativeKeyword = "Given ",
                TableArgument = null,
                DocStringArgument = null,
            };

            var formatter = Container.Resolve<HtmlStepFormatter>();
            XElement actual = formatter.Format(step);

            var expected = new XElement(
                this.xmlns + "li",
                new XAttribute("class", "step"),
                new XElement(this.xmlns + "span", new XAttribute("class", "keyword"), ExpectedGivenHtml),
                "a simple step");

            Check.That(expected).IsDeeplyEqualTo(actual);
        }
Beispiel #20
0
        public void Simple_steps_are_formatted_as_list_items()
        {
            var step = new Step
                           {
                               Keyword = Keyword.Given,
                               Name = "a simple step",
                               NativeKeyword = "Given ",
                               TableArgument = null,
                               DocStringArgument = null,
                           };

            var formatter = Container.Resolve<HtmlStepFormatter>();
            XElement actual = formatter.Format(step);

            XNamespace xmlns = XNamespace.Get("http://www.w3.org/1999/xhtml");
            var expected = new XElement(xmlns + "li",
                                        new XAttribute("class", "step"),
                                        new XElement(xmlns + "span", new XAttribute("class", "keyword"),
                                                     EXPECTED_GIVEN_HTML),
                                        "a simple step"
                );

            Check.That(expected).IsDeeplyEqualTo(actual);
        }
        public JsonStep Map(Step step)
        {
            if (step == null)
            {
                return null;
            }

            var result = new JsonStep
            {
                Keyword = this.keywordMapper.Map(step.Keyword),
                NativeKeyword = step.NativeKeyword,
                Name = step.Name,
                TableArgument = this.tableMapper.Map(step.TableArgument),
                DocStringArgument = step.DocStringArgument,
                StepComments = new List<JsonComment>(),
                AfterLastStepComments = new List<JsonComment>()
            };

            var comments = (step.Comments ?? new List<Comment>()).ToArray();
            result.StepComments.AddRange(comments.Where(s => s.Type == CommentType.StepComment).Select(this.commentMapper.Map));
            result.AfterLastStepComments.AddRange(comments.Where(s => s.Type == CommentType.AfterLastStepComment).Select(this.commentMapper.Map));

            return result;
        }
        public void Tables_are_formatted_as_list_items_with_tables_internal()
        {
            var table = new Table
            {
                HeaderRow = new TableRow("Column 1", "Column 2"),
                DataRows = new List<TableRow> { new TableRow("Value 1", "Value 2") }
            };

            var step = new Step
            {
                Keyword = Keyword.Given,
                NativeKeyword = "Given ",
                Name = "a simple step",
                TableArgument = table,
                DocStringArgument = null,
            };

            var formatter = Container.Resolve<HtmlStepFormatter>();
            XElement actual = formatter.Format(step);

            XNamespace xmlns = XNamespace.Get("http://www.w3.org/1999/xhtml");
            var expected = new XElement(
                xmlns + "li",
                new XAttribute("class", "step"),
                new XElement(xmlns + "span", new XAttribute("class", "keyword"), ExpectedGivenHtml),
                new XText("a simple step"),
                new XElement(
                    xmlns + "div",
                    new XAttribute("class", "table_container"),
                    new XElement(
                        xmlns + "table",
                        new XAttribute("class", "datatable"),
                        new XElement(
                            xmlns + "thead",
                            new XElement(
                                xmlns + "tr",
                                new XElement(
                                    xmlns + "th",
                                    "Column 1"),
                                new XElement(
                                    xmlns + "th",
                                    "Column 2"))),
                        new XElement(
                            xmlns + "tbody",
                            new XElement(
                                xmlns + "tr",
                                new XElement(
                                    xmlns + "td",
                                    "Value 1"),
                                new XElement(
                                    xmlns + "td",
                                    "Value 2"))))));

            Check.That(expected).IsDeeplyEqualTo(actual);
        }
 public void AddStep(Step step)
 {
     this.steps.Add(step);
 }
        public void Map_WithAfterLastStepComments_ReturnsThoseComments()
        {
            var step = new Step
            {
                Comments = new List<Comment>
                           {
                               new Comment { Text = "My AfterLastStepComment Comment", Type = CommentType.AfterLastStepComment },
                           }
            };

            var mapper = CreateMapper();

            var actual = mapper.Map(step);

            Check.That(actual.AfterLastStepComments[0].Text).IsEqualTo("My AfterLastStepComment Comment");
        }
        public void Map_WithTable_ReturnsTableAndNullDocString()
        {
            var step = new Step
            {
                TableArgument = new Table
                {
                    HeaderRow = new TableRow("row 1", "row 2")
                }
            };

            var mapper = CreateMapper();

            var actual = mapper.Map(step);

            Check.That(actual.TableArgument.HeaderRow).ContainsExactly("row 1", "row 2");
            Check.That(actual.DocStringArgument).IsNull();
        }
        public void Map_WithName_ReturnsName()
        {
            var step = new Step { Name = "I run this step" };

            var mapper = CreateMapper();

            var actual = mapper.Map(step);

            Check.That(actual.Name).IsEqualTo("I run this step");
        }
        public void Map_WithDocString_ReturnsDocStringAndNoTableArgument()
        {
            var step = new Step { DocStringArgument = "Some longer text" };

            var mapper = CreateMapper();

            var actual = mapper.Map(step);

            Check.That(actual.DocStringArgument).IsEqualTo("Some longer text");
            Check.That(actual.TableArgument).IsNull();
        }
        public void Map_WithoutAfterLastStepComments_ReturnsEmptyList()
        {
            var step = new Step
            {
                Comments = new List<Comment>
                           {
                               new Comment { Text = "My Step Comment", Type = CommentType.StepComment },
                               new Comment { Text = "My Normal comment", Type = CommentType.Normal }
                           }
            };

            var mapper = CreateMapper();

            var actual = mapper.Map(step);

            Check.That(actual.AfterLastStepComments.Count).IsEqualTo(0);
        }
        public void Steps_get_selected_Language()
        {
            var step = new Step
            {
                Keyword = Keyword.Given,
                Name = "ett enkelt steg",
                NativeKeyword = "Givet ",
                TableArgument = null,
                DocStringArgument = null,
            };

            var configuration = Container.Resolve<IConfiguration>();
            configuration.Language = "sv";

            var formatter = Container.Resolve<HtmlStepFormatter>();
            XElement actual = formatter.Format(step);

            XNamespace xmlns = XNamespace.Get("http://www.w3.org/1999/xhtml");
            var expected = new XElement(
                xmlns + "li",
                new XAttribute("class", "step"),
                new XElement(xmlns + "span", new XAttribute("class", "keyword"), "Givet "),
                "ett enkelt steg");

            Check.That(expected).IsDeeplyEqualTo(actual);
        }
        public void Map_WithNullComments_ReturnsAfterLastStepCommentsList()
        {
            var step = new Step { Comments = null };

            var mapper = CreateMapper();

            var actual = mapper.Map(step);

            Check.That(actual.AfterLastStepComments.Count).IsEqualTo(0);
        }