2007-02-07 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.XML / Test / System.Xml.Serialization / SoapReflectionImporterTests.cs
index 95bb817ca0fdabc1ee4e131086508910f91b63e1..b6c92dcddbe9e261f290ce4258b494ed5190c3a7 100644 (file)
@@ -9,6 +9,7 @@
 
 using System;
 using System.Collections;
+using DefaultValueAttribute = System.ComponentModel.DefaultValueAttribute;
 using System.Xml;
 using System.Xml.Schema;
 using System.Xml.Serialization;
@@ -64,7 +65,6 @@ namespace MonoTests.System.XmlSerialization
                }
                
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestIntTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (int));
@@ -114,7 +114,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestStringTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (string));
@@ -213,7 +212,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestByteTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (byte));
@@ -259,7 +257,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestBoolTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (bool));
@@ -284,7 +281,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestShortTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (short));
@@ -309,7 +305,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestUnsignedShortTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (ushort));
@@ -334,7 +329,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestUIntTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (uint));
@@ -359,7 +353,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestLongTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (long));
@@ -384,7 +377,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestULongTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (ulong));
@@ -409,7 +401,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestFloatTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (float));
@@ -434,7 +425,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestDoubleTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (double));
@@ -459,7 +449,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestDateTimeTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (DateTime));
@@ -509,7 +498,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestGuidTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (Guid));
@@ -559,7 +547,6 @@ namespace MonoTests.System.XmlSerialization
                }
                
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestDecimalTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (decimal));
@@ -584,7 +571,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestXmlQualifiedNameTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (XmlQualifiedName));
@@ -634,7 +620,6 @@ namespace MonoTests.System.XmlSerialization
                }
                
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestSByteTypeMapping ()
                {
                        XmlTypeMapping tm = Map (typeof (sbyte));
@@ -684,7 +669,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TestCharTypeMapping()
                {
                        XmlTypeMapping tm = Map (typeof (char));
@@ -1049,6 +1033,99 @@ namespace MonoTests.System.XmlSerialization
                        Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][]", tm.TypeFullName, "#B4");
                }
 
