public void TestSerializeDefaultValueAttribute() { XmlAttributeOverrides overrides = new XmlAttributeOverrides(); XmlAttributes attr = new XmlAttributes(); string defaultValueInstance = "nothing"; attr.XmlDefaultValue = defaultValueInstance; overrides.Add(typeof(SimpleClass), "something", attr); // use the default SimpleClass simple = new SimpleClass(); Serialize(simple, overrides); AssertEquals(Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText); // same value as default simple.something = defaultValueInstance; Serialize(simple, overrides); AssertEquals(Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText); // some other value simple.something = "hello"; Serialize(simple, overrides); AssertEquals(Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>hello</something></SimpleClass>"), WriterText); }
public void TestSerializeXmlAttributeAttribute() { // null XmlAttributeOverrides overrides = new XmlAttributeOverrides(); XmlAttributes attr = new XmlAttributes(); attr.XmlAttribute = new XmlAttributeAttribute(); overrides.Add(typeof(SimpleClass), "something", attr); SimpleClass simple = new SimpleClass();; Serialize(simple, overrides); AssertEquals("#1", Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText); // regular simple.something = "hello"; Serialize(simple, overrides); AssertEquals ("#2", Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' something='hello' />"), WriterText); // AttributeName attr.XmlAttribute.AttributeName = "somethingelse"; Serialize(simple, overrides); AssertEquals ("#3", Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' somethingelse='hello' />"), WriterText); // Type // FIXME this should work, shouldnt it? // attr.XmlAttribute.Type = typeof(string); // Serialize(simple, overrides); // Assert(WriterText.EndsWith(" something='hello' />")); // Namespace attr.XmlAttribute.Namespace = "some:urn"; Serialize(simple, overrides); AssertEquals ("#4", Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' d1p1:somethingelse='hello' xmlns:d1p1='some:urn' />"), WriterText); // FIXME DataType // FIXME XmlSchemaForm Form // FIXME write XmlQualifiedName as attribute }
public void TestSerializeXmlElementAttribute() { XmlAttributeOverrides overrides = new XmlAttributeOverrides(); XmlAttributes attr = new XmlAttributes(); XmlElementAttribute element = new XmlElementAttribute(); attr.XmlElements.Add(element); overrides.Add(typeof(SimpleClass), "something", attr); // null SimpleClass simple = new SimpleClass();; Serialize(simple, overrides); AssertEquals(Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText); // not null simple.something = "hello"; Serialize(simple, overrides); AssertEquals (Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>hello</something></SimpleClass>"), WriterText); //ElementName element.ElementName = "saying"; Serialize(simple, overrides); AssertEquals (Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><saying>hello</saying></SimpleClass>"), WriterText); //IsNullable element.IsNullable = false; simple.something = null; Serialize(simple, overrides); AssertEquals(Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"),WriterText); element.IsNullable = true; simple.something = null; Serialize(simple, overrides); AssertEquals (Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><saying xsi:nil='true' /></SimpleClass>"), WriterText); //Namespace element.ElementName = null; element.IsNullable = false; element.Namespace = "some:urn"; simple.something = "hello"; Serialize(simple, overrides); AssertEquals (Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something xmlns='some:urn'>hello</something></SimpleClass>"), WriterText); //FIXME DataType //FIXME Form //FIXME Type }
public void TestSerializeXmlTextAttribute() { SimpleClass simple = new SimpleClass(); simple.something = "hello"; XmlAttributeOverrides overrides = new XmlAttributeOverrides(); XmlAttributes attr = new XmlAttributes(); overrides.Add(typeof(SimpleClass), "something", attr); attr.XmlText = new XmlTextAttribute(); Serialize(simple, overrides); AssertEquals(Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>hello</SimpleClass>"), WriterText); attr.XmlText = new XmlTextAttribute(typeof(string)); Serialize(simple, overrides); AssertEquals(Infoset("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>hello</SimpleClass>"), WriterText); try { attr.XmlText = new XmlTextAttribute(typeof(byte[])); Serialize(simple, overrides); Fail("XmlText.Type does not match the type it serializes: this should have failed"); } catch (Exception) { } try { attr.XmlText = new XmlTextAttribute(); attr.XmlText.DataType = "sometype"; Serialize(simple, overrides); Fail("XmlText.DataType does not match the type it serializes: this should have failed"); } catch (Exception) { } }
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 TestSerializeSimpleClass() { SimpleClass simple = new SimpleClass(); Serialize(simple); AssertEquals(Infoset("<SimpleClass 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("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>hello</something></SimpleClass>"), WriterText); }
public void TestSerializeClassArrayContainer() { ClassArrayContainer container = new ClassArrayContainer(); Serialize(container); AssertEquals(Infoset("<ClassArrayContainer xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"),WriterText); SimpleClass simple1 = new SimpleClass(); simple1.something = "hello"; SimpleClass simple2 = new SimpleClass(); simple2.something = "hello"; container.items = new SimpleClass[2]; container.items[0] = simple1; container.items[1] = simple2; Serialize(container); AssertEquals(Infoset("<ClassArrayContainer xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' ><items><SimpleClass><something>hello</something></SimpleClass><SimpleClass><something>hello</something></SimpleClass></items></ClassArrayContainer>"),WriterText); }
[Category ("NotWorking")] // SerializationCodeGenerator outputs wrong xsi:type for flagencoded in #C1 public void TestSerializeDefaultValueAttribute_Encoded () { SoapAttributeOverrides overrides = new SoapAttributeOverrides (); SoapAttributes attr = new SoapAttributes (); attr.SoapAttribute = new SoapAttributeAttribute (); string defaultValueInstance = "nothing"; attr.SoapDefaultValue = defaultValueInstance; overrides.Add (typeof (SimpleClass), "something", attr); // use the default SimpleClass simple = new SimpleClass (); SerializeEncoded (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass id='id1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A1"); // same value as default simple.something = defaultValueInstance; SerializeEncoded (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass id='id1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A2"); // some other value simple.something = "hello"; SerializeEncoded (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass id='id1' something='hello' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A3"); attr.SoapAttribute = null; attr.SoapElement = new SoapElementAttribute (); // use the default simple = new SimpleClass (); SerializeEncoded (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass id='id1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#B1"); // same value as default simple.something = defaultValueInstance; SerializeEncoded (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass id='id1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something xsi:type='xsd:string'>nothing</something></SimpleClass>"), WriterText, "#B2"); // some other value simple.something = "hello"; SerializeEncoded (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass id='id1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something xsi:type='xsd:string'>hello</something></SimpleClass>"), WriterText, "#B3"); overrides = new SoapAttributeOverrides (); attr = new SoapAttributes (); attr.SoapElement = new SoapElementAttribute ("flagenc"); overrides.Add (typeof (TestDefault), "flagencoded", attr); // use the default (from MS KB325691) TestDefault testDefault = new TestDefault (); SerializeEncoded (testDefault); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault xsi:type='xsd:string'>Default Value</strDefault>" + " <boolT xsi:type='xsd:boolean'>true</boolT>" + " <boolF xsi:type='xsd:boolean'>false</boolF>" + " <decimalval xsi:type='xsd:decimal'>10</decimalval>" + " <flag xsi:type='FlagEnum'>e1 e4</flag>" + " <flagencoded xsi:type='flagenum'>one four</flagencoded>" + "</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C1"); SerializeEncoded (testDefault, overrides); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault xsi:type='xsd:string'>Default Value</strDefault>" + " <boolT xsi:type='xsd:boolean'>true</boolT>" + " <boolF xsi:type='xsd:boolean'>false</boolF>" + " <decimalval xsi:type='xsd:decimal'>10</decimalval>" + " <flag xsi:type='FlagEnum'>e1 e4</flag>" + " <flagenc xsi:type='flagenum'>one four</flagenc>" + "</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C2"); SerializeEncoded (testDefault, overrides, AnotherNamespace); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault xsi:type='xsd:string'>Default Value</strDefault>" + " <boolT xsi:type='xsd:boolean'>true</boolT>" + " <boolF xsi:type='xsd:boolean'>false</boolF>" + " <decimalval xsi:type='xsd:decimal'>10</decimalval>" + " <flag xmlns:q2='{2}' xsi:type='q2:FlagEnum'>e1 e4</flag>" + " <flagenc xmlns:q3='{2}' xsi:type='q3:flagenum'>one four</flagenc>" + "</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace, AnotherNamespace)), WriterText, "#C3"); // non-default values testDefault.strDefault = "Some Text"; testDefault.boolT = false; testDefault.boolF = true; testDefault.decimalval = 20m; testDefault.flag = FlagEnum.e2; testDefault.flagencoded = FlagEnum_Encoded.e2 | FlagEnum_Encoded.e1; SerializeEncoded (testDefault); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault xsi:type='xsd:string'>Some Text</strDefault>" + " <boolT xsi:type='xsd:boolean'>false</boolT>" + " <boolF xsi:type='xsd:boolean'>true</boolF>" + " <decimalval xsi:type='xsd:decimal'>20</decimalval>" + " <flag xsi:type='FlagEnum'>e2</flag>" + " <flagencoded xsi:type='flagenum'>one two</flagencoded>" + "</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C4"); SerializeEncoded (testDefault, overrides); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault xsi:type='xsd:string'>Some Text</strDefault>" + " <boolT xsi:type='xsd:boolean'>false</boolT>" + " <boolF xsi:type='xsd:boolean'>true</boolF>" + " <decimalval xsi:type='xsd:decimal'>20</decimalval>" + " <flag xsi:type='FlagEnum'>e2</flag>" + " <flagenc xsi:type='flagenum'>one two</flagenc>" + "</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C5"); attr = new SoapAttributes (); attr.SoapType = new SoapTypeAttribute ("flagenum", "yetanother:urn"); overrides.Add (typeof (FlagEnum_Encoded), attr); SerializeEncoded (testDefault, overrides, AnotherNamespace); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault xsi:type='xsd:string'>Some Text</strDefault>" + " <boolT xsi:type='xsd:boolean'>false</boolT>" + " <boolF xsi:type='xsd:boolean'>true</boolF>" + " <decimalval xsi:type='xsd:decimal'>20</decimalval>" + " <flag xmlns:q2='{2}' xsi:type='q2:FlagEnum'>e2</flag>" + " <flagenc xmlns:q3='yetanother:urn' xsi:type='q3:flagenum'>one two</flagenc>" + "</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace, AnotherNamespace)), WriterText, "#C6"); attr = new SoapAttributes (); attr.SoapType = new SoapTypeAttribute ("testDefault"); overrides.Add (typeof (TestDefault), attr); SerializeEncoded (testDefault, overrides, AnotherNamespace); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<q1:testDefault id='id1' xmlns:q1='{2}' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault xsi:type='xsd:string'>Some Text</strDefault>" + " <boolT xsi:type='xsd:boolean'>false</boolT>" + " <boolF xsi:type='xsd:boolean'>true</boolF>" + " <decimalval xsi:type='xsd:decimal'>20</decimalval>" + " <flag xsi:type='q1:FlagEnum'>e2</flag>" + " <flagenc xmlns:q2='yetanother:urn' xsi:type='q2:flagenum'>one two</flagenc>" + "</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace, AnotherNamespace)), WriterText, "#C7"); }
public void TestSerializeDefaultValueAttribute () { XmlAttributeOverrides overrides = new XmlAttributeOverrides (); XmlAttributes attr = new XmlAttributes (); string defaultValueInstance = "nothing"; attr.XmlDefaultValue = defaultValueInstance; overrides.Add (typeof (SimpleClass), "something", attr); // use the default SimpleClass simple = new SimpleClass (); Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A1"); // same value as default simple.something = defaultValueInstance; Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A2"); // some other value simple.something = "hello"; Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>hello</something></SimpleClass>"), WriterText, "#A3"); overrides = new XmlAttributeOverrides (); attr = new XmlAttributes (); attr.XmlAttribute = new XmlAttributeAttribute (); attr.XmlDefaultValue = defaultValueInstance; overrides.Add (typeof (SimpleClass), "something", attr); // use the default simple = new SimpleClass (); Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#B1"); // same value as default simple.something = defaultValueInstance; Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#B2"); // some other value simple.something = "hello"; Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass something='hello' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#B3"); overrides = new XmlAttributeOverrides (); attr = new XmlAttributes (); attr.XmlAttribute = new XmlAttributeAttribute ("flagenc"); overrides.Add (typeof (TestDefault), "flagencoded", attr); // use the default TestDefault testDefault = new TestDefault (); Serialize (testDefault); Assert.AreEqual (Infoset ("<testDefault xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C1"); // use the default with overrides Serialize (testDefault, overrides); Assert.AreEqual (Infoset ("<testDefault flagenc='e1 e4' xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C2"); overrides = new XmlAttributeOverrides (); attr = new XmlAttributes (); attr.XmlAttribute = new XmlAttributeAttribute ("flagenc"); attr.XmlDefaultValue = (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4); // add default again overrides.Add (typeof (TestDefault), "flagencoded", attr); // use the default with overrides Serialize (testDefault, overrides); Assert.AreEqual (Infoset ("<testDefault xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C3"); // use the default with overrides and default namspace Serialize (testDefault, overrides, AnotherNamespace); Assert.AreEqual (Infoset ("<testDefault xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C4"); // non-default values testDefault.strDefault = "Some Text"; testDefault.boolT = false; testDefault.boolF = true; testDefault.decimalval = 20m; testDefault.flag = FlagEnum.e2; testDefault.flagencoded = FlagEnum_Encoded.e2 | FlagEnum_Encoded.e1; Serialize (testDefault); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<testDefault xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault>Some Text</strDefault>" + " <boolT>false</boolT>" + " <boolF>true</boolF>" + " <decimalval>20</decimalval>" + " <flag>two</flag>" + " <flagencoded>e1 e2</flagencoded>" + "</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C5"); Serialize (testDefault, overrides); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<testDefault flagenc='e1 e2' xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault>Some Text</strDefault>" + " <boolT>false</boolT>" + " <boolF>true</boolF>" + " <decimalval>20</decimalval>" + " <flag>two</flag>" + "</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C6"); Serialize (testDefault, overrides, AnotherNamespace); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<testDefault flagenc='e1 e2' xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault>Some Text</strDefault>" + " <boolT>false</boolT>" + " <boolF>true</boolF>" + " <decimalval>20</decimalval>" + " <flag>two</flag>" + "</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C7"); attr = new XmlAttributes (); XmlTypeAttribute xmlType = new XmlTypeAttribute ("flagenum"); xmlType.Namespace = "yetanother:urn"; attr.XmlType = xmlType; overrides.Add (typeof (FlagEnum_Encoded), attr); Serialize (testDefault, overrides, AnotherNamespace); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<testDefault flagenc='e1 e2' xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault>Some Text</strDefault>" + " <boolT>false</boolT>" + " <boolF>true</boolF>" + " <decimalval>20</decimalval>" + " <flag>two</flag>" + "</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText, "#C8"); attr = new XmlAttributes (); attr.XmlType = new XmlTypeAttribute ("testDefault"); overrides.Add (typeof (TestDefault), attr); Serialize (testDefault, overrides, AnotherNamespace); Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture, "<testDefault flagenc='e1 e2' xmlns='{2}' xmlns:xsd='{0}' xmlns:xsi='{1}'>" + " <strDefault>Some Text</strDefault>" + " <boolT>false</boolT>" + " <boolF>true</boolF>" + " <decimalval>20</decimalval>" + " <flag>two</flag>" + "</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace, AnotherNamespace)), WriterText, "#C9"); }
public void TestSerializeXmlTextAttribute () { SimpleClass simple = new SimpleClass (); simple.something = "hello"; XmlAttributeOverrides overrides = new XmlAttributeOverrides (); XmlAttributes attr = new XmlAttributes (); overrides.Add (typeof (SimpleClass), "something", attr); attr.XmlText = new XmlTextAttribute (); Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>hello</SimpleClass>"), WriterText, "#1"); attr.XmlText = new XmlTextAttribute (typeof (string)); Serialize (simple, overrides); Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>hello</SimpleClass>"), WriterText, "#2"); try { attr.XmlText = new XmlTextAttribute (typeof (byte[])); Serialize (simple, overrides); Assert.Fail ("#A1: XmlText.Type does not match the type it serializes: this should have failed"); } catch (InvalidOperationException ex) { // there was an error reflecting type 'MonoTests.System.Xml.TestClasses.SimpleClass' Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2"); Assert.IsNotNull (ex.Message, "#A3"); Assert.IsTrue (ex.Message.IndexOf (typeof (SimpleClass).FullName) != -1, "#A4"); Assert.IsNotNull (ex.InnerException, "#A5"); // there was an error reflecting field 'something'. Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#A6"); Assert.IsNotNull (ex.InnerException.Message, "#A7"); Assert.IsTrue (ex.InnerException.Message.IndexOf ("something") != -1, "#A8"); Assert.IsNotNull (ex.InnerException.InnerException, "#A9"); // the type for XmlText may not be specified for primitive types. Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.InnerException.GetType (), "#A10"); Assert.IsNotNull (ex.InnerException.InnerException.Message, "#A11"); Assert.IsNull (ex.InnerException.InnerException.InnerException, "#A12"); } try { attr.XmlText = new XmlTextAttribute (); attr.XmlText.DataType = "sometype"; Serialize (simple, overrides); Assert.Fail ("#B1: XmlText.DataType does not match the type it serializes: this should have failed"); } catch (InvalidOperationException ex) { // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.SimpleClass'. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2"); Assert.IsNotNull (ex.Message, "#B3"); Assert.IsTrue (ex.Message.IndexOf (typeof (SimpleClass).FullName) != -1, "#B4"); Assert.IsNotNull (ex.InnerException, "#B5"); // There was an error reflecting field 'something'. Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#B6"); Assert.IsNotNull (ex.InnerException.Message, "#B7"); Assert.IsTrue (ex.InnerException.Message.IndexOf ("something") != -1, "#B8"); Assert.IsNotNull (ex.InnerException.InnerException, "#B9"); //FIXME /* // There was an error reflecting type 'System.String'. Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.InnerException.GetType (), "#B10"); Assert.IsNotNull (ex.InnerException.InnerException.Message, "#B11"); Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (string).FullName) != -1, "#B12"); Assert.IsNotNull (ex.InnerException.InnerException.InnerException, "#B13"); // Value 'sometype' cannot be used for the XmlElementAttribute.DataType property. // The datatype 'http://www.w3.org/2001/XMLSchema:sometype' is missing. Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.InnerException.InnerException.GetType (), "#B14"); Assert.IsNotNull (ex.InnerException.InnerException.InnerException.Message, "#B15"); Assert.IsTrue (ex.InnerException.InnerException.InnerException.Message.IndexOf ("http://www.w3.org/2001/XMLSchema:sometype") != -1, "#B16"); Assert.IsNull (ex.InnerException.InnerException.InnerException.InnerException, "#B17"); */ } }
public ListDefaults() { ed = new SimpleClass(); str = "hola"; }
public void Add (SimpleClass value) { _list.Add (value); }