Serialize() public method

Serialize the object as XML
public Serialize ( object obj ) : string
obj object Object to serialize
return string
Exemplo n.º 1
0
        public void Can_serialize_simple_POCO_With_Attribute_Options_Defined()
        {
            var poco = new WackyPerson {
                Name = "Foo",
                Age = 50,
                Price = 19.95m,
                StartDate = new DateTime(2009, 12, 18, 10, 2, 23)
            };

            var xml = new XmlSerializer();
            var doc = xml.Serialize(poco);
            var expected = GetSimplePocoXDocWackyNames();

            Assert.Equal(expected.ToString(), doc.ToString());
        }
Exemplo n.º 2
0
        public void Can_serialize_simple_POCO_With_DateFormat_Specified()
        {
            var poco = new Person {
                Name = "Foo",
                Age = 50,
                Price = 19.95m,
                StartDate = new DateTime(2009, 12, 18, 10, 2, 23)
            };

            var xml = new XmlSerializer();
            xml.DateFormat = DateFormat.Iso8601;
            var doc = xml.Serialize(poco);
            var expected = GetSimplePocoXDocWithIsoDate();

            Assert.Equal(expected.ToString(), doc.ToString());
        }
Exemplo n.º 3
0
        public void Can_serialize_simple_POCO()
        {
            var poco = new Person {
                Name = "Foo",
                Age = 50,
                Price = 19.95m,
                StartDate = new DateTime(2009, 12, 18, 10, 2, 23),
                Items = new List<Item> {
                    new Item { Name = "One", Value = 1 },
                    new Item { Name = "Two", Value = 2 },
                    new Item { Name = "Three", Value = 3 }
                }
            };

            var xml = new XmlSerializer();
            var doc = xml.Serialize(poco);
            var expected = GetSimplePocoXDoc();

            Assert.Equal(expected.ToString(), doc.ToString());
        }
Exemplo n.º 4
0
        public void Can_serialize_simple_POCO_With_Different_Root_Element()
        {
            var poco = new Person {
                Name = "Foo",
                Age = 50,
                Price = 19.95m,
                StartDate = new DateTime(2009, 12, 18, 10, 2, 23)
            };

            var xml = new XmlSerializer();
            xml.RootElement = "Result";
            var doc = xml.Serialize(poco);
            var expected = GetSimplePocoXDocWithRoot();

            Assert.Equal(expected.ToString(), doc.ToString());
        }
Exemplo n.º 5
0
        public void Serializes_Properties_In_Specified_Order()
        {
            var ordered = new OrderedProperties();
            ordered.Name = "Name";
            ordered.Age = 99;
            ordered.StartDate = new DateTime(2010, 1, 1);

            var xml = new XmlSerializer();
            var doc = xml.Serialize(ordered);

            var expected = GetSortedPropsXDoc();

            Assert.Equal(expected.ToString(), doc.ToString());
        }