Beispiel #1
0
        public static void SerializeEmpty()
        {
            var empty  = new EmptyClass();
            var result = XmlWriteBuffer.SerializeStatic(empty);

            Assert.Equal("<emptyClass/>", result);
        }
Beispiel #2
0
        public static void SlamStackDeserializeError()
        {
            var head       = BuildStackSlammer(XmlReadBuffer.s_maxDepth);
            var serialized = XmlWriteBuffer.SerializeStatic(head);

            Assert.Throws <Exception>(() => XmlReadBuffer.ReadStatic <StackSlam>(serialized));
        }
Beispiel #3
0
        public static void SerializeAttributes()
        {
            var truth = new WithAttributes
            {
                m_int    = -1,
                m_uint   = uint.MaxValue,
                m_double = 3.14,
                m_string = "david and tim<",
                m_bool   = true,
                m_byte   = 128
            };

            const string expected =
                "<attrs int='-1' uint='4294967295' double='3.14' bool='1' byte='128' string='david and tim&lt;'/>";
            const string expectedCompatible =
                "<attrs int='-1'uint='4294967295'double='3.14'bool='1'byte='128'string='david and tim&lt;'/>";
            const string expectedWithDecl =
                "<?xml version='1.0'?><attrs int='-1' uint='4294967295' double='3.14' bool='1' byte='128' string='david and tim&lt;'/>";
            const string expectedWithComment =
                "<?xml version='1.0'?><!--<attrs wont be parsed in comment>--><attrs int='-1' uint='4294967295' double='3.14' bool='1' byte='128' string='david and tim&lt;'/>";

            var result = XmlWriteBuffer.SerializeStatic(truth);

            Assert.Equal(expected, result);

            AssertEqualWithAttrs(expected, truth);
            AssertEqualWithAttrs(expectedCompatible, truth);
            AssertEqualWithAttrs(expectedWithDecl, truth);
            AssertEqualWithAttrs(expectedWithComment, truth);
        }
Beispiel #4
0
        public static void SerializeLongName()
        {
            var longName = new VeryLongName();
            var result   = XmlWriteBuffer.SerializeStatic(longName);

            Assert.Equal($"<{VeryLongName.c_longName}/>", result);
        }
Beispiel #5
0
        public static void SerializeStringBody(CDataMode cdataMode)
        {
            var truth = new StringBody()
            {
                m_fullBody = "asdjhasjkdhakjsdhjkahsdjhkasdhasd<>&&"
            };
            var result = XmlWriteBuffer.SerializeStatic(truth, cdataMode);

            var deserialized = XmlReadBuffer.ReadStatic <StringBody>(result, cdataMode);

            Assert.Equal(truth.m_fullBody, deserialized.m_fullBody);
        }
Beispiel #6
0
        public static void SerializeStringBodies(CDataMode cdataMode)
        {
            var truth = new StringBodies
            {
                m_a     = "blah1<>&&",
                m_b     = "blah2",
                m_null  = null,
                m_empty = string.Empty
            };
            var result = XmlWriteBuffer.SerializeStatic(truth, cdataMode);

            var deserialized = XmlReadBuffer.ReadStatic <StringBodies>(result, cdataMode);

            Assert.Equal(truth.m_a, deserialized.m_a);
            Assert.Equal(truth.m_b, deserialized.m_b);
            //Assert.Equal(truth.m_null, deserialized.m_null); // todo: do we want to avoid writing nulls?? currently empty string
            Assert.Equal(truth.m_empty, deserialized.m_empty);
        }
Beispiel #7
0
 public static void SerializeNull()
 {
     Assert.Throws <ArgumentNullException>(() => XmlWriteBuffer.SerializeStatic(null));
 }
Beispiel #8
0
 public static void SlamStackDeserialize()
 {
     var head         = BuildStackSlammer(XmlReadBuffer.s_maxDepth - 1);
     var serialized   = XmlWriteBuffer.SerializeStatic(head);
     var deserialized = XmlReadBuffer.ReadStatic <StackSlam>(serialized);
 }
Beispiel #9
0
 public static void SlamStackSerialize()
 {
     var head       = BuildStackSlammer(1000);
     var serialized = XmlWriteBuffer.SerializeStatic(head);
 }
Beispiel #10
0
 private static string EncodeStr(string input, bool attribute)
 {
     using var buffer = XmlWriteBuffer.Create();
     buffer.EncodeText(input, attribute);
     return buffer.ToStr();
 }
Beispiel #11
0
 public string WriteBuffer_BestCaseBaseline()
 {
     using var writeBuffer = XmlWriteBuffer.Create();
     writeBuffer.PutString(s_bestCaseStr);
     return(writeBuffer.ToStr());
 }
Beispiel #12
0
 private static string EncodeUsingWriteBuffer(string toEncode)
 {
     using var writeBuffer = XmlWriteBuffer.Create();
     writeBuffer.EncodeText(toEncode);
     return(writeBuffer.ToStr());
 }