예제 #1
0
        public void Should_Write_Tables()
        {
            var row      = new string[] { "unit_type", "miles" };
            var row2     = new string[] { "unit_type", "miles", "23" };
            var expected = new string[]
            {
                "[DATA]",
                string.Empty,
                "| unit_type | miles |",
                "| unit_type | miles |",
                string.Empty,
                "| unit_type | miles | 23 |",
                "| unit_type | miles | 23 |"
            };
            var sb = new StringBuilder();

            using (var subject = new IonWriter(new StringWriter(sb)))
            {
                subject.WriteSection("DATA");
                Assert.AreEqual(WriterState.Section, subject.State);
                subject.WriteTableRow(row);
                subject.WriteTableRow(row);
                Assert.AreEqual(WriterState.Section | WriterState.TableRow, subject.State);
                subject.WriteEmptyLine();
                Assert.AreEqual(WriterState.Section, subject.State);
                subject.WriteTableRow(row2);
                subject.WriteTableRow(row2);
                Assert.AreEqual(WriterState.Section | WriterState.TableRow, subject.State);
            }
            CollectionAssert.AreEquivalent(expected, sb.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
        }
예제 #2
0
        public void Should_Write_Table_Cell_With_Custom_Value()
        {
            var expected = new string[]
            {
                "| unit_type | miles |",
                "| unit_type | miles |",
                string.Empty,
                "| my custom table |",
                string.Empty,
            };
            var sb = new StringBuilder();

            using (var subject = new IonWriter(new StringWriter(sb)))
            {
                subject.WriteTableCell((tw) => tw.Write("unit_type"));
                subject.WriteTableCell((tw) => tw.Write("miles"), true);
                subject.WriteTableCell("unit_type");
                subject.WriteTableCell("miles", true);
                Assert.AreEqual(WriterState.TableRow, subject.State);
                subject.WriteEmptyLine();
                Assert.AreEqual(WriterState.None, subject.State);
                subject.WriteTableCell((tw) => tw.Write("my custom table"), true);
                Assert.AreEqual(WriterState.TableRow, subject.State);
            }
            CollectionAssert.AreEquivalent(expected, sb.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
        }
예제 #3
0
        public void Should_Write_Multiple_Sections()
        {
            var header   = new string[] { "key", "val" };
            var row      = new string[] { "unit_type", "miles" };
            var expected = new string[]
            {
                "[META]",
                "test=\"value\"",
                string.Empty,
                "[DATA]",
                "table_name=\"test\"",
                string.Empty,
                "| key | val |",
                "|-----|-----|",
                "| unit_type | miles |",
                "| unit_type | miles |",
                string.Empty
            };
            var sb = new StringBuilder();

            using (var subject = new IonWriter(new StringWriter(sb)))
            {
                subject.WriteSection("META");
                Assert.AreEqual(WriterState.Section, subject.State);
                subject.WriteProperty("test", "value");
                Assert.AreEqual(WriterState.Section | WriterState.Property, subject.State);
                subject.WriteSection("DATA");
                Assert.AreEqual(WriterState.Section, subject.State);
                subject.WriteProperty("table_name", "test");
                subject.WriteEmptyLine();
                subject.WriteTableHeader(header);
                subject.WriteTableRow(row);
                subject.WriteTableRow(row);
                Assert.AreEqual(WriterState.Section | WriterState.TableRow, subject.State);
            }
            CollectionAssert.AreEquivalent(expected, sb.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
        }