public void TestSerializeSimpleClassWithOverrides() { // Also tests XmlIgnore XmlAttributeOverrides overrides = new XmlAttributeOverrides(); XmlAttributes attr = new XmlAttributes(); attr.XmlIgnore = true; overrides.Add(typeof(SimpleClassWithXmlAttributes), "something", attr); SimpleClassWithXmlAttributes simple = new SimpleClassWithXmlAttributes(); simple.something = "hello"; Serialize(simple, overrides); AssertEquals(Infoset("<simple xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText); }
public void TestSerializeXmlRootAttribute() { // constructor override & element name XmlRootAttribute root = new XmlRootAttribute(); root.ElementName = "renamed"; SimpleClassWithXmlAttributes simpleWithAttributes = new SimpleClassWithXmlAttributes(); Serialize(simpleWithAttributes, root); AssertEquals(Infoset("<renamed xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText); SimpleClass simple = null; root.IsNullable = false; try { Serialize(simple, root); Fail("Cannot serialize null object if XmlRoot's IsNullable == false"); } catch (Exception) { } root.IsNullable = true; try { Serialize(simple, root); Fail("Cannot serialize null object if XmlRoot's IsNullable == true"); } catch (Exception) { } simple = new SimpleClass(); root.ElementName = null; root.Namespace = "some.urn"; Serialize(simple, root); AssertEquals(Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='some.urn' />"), WriterText); }
public void TestSerializeSimpleClassWithXmlAttributes() { SimpleClassWithXmlAttributes simple = new SimpleClassWithXmlAttributes(); Serialize(simple); AssertEquals(Infoset("<simple xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText); simple.something = "hello"; Serialize(simple); AssertEquals (Infoset("<simple xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' member='hello' />"), WriterText); }