public void WriteValue_should_use_cdata_if_required() { // arrange TextWriter writer = new StringWriter(); var xmlWriter = XmlWriter.Create(writer); var expected = "<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?>" + "<tag type=\"Compound\">" + "<alpha type=\"String\">" + "<![CDATA[<BAD>]]>" + "</alpha>" + "</tag>"; var target = new XmlTagWriter(xmlWriter); target.WriteStartDocument(); target.WriteStartTag(TagType.Compound); // act target.WriteTag("alpha", "<BAD>"); // assert target.WriteEndTag(); target.WriteEndDocument(); var actual = writer.ToString(); Assert.Equal(expected, actual); }
public void Constructor_allows_external_writer() { // arrange Tag actual; Tag expected = CreateComplexData(); TextWriter textWriter = new StringWriter(); var writer = XmlWriter.Create(textWriter, new XmlWriterSettings { Indent = true }); TagWriter target = new XmlTagWriter(writer); // act target.WriteStartDocument(); target.WriteTag(expected); target.WriteEndDocument(); using (TextReader textReader = new StringReader(textWriter.ToString())) { using (var reader = XmlReader.Create(textReader)) { actual = new XmlTagReader(reader).ReadTag(); } } // assert NbtAssert.Equal(expected, actual); }
public void WritePredefinedXmlDocument() { using (Stream stream = new MemoryStream()) { TagWriter writer = new XmlTagWriter(stream); writer.WriteStartDocument(); writer.WriteTag(_predefined); writer.WriteEndDocument(); } }
public void WriteXmlDocument() { TagCompound root; TagCompound compound; TagCompound child; TagList list; root = new TagCompound(); root.Name = "Level"; root.Value.Add("longTest", 9223372036854775807); root.Value.Add("shortTest", (short)32767); root.Value.Add("stringTest", "HELLO WORLD THIS IS A TEST STRING ÅÄÖ!"); root.Value.Add("floatTest", (float)0.498231471); root.Value.Add("intTest", 2147483647); compound = (TagCompound)root.Value.Add("nested compound test", TagType.Compound); child = (TagCompound)compound.Value.Add("ham", TagType.Compound); child.Value.Add("name", "Hampus"); child.Value.Add("value", (float)0.75); child = (TagCompound)compound.Value.Add("egg", TagType.Compound); child.Value.Add("name", "Eggbert"); child.Value.Add("value", (float)0.5); list = (TagList)root.Value.Add("listTest (long)", TagType.List, TagType.Long); list.Value.Add((long)11); list.Value.Add((long)12); list.Value.Add((long)13); list.Value.Add((long)14); list.Value.Add((long)15); list = (TagList)root.Value.Add("listTest (compound)", TagType.List, TagType.Compound); child = (TagCompound)list.Value.Add(TagType.Compound); child.Value.Add("name", "Compound tag #0"); child.Value.Add("created-on", 1264099775885); child = (TagCompound)list.Value.Add(TagType.Compound); child.Value.Add("name", "Compound tag #1"); child.Value.Add("created-on", 1264099775885); root.Value.Add("byteTest", (byte)127); root.Value.Add("byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))", SampleByteArray); root.Value.Add("doubleTest", 0.49312871321823148); using (Stream stream = new MemoryStream()) { TagWriter writer; writer = new XmlTagWriter(stream); writer.WriteStartDocument(); writer.WriteTag(root); writer.WriteEndDocument(); } }