+               [Test]
+#if ONLY_1_1
+               [Category ("NotDotNet")] // wrong error message is reported in .NET 1.1
+#endif
+               public void TypeMapping_Attribute_ComplexType ()
+               {
+                       SoapAttributes attrs = new SoapAttributes (typeof (Field_Encoded).GetMember ("Names")[0]);
+                       attrs.SoapAttribute = new SoapAttributeAttribute (); // SoapAttribute cannot be used to encode complex types
+                       SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
+                       overrides.Add (typeof (Field_Encoded), "Names", attrs);
+
+                       try {
+                               Map (typeof (Field_Encoded), overrides);
+                               Assert.Fail ("#A1");
+                       } catch (InvalidOperationException ex) {
+                               // Cannot serialize member 'Names' of type System.String[].
+                               // SoapAttribute cannot be used to encode complex types.
+                               Assert.IsNotNull (ex.Message, "#A2");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (string[]).FullName) != -1, "#A3");
+                               Assert.IsTrue (ex.Message.IndexOf ("SoapAttribute") != -1, "#A4");
+                               Assert.IsNull (ex.InnerException, "#A5");
+                       }
+               }
+
+               [Test]
+               public void TypeMapping_Field ()
+               {
+                       XmlTypeMapping tm = Map (typeof (Field));
+                       Assert.AreEqual ("Field", tm.ElementName, "#1");
+                       Assert.AreEqual (string.Empty, tm.Namespace, "#2");
+                       Assert.AreEqual ("Field", tm.TypeName, "#3");
+                       Assert.AreEqual ("MonoTests.System.Xml.TestClasses.Field", tm.TypeFullName, "#4");
+               }
+
+               [Test]
+               public void TypeMapping_Field_DefaultNamespace ()
+               {
+                       XmlTypeMapping tm = Map (typeof (Field), SomeNamespace);
+                       Assert.AreEqual ("Field", tm.ElementName, "#1");
+                       Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
+                       Assert.AreEqual ("Field", tm.TypeName, "#3");
+                       Assert.AreEqual ("MonoTests.System.Xml.TestClasses.Field", tm.TypeFullName, "#4");
+               }
+
+               [Test]
+               public void TypeMapping_Field_Encoded ()
+               {
+                       XmlTypeMapping tm = Map (typeof (Field_Encoded));
+                       Assert.AreEqual ("field", tm.ElementName, "#1");
+                       Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
+                       Assert.AreEqual ("Field_Encoded", tm.TypeName, "#3");
+                       Assert.AreEqual ("MonoTests.System.Xml.TestClasses.Field_Encoded", tm.TypeFullName, "#4");
+               }
+
+               [Test]
+               public void TypeMapping_Field_Encoded_DefaultNamespace ()
+               {
+                       XmlTypeMapping tm = Map (typeof (Field_Encoded), AnotherNamespace);
+                       Assert.AreEqual ("field", tm.ElementName, "#1");
+                       Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
+                       Assert.AreEqual ("Field_Encoded", tm.TypeName, "#3");
+                       Assert.AreEqual ("MonoTests.System.Xml.TestClasses.Field_Encoded", tm.TypeFullName, "#4");
+               }
+
+               [Test]
+               public void TypeMapping_FlagEnum ()
+               {
+                       XmlTypeMapping tm = Map (typeof (FlagEnum));
+                       Assert.AreEqual ("FlagEnum", tm.ElementName, "#1");
+                       Assert.AreEqual (string.Empty, tm.Namespace, "#2");
+                       Assert.AreEqual ("FlagEnum", tm.TypeName, "#3");
+                       Assert.AreEqual ("MonoTests.System.Xml.TestClasses.FlagEnum", tm.TypeFullName, "#4");
+               }
+
+               [Test]
+               public void TypeMapping_FlagEnum_DefaultNamespace ()
+               {
+                       XmlTypeMapping tm = Map (typeof (FlagEnum), SomeNamespace);
+                       Assert.AreEqual ("FlagEnum", tm.ElementName, "#1");
+                       Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
+                       Assert.AreEqual ("FlagEnum", tm.TypeName, "#3");
+                       Assert.AreEqual ("MonoTests.System.Xml.TestClasses.FlagEnum", tm.TypeFullName, "#4");
+               }
+
+               [Test]
+               [ExpectedException (typeof (NotSupportedException))]
+               public void TypeMapping_IDictionary ()
+               {
+                       // The type MonoTests.System.Xml.TestClasses.DictionaryWithIndexer 
+                       // is not supported because it implements IDictionary.
+                       Map (typeof (DictionaryWithIndexer));
+               }
+
                [Test]
                [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                public void TypeMapping_IEnumerable_SimpleClass ()
@@ -1112,7 +1189,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                [ExpectedException (typeof (InvalidOperationException))]
                public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod ()
                {
@@ -1120,7 +1196,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                [ExpectedException (typeof (InvalidOperationException))]
                public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod_Array ()
                {
@@ -1160,11 +1235,9 @@ namespace MonoTests.System.XmlSerialization
 
                [Test]
                [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
-/*
 #if ONLY_1_1
                [Category ("NotDotNet")] // results in NullReferenceException in .NET 1.1 (SP1)
 #endif
- */
                public void TypeMapping_IEnumerable_SimpleClass_PrivateGetEnumerator ()
                {
                        XmlTypeMapping tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator));
@@ -1195,7 +1268,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                [ExpectedException (typeof (InvalidOperationException))]
                public void TypeMapping_ICollection_Object_NoMatchingAddMethod ()
                {
@@ -1203,7 +1275,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                [ExpectedException (typeof (InvalidOperationException))]
                public void TypeMapping_ICollection_Object_NoMatchingAddMethod_Array ()
                {
@@ -1211,7 +1282,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                [ExpectedException (typeof (InvalidOperationException))]
                public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod ()
                {
@@ -1219,7 +1289,6 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
-               [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
                [ExpectedException (typeof (InvalidOperationException))]
                public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod_Array ()
                {
@@ -1316,6 +1385,65 @@ namespace MonoTests.System.XmlSerialization
                        Map (typeof (SimpleClassCollectionNoIntIndexer[]));
                }
 
+               [Test]
+               public void TypeMapping_InvalidDefault ()
+               {
+                       SoapAttributes attrs = new SoapAttributes (typeof (Field_Encoded).GetMember ("Modifiers")[0]);
+                       attrs.SoapDefaultValue = 2; // not a defined enum value
+                       SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
+                       overrides.Add (typeof (Field_Encoded), "Modifiers", attrs);
+
+                       try {
+                               Map (typeof (Field_Encoded), overrides);
+                               Assert.Fail ("#A1");
+                       } catch (InvalidOperationException ex) {
+                               // Enum System.Int32 cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
+                               Assert.IsNotNull (ex.Message, "#A2");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (int).FullName) != -1, "#A3");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#A4");
+                               Assert.IsNull (ex.InnerException, "#A5");
+                       }
+
+                       attrs.SoapDefaultValue = "2"; // not of the same type as the underlying enum type (System.Int32)
+
+                       try {
+                               Map (typeof (Field_Encoded), overrides);
+                               Assert.Fail ("#B1");
+                       } catch (InvalidOperationException ex) {
+                               // Enum System.String cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
+                               Assert.IsNotNull (ex.Message, "#B2");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (string).FullName) != -1, "#B3");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#B4");
+                               Assert.IsNull (ex.InnerException, "#B5");
+                       }
+
+                       attrs.SoapDefaultValue = EnumDefaultValueNF.e2; // other enum type
+
+                       try {
+                               Map (typeof (Field_Encoded), overrides);
+                               Assert.Fail ("#C1");
+                       } catch (InvalidOperationException ex) {
+                               // Enum MonoTests.System.Xml.TestClasses.EnumDefaultValueNF cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
+                               Assert.IsNotNull (ex.Message, "#C2");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (EnumDefaultValueNF).FullName) != -1, "#C3");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#C4");
+                               Assert.IsNull (ex.InnerException, "#C5");
+                       }
+
+                       attrs.SoapDefaultValue = (MapModifiers) 20; // non-existing enum value
+
+                       try {
+                               Map (typeof (Field_Encoded), overrides);
+                               Assert.Fail ("#D1");
+                       } catch (InvalidOperationException ex) {
+                               // Value '20' cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
+                               Assert.IsNotNull (ex.Message, "#D2");
+                               Assert.IsTrue (ex.Message.IndexOf ("'20'") != -1, "#D3");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#D4");
+                               Assert.IsNull (ex.InnerException, "#D5");
+                       }
+               }
+
                [Test]
                [Category ("NotWorking")]
                public void TestImportMembersMapping()