Ejemplo n.º 1
0
        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
        }
Ejemplo n.º 2
0
        public void FakeTableWithWrongPositionPartExtractionTest()
        {
            const int width  = 20;
            const int height = 40;
            var       table  = new FakeTable(width, height);

            var tablePart = table.GetTablePart(new Rectangle(new CellPosition(-1, 0), new CellPosition(1, 1)));

            tablePart.Should().BeNull();
        }