public void FakeTablePartExtractionTest() { const int width = 20; const int height = 40; var table = new FakeTable(width, height); for (var x = 0; x < width; ++x) { for (var y = 0; y < height; ++y) { table.InsertCell(new CellPosition(y + 1, x + 1)); } } var positions = new[] { new CellPosition(1, 1), new CellPosition(40, 20), new CellPosition(10, 10) }; var stringValues = new[] { "Test Value", "Test Test", "Another text" }; for (var i = 0; i < positions.Count(); ++i) { var cell = table.InsertCell(positions[i]); cell.StringValue = stringValues[i]; } var tablePart = table.GetTablePart(new Rectangle(new CellPosition(9, 9), new CellPosition(40, 20))); tablePart.Cells.Count().Should().Be(32); foreach (var row in tablePart.Cells) { row.Count().Should().Be(12); } var targetRow = tablePart.Cells.FirstOrDefault(row => row.FirstOrDefault(cell => cell.StringValue == "Another text") != null); targetRow.Should().NotBeNull(); // ReSharper disable AssignNullToNotNullAttribute var targetCell = targetRow.FirstOrDefault(cell => cell.StringValue == "Another text"); // ReSharper restore AssignNullToNotNullAttribute targetCell.Should().NotBeNull(); // ReSharper disable PossibleNullReferenceException targetCell.CellPosition.RowIndex.Should().Be(10); // ReSharper restore PossibleNullReferenceException targetCell.CellPosition.ColumnIndex.Should().Be(10); targetRow = tablePart.Cells.LastOrDefault(); targetRow.Should().NotBeNull(); // ReSharper disable AssignNullToNotNullAttribute targetCell = tablePart.Cells.LastOrDefault().LastOrDefault(); // ReSharper restore AssignNullToNotNullAttribute targetCell.Should().NotBeNull(); // ReSharper disable PossibleNullReferenceException targetCell.StringValue.Should().Be("Test Test"); // ReSharper restore PossibleNullReferenceException }
public void SimpleTestWithArray() { var model = new[] { "a", "b", "c", "d", "e" }; var template = new FakeTable(1, 1); var cell = template.InsertCell(new CellPosition(1, 1)); cell.StringValue = "Template:RootTemplate:A1:A1"; var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger); var target = new FakeTable(10, 10); var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger), new Style(new FakeCell(new CellPosition("A1")) { StyleId = "(1,1)" })); templateEngine.Render(tableBuilder, model); target.GetCell(new CellPosition("B2")).StringValue.Should().Be("a"); target.GetCell(new CellPosition("B3")).StringValue.Should().Be("b"); target.GetCell(new CellPosition("B4")).StringValue.Should().Be("c"); target.GetCell(new CellPosition("B5")).StringValue.Should().Be("d"); target.GetCell(new CellPosition("B6")).StringValue.Should().Be("e"); DebugPrinting(target, new CellPosition(1, 1), new CellPosition(10, 10)); }
public void FakeTableCellSearchTest() { const int width = 20; const int height = 40; var table = new FakeTable(width, height); var positions = new[] { new CellPosition(1, 1), new CellPosition(40, 20), new CellPosition(10, 10) }; var stringValues = new[] { "Test Value", "Test Test", "Another text" }; for (var i = 0; i < positions.Count(); ++i) { var cell = table.InsertCell(positions[i]); cell.StringValue = stringValues[i]; } var cells = table.SearchCellByText("Test"); var cellsArray = cells as ICell[] ?? cells.ToArray(); cellsArray.Length.Should().Be(2); cellsArray[0].Should().NotBeNull(); cellsArray[1].Should().NotBeNull(); cellsArray[0].CellPosition.RowIndex.Should().Be(1); cellsArray[0].CellPosition.ColumnIndex.Should().Be(1); cellsArray[1].CellPosition.RowIndex.Should().Be(40); cellsArray[1].CellPosition.ColumnIndex.Should().Be(20); }
public void FakeTableWrongPositionCellInsertionTest(int wrongRowIndex, int wrongColumnIndex) { const int width = 20; const int height = 40; var table = new FakeTable(width, height); var cell = table.InsertCell(new CellPosition(wrongRowIndex, wrongColumnIndex)); cell.Should().BeNull(); }
public void FakeTableCellInsertionTest() { const int width = 20; const int height = 40; var table = new FakeTable(width, height); var position = new CellPosition(10, 10); var cell = table.InsertCell(position); cell.Should().NotBeNull(); }
public void FakeTableCellManipulationTest() { const int width = 20; const int height = 40; var table = new FakeTable(width, height); var position = new CellPosition(10, 10); var cell = table.InsertCell(position); cell.Should().NotBeNull(); const string testValue = "Test Value"; cell.StringValue = testValue; cell = table.GetCell(position); cell.Should().NotBeNull(); cell.StringValue.Should().Be(testValue); }
public void StringValuePrintingTest() { var template = new FakeTable(1, 1); var cell = template.InsertCell(new CellPosition(1, 1)); cell.StringValue = "Template:RootTemplate:A1:A1"; var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger); var target = new FakeTable(10, 10); var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger), new Style(new FakeCell(new CellPosition("A1")) { StyleId = "(1,1)" })); templateEngine.Render(tableBuilder, "TestStringValue"); target.GetCell(new CellPosition("B2")).StringValue.Should().Be("TestStringValue"); ((FakeCell)target.GetCell(new CellPosition("B2"))).StyleId.Should().Be("(1,1)"); }