using System.Xml.Serialization;
using NUnit.Framework;
+#if NET_2_0
+using System.Collections.Generic;
+#endif
using MonoTests.System.Xml.TestClasses;
new XmlSerializer (typeof(WrongChoices));
}
+ [Test]
+ public void XmlArrayOnByteArray ()
+ {
+ new XmlSerializer (typeof (XmlArrayOnByteArrayType));
+ }
+
#if NET_2_0
+
+ [Test]
+ public void ImportNullableInt ()
+ {
+ XmlReflectionImporter imp = new XmlReflectionImporter ();
+ XmlTypeMapping map = imp.ImportTypeMapping (typeof (int?));
+ XmlSchemas schemas = new XmlSchemas ();
+ XmlSchemaExporter exp = new XmlSchemaExporter (schemas);
+ exp.ExportTypeMapping (map);
+ XmlSchema schema = schemas [0];
+ XmlSchemaElement el = schema.Items [0] as XmlSchemaElement;
+ Assert.AreEqual ("int", el.Name, "#1");
+ Assert.AreEqual (new XmlQualifiedName ("int", XmlSchema.Namespace), el.SchemaTypeName, "#2");
+ Assert.AreEqual (true, el.IsNillable, "#3");
+ }
+
[Test]
public void ImportNullableContainer ()
{
new XmlSerializer (typeof (NullableContainer));
}
+
+ [Test]
+ public void ImportNullableContainer2 ()
+ {
+ XmlReflectionImporter imp = new XmlReflectionImporter ();
+ XmlTypeMapping map = imp.ImportTypeMapping (typeof (NullableContainer2));
+ XmlSchemas schemas = new XmlSchemas ();
+ XmlSchemaExporter exp = new XmlSchemaExporter (schemas);
+ exp.ExportTypeMapping (map);
+
+ XmlSchema schema = schemas [0];
+ XmlSchemaComplexType el = schema.Items [1] as XmlSchemaComplexType;
+
+ XmlSchemaSequence s = el.Particle as XmlSchemaSequence;
+ XmlSchemaElement el2 = s.Items [0] as XmlSchemaElement;
+ Assert.IsTrue (el2.IsNillable);
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void ImportGenericTypeDefinition ()
+ {
+ new XmlSerializer (typeof (List<int>).GetGenericTypeDefinition ());
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void XmlSchemaProviderMissingMethod ()
+ {
+ new XmlSerializer (typeof (XmlSchemaProviderMissingMethodType));
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void XmlSchemaProviderMethodNonStatic ()
+ {
+ new XmlSerializer (typeof (XmlSchemaProviderNonStaticType));
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void XmlSchemaProviderMethodIncorrectReturn ()
+ {
+ new XmlSerializer (typeof (XmlSchemaProviderIncorrectReturnType));
+ }
#endif
public class Employee : IXmlSerializable
private IEnumerator _baseEnumerator;
}
+ public class XmlArrayOnByteArrayType
+ {
+ [XmlArray]
+ [XmlArrayItem ("Byte", IsNullable =false)]
+ public byte [] Args;
+ }
+
#if NET_2_0
public class NullableContainer
{
[XmlElement (IsNullable = true)]
public int? NilInt;
}
+
+ public class NullableContainer2
+ {
+ int? value;
+
+ public int? NullableInt {
+ get { return value; }
+ set { this.value = value; }
+ }
+ }
+
+ [XmlSchemaProvider ("GetXsdType")]
+ public class XmlSchemaProviderMissingMethodType : IXmlSerializable
+ {
+ public void ReadXml (XmlReader reader)
+ {
+ }
+
+ public void WriteXml (XmlWriter writer)
+ {
+ }
+
+ public XmlSchema GetSchema ()
+ {
+ return null;
+ }
+ }
+
+ [XmlSchemaProvider ("GetXsdType")]
+ public class XmlSchemaProviderNonStaticType : IXmlSerializable
+ {
+ public void ReadXml (XmlReader reader)
+ {
+ }
+
+ public void WriteXml (XmlWriter writer)
+ {
+ }
+
+ public XmlSchema GetSchema ()
+ {
+ return null;
+ }
+
+ public object GetXsdType ()
+ {
+ return null;
+ }
+ }
+
+ [XmlSchemaProvider ("GetXsdType")]
+ public class XmlSchemaProviderIncorrectReturnType : IXmlSerializable
+ {
+ public void ReadXml (XmlReader reader)
+ {
+ }
+
+ public void WriteXml (XmlWriter writer)
+ {
+ }
+
+ public XmlSchema GetSchema ()
+ {
+ return null;
+ }
+
+ public static object GetXsdType ()
+ {
+ return null;
+ }
+ }
#endif
}
}