public void Format(IXLWorksheet worksheet, Table table, ref int row)
        {
            int startRow = row;
            int headerColumn = TableStartColumn;
            foreach (string cell in table.HeaderRow)
            {
                worksheet.Cell(row, headerColumn).Style.Font.SetBold();
                worksheet.Cell(row, headerColumn).Style.Font.SetItalic();
                worksheet.Cell(row, headerColumn).Style.Fill.SetBackgroundColor(XLColor.AliceBlue);
                worksheet.Cell(row, headerColumn++).Value = cell;
            }
            row++;

            foreach (TableRow dataRow in table.DataRows)
            {
                int dataColumn = TableStartColumn;
                foreach (string cell in dataRow)
                {
                    worksheet.Cell(row, dataColumn++).Value = cell;
                }
                row++;
            }

            int lastRow = row - 1;
            int lastColumn = headerColumn - 1;

            worksheet.Range(startRow, TableStartColumn, lastRow, lastColumn).Style.Border.TopBorder =
                XLBorderStyleValues.Thin;
            worksheet.Range(startRow, TableStartColumn, lastRow, lastColumn).Style.Border.LeftBorder =
                XLBorderStyleValues.Thin;
            worksheet.Range(startRow, TableStartColumn, lastRow, lastColumn).Style.Border.BottomBorder =
                XLBorderStyleValues.Thin;
            worksheet.Range(startRow, TableStartColumn, lastRow, lastColumn).Style.Border.RightBorder =
                XLBorderStyleValues.Thin;
        }
        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();
        }
Exemple #3
0
        public XElement Format(Table table)
        {
            if (table == null) return null;

            return 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",
                                                                       table.HeaderRow.Select(
                                                                           cell => new XElement(xmlns + "th", cell))
                                                              )
                                                 ),
                                             new XElement(xmlns + "tbody",
                                                          table.DataRows.Select(row => new XElement(xmlns + "tr",
                                                                                                    row.Select(
                                                                                                        cell =>
                                                                                                        new XElement(
                                                                                                            xmlns + "td",
                                                                                                            cell)))
                                                              )
                                                 )
                                    ));
        }
        public void ThenCanFormatNormalTableSuccessfully()
        {
            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 htmlTableFormatter = Kernel.Get<HtmlTableFormatter>();

            var output = htmlTableFormatter.Format(table);

            output.ShouldNotBeNull();
            output.ShouldHaveAttribute("class", "table_container");
            output.ShouldHaveElement("table");

            var tableElement = output.Element(XName.Get("table", HtmlNamespace.Xhtml.NamespaceName));
            tableElement.ShouldHaveElement("thead");
            tableElement.ShouldHaveElement("tbody");
        }
 public XElement Format(Table table)
 {
     return new XElement(xmlns + "table",
                     new XElement(xmlns + "thead",
                         new XElement(xmlns + "tr",
                             table.HeaderRow.Select(cell => new XElement(xmlns + "th", cell))
                         )
                     ),
                     new XElement(xmlns + "tbody",
                         table.DataRows.Select(row => new XElement(xmlns + "tr",
                             row.Select(cell => new XElement(xmlns + "td", cell)))
                         )
                     )
                 );
 }
        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 = Kernel.Get<HtmlStepFormatter>();
            var actual = formatter.Format(step);

            var 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),
                               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")
                                           )
                                       )
                                   )
                               )
                           );

            AssertDeepEqualNodes(expected, actual);
        }
        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 void Format(XElement parentElement, Table table)
        {
            var simpletable = new XElement("simpletable");

            var headerRow = new XElement("sthead");
            foreach (var cell in table.HeaderRow)
            {
                headerRow.Add(new XElement("stentry", cell));
            }
            simpletable.Add(headerRow);

            foreach (var row in table.DataRows)
            {
                var strow = new XElement("strow");
                foreach (var cell in row)
                {
                    strow.Add(new XElement("stentry", cell));
                }
                simpletable.Add(strow);
            }

            parentElement.Add(simpletable);
        }
        public void ThenTableAddedSuccessfully()
        {
            var excelTableFormatter = Kernel.Get<ExcelTableFormatter>();
            var table = new Table();
            table.HeaderRow = new TableRow("Var1", "Var2", "Var3", "Var4");
            table.DataRows =
                new List<TableRow>(new[] {new TableRow("1", "2", "3", "4"), new TableRow("5", "6", "7", "8")});

            using (var workbook = new XLWorkbook())
            {
                IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
                int row = 6;
                excelTableFormatter.Format(worksheet, table, ref row);

                worksheet.Cell("D6").Value.ShouldEqual("Var1");
                worksheet.Cell("E6").Value.ShouldEqual("Var2");
                worksheet.Cell("F6").Value.ShouldEqual("Var3");
                worksheet.Cell("G6").Value.ShouldEqual("Var4");
                worksheet.Cell("D7").Value.ShouldEqual(1.0);
                worksheet.Cell("E7").Value.ShouldEqual(2.0);
                worksheet.Cell("F7").Value.ShouldEqual(3.0);
                worksheet.Cell("G7").Value.ShouldEqual(4.0);
                worksheet.Cell("D8").Value.ShouldEqual(5.0);
                worksheet.Cell("E8").Value.ShouldEqual(6.0);
                worksheet.Cell("F8").Value.ShouldEqual(7.0);
                worksheet.Cell("G8").Value.ShouldEqual(8.0);
                row.ShouldEqual(9);
            }
        }