예제 #1
0
        public XElement Format(Table table, ScenarioOutline scenarioOutline, bool includeResults)
        {
            if (table == null) return null;

            var headerCells = table.HeaderRow.ToArray();

            if (includeResults)
            {
                headerCells = headerCells.Concat(new[] { " " }).ToArray();
            }

            return new XElement(this.xmlns + "div",
                                new XAttribute("class", "table_container"),
                                new XElement(this.xmlns + "table",
                                             new XAttribute("class", "datatable"),
                                             new XElement(this.xmlns + "thead",
                                                          new XElement(this.xmlns + "tr",
                                                                       headerCells.Select(
                                                                           cell => new XElement(this.xmlns + "th", cell))
                                                              )
                                                 ),
                                             new XElement(this.xmlns + "tbody",
                                                          table.DataRows.Select(row => this.FormatRow(row, scenarioOutline, includeResults))
                                                 )
                                    ));
        }
        public void ThenTableAddedSuccessfully()
        {
            var excelTableFormatter = Container.Resolve<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);

                Check.That(worksheet.Cell("D6").Value).IsEqualTo("Var1");
                Check.That(worksheet.Cell("E6").Value).IsEqualTo("Var2");
                Check.That(worksheet.Cell("F6").Value).IsEqualTo("Var3");
                Check.That(worksheet.Cell("G6").Value).IsEqualTo("Var4");
                Check.That(worksheet.Cell("D7").Value).IsEqualTo(1.0);
                Check.That(worksheet.Cell("E7").Value).IsEqualTo(2.0);
                Check.That(worksheet.Cell("F7").Value).IsEqualTo(3.0);
                Check.That(worksheet.Cell("G7").Value).IsEqualTo(4.0);
                Check.That(worksheet.Cell("D8").Value).IsEqualTo(5.0);
                Check.That(worksheet.Cell("E8").Value).IsEqualTo(6.0);
                Check.That(worksheet.Cell("F8").Value).IsEqualTo(7.0);
                Check.That(worksheet.Cell("G8").Value).IsEqualTo(8.0);
                Check.That(row).IsEqualTo(9);
            }
        }
예제 #3
0
        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 = Container.Resolve<HtmlTableFormatter>();

            var output = htmlTableFormatter.Format(table);

            Check.That(output).IsNotNull();
            Check.That(output).HasAttribute("class", "table_container");
            Check.That(output).HasElement("table");

            var tableElement = output.Element(XName.Get("table", HtmlNamespace.Xhtml.NamespaceName));
            Check.That(tableElement).HasElement("thead");
            Check.That(tableElement).HasElement("tbody");
        }
        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);

            Check.That(output).ContainsGherkinScenario();
            Check.That(output).ContainsGherkinTable();
        }
        public void Map_TableWithHeaderRow_ReturnsJsonTableWithHeaderRow()
        {
            var table = new Table { HeaderRow = new TableRow("column 1", "column 2") };

            var mapper = CreateMapper();

            var actual = mapper.Map(table);

            Check.That(actual.HeaderRow).ContainsExactly("column 1", "column 2");
        }
        public void Map_TableWithHeaderRow_ReturnsJsonTableWithoutHeaderRow()
        {
            var table = new Table {  HeaderRow = null };

            var mapper = CreateMapper();

            var actual = mapper.Map(table);

            Check.That(actual.HeaderRow).IsNull();
        }
예제 #7
0
        public JsonTable Map(Table table)
        {
            if (table == null)
            {
                return null;
            }

            return new JsonTable
            {
                HeaderRow = this.tableRowMapper.Map(table.HeaderRow),
                DataRows = (table.DataRows ?? new List<TableRow>()).Select(this.tableRowMapper.Map).ToList()
            };
        }
        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 Map_TableWithDataRows_ReturnsJsonTableWithDataRows()
        {
            var table = new Table
            {
                DataRows = new List<TableRow>
                {
                    new TableRow("cell 1-1", "cell 1-2"),
                    new TableRow("cell 2-1", "cell 2-2")
                }
            };

            var mapper = CreateMapper();

            var actual = mapper.Map(table);

            Check.That(actual.DataRows.Count).IsEqualTo(2);
            Check.That(actual.DataRows[0]).ContainsExactly("cell 1-1", "cell 1-2");
            Check.That(actual.DataRows[1]).ContainsExactly("cell 2-1", "cell 2-2");
        }
        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);

                Check.That(worksheet.Cell("B3").Value).IsEqualTo(scenarioOutline.Name);
                Check.That(worksheet.Cell("C4").Value).IsEqualTo(scenarioOutline.Description);
                Check.That(worksheet.Cell("B6").Value).IsEqualTo("Examples");
                Check.That(worksheet.Cell("D7").Value).IsEqualTo("Var1");
                Check.That(worksheet.Cell("E7").Value).IsEqualTo("Var2");
                Check.That(worksheet.Cell("F7").Value).IsEqualTo("Var3");
                Check.That(worksheet.Cell("G7").Value).IsEqualTo("Var4");
                Check.That(worksheet.Cell("D8").Value).IsEqualTo(1.0);
                Check.That(worksheet.Cell("E8").Value).IsEqualTo(2.0);
                Check.That(worksheet.Cell("F8").Value).IsEqualTo(3.0);
                Check.That(worksheet.Cell("G8").Value).IsEqualTo(4.0);
                Check.That(worksheet.Cell("D9").Value).IsEqualTo(5.0);
                Check.That(worksheet.Cell("E9").Value).IsEqualTo(6.0);
                Check.That(worksheet.Cell("F9").Value).IsEqualTo(7.0);
                Check.That(worksheet.Cell("G9").Value).IsEqualTo(8.0);
                Check.That(row).IsEqualTo(10);
            }
        }
예제 #11
0
        public void Format(IXLWorksheet worksheet, Table table, ref int row)
        {
            int startRow = row;
            int headerColumn = TableStartColumn;
            foreach (string cell in table.HeaderRow.Cells)
            {
                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.Cells)
                {
                    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;
        }
예제 #12
0
        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);
        }
예제 #13
0
 public XElement Format(Table table)
 {
     return Format(table, null, false);
 }
        public void Map_TableWithNullDataRow_ReturnsJsonTableWithEmptyDataRows()
        {
            var table = new Table { DataRows = null };

            var mapper = CreateMapper();

            var actual = mapper.Map(table);

            Check.That(actual.DataRows).IsNotNull();
        }
예제 #15
0
 public XElement Format(Table table)
 {
     return this.Format(table, null);
 }