2007-09-25 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.XML / Test / System.Xml.Serialization / XmlReflectionImporterTests.cs
index 45c433ea2a596034e958d2cc751bed720ed040d8..6e2778957378b44178f77d4a56e99c8a851f09b2 100644 (file)
@@ -17,6 +17,9 @@ using System.Xml.Schema;
 using System.Xml.Serialization;
 
 using NUnit.Framework;
+#if NET_2_0
+using System.Collections.Generic;
+#endif
 
 using MonoTests.System.Xml.TestClasses;
 
@@ -1535,12 +1538,79 @@ namespace MonoTests.System.XmlSerialization
                        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
@@ -2009,12 +2079,90 @@ namespace MonoTests.System.XmlSerialization
                        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
        }
 }