public void Should_Write_Multiple_Properties() { var sb = new StringBuilder(); using (var subject = new IonWriter(new StringWriter(sb))) { subject.WriteSection("META"); Assert.AreEqual(WriterState.Section, subject.State); subject.WriteProperty("test", 24.3f); subject.WriteProperty("test1", "test1val"); subject.WriteProperty("test2", true); Assert.AreEqual(WriterState.Section | WriterState.Property, subject.State); } Assert.AreEqual(string.Format("[META]{0}test=24.3{0}test1=\"test1val\"{0}test2=true{0}", Environment.NewLine), sb.ToString()); }
public void Should_Write_Integer_Property() { var sb = new StringBuilder(); using (var subject = new IonWriter(new StringWriter(sb))) { subject.WriteSection("META"); Assert.AreEqual(WriterState.Section, subject.State); subject.WriteProperty("test", 1000); Assert.AreEqual(WriterState.Section | WriterState.Property, subject.State); } Assert.AreEqual(string.Format("[META]{0}test=1000{0}", Environment.NewLine), sb.ToString()); }
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)); }
public void Should_Write_Escaped_Newlines_String_Property() { var sb = new StringBuilder(); using (var subject = new IonWriter(new StringWriter(sb), new WriterOptions { EscapeQuotes = true, EscapeNewLineChars = true })) { subject.WriteSection("META"); Assert.AreEqual(WriterState.Section, subject.State); subject.WriteProperty("test", "value"); Assert.AreEqual(WriterState.Section | WriterState.Property, subject.State); } Assert.AreEqual(string.Format("[META]{0}test=\\\"value\\\"{0}", Consts.IonSpecialChars.NewLineEscaped), sb.ToString()); }
public void Should_Write_Custom_Property() { var sb = new StringBuilder(); using (var subject = new IonWriter(new StringWriter(sb))) { subject.WriteSection("META"); Assert.AreEqual(WriterState.Section, subject.State); subject.WriteProperty("test", (tw) => { tw.Write('['); tw.Write(23); tw.Write(','); tw.Write(23); tw.Write(','); tw.Write(23); tw.Write(','); tw.Write(23); tw.Write(']'); }); Assert.AreEqual(WriterState.Section | WriterState.Property, subject.State); } Assert.AreEqual(string.Format("[META]{0}test=[23,23,23,23]{0}", Environment.NewLine), sb.ToString()); }