Beispiel #1
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 #2
0
        private static void AssertEqualWithAttrs(string serialiezd, WithAttributes truth)
        {
            var deserialized = XmlReadBuffer.ReadStatic <WithAttributes>(serialiezd);

            Assert.Equal(truth.m_int, deserialized.m_int);
            Assert.Equal(truth.m_uint, deserialized.m_uint);
            Assert.Equal(truth.m_double, deserialized.m_double);
            Assert.Equal(truth.m_string, deserialized.m_string);
        }