public void Reading_data_fills_table()
        {
            // Arrange
            var mockReader = new Mock <ICsvReader>();

            mockReader.Setup(reader => reader.Read())
            .Returns(new List <string>
            {
                "Id,Title,Year,Summary",
                "1,Dr. No,1963,Excellent",
                "2,Goldfinger,1965,Good"
            });

            // Act
            var table = CsvTable.ReadFrom(mockReader.Object);

            // Assert
            Assert.Equal(expected: 2, actual: table.Rows.Count());
            Assert.Equal(expected: "Dr. No", actual: table.Rows[0].Cells[1].Value);
        }
        public void Convert_table_to_builder()
        {
            // Arrange
            var table = CsvTable.ReadFrom(() => new List <string>
            {
                "Id,Title,Year,Summary",
                "1,Dr. No,1963,Excellent",
                "2,Goldfinger,1965,Good"
            });

            var lines = new List <string>();

            // Act
            var builder = table.ToBuilder();

            builder.WriteTo(rows => lines = rows);

            // Assert
            Assert.Equal(expected: 3, actual: lines.Count);
            Assert.Equal(expected: "Id,Title,Year,Summary", actual: lines[0]);
            Assert.Equal(expected: "1,Dr. No,1963,Excellent", actual: lines[1]);
        }
Example #3
0
 public static CsvTable ToTable(this CsvBuilder builder)
 => CsvTable.ReadFrom(() => builder.ToLines());