public void Draw_Success() { // Arrange List<TestEntity> testData = new List<TestEntity> { new TestEntity { Id = 1, Value = "Short" }, new TestEntity { Id = 2, Value = "Loooooooooooong" }, }; Table<TestEntity> table = new Table<TestEntity> { Columns = { new Column<TestEntity>("Id", c => c.Id.ToString()), new Column<TestEntity>("Value", c => c.Value), }, }; TestWriter<TestEntity> testWriter = new TestWriter<TestEntity>(this.Writer); // Act testWriter.Draw(table, testData); // Assert var result = this.Writer.ToString(); result.Should().NotBeNullOrWhiteSpace("Draw should render the table."); var lines = result.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); lines.Length.Should().Be(6, "Draw should generate the correct number of lines."); }
public void Draw_DefaultNullColumnValue_Success() { // Arrange List<TestEntity> testData = new List<TestEntity> { new TestEntity { Id = 1, Value = null }, }; Table<TestEntity> table = new Table<TestEntity> { Columns = { new Column<TestEntity>("Id", c => c.Id.ToString()), new Column<TestEntity>("Value", c => c.Value), }, }; TestWriter<TestEntity> testWriter = new TestWriter<TestEntity>(this.Writer); // Act testWriter.Draw(table, testData); // Assert var result = this.Writer.ToString(); result.Should().NotBeNullOrWhiteSpace("Draw should render the table."); var lines = result.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); lines.Length.Should().Be(5, "Draw should generate the correct number of lines."); lines[0].Should().Be("┌────┬───────┐"); lines[1].Should().Be("│ Id │ Value │"); lines[2].Should().Be("├────┼───────┤"); lines[3].Should().Be("│ 1 │ │"); lines[4].Should().Be("└────┴───────┘"); }
public void Draw_CustomTableConfig_Success() { // Arrange List<TestEntity> testData = new List<TestEntity> { new TestEntity { Id = 1, Value = "Short" }, new TestEntity { Id = 2, Value = "Loooooooooooong" }, }; Table<TestEntity> table = new Table<TestEntity> { Columns = { new Column<TestEntity>("Id", c => c.Id.ToString()), new Column<TestEntity>("Value", c => c.Value), }, }; TestWriter<TestEntity> testWriter = new TestWriter<TestEntity>(this.Writer); TableConfig customTableConfig = new TableConfig { BottomLeftCharacter = '#', HorizontalBottomJointCharacter = '#', BottomRightCharacter = '#', HorizontalCharacter = '#', HorizontalTopJointCharacter = '#', IntersectionJointCharacter = '#', TopLeftCharacter = '#', TopRightCharacter = '#', VerticalCharacter = '#', VerticalLeftJointCharacter = '#', VerticalRightJointCharacter = '#', }; // Act testWriter.Draw(table, testData, customTableConfig); // Assert var result = this.Writer.ToString(); result.Should().NotBeNullOrWhiteSpace("Draw should render the table."); var lines = result.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); lines.Length.Should().Be(6, "Draw should generate the correct number of lines."); lines[0].Should().Be("########################"); lines[1].Should().Be("# Id # Value #"); lines[2].Should().Be("########################"); lines[3].Should().Be("# 1 # Short #"); lines[4].Should().Be("# 2 # Loooooooooooong #"); lines[5].Should().Be("########################"); }
public void Draw_IndexColumn_Success() { // Arrange List<TestEntity> testData = new List<TestEntity> { new TestEntity { Id = 1, Value = "Short" }, new TestEntity { Id = 2, Value = "Loooooooooooong" }, }; Table<TestEntity> table = new Table<TestEntity> { Title = "Title", ShowIndexColumn = true, Columns = { new Column<TestEntity>("Id", c => c.Id.ToString()), new Column<TestEntity>("Value", c => c.Value), }, }; TestWriter<TestEntity> testWriter = new TestWriter<TestEntity>(this.Writer); // Act testWriter.Draw(table, testData); // Assert var result = this.Writer.ToString(); result.Should().NotBeNullOrWhiteSpace("Draw should render the table."); var lines = result.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); lines.Length.Should().Be(8, "Draw should generate the correct number of lines."); lines[0].Should().Be("┌──────────────────────────┐"); lines[1].Should().Be("│ Title │"); lines[2].Should().Be("├───┬────┬─────────────────┤"); lines[3].Should().Be("│ │ Id │ Value │"); lines[4].Should().Be("├───┼────┼─────────────────┤"); lines[5].Should().Be("│ 1 │ 1 │ Short │"); lines[6].Should().Be("│ 2 │ 2 │ Loooooooooooong │"); lines[7].Should().Be("└───┴────┴─────────────────┘"); }