Пример #1
0
        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 WriteXmlDirect()
        {
            using (Stream stream = new MemoryStream())
            {
                TagWriter writer;

                writer = new XmlTagWriter(stream);
                writer.WriteStartDocument();
                writer.WriteStartTag("Level", TagType.Compound);
                writer.WriteTag("longTest", 9223372036854775807);
                writer.WriteTag("shortTest", (short)32767);
                writer.WriteTag("stringTest", "HELLO WORLD THIS IS A TEST STRING ÅÄÖ!");
                writer.WriteTag("floatTest", (float)0.498231471);
                writer.WriteTag("intTest", 2147483647);
                writer.WriteStartTag("nested compound test", TagType.Compound);
                writer.WriteStartTag("ham", TagType.Compound);
                writer.WriteTag("name", "Hampus");
                writer.WriteTag("value", 0.75F);
                writer.WriteEndTag();
                writer.WriteStartTag("egg", TagType.Compound);
                writer.WriteTag("name", "Eggbert");
                writer.WriteTag("value", 0.5F);
                writer.WriteEndTag();
                writer.WriteEndTag();
                writer.WriteStartTag("listTest (long)", TagType.List, TagType.Long, 5);
                writer.WriteTag((long)11);
                writer.WriteTag((long)12);
                writer.WriteTag((long)13);
                writer.WriteTag((long)14);
                writer.WriteTag((long)15);
                writer.WriteEndTag();
                writer.WriteStartTag("listTest (compound)", TagType.List, TagType.Compound, 2);
                writer.WriteStartTag(TagType.Compound);
                writer.WriteTag("name", "Compound tag #0");
                writer.WriteTag("created-on", 1264099775885);
                writer.WriteEndTag();
                writer.WriteStartTag(TagType.Compound);
                writer.WriteTag("name", "Compound tag #1");
                writer.WriteTag("created-on", 1264099775885);
                writer.WriteEndTag();
                writer.WriteEndTag();
                writer.WriteTag("byteTest", (byte)127);
                writer.WriteTag("byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))", SampleByteArray);
                writer.WriteTag("doubleTest", 0.49312871321823148);
                writer.WriteEndTag();
                writer.WriteEndDocument();
            }
        }