Example #1
0
        public void ShouldConvertTable()
        {
            const int    entityId = 23;
            const long   value0   = 5234L;
            const string value1   = "hello, world";

            var collection = GetTestCollection(entityId, value0, value1);

            var result = _target.Render(collection);

            AssertResult(result, entityId, value0, value1);
        }
Example #2
0
        private void ActAndValidate(int entityCount = 1)
        {
            TextWriter textWriter = new StringWriter();

            IHtmlContent content = _renderer.Render(_tableConfig, entityCount);

            _nodes.Should().NotBeNull();
            _nodes.Should().HaveCount(1);
            _nodes.ElementAt(0).Element.TagName.Should().Be("div");
            content.WriteTo(textWriter, new HtmlEncoder());
            textWriter.ToString().Should().Be("Content");
            if (_tableState.ContainerId == null)
            {
                Guid id;

                Guid.TryParse(_nodes.ElementAt(0).Element.Attributes["Id"], out id).Should().BeTrue();
                _containerId = id.ToString();
            }
        }
Example #3
0
        public async Task Table_Rendering_Does_Not_Crash()
        {
            var result = await _fixture.Table.GetAsync(_fixture.Request);

            var renderer        = new TableRenderer();
            var table           = renderer.Render(_fixture.Table, result);
            var orderedEntities = _fixture.DataSource.Get().OrderBy(x => x.Id).ToArray();

            Assert.Equal(orderedEntities.Length, table.Rows.Length);
            for (int i = 0; i < table.Rows.Length; i++)
            {
                Assert.Equal(table.DataTable.Columns.Length, table.Rows[i].Columns.Length);
                Assert.Equal(orderedEntities[i].Id, (int)table.Rows[i]["Id"].Value);
                Assert.Equal(orderedEntities[i].Name, (string)table.Rows[i]["Name"].Value);
                for (int j = 0; j < table.Columns.Length; j++)
                {
                    Assert.Equal(table.DataTable.Columns.Single(x => x.Target == j).Name, table.Rows[i][j].Column.Name);
                    Assert.Equal(table.DataTable.Columns[j].Name, table.Rows[i][j].Column.Name);
                }
            }
        }
Example #4
0
    /// <inheritdoc/>
    protected override IEnumerable <Segment> Render(RenderContext context, int maxWidth)
    {
        if (context is null)
        {
            throw new ArgumentNullException(nameof(context));
        }

        var measurer = new TableMeasurer(this, context);

        // Calculate the column and table width
        var totalCellWidth = measurer.CalculateTotalCellWidth(maxWidth);
        var columnWidths   = measurer.CalculateColumnWidths(totalCellWidth);
        var tableWidth     = columnWidths.Sum() + measurer.GetNonColumnWidth();

        // Get the rows to render
        var rows = GetRenderableRows();

        // Render the table
        return(TableRenderer.Render(
                   new TableRendererContext(this, context, rows, tableWidth, maxWidth),
                   columnWidths));
    }