Esempio n. 1
0
        public void WriteHandlesAList()
        {
            var attribute  = new ReflectorPropertyAttribute("list");
            var serialiser = new NameValuePairSerialiser(null, attribute, true);
            var values     = new NameValuePair[]
            {
                new NameValuePair("name1", "the value of 1"),
                new NameValuePair("name2", "the value of 2")
            };
            var builder = new StringBuilder();

            using (var stringWriter = new StringWriter(builder))
            {
                var settings = new XmlWriterSettings
                {
                    Indent = false,
                    NewLineOnAttributes = false,
                    OmitXmlDeclaration  = true
                };
                using (var writer = XmlWriter.Create(stringWriter, settings))
                {
                    serialiser.Write(writer, values);
                }
            }

            Assert.AreEqual(
                "<list><value name=\"name1\">the value of 1</value><value name=\"name2\">the value of 2</value></list>",
                builder.ToString());
        }
Esempio n. 2
0
        public void WriteHandlesASingleItem()
        {
            var attribute  = new ReflectorPropertyAttribute("value");
            var serialiser = new NameValuePairSerialiser(null, attribute, false);
            var value      = new NameValuePair("a name", "the value");
            var builder    = new StringBuilder();

            using (var stringWriter = new StringWriter(builder))
            {
                var settings = new XmlWriterSettings
                {
                    Indent = false,
                    NewLineOnAttributes = false,
                    OmitXmlDeclaration  = true
                };
                using (var writer = XmlWriter.Create(stringWriter, settings))
                {
                    serialiser.Write(writer, value);
                }
            }

            Assert.AreEqual("<value name=\"a name\">the value</value>", builder.ToString());
        }