New test.
[mono.git] / mcs / class / System.XML / Test / System.Xml.Serialization / XmlReflectionImporterTests.cs
1 //
2 // System.Xml.Serialization.XmlReflectionImporterTests
3 //
4 // Author:
5 //   Erik LeBel (eriklebel@yahoo.ca)
6 //
7 // (C) 2003 Erik LeBel
8 // 
9 // FIXME test some of these with Xml Attributes attached to some members: 
10 // do the names get carried over to Element for XmlAttributeAttribute and XmlElementAttribute?
11 // 
12
13 using System;
14 using System.Collections;
15 using System.Xml;
16 using System.Xml.Schema;
17 using System.Xml.Serialization;
18
19 using NUnit.Framework;
20
21 using MonoTests.System.Xml.TestClasses;
22
23 namespace MonoTests.System.XmlSerialization
24 {
25         // debugging class
26         internal class Debug
27         {
28                 public static void Print(XmlTypeMapping tm)
29                 {
30                         Console.WriteLine("/XmlTypeMapping:");
31                         Console.WriteLine("ElementName: {0} ", tm.ElementName);
32                         Console.WriteLine("Namespace: {0} ", tm.Namespace);
33                         Console.WriteLine("TypeName: {0} ", tm.TypeName);
34                         Console.WriteLine("FullTypeName: {0} ", tm.TypeFullName);
35                 }
36
37                 public static void Print(XmlMemberMapping mm)
38                 {
39                         Console.WriteLine("/XmlMemberMapping:");
40                         Console.WriteLine("Any: {0} ", mm.Any);
41                         Console.WriteLine("ElementName: {0} ", mm.ElementName);
42                         Console.WriteLine("MemberName: {0} ", mm.MemberName);
43                         Console.WriteLine("Namespace: {0} ", mm.Namespace);
44                         Console.WriteLine("TypeFullName: {0} ", mm.TypeFullName);
45                         Console.WriteLine("TypeName: {0} ", mm.TypeName);
46                         Console.WriteLine("TypeNamespace: {0} ", mm.TypeNamespace);
47                 }
48         }
49
50         [TestFixture]
51         public class XmlReflectionImporterTests
52         {
53                 private const string SomeNamespace = "some:urn";
54                 private const string AnotherNamespace = "another:urn";
55                 private const string XmlSchemaNamespace = "http://www.w3.org/2001/XMLSchema";
56
57                 // these Map methods re-create the XmlReflectionImporter at every call.
58
59                 private XmlTypeMapping Map(Type t)
60                 {
61                         XmlReflectionImporter ri = new XmlReflectionImporter();
62                         XmlTypeMapping tm = ri.ImportTypeMapping(t);
63                         //Debug.Print(tm);
64
65                         return tm;
66                 }
67
68                 private XmlTypeMapping Map(Type t, XmlRootAttribute root)
69                 {
70                         XmlReflectionImporter ri = new XmlReflectionImporter();
71                         XmlTypeMapping tm = ri.ImportTypeMapping(t, root);
72
73                         return tm;
74                 }
75
76                 private XmlTypeMapping Map(Type t, string ns)
77                 {
78                         XmlReflectionImporter ri = new XmlReflectionImporter(ns);
79                         XmlTypeMapping tm = ri.ImportTypeMapping(t);
80                         //Debug.Print(tm);
81
82                         return tm;
83                 }
84
85                 private XmlTypeMapping Map (Type t, string ns, XmlRootAttribute root)
86                 {
87                         XmlReflectionImporter ri = new XmlReflectionImporter (ns);
88                         XmlTypeMapping tm = ri.ImportTypeMapping (t, root);
89
90                         return tm;
91                 }
92
93                 private XmlTypeMapping Map(Type t, XmlAttributeOverrides overrides)
94                 {
95                         XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
96                         XmlTypeMapping tm = ri.ImportTypeMapping(t);
97                         //Debug.Print(tm);
98
99                         return tm;
100                 }
101
102                 private XmlMembersMapping MembersMap(Type t, XmlAttributeOverrides overrides, 
103                         XmlReflectionMember [] members, bool inContainer)
104                 {
105                         XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
106                         XmlMembersMapping mm = ri.ImportMembersMapping(null, null, members, inContainer);
107                         
108                         return mm;
109                 }
110                 
111                 [Test]
112                 public void TestIntTypeMapping()
113                 {
114                         XmlTypeMapping tm = Map(typeof(int));
115                         Assert.AreEqual ("int", tm.ElementName, "#1");
116                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
117                         Assert.AreEqual ("Int32", tm.TypeName, "#3");
118                         Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
119                 }
120
121                 [Test]
122 #if NET_2_0
123                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
124 #endif
125                 public void TestIntTypeMapping_Array ()
126                 {
127                         XmlTypeMapping tm = Map(typeof(int[]));
128                         Assert.AreEqual ("ArrayOfInt", tm.ElementName, "#A1");
129                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
130 #if NET_2_0
131                         Assert.AreEqual ("ArrayOfInt32", tm.TypeName, "#A3");
132 #else
133                         Assert.AreEqual ("Int32[]", tm.TypeName, "#A3");
134 #endif
135                         Assert.AreEqual ("System.Int32[]", tm.TypeFullName, "#A4");
136
137                         tm = Map (typeof (int[][]));
138                         Assert.AreEqual ("ArrayOfArrayOfInt", tm.ElementName, "#B1");
139                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
140 #if NET_2_0
141                         Assert.AreEqual ("ArrayOfArrayOfInt32", tm.TypeName, "#B3");
142 #else
143                         Assert.AreEqual ("Int32[][]", tm.TypeName, "#B3");
144 #endif
145                         Assert.AreEqual ("System.Int32[][]", tm.TypeFullName, "#B4");
146
147                         tm = Map (typeof (int[][][]));
148                         Assert.AreEqual ("ArrayOfArrayOfArrayOfInt", tm.ElementName, "#C1");
149                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
150 #if NET_2_0
151                         Assert.AreEqual ("ArrayOfArrayOfArrayOfInt32", tm.TypeName, "#C3");
152 #else
153                         Assert.AreEqual ("Int32[][][]", tm.TypeName, "#C3");
154 #endif
155                         Assert.AreEqual ("System.Int32[][][]", tm.TypeFullName, "#C4");
156                 }
157
158                 [Test]
159                 public void TestStringTypeMapping()
160                 {
161                         XmlTypeMapping tm = Map(typeof(string));
162                         Assert.AreEqual ("string", tm.ElementName, "#1");
163                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
164                         Assert.AreEqual ("String", tm.TypeName, "#3");
165                         Assert.AreEqual ("System.String", tm.TypeFullName, "#4");
166                 }
167
168                 [Test]
169 #if NET_2_0
170                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
171 #endif
172                 public void TestStringTypeMapping_Array ()
173                 {
174                         XmlTypeMapping tm = Map (typeof (string[]));
175                         Assert.AreEqual ("ArrayOfString", tm.ElementName, "#A1");
176                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
177 #if NET_2_0
178                         Assert.AreEqual ("ArrayOfString", tm.TypeName, "#A3");
179 #else
180                         Assert.AreEqual ("String[]", tm.TypeName, "#A3");
181 #endif
182                         Assert.AreEqual ("System.String[]", tm.TypeFullName, "#A4");
183
184                         tm = Map (typeof (string[][]));
185                         Assert.AreEqual ("ArrayOfArrayOfString", tm.ElementName, "#B1");
186                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
187 #if NET_2_0
188                         Assert.AreEqual ("ArrayOfArrayOfString", tm.TypeName, "#B3");
189 #else
190                         Assert.AreEqual ("String[][]", tm.TypeName, "#B3");
191 #endif
192                         Assert.AreEqual ("System.String[][]", tm.TypeFullName, "#B4");
193
194                         tm = Map (typeof (string[][][]));
195                         Assert.AreEqual ("ArrayOfArrayOfArrayOfString", tm.ElementName, "#C1");
196                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
197 #if NET_2_0
198                         Assert.AreEqual ("ArrayOfArrayOfArrayOfString", tm.TypeName, "#C3");
199 #else
200                         Assert.AreEqual ("String[][][]", tm.TypeName, "#C3");
201 #endif
202                         Assert.AreEqual ("System.String[][][]", tm.TypeFullName, "#C4");
203                 }
204
205                 [Test]
206                 public void TestObjectTypeMapping()
207                 {
208                         XmlTypeMapping tm = Map(typeof(object));
209                         Assert.AreEqual ("anyType", tm.ElementName, "#1");
210                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
211                         Assert.AreEqual ("Object", tm.TypeName, "#3");
212                         Assert.AreEqual ("System.Object", tm.TypeFullName, "#4");
213                 }
214
215                 [Test]
216 #if NET_2_0
217                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
218 #endif
219                 public void TestObjectTypeMapping_Array ()
220                 {
221                         XmlTypeMapping tm = Map (typeof (object[]));
222                         Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#A1");
223                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
224 #if NET_2_0
225                         Assert.AreEqual ("ArrayOfObject", tm.TypeName, "#A3");
226 #else
227                         Assert.AreEqual ("Object[]", tm.TypeName, "#A3");
228 #endif
229                         Assert.AreEqual ("System.Object[]", tm.TypeFullName, "#A4");
230
231                         tm = Map (typeof (object[][]));
232                         Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#B1");
233                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
234 #if NET_2_0
235                         Assert.AreEqual ("ArrayOfArrayOfObject", tm.TypeName, "#B3");
236 #else
237                         Assert.AreEqual ("Object[][]", tm.TypeName, "#B3");
238 #endif
239                         Assert.AreEqual ("System.Object[][]", tm.TypeFullName, "#B4");
240
241                         tm = Map (typeof (object[][][]));
242                         Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
243                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
244 #if NET_2_0
245                         Assert.AreEqual ("ArrayOfArrayOfArrayOfObject", tm.TypeName, "#C3");
246 #else
247                         Assert.AreEqual ("Object[][][]", tm.TypeName, "#C3");
248 #endif
249                         Assert.AreEqual ("System.Object[][][]", tm.TypeFullName, "#C4");
250                 }
251
252                 [Test]
253                 public void TestByteTypeMapping()
254                 {
255                         XmlTypeMapping tm = Map(typeof(byte));
256                         Assert.AreEqual ("unsignedByte", tm.ElementName, "#1");
257                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
258                         Assert.AreEqual ("Byte", tm.TypeName, "#3");
259                         Assert.AreEqual ("System.Byte", tm.TypeFullName, "#4");
260                 }
261
262                 [Test]
263 #if NET_2_0
264                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
265 #endif
266                 public void TestByteTypeMapping_Array ()
267                 {
268                         XmlTypeMapping tm = Map(typeof(byte[]));
269                         Assert.AreEqual ("base64Binary", tm.ElementName, "#A1");
270                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
271                         Assert.AreEqual ("Byte[]", tm.TypeName, "#A3");
272                         Assert.AreEqual ("System.Byte[]", tm.TypeFullName, "#A4");
273
274                         tm = Map (typeof (byte[][]));
275                         Assert.AreEqual ("ArrayOfBase64Binary", tm.ElementName, "#B1");
276                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
277 #if NET_2_0
278                         Assert.AreEqual ("ArrayOfArrayOfByte", tm.TypeName, "#B3");
279 #else
280                         Assert.AreEqual ("Byte[][]", tm.TypeName, "#B3");
281 #endif
282                         Assert.AreEqual ("System.Byte[][]", tm.TypeFullName, "#B4");
283
284                         tm = Map (typeof (byte[][][]));
285                         Assert.AreEqual ("ArrayOfArrayOfBase64Binary", tm.ElementName, "#C1");
286                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
287 #if NET_2_0
288                         Assert.AreEqual ("ArrayOfArrayOfArrayOfByte", tm.TypeName, "#C3");
289 #else
290                         Assert.AreEqual ("Byte[][][]", tm.TypeName, "#C3");
291 #endif
292                         Assert.AreEqual ("System.Byte[][][]", tm.TypeFullName, "#C4");
293                 }
294
295                 [Test]
296                 public void TestBoolTypeMapping()
297                 {
298                         XmlTypeMapping tm = Map(typeof(bool));
299                         Assert.AreEqual ("boolean", tm.ElementName, "#1");
300                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
301                         Assert.AreEqual ("Boolean", tm.TypeName, "#3");
302                         Assert.AreEqual ("System.Boolean", tm.TypeFullName, "#4");
303                 }
304
305                 [Test]
306                 public void TestShortTypeMapping()
307                 {
308                         XmlTypeMapping tm = Map(typeof(short));
309                         Assert.AreEqual ("short", tm.ElementName, "#1");
310                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
311                         Assert.AreEqual ("Int16", tm.TypeName, "#3");
312                         Assert.AreEqual ("System.Int16", tm.TypeFullName, "#4");
313                 }
314
315                 [Test]
316                 public void TestUnsignedShortTypeMapping()
317                 {
318                         XmlTypeMapping tm = Map(typeof(ushort));
319                         Assert.AreEqual ("unsignedShort", tm.ElementName, "#1");
320                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
321                         Assert.AreEqual ("UInt16", tm.TypeName, "#3");
322                         Assert.AreEqual ("System.UInt16", tm.TypeFullName, "#4");
323                 }
324                 
325                 [Test]
326                 public void TestUIntTypeMapping()
327                 {
328                         XmlTypeMapping tm = Map(typeof(uint));
329                         Assert.AreEqual ("unsignedInt", tm.ElementName, "#1");
330                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
331                         Assert.AreEqual ("UInt32", tm.TypeName, "#3");
332                         Assert.AreEqual ("System.UInt32", tm.TypeFullName, "#4");
333                 }
334                 
335                 [Test]
336                 public void TestLongTypeMapping()
337                 {
338                         XmlTypeMapping tm = Map(typeof(long));
339                         Assert.AreEqual ("long", tm.ElementName, "#1");
340                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
341                         Assert.AreEqual ("Int64", tm.TypeName, "#3");
342                         Assert.AreEqual ("System.Int64", tm.TypeFullName, "#4");
343                 }
344                 
345                 [Test]
346                 public void TestULongTypeMapping()
347                 {
348                         XmlTypeMapping tm = Map(typeof(ulong));
349                         Assert.AreEqual ("unsignedLong", tm.ElementName, "#1");
350                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
351                         Assert.AreEqual ("UInt64", tm.TypeName, "#3");
352                         Assert.AreEqual ("System.UInt64", tm.TypeFullName, "#4");
353                 }
354                 
355                 [Test]
356                 public void TestFloatTypeMapping()
357                 {
358                         XmlTypeMapping tm = Map(typeof(float));
359                         Assert.AreEqual ("float", tm.ElementName, "#1");
360                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
361                         Assert.AreEqual ("Single", tm.TypeName, "#3");
362                         Assert.AreEqual ("System.Single", tm.TypeFullName, "#4");
363                 }
364                 
365                 [Test]
366                 public void TestDoubleTypeMapping()
367                 {
368                         XmlTypeMapping tm = Map(typeof(double));
369                         Assert.AreEqual ("double", tm.ElementName, "#1");
370                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
371                         Assert.AreEqual ("Double", tm.TypeName, "#3");
372                         Assert.AreEqual ("System.Double", tm.TypeFullName, "#4");
373                 }
374                 
375                 [Test]
376                 public void TestDateTimeTypeMapping()
377                 {
378                         XmlTypeMapping tm = Map(typeof(DateTime));
379                         Assert.AreEqual ("dateTime", tm.ElementName, "#1");
380                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
381                         Assert.AreEqual ("DateTime", tm.TypeName, "#3");
382                         Assert.AreEqual ("System.DateTime", tm.TypeFullName, "#4");
383                 }
384
385                 [Test]
386 #if NET_2_0
387                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
388 #endif
389                 public void TestDateTimeTypeMapping_Array ()
390                 {
391                         XmlTypeMapping tm = Map (typeof (DateTime[]));
392                         Assert.AreEqual ("ArrayOfDateTime", tm.ElementName, "#A1");
393                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
394 #if NET_2_0
395                         Assert.AreEqual ("ArrayOfDateTime", tm.TypeName, "#A3");
396 #else
397                         Assert.AreEqual ("DateTime[]", tm.TypeName, "#A3");
398 #endif
399                         Assert.AreEqual ("System.DateTime[]", tm.TypeFullName, "#A4");
400
401                         tm = Map (typeof (DateTime[][]));
402                         Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.ElementName, "#B1");
403                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
404 #if NET_2_0
405                         Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.TypeName, "#B3");
406 #else
407                         Assert.AreEqual ("DateTime[][]", tm.TypeName, "#B3");
408 #endif
409                         Assert.AreEqual ("System.DateTime[][]", tm.TypeFullName, "#B4");
410
411                         tm = Map (typeof (DateTime[][][]));
412                         Assert.AreEqual ("ArrayOfArrayOfArrayOfDateTime", tm.ElementName, "#C1");
413                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
414 #if NET_2_0
415                         Assert.AreEqual ("ArrayOfArrayOfArrayOfDateTime", tm.TypeName, "#C3");
416 #else
417                         Assert.AreEqual ("DateTime[][][]", tm.TypeName, "#C3");
418 #endif
419                         Assert.AreEqual ("System.DateTime[][][]", tm.TypeFullName, "#C4");
420                 }
421
422                 [Test]
423                 public void TestGuidTypeMapping()
424                 {
425                         XmlTypeMapping tm = Map(typeof(Guid));
426                         Assert.AreEqual ("guid", tm.ElementName, "#1");
427                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
428                         Assert.AreEqual ("Guid", tm.TypeName, "#3");
429                         Assert.AreEqual ("System.Guid", tm.TypeFullName, "#4");
430                 }
431
432                 [Test]
433 #if NET_2_0
434                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
435 #endif
436                 public void TestGuidTypeMapping_Array ()
437                 {
438                         XmlTypeMapping tm = Map (typeof (Guid[]));
439                         Assert.AreEqual ("ArrayOfGuid", tm.ElementName, "#A1");
440                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
441 #if NET_2_0
442                         Assert.AreEqual ("ArrayOfGuid", tm.TypeName, "#A3");
443 #else
444                         Assert.AreEqual ("Guid[]", tm.TypeName, "#A3");
445 #endif
446                         Assert.AreEqual ("System.Guid[]", tm.TypeFullName, "#A4");
447
448                         tm = Map (typeof (Guid[][]));
449                         Assert.AreEqual ("ArrayOfArrayOfGuid", tm.ElementName, "#B1");
450                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
451 #if NET_2_0
452                         Assert.AreEqual ("ArrayOfArrayOfGuid", tm.TypeName, "#B3");
453 #else
454                         Assert.AreEqual ("Guid[][]", tm.TypeName, "#B3");
455 #endif
456                         Assert.AreEqual ("System.Guid[][]", tm.TypeFullName, "#B4");
457
458                         tm = Map (typeof (Guid[][][]));
459                         Assert.AreEqual ("ArrayOfArrayOfArrayOfGuid", tm.ElementName, "#C1");
460                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
461 #if NET_2_0
462                         Assert.AreEqual ("ArrayOfArrayOfArrayOfGuid", tm.TypeName, "#C3");
463 #else
464                         Assert.AreEqual ("Guid[][][]", tm.TypeName, "#C3");
465 #endif
466                         Assert.AreEqual ("System.Guid[][][]", tm.TypeFullName, "#C4");
467                 }
468
469                 [Test]
470                 public void TestDecimalTypeMapping()
471                 {
472                         XmlTypeMapping tm = Map(typeof(decimal));
473                         Assert.AreEqual ("decimal", tm.ElementName, "#1");
474                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
475                         Assert.AreEqual ("Decimal", tm.TypeName, "#3");
476                         Assert.AreEqual ("System.Decimal", tm.TypeFullName, "#4");
477                 }
478                 
479                 [Test]
480                 public void TestXmlQualifiedNameTypeMapping()
481                 {
482                         XmlTypeMapping tm = Map(typeof(XmlQualifiedName));
483                         Assert.AreEqual ("QName", tm.ElementName, "#1");
484                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
485                         Assert.AreEqual ("XmlQualifiedName", tm.TypeName, "#3");
486                         Assert.AreEqual ("System.Xml.XmlQualifiedName", tm.TypeFullName, "#4");
487                 }
488                 
489                 [Test]
490                 public void TestSByteTypeMapping()
491                 {
492                         XmlTypeMapping tm = Map(typeof(sbyte));
493                         Assert.AreEqual ("byte", tm.ElementName, "#1");
494                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
495                         Assert.AreEqual ("SByte", tm.TypeName, "#3");
496                         Assert.AreEqual ("System.SByte", tm.TypeFullName, "#4");
497                 }
498                 
499
500                 [Test]
501                 public void TestCharTypeMapping()
502                 {
503                         XmlTypeMapping tm = Map(typeof(char));
504                         Assert.AreEqual ("char", tm.ElementName, "#1");
505                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
506                         Assert.AreEqual ("Char", tm.TypeName, "#3");
507                         Assert.AreEqual ("System.Char", tm.TypeFullName, "#4");
508                 }
509
510                 [Test]
511 #if NET_2_0
512                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
513 #endif
514                 public void TestCharTypeMapping_Array ()
515                 {
516                         XmlTypeMapping tm = Map (typeof (char[]));
517                         Assert.AreEqual ("ArrayOfChar", tm.ElementName, "#A1");
518                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
519 #if NET_2_0
520                         Assert.AreEqual ("ArrayOfChar", tm.TypeName, "#A3");
521 #else
522                         Assert.AreEqual ("Char[]", tm.TypeName, "#A3");
523 #endif
524                         Assert.AreEqual ("System.Char[]", tm.TypeFullName, "#A4");
525
526                         tm = Map (typeof (char[][]));
527                         Assert.AreEqual ("ArrayOfArrayOfChar", tm.ElementName, "#B1");
528                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
529 #if NET_2_0
530                         Assert.AreEqual ("ArrayOfArrayOfChar", tm.TypeName, "#B3");
531 #else
532                         Assert.AreEqual ("Char[][]", tm.TypeName, "#B3");
533 #endif
534                         Assert.AreEqual ("System.Char[][]", tm.TypeFullName, "#B4");
535
536                         tm = Map (typeof (char[][][]));
537                         Assert.AreEqual ("ArrayOfArrayOfArrayOfChar", tm.ElementName, "#C1");
538                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
539 #if NET_2_0
540                         Assert.AreEqual ("ArrayOfArrayOfArrayOfChar", tm.TypeName, "#C3");
541 #else
542                         Assert.AreEqual ("Char[][][]", tm.TypeName, "#C3");
543 #endif
544                         Assert.AreEqual ("System.Char[][][]", tm.TypeFullName, "#C4");
545                 }
546
547                 [Test]
548                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
549                 public void TestXmlNodeTypeMapping ()
550                 {
551                         Type type = typeof (XmlNode);
552
553                         XmlTypeMapping tm = Map (type);
554                         Assert.AreEqual (string.Empty, tm.ElementName, "#A1");
555                         Assert.IsNull (tm.Namespace, "#A2");
556                         Assert.AreEqual ("XmlNode", tm.TypeName, "#A3");
557                         Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#A4");
558
559                         tm = Map (type, AnotherNamespace);
560                         Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
561                         Assert.IsNull (tm.Namespace, "#B2");
562                         Assert.AreEqual ("XmlNode", tm.TypeName, "#B3");
563                         Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#B4");
564
565                         XmlRootAttribute root = new XmlRootAttribute ("somename");
566                         root.Namespace = SomeNamespace;
567                         tm = Map (type, root);
568                         Assert.AreEqual ("somename", tm.ElementName, "#C1");
569                         Assert.IsNull (tm.Namespace, "#C2");
570                         Assert.AreEqual ("XmlNode", tm.TypeName, "#C3");
571                         Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#C4");
572
573                         tm = Map (type, AnotherNamespace, root);
574                         Assert.AreEqual ("somename", tm.ElementName, "#D1");
575                         Assert.IsNull (tm.Namespace, "#D2");
576                         Assert.AreEqual ("XmlNode", tm.TypeName, "#D3");
577                         Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#D4");
578
579                         root.Namespace = null;
580                         tm = Map (type, root);
581                         Assert.AreEqual ("somename", tm.ElementName, "#E1");
582                         Assert.IsNull (tm.Namespace, "#E2");
583                         Assert.AreEqual ("XmlNode", tm.TypeName, "#E3");
584                         Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#E4");
585
586                         tm = Map (type, AnotherNamespace, root);
587                         Assert.AreEqual ("somename", tm.ElementName, "#F1");
588                         Assert.IsNull (tm.Namespace, "#F2");
589                         Assert.AreEqual ("XmlNode", tm.TypeName, "#F3");
590                         Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#F4");
591                 }
592
593                 [Test]
594                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
595                 public void TestXmlElementTypeMapping ()
596                 {
597                         Type type = typeof (XmlElement);
598
599                         XmlTypeMapping tm = Map (type);
600                         Assert.AreEqual (string.Empty, tm.ElementName, "#1");
601                         Assert.IsNull (tm.Namespace, "#2");
602                         Assert.AreEqual ("XmlElement", tm.TypeName, "#3");
603                         Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#4");
604
605                         tm = Map (type, AnotherNamespace);
606                         Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
607                         Assert.IsNull (tm.Namespace, "#B2");
608                         Assert.AreEqual ("XmlElement", tm.TypeName, "#B3");
609                         Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#B4");
610
611                         XmlRootAttribute root = new XmlRootAttribute ("somename");
612                         root.Namespace = SomeNamespace;
613                         tm = Map (type, root);
614                         Assert.AreEqual ("somename", tm.ElementName, "#C1");
615                         Assert.IsNull (tm.Namespace, "#C2");
616                         Assert.AreEqual ("XmlElement", tm.TypeName, "#C3");
617                         Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#C4");
618
619                         tm = Map (type, AnotherNamespace, root);
620                         Assert.AreEqual ("somename", tm.ElementName, "#D1");
621                         Assert.IsNull (tm.Namespace, "#D2");
622                         Assert.AreEqual ("XmlElement", tm.TypeName, "#D3");
623                         Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#D4");
624
625                         root.Namespace = null;
626                         tm = Map (type, root);
627                         Assert.AreEqual ("somename", tm.ElementName, "#E1");
628                         Assert.IsNull (tm.Namespace, "#E2");
629                         Assert.AreEqual ("XmlElement", tm.TypeName, "#E3");
630                         Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#E4");
631
632                         tm = Map (type, AnotherNamespace, root);
633                         Assert.AreEqual ("somename", tm.ElementName, "#F1");
634                         Assert.IsNull (tm.Namespace, "#F2");
635                         Assert.AreEqual ("XmlElement", tm.TypeName, "#F3");
636                         Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#F4");
637                 }
638
639                 [Test]
640                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
641                 public void TestXmlNotationTypeMapping ()
642                 {
643                         Type type = typeof (XmlNotation);
644
645                         XmlTypeMapping tm = Map (type);
646                         Assert.AreEqual (string.Empty, tm.ElementName, "#1");
647                         Assert.IsNull (tm.Namespace, "#2");
648                         Assert.AreEqual ("XmlNotation", tm.TypeName, "#3");
649                         Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#4");
650
651                         tm = Map (type, AnotherNamespace);
652                         Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
653                         Assert.IsNull (tm.Namespace, "#B2");
654                         Assert.AreEqual ("XmlNotation", tm.TypeName, "#B3");
655                         Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#B4");
656
657                         XmlRootAttribute root = new XmlRootAttribute ("somename");
658                         root.Namespace = SomeNamespace;
659                         tm = Map (type, root);
660                         Assert.AreEqual ("somename", tm.ElementName, "#C1");
661                         Assert.IsNull (tm.Namespace, "#C2");
662                         Assert.AreEqual ("XmlNotation", tm.TypeName, "#C3");
663                         Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#C4");
664
665                         tm = Map (type, AnotherNamespace, root);
666                         Assert.AreEqual ("somename", tm.ElementName, "#D1");
667                         Assert.IsNull (tm.Namespace, "#D2");
668                         Assert.AreEqual ("XmlNotation", tm.TypeName, "#D3");
669                         Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#D4");
670
671                         root.Namespace = null;
672                         tm = Map (type, root);
673                         Assert.AreEqual ("somename", tm.ElementName, "#E1");
674                         Assert.IsNull (tm.Namespace, "#E2");
675                         Assert.AreEqual ("XmlNotation", tm.TypeName, "#E3");
676                         Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#E4");
677
678                         tm = Map (type, AnotherNamespace, root);
679                         Assert.AreEqual ("somename", tm.ElementName, "#F1");
680                         Assert.IsNull (tm.Namespace, "#F2");
681                         Assert.AreEqual ("XmlNotation", tm.TypeName, "#F3");
682                         Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#F4");
683                 }
684
685                 [Test]
686                 public void TestXmlSerializableTypeMapping ()
687                 {
688                         XmlTypeMapping tm = Map (typeof (Employee));
689                         Assert.AreEqual ("Employee", tm.ElementName, "#1");
690                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
691                         Assert.AreEqual ("Employee", tm.TypeName, "#3");
692                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee", tm.TypeFullName, "#4");
693                 }
694
695                 [Test]
696 #if NET_2_0
697                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
698 #endif
699                 public void TestXmlSerializableTypeMapping_Array ()
700                 {
701                         XmlTypeMapping tm = Map (typeof (Employee[]));
702                         Assert.AreEqual ("ArrayOfEmployee", tm.ElementName, "#A1");
703                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
704 #if NET_2_0
705                         Assert.AreEqual ("ArrayOfEmployee", tm.TypeName, "#A3");
706 #else
707                         Assert.AreEqual ("Employee[]", tm.TypeName, "#A3");
708 #endif
709                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[]", tm.TypeFullName, "#A4");
710
711                         tm = Map (typeof (Employee[][]));
712                         Assert.AreEqual ("ArrayOfArrayOfEmployee", tm.ElementName, "#B1");
713                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
714 #if NET_2_0
715                         Assert.AreEqual ("ArrayOfArrayOfEmployee", tm.TypeName, "#B3");
716 #else
717                         Assert.AreEqual ("Employee[][]", tm.TypeName, "#B3");
718 #endif
719                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[][]", tm.TypeFullName, "#B4");
720
721                         tm = Map (typeof (Employee[][][]));
722                         Assert.AreEqual ("ArrayOfArrayOfArrayOfEmployee", tm.ElementName, "#C1");
723                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
724 #if NET_2_0
725                         Assert.AreEqual ("ArrayOfArrayOfArrayOfEmployee", tm.TypeName, "#C3");
726 #else
727                         Assert.AreEqual ("Employee[][][]", tm.TypeName, "#C3");
728 #endif
729                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[][][]", tm.TypeFullName, "#C4");
730                 }
731
732                 [Test]
733                 public void TestClassTypeMapping_NestedStruct ()
734                 {
735                         XmlTypeMapping tm = Map (typeof (NestedStruct));
736                         Assert.AreEqual ("NestedStruct", tm.ElementName, "#1");
737                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
738                         Assert.AreEqual ("NestedStruct", tm.TypeName, "#3");
739                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.NestedStruct", tm.TypeFullName, "#4");
740                 }
741
742                 [Test]
743                 [ExpectedException (typeof (ArgumentNullException))]
744                 public void TestNullTypeMapping()
745                 {
746                         Map(null);
747                 }
748
749                 [Test]
750                 public void TestIntTypeMappingWithDefaultNamespaces()
751                 {
752                         XmlTypeMapping tm = Map(typeof(int), SomeNamespace);
753                         Assert.AreEqual ("int", tm.ElementName, "#1");
754                         Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
755                         Assert.AreEqual ("Int32", tm.TypeName, "#3");
756                         Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
757                 }
758
759                 [Test]
760                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
761                 public void TestStructTypeMapping ()
762                 {
763                         XmlTypeMapping tm = Map (typeof (TimeSpan));
764                         Assert.AreEqual ("TimeSpan", tm.ElementName, "#1");
765                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
766                         Assert.AreEqual ("TimeSpan", tm.TypeName, "#3");
767                         Assert.AreEqual ("System.TimeSpan", tm.TypeFullName, "#4");
768                 }
769
770                 [Test]
771                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
772                 public void TestStructTypeMapping_Array ()
773                 {
774                         XmlTypeMapping tm = Map (typeof (TimeSpan[]));
775                         Assert.AreEqual ("ArrayOfTimeSpan", tm.ElementName, "#A1");
776                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
777 #if NET_2_0
778                         Assert.AreEqual ("ArrayOfTimeSpan", tm.TypeName, "#A3");
779 #else
780                         Assert.AreEqual ("TimeSpan[]", tm.TypeName, "#A3");
781 #endif
782                         Assert.AreEqual ("System.TimeSpan[]", tm.TypeFullName, "#A4");
783
784                         tm = Map (typeof (TimeSpan[][]));
785                         Assert.AreEqual ("ArrayOfArrayOfTimeSpan", tm.ElementName, "#B1");
786                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
787 #if NET_2_0
788                         Assert.AreEqual ("ArrayOfArrayOfTimeSpan", tm.TypeName, "#B3");
789 #else
790                         Assert.AreEqual ("TimeSpan[][]", tm.TypeName, "#B3");
791 #endif
792                         Assert.AreEqual ("System.TimeSpan[][]", tm.TypeFullName, "#B4");
793
794                         tm = Map (typeof (TimeSpan[][][]));
795                         Assert.AreEqual ("ArrayOfArrayOfArrayOfTimeSpan", tm.ElementName, "#C1");
796                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
797 #if NET_2_0
798                         Assert.AreEqual ("ArrayOfArrayOfArrayOfTimeSpan", tm.TypeName, "#C3");
799 #else
800                         Assert.AreEqual ("TimeSpan[][][]", tm.TypeName, "#C3");
801 #endif
802                         Assert.AreEqual ("System.TimeSpan[][][]", tm.TypeFullName, "#C4");
803                 }
804
805                 [Test]
806                 public void TestEnumTypeMapping ()
807                 {
808                         XmlTypeMapping tm = Map (typeof (AttributeTargets));
809                         Assert.AreEqual ("AttributeTargets", tm.ElementName, "#1");
810                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
811                         Assert.AreEqual ("AttributeTargets", tm.TypeName, "#3");
812                         Assert.AreEqual ("System.AttributeTargets", tm.TypeFullName, "#4");
813                 }
814
815                 [Test]
816 #if NET_2_0
817                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
818 #endif
819                 public void TestEnumTypeMapping_Array ()
820                 {
821                         XmlTypeMapping tm = Map (typeof (AttributeTargets[]));
822                         Assert.AreEqual ("ArrayOfAttributeTargets", tm.ElementName, "#A1");
823                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
824 #if NET_2_0
825                         Assert.AreEqual ("ArrayOfAttributeTargets", tm.TypeName, "#A3");
826 #else
827                         Assert.AreEqual ("AttributeTargets[]", tm.TypeName, "#A3");
828 #endif
829                         Assert.AreEqual ("System.AttributeTargets[]", tm.TypeFullName, "#A4");
830
831                         tm = Map (typeof (AttributeTargets[][]));
832                         Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.ElementName, "#B1");
833                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
834 #if NET_2_0
835                         Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.TypeName, "#B3");
836 #else
837                         Assert.AreEqual ("AttributeTargets[][]", tm.TypeName, "#B3");
838 #endif
839                         Assert.AreEqual ("System.AttributeTargets[][]", tm.TypeFullName, "#B4");
840
841                         tm = Map (typeof (AttributeTargets[][][]));
842                         Assert.AreEqual ("ArrayOfArrayOfArrayOfAttributeTargets", tm.ElementName, "#C1");
843                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
844 #if NET_2_0
845                         Assert.AreEqual ("ArrayOfArrayOfArrayOfAttributeTargets", tm.TypeName, "#C3");
846 #else
847                         Assert.AreEqual ("AttributeTargets[][][]", tm.TypeName, "#C3");
848 #endif
849                         Assert.AreEqual ("System.AttributeTargets[][][]", tm.TypeFullName, "#C4");
850                 }
851
852                 [Test]
853                 public void TestClassTypeMapping()
854                 {
855                         XmlTypeMapping tm = Map (typeof (SimpleClass));
856                         Assert.AreEqual ("SimpleClass", tm.ElementName, "#1");
857                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
858                         Assert.AreEqual ("SimpleClass", tm.TypeName, "#3");
859                         Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass", tm.TypeFullName, "#4");
860                 }
861
862                 [Test]
863 #if NET_2_0
864                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
865 #endif
866                 public void TestClassTypeMapping_Array ()
867                 {
868                         XmlTypeMapping tm = Map (typeof (SimpleClass[]));
869                         Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#A1");
870                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
871 #if NET_2_0
872                         Assert.AreEqual ("ArrayOfSimpleClass", tm.TypeName, "#A3");
873 #else
874                         Assert.AreEqual ("SimpleClass[]", tm.TypeName, "#A3");
875 #endif
876                         Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[]", tm.TypeFullName, "#A4");
877
878                         tm = Map (typeof (SimpleClass[][]));
879                         Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
880                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
881 #if NET_2_0
882                         Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.TypeName, "#B3");
883 #else
884                         Assert.AreEqual ("SimpleClass[][]", tm.TypeName, "#B3");
885 #endif
886                         Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][]", tm.TypeFullName, "#B4");
887
888                         tm = Map (typeof (SimpleClass[][][]));
889                         Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
890                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
891 #if NET_2_0
892                         Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.TypeName, "#C3");
893 #else
894                         Assert.AreEqual ("SimpleClass[][][]", tm.TypeName, "#C3");
895 #endif
896                         Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][][]", tm.TypeFullName, "#C4");
897                 }
898
899                 [Test]
900                 [ExpectedException (typeof (NotSupportedException))]
901                 public void TypeMapping_IDictionary ()
902                 {
903                         // The type MonoTests.System.Xml.TestClasses.DictionaryWithIndexer 
904                         // is not supported because it implements IDictionary.
905                         Map (typeof (DictionaryWithIndexer));
906                 }
907
908                 [Test]
909 #if NET_2_0
910                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
911 #endif
912                 public void TypeMapping_IEnumerable_SimpleClass ()
913                 {
914                         XmlTypeMapping tm = Map (typeof (SimpleClassEnumerable));
915                         Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#1");
916                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
917                         Assert.AreEqual ("SimpleClassEnumerable", tm.TypeName, "#3");
918                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable", tm.TypeFullName, "#4");
919
920                         tm = Map (typeof (SimpleClassEnumerable[]));
921                         Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
922                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
923 #if NET_2_0
924                         Assert.AreEqual ("ArrayOfSimpleClassEnumerable", tm.TypeName, "#A3");
925 #else
926                         Assert.AreEqual ("SimpleClassEnumerable[]", tm.TypeName, "#A3");
927 #endif
928                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[]", tm.TypeFullName, "#A4");
929
930                         tm = Map (typeof (SimpleClassEnumerable[][]));
931                         Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
932                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
933 #if NET_2_0
934                         Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerable", tm.TypeName, "#B3");
935 #else
936                         Assert.AreEqual ("SimpleClassEnumerable[][]", tm.TypeName, "#B3");
937 #endif
938                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[][]", tm.TypeFullName, "#B4");
939
940                         tm = Map (typeof (SimpleClassEnumerable[][][]));
941                         Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
942                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
943 #if NET_2_0
944                         Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerable", tm.TypeName, "#C3");
945 #else
946                         Assert.AreEqual ("SimpleClassEnumerable[][][]", tm.TypeName, "#C3");
947 #endif
948                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[][][]", tm.TypeFullName, "#C4");
949                 }
950
951                 [Test]
952 #if NET_2_0
953                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
954 #endif
955                 public void TypeMapping_IEnumerable_Object ()
956                 {
957                         XmlTypeMapping tm = Map (typeof (ObjectEnumerable));
958                         Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
959                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
960                         Assert.AreEqual ("ObjectEnumerable", tm.TypeName, "#3");
961                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable", tm.TypeFullName, "#4");
962
963                         tm = Map (typeof (ObjectEnumerable[]));
964                         Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
965                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
966 #if NET_2_0
967                         Assert.AreEqual ("ArrayOfObjectEnumerable", tm.TypeName, "#A3");
968 #else
969                         Assert.AreEqual ("ObjectEnumerable[]", tm.TypeName, "#A3");
970 #endif
971                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[]", tm.TypeFullName, "#A4");
972
973                         tm = Map (typeof (ObjectEnumerable[][]));
974                         Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
975                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
976 #if NET_2_0
977                         Assert.AreEqual ("ArrayOfArrayOfObjectEnumerable", tm.TypeName, "#B3");
978 #else
979                         Assert.AreEqual ("ObjectEnumerable[][]", tm.TypeName, "#B3");
980 #endif
981                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[][]", tm.TypeFullName, "#B4");
982
983                         tm = Map (typeof (ObjectEnumerable[][][]));
984                         Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
985                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
986 #if NET_2_0
987                         Assert.AreEqual ("ArrayOfArrayOfArrayOfObjectEnumerable", tm.TypeName, "#C3");
988 #else
989                         Assert.AreEqual ("ObjectEnumerable[][][]", tm.TypeName, "#C3");
990 #endif
991                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[][][]", tm.TypeFullName, "#C4");
992                 }
993
994                 [Test]
995                 [ExpectedException (typeof (InvalidOperationException))]
996                 public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod ()
997                 {
998                         Map (typeof (ObjectEnumerableNoMatchingAddMethod));
999                 }
1000
1001                 [Test]
1002                 [ExpectedException (typeof (InvalidOperationException))]
1003                 public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod_Array ()
1004                 {
1005                         Map (typeof (ObjectEnumerableNoMatchingAddMethod[]));
1006                 }
1007
1008                 [Test]
1009 #if NET_2_0
1010                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1011 #endif
1012                 public void TypeMapping_IEnumerable_SimpleClass_PrivateCurrent ()
1013                 {
1014                         XmlTypeMapping tm = Map (typeof (SimpleClassEnumerablePrivateCurrent));
1015                         Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
1016                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
1017                         Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent", tm.TypeName, "#3");
1018                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent", tm.TypeFullName, "#4");
1019
1020                         tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[]));
1021                         Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
1022                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1023 #if NET_2_0
1024                         Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#A3");
1025 #else
1026                         Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[]", tm.TypeName, "#A3");
1027 #endif
1028                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[]", tm.TypeFullName, "#A4");
1029
1030                         tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[][]));
1031                         Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
1032                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1033 #if NET_2_0
1034                         Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#B3");
1035 #else
1036                         Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[][]", tm.TypeName, "#B3");
1037 #endif
1038                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[][]", tm.TypeFullName, "#B4");
1039
1040                         tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[][][]));
1041                         Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
1042                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1043 #if NET_2_0
1044                         Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#C3");
1045 #else
1046                         Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[][][]", tm.TypeName, "#C3");
1047 #endif
1048                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[][][]", tm.TypeFullName, "#C4");
1049                 }
1050
1051                 [Test]
1052 #if NET_2_0
1053                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1054 #endif
1055 #if ONLY_1_1
1056                 [Category ("NotDotNet")] // results in NullReferenceException in .NET 1.1 (SP1)
1057 #endif
1058                 public void TypeMapping_IEnumerable_SimpleClass_PrivateGetEnumerator ()
1059                 {
1060                         XmlTypeMapping tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator));
1061                         Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
1062                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
1063                         Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#3");
1064                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator", tm.TypeFullName, "#4");
1065
1066                         tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[]));
1067                         Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
1068                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1069 #if NET_2_0
1070                         Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#A3");
1071 #else
1072                         Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[]", tm.TypeName, "#A3");
1073 #endif
1074                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[]", tm.TypeFullName, "#A4");
1075
1076                         tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[][]));
1077                         Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
1078                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1079 #if NET_2_0
1080                         Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#B3");
1081 #else
1082                         Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[][]", tm.TypeName, "#B3");
1083 #endif
1084                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[][]", tm.TypeFullName, "#B4");
1085
1086                         tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[][][]));
1087                         Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
1088                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1089 #if NET_2_0
1090                         Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#C3");
1091 #else
1092                         Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[][][]", tm.TypeName, "#C3");
1093 #endif
1094                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[][][]", tm.TypeFullName, "#C4");
1095                 }
1096
1097                 [Test]
1098                 [ExpectedException (typeof (InvalidOperationException))]
1099                 public void TypeMapping_ICollection_Object_NoMatchingAddMethod ()
1100                 {
1101                         Map (typeof (ObjectCollectionNoMatchingAddMethod));
1102                 }
1103
1104                 [Test]
1105                 [ExpectedException (typeof (InvalidOperationException))]
1106                 public void TypeMapping_ICollection_Object_NoMatchingAddMethod_Array ()
1107                 {
1108                         Map (typeof (ObjectCollectionNoMatchingAddMethod[]));
1109                 }
1110
1111                 [Test]
1112                 [ExpectedException (typeof (InvalidOperationException))]
1113                 public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod ()
1114                 {
1115                         Map (typeof (SimpleClassCollectionNoMatchingAddMethod));
1116                 }
1117
1118                 [Test]
1119                 [ExpectedException (typeof (InvalidOperationException))]
1120                 public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod_Array ()
1121                 {
1122                         Map (typeof (SimpleClassCollectionNoMatchingAddMethod[]));
1123                 }
1124
1125                 [Test]
1126 #if NET_2_0
1127                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1128 #endif
1129                 public void TypeMapping_ICollection_SimpleClass ()
1130                 {
1131                         XmlTypeMapping tm = Map (typeof (SimpleClassCollection));
1132                         Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#1");
1133                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
1134                         Assert.AreEqual ("SimpleClassCollection", tm.TypeName, "#3");
1135                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection", tm.TypeFullName, "#4");
1136
1137                         tm = Map (typeof (SimpleClassCollection[]));
1138                         Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
1139                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1140 #if NET_2_0
1141                         Assert.AreEqual ("ArrayOfSimpleClassCollection", tm.TypeName, "#A3");
1142 #else
1143                         Assert.AreEqual ("SimpleClassCollection[]", tm.TypeName, "#A3");
1144 #endif
1145                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[]", tm.TypeFullName, "#A4");
1146
1147                         tm = Map (typeof (SimpleClassCollection[][]));
1148                         Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
1149                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1150 #if NET_2_0
1151                         Assert.AreEqual ("ArrayOfArrayOfSimpleClassCollection", tm.TypeName, "#B3");
1152 #else
1153                         Assert.AreEqual ("SimpleClassCollection[][]", tm.TypeName, "#B3");
1154 #endif
1155                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[][]", tm.TypeFullName, "#B4");
1156
1157                         tm = Map (typeof (SimpleClassCollection[][][]));
1158                         Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
1159                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1160 #if NET_2_0
1161                         Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassCollection", tm.TypeName, "#C3");
1162 #else
1163                         Assert.AreEqual ("SimpleClassCollection[][][]", tm.TypeName, "#C3");
1164 #endif
1165                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[][][]", tm.TypeFullName, "#C4");
1166                 }
1167
1168                 [Test]
1169 #if NET_2_0
1170                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1171 #endif
1172                 public void TypeMapping_ICollection_Object ()
1173                 {
1174                         XmlTypeMapping tm = Map (typeof (ObjectCollection));
1175                         Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
1176                         Assert.AreEqual (string.Empty, tm.Namespace, "#2");
1177                         Assert.AreEqual ("ObjectCollection", tm.TypeName, "#3");
1178                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection", tm.TypeFullName, "#4");
1179
1180                         tm = Map (typeof (ObjectCollection[]));
1181                         Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
1182                         Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1183 #if NET_2_0
1184                         Assert.AreEqual ("ArrayOfObjectCollection", tm.TypeName, "#A3");
1185 #else
1186                         Assert.AreEqual ("ObjectCollection[]", tm.TypeName, "#A3");
1187 #endif
1188                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[]", tm.TypeFullName, "#A4");
1189
1190                         tm = Map (typeof (ObjectCollection[][]));
1191                         Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
1192                         Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1193 #if NET_2_0
1194                         Assert.AreEqual ("ArrayOfArrayOfObjectCollection", tm.TypeName, "#B3");
1195 #else
1196                         Assert.AreEqual ("ObjectCollection[][]", tm.TypeName, "#B3");
1197 #endif
1198                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[][]", tm.TypeFullName, "#B4");
1199
1200                         tm = Map (typeof (ObjectCollection[][][]));
1201                         Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
1202                         Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1203 #if NET_2_0
1204                         Assert.AreEqual ("ArrayOfArrayOfArrayOfObjectCollection", tm.TypeName, "#C3");
1205 #else
1206                         Assert.AreEqual ("ObjectCollection[][][]", tm.TypeName, "#C3");
1207 #endif
1208                         Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[][][]", tm.TypeFullName, "#C4");
1209                 }
1210
1211                 [Test]
1212                 [ExpectedException (typeof (InvalidOperationException))]
1213                 public void TypeMapping_ICollection_Object_NoIntIndexer ()
1214                 {
1215                         Map (typeof (ObjectCollectionNoIntIndexer));
1216                 }
1217
1218                 [Test]
1219                 [ExpectedException (typeof (InvalidOperationException))]
1220                 public void TypeMapping_ICollection_Object_NoIntIndexer_Array ()
1221                 {
1222                         Map (typeof (ObjectCollectionNoIntIndexer[]));
1223                 }
1224
1225                 [Test]
1226                 [ExpectedException (typeof (InvalidOperationException))]
1227                 public void TypeMapping_ICollection_SimpleClass_NoIntIndexer ()
1228                 {
1229                         Map (typeof (SimpleClassCollectionNoIntIndexer));
1230                 }
1231
1232                 [Test]
1233                 [ExpectedException (typeof (InvalidOperationException))]
1234                 public void TypeMapping_ICollection_SimpleClass_NoIntIndexer_Array ()
1235                 {
1236                         Map (typeof (SimpleClassCollectionNoIntIndexer[]));
1237                 }
1238
1239                 [Test]
1240                 public void TypeMapping_InvalidDefault ()
1241                 {
1242                         XmlAttributes attrs = new XmlAttributes (typeof (Field).GetMember ("Modifiers") [0]);
1243                         attrs.XmlDefaultValue = 2; // not a defined enum value
1244                         XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
1245                         overrides.Add (typeof (Field), "Modifiers", attrs);
1246
1247                         try {
1248                                 Map (typeof (Field), overrides);
1249                                 Assert.Fail ("#A1");
1250                         } catch (InvalidOperationException ex) {
1251                                 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1252                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1253                                 Assert.IsNotNull (ex.Message, "#A3");
1254                                 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#A4");
1255                                 Assert.IsNotNull (ex.InnerException, "#A5");
1256
1257                                 // There was an error reflecting field 'Modifiers'
1258                                 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#A6");
1259                                 Assert.IsNotNull (ex.InnerException.Message, "#A7");
1260                                 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#A8");
1261                                 Assert.IsNotNull (ex.InnerException.InnerException, "#A9");
1262
1263                                 // Value '2' cannot be converted to System.Int32
1264                                 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.InnerException.GetType (), "#A10");
1265                                 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#A11");
1266                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'2'") != -1, "#A12");
1267                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (int).FullName) != -1, "#A13");
1268                                 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#A14");
1269                         }
1270
1271                         attrs.XmlDefaultValue = "2"; // not of the same type as the underlying enum type (System.Int32)
1272
1273                         try {
1274                                 Map (typeof (Field), overrides);
1275                                 Assert.Fail ("#B1");
1276                         } catch (InvalidOperationException ex) {
1277                                 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1278                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
1279                                 Assert.IsNotNull (ex.Message, "#B3");
1280                                 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#B4");
1281                                 Assert.IsNotNull (ex.InnerException, "#B5");
1282
1283                                 // There was an error reflecting field 'Modifiers'
1284                                 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#B6");
1285                                 Assert.IsNotNull (ex.InnerException.Message, "#B7");
1286                                 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#B8");
1287                                 Assert.IsNotNull (ex.InnerException.InnerException, "#B9");
1288
1289                                 // Enum underlying type and the object must be same type or object.
1290                                 // Type passed in was 'System.String'; the enum underlying type was
1291                                 // 'System.Int32'.
1292                                 Assert.AreEqual (typeof (ArgumentException), ex.InnerException.InnerException.GetType (), "#B10");
1293                                 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#B11");
1294                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (string).FullName) != -1, "#B12");
1295                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (int).FullName) != -1, "#B13");
1296                                 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#B14");
1297                         }
1298
1299                         attrs.XmlDefaultValue = EnumDefaultValueNF.e2; // other enum type
1300
1301                         try {
1302                                 Map (typeof (Field), overrides);
1303                                 Assert.Fail ("#C1");
1304                         } catch (InvalidOperationException ex) {
1305                                 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1306                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
1307                                 Assert.IsNotNull (ex.Message, "#C3");
1308                                 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#C4");
1309                                 Assert.IsNotNull (ex.InnerException, "#C5");
1310
1311                                 // There was an error reflecting field 'Modifiers'
1312                                 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#C6");
1313                                 Assert.IsNotNull (ex.InnerException.Message, "#C7");
1314                                 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#C8");
1315                                 Assert.IsNotNull (ex.InnerException.InnerException, "#C9");
1316
1317                                 // Object must be the same type as the enum. The type passed in
1318                                 // was MonoTests.System.Xml.TestClasses.EnumDefaultValueNF; the
1319                                 // enum type was MonoTests.System.Xml.TestClasses.MapModifiers
1320                                 Assert.AreEqual (typeof (ArgumentException), ex.InnerException.InnerException.GetType (), "#C10");
1321                                 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#C11");
1322                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (EnumDefaultValueNF).FullName) != -1, "#C12");
1323                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#C13");
1324                                 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#C14");
1325                         }
1326
1327                         attrs.XmlDefaultValue = (MapModifiers) 20; // non-existing enum value
1328
1329                         try {
1330                                 Map (typeof (Field), overrides);
1331                                 Assert.Fail ("#D1");
1332                         } catch (InvalidOperationException ex) {
1333                                 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1334                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1335                                 Assert.IsNotNull (ex.Message, "#D3");
1336                                 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#D4");
1337                                 Assert.IsNotNull (ex.InnerException, "#D5");
1338
1339                                 // There was an error reflecting field 'Modifiers'
1340                                 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#D6");
1341                                 Assert.IsNotNull (ex.InnerException.Message, "#D7");
1342                                 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#D8");
1343                                 Assert.IsNotNull (ex.InnerException.InnerException, "#D9");
1344
1345                                 // Value '20' cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
1346                                 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.InnerException.GetType (), "#D10");
1347                                 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#D11");
1348                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'20'") != -1, "#D12");
1349                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#D13");
1350                                 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#D14");
1351                         }
1352                 }
1353
1354                 [Test]
1355                 [ExpectedException (typeof (ArgumentNullException))]
1356                 public void TypeMapping_Null ()
1357                 {
1358                         Map ((Type) null);
1359                 }
1360
1361                 [Test]
1362                 [ExpectedException (typeof (NotSupportedException))]
1363                 public void TypeMapping_Void ()
1364                 {
1365                         Map (typeof (void));
1366                 }
1367
1368                 [Test]
1369                 public void TypeMapping_WrongChoices ()
1370                 {
1371                         try {
1372                                 Map (typeof (WrongChoices));
1373                                 Assert.Fail ("#1");
1374                         } catch (InvalidOperationException ex) {
1375                                 // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.WrongChoices'
1376                                 Assert.IsNotNull (ex.Message, "#2");
1377                                 Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (WrongChoices).FullName + "'") != -1, "#3");
1378                                 Assert.IsNotNull (ex.InnerException, "#4");
1379
1380                                 // There was an error reflecting field 'MyChoice'
1381                                 Assert.IsNotNull (ex.InnerException.Message, "#5");
1382                                 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'MyChoice'") != -1, "#6");
1383                                 Assert.IsNotNull (ex.InnerException.InnerException, "#7");
1384
1385                                 // Type MonoTests.System.Xml.TestClasses.ItemChoiceType is missing 
1386                                 // enumeration value 'StrangeOne' for element 'StrangeOne' from
1387                                 // namespace ''.
1388                                 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#8");
1389                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (ItemChoiceType).FullName) != -1, "#9");
1390                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'StrangeOne'") != -1, "#10");
1391                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("''") != -1, "#11");
1392                         }
1393                 }
1394
1395                 [Test] // bug #77591
1396                 public void TypeMapping_XmlText_PrimitiveTypes ()
1397                 {
1398                         XmlAttributeOverrides overrides = null;
1399                         XmlAttributes attrs = null;
1400
1401                         overrides = new XmlAttributeOverrides ();
1402                         attrs = new  XmlAttributes ();
1403                         attrs.XmlText = new XmlTextAttribute (typeof (int));
1404                         overrides.Add (typeof (Field), "Modifiers", attrs);
1405
1406                         try {
1407                                 Map (typeof (Field), overrides);
1408                                 Assert.Fail ("#A1");
1409                         } catch (InvalidOperationException ex) {
1410                                 // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.Field'
1411                                 Assert.IsNotNull (ex.Message, "#A2");
1412                                 Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (Field).FullName + "'") != -1, "#A3");
1413                                 Assert.IsNotNull (ex.InnerException, "#A4");
1414
1415                                 // There was an error reflecting field 'Modifiers'
1416                                 Assert.IsNotNull (ex.InnerException.Message, "#A5");
1417                                 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#A6");
1418                                 Assert.IsNotNull (ex.InnerException.InnerException, "#A7");
1419
1420                                 // The type for XmlText may not be specified for primitive types
1421                                 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#A8");
1422                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("XmlText") != -1, "#A9");
1423                         }
1424
1425                         overrides = new XmlAttributeOverrides ();
1426                         attrs = new XmlAttributes ();
1427                         attrs.XmlText = new XmlTextAttribute (typeof (int));
1428                         overrides.Add (typeof (Field), "Street", attrs);
1429
1430                         try {
1431                                 Map (typeof (Field), overrides);
1432                                 Assert.Fail ("#B1");
1433                         } catch (InvalidOperationException ex) {
1434                                 // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.Field'
1435                                 Assert.IsNotNull (ex.Message, "#B2");
1436                                 Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (Field).FullName + "'") != -1, "#B3");
1437                                 Assert.IsNotNull (ex.InnerException, "#B4");
1438
1439                                 // There was an error reflecting field 'Street'
1440                                 Assert.IsNotNull (ex.InnerException.Message, "#B5");
1441                                 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Street'") != -1, "#B6");
1442                                 Assert.IsNotNull (ex.InnerException.InnerException, "#B7");
1443
1444                                 // The type for XmlText may not be specified for primitive types
1445                                 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#B8");
1446                                 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("XmlText") != -1, "#B9");
1447                         }
1448
1449                         overrides = new XmlAttributeOverrides ();
1450                         attrs = new XmlAttributes ();
1451                         attrs.XmlText = new XmlTextAttribute (typeof (MapModifiers));
1452                         overrides.Add (typeof (Field), "Modifiers", attrs);
1453                         Map (typeof (Field), overrides);
1454
1455                         overrides = new XmlAttributeOverrides ();
1456                         attrs = new XmlAttributes ();
1457                         attrs.XmlText = new XmlTextAttribute (typeof (string));
1458                         overrides.Add (typeof (Field), "Street", attrs);
1459                         Map (typeof (Field), overrides);
1460                 }
1461
1462                 [Test]
1463                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1464                 public void TestImportMembersMapping()
1465                 {
1466                         Type type = typeof(SimpleClass);
1467                         XmlAttributes attrs = new  XmlAttributes();
1468                         XmlAttributeOverrides overrides = new XmlAttributeOverrides();
1469                         overrides.Add(typeof(SimpleClass), attrs);
1470
1471                         XmlReflectionMember[] members = new XmlReflectionMember[0];
1472                         XmlMembersMapping mm;
1473                         try
1474                         {
1475                                 mm = MembersMap(type, overrides, members, true);
1476                                 Assert.Fail("Should not be able to fetch an empty XmlMembersMapping");
1477                         }
1478                         catch (Exception)
1479                         {
1480                         }
1481                         
1482                         XmlReflectionMember rm = new XmlReflectionMember();
1483                         rm.IsReturnValue = false;
1484                         rm.MemberName = "something";
1485                         rm.MemberType = typeof(string);
1486                         members = new XmlReflectionMember[1];
1487                         members[0] = rm;
1488
1489                         mm = MembersMap(type, overrides, members, false);
1490
1491                         Equals(mm.Count, 1);
1492
1493                         XmlMemberMapping smm = mm[0];
1494                         Assert.IsFalse (smm.Any, "#1");
1495                         Assert.AreEqual ("something", smm.ElementName, "#2");
1496                         Assert.AreEqual ("something", smm.MemberName, "#3");
1497                         Assert.IsNull (smm.Namespace, "#4");
1498                         Assert.AreEqual ("System.String", smm.TypeFullName, "#5");
1499                         Assert.AreEqual ("string", smm.TypeName, "#6");
1500 #if NET_2_0
1501                         Assert.AreEqual (XmlSchemaNamespace, smm.TypeNamespace, "#7");
1502 #else
1503                         Assert.IsNull (smm.TypeNamespace, "#7");
1504 #endif
1505
1506                         rm = new XmlReflectionMember();
1507                         rm.IsReturnValue = false;
1508                         rm.MemberName = "nothing";
1509                         rm.MemberType = typeof(string);
1510                         members = new XmlReflectionMember[1];
1511                         members[0] = rm;
1512
1513                         mm = MembersMap(type, overrides, members, false);
1514                         Assert.AreEqual (1, mm.Count, "#8");
1515                 }
1516
1517                 [Test]
1518                 public void TestIntTypeMappingWithXmlRootAttribute()
1519                 {
1520                         const string TheNamespace = "another:urn";
1521                         XmlRootAttribute root = new XmlRootAttribute("price");
1522                         root.Namespace = TheNamespace;
1523                         
1524                         XmlTypeMapping tm = Map(typeof(int), root);
1525                         Assert.AreEqual ("price", tm.ElementName, "#1");
1526                         Assert.AreEqual (TheNamespace, tm.Namespace, "#2");
1527                         Assert.AreEqual ("Int32", tm.TypeName, "#3");
1528                         Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
1529                 }
1530                 
1531                 [Test]
1532                 [ExpectedException (typeof (InvalidOperationException))]
1533                 public void TestSerializeWrongChoice ()
1534                 {
1535                         new XmlSerializer (typeof(WrongChoices));
1536                 }
1537
1538 #if NET_2_0
1539                 [Test]
1540                 public void ImportNullableContainer ()
1541                 {
1542                         new XmlSerializer (typeof (NullableContainer));
1543                 }
1544 #endif
1545
1546                 public class Employee : IXmlSerializable
1547                 {
1548                         private string _firstName;
1549                         private string _lastName;
1550                         private string _address;
1551
1552                         public XmlSchema GetSchema ()
1553                         {
1554                                 return null;
1555                         }
1556
1557                         public void WriteXml (XmlWriter writer)
1558                         {
1559                                 writer.WriteStartElement ("employee", "urn:devx-com");
1560                                 writer.WriteAttributeString ("firstName", _firstName);
1561                                 writer.WriteAttributeString ("lastName", _lastName);
1562                                 writer.WriteAttributeString ("address", _address);
1563                                 writer.WriteEndElement ();
1564                         }
1565
1566                         public void ReadXml (XmlReader reader)
1567                         {
1568                                 XmlNodeType type = reader.MoveToContent ();
1569                                 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
1570                                         _firstName = reader["firstName"];
1571                                         _lastName = reader["lastName"];
1572                                         _address = reader["address"];
1573                                 }
1574                         }
1575                 }
1576
1577                 public class NestedStruct
1578                 {
1579                         public TimeSpan Period = TimeSpan.MaxValue;
1580                 }
1581
1582                 public class ObjectEnumerable : IEnumerable
1583                 {
1584                         public void Add (int value)
1585                         {
1586                         }
1587
1588                         public void Add (object value)
1589                         {
1590                         }
1591
1592                         public IEnumerator GetEnumerator ()
1593                         {
1594                                 return new ArrayList ().GetEnumerator ();
1595                         }
1596                 }
1597
1598                 public class SimpleClassEnumerable : IEnumerable
1599                 {
1600                         public void Add (int value)
1601                         {
1602                         }
1603
1604                         public void Add (object value)
1605                         {
1606                         }
1607
1608                         IEnumerator IEnumerable.GetEnumerator ()
1609                         {
1610                                 return GetEnumerator ();
1611                         }
1612
1613                         public SimpleClassEnumerator GetEnumerator ()
1614                         {
1615                                 return new SimpleClassEnumerator (new ArrayList ());
1616                         }
1617                 }
1618
1619                 public class SimpleClassEnumerablePrivateGetEnumerator : IEnumerable
1620                 {
1621                         public void Add (object value)
1622                         {
1623                         }
1624
1625                         IEnumerator IEnumerable.GetEnumerator ()
1626                         {
1627                                 return new ArrayList ().GetEnumerator ();
1628                         }
1629                 }
1630
1631                 public class SimpleClassEnumerablePrivateCurrent : IEnumerable
1632                 {
1633                         public void Add (object value)
1634                         {
1635                         }
1636
1637                         IEnumerator IEnumerable.GetEnumerator ()
1638                         {
1639                                 return GetEnumerator ();
1640                         }
1641
1642                         public NoCurrentEnumerator GetEnumerator ()
1643                         {
1644                                 return new NoCurrentEnumerator (new ArrayList ());
1645                         }
1646                 }
1647
1648                 // GetEnumerator().Current returns object, but there's no corresponding
1649                 // Add (System.Object) method
1650                 public class ObjectEnumerableNoMatchingAddMethod : IEnumerable
1651                 {
1652                         public void Add (int value)
1653                         {
1654                         }
1655
1656                         public IEnumerator GetEnumerator ()
1657                         {
1658                                 return new ArrayList ().GetEnumerator ();
1659                         }
1660                 }
1661
1662                 // GetEnumerator().Current returns SimpleClass, but there's no 
1663                 // corresponding Add (SimpleClass) method
1664                 public class SimpleClassCollectionNoMatchingAddMethod : ICollection
1665                 {
1666                         public SimpleClass this[int index]
1667                         {
1668                                 get
1669                                 {
1670                                         return (SimpleClass) _list[index];
1671                                 }
1672                         }
1673
1674                         public int Count
1675                         {
1676                                 get { return _list.Count; }
1677                         }
1678
1679                         public bool IsSynchronized
1680                         {
1681                                 get { return _list.IsSynchronized; }
1682                         }
1683
1684                         public object SyncRoot
1685                         {
1686                                 get { return _list.SyncRoot; }
1687                         }
1688
1689                         public void CopyTo (Array array, int index)
1690                         {
1691                                 _list.CopyTo (array, index);
1692                         }
1693
1694                         IEnumerator IEnumerable.GetEnumerator ()
1695                         {
1696                                 return GetEnumerator ();
1697                         }
1698
1699                         public SimpleClassEnumerator GetEnumerator ()
1700                         {
1701                                 return new SimpleClassEnumerator (_list);
1702                         }
1703
1704                         private ArrayList _list = new ArrayList ();
1705                 }
1706
1707                 // GetEnumerator().Current returns object, but there's no corresponding
1708                 // Add (System.Object) method
1709                 public class ObjectCollectionNoMatchingAddMethod : ICollection
1710                 {
1711                         public object this[int index]
1712                         {
1713                                 get
1714                                 {
1715                                         return _list[index];
1716                                 }
1717                         }
1718
1719                         public int Count
1720                         {
1721                                 get { return _list.Count; }
1722                         }
1723
1724                         public bool IsSynchronized
1725                         {
1726                                 get { return _list.IsSynchronized; }
1727                         }
1728
1729                         public object SyncRoot
1730                         {
1731                                 get { return _list.SyncRoot; }
1732                         }
1733
1734                         public void CopyTo (Array array, int index)
1735                         {
1736                                 _list.CopyTo (array, index);
1737                         }
1738
1739                         IEnumerator IEnumerable.GetEnumerator ()
1740                         {
1741                                 return GetEnumerator ();
1742                         }
1743
1744                         public IEnumerator GetEnumerator ()
1745                         {
1746                                 return _list.GetEnumerator ();
1747                         }
1748
1749                         private ArrayList _list = new ArrayList ();
1750                 }
1751
1752                 // Does not have int indexer.
1753                 public class SimpleClassCollectionNoIntIndexer : ICollection
1754                 {
1755                         public SimpleClass this[string name]
1756                         {
1757                                 get
1758                                 {
1759                                         return new SimpleClass ();
1760                                 }
1761                         }
1762
1763                         public int Count
1764                         {
1765                                 get { return _list.Count; }
1766                         }
1767
1768                         public bool IsSynchronized
1769                         {
1770                                 get { return _list.IsSynchronized; }
1771                         }
1772
1773                         public object SyncRoot
1774                         {
1775                                 get { return _list.SyncRoot; }
1776                         }
1777
1778                         public void CopyTo (Array array, int index)
1779                         {
1780                                 _list.CopyTo (array, index);
1781                         }
1782
1783                         IEnumerator IEnumerable.GetEnumerator ()
1784                         {
1785                                 return GetEnumerator ();
1786                         }
1787
1788                         public SimpleClassEnumerator GetEnumerator ()
1789                         {
1790                                 return new SimpleClassEnumerator (_list);
1791                         }
1792
1793                         public void Add (SimpleClass value)
1794                         {
1795                                 _list.Add (value);
1796                         }
1797
1798                         private ArrayList _list = new ArrayList ();
1799                 }
1800
1801                 // Does not have int indexer.
1802                 public class ObjectCollectionNoIntIndexer : ICollection
1803                 {
1804                         public object this[string name]
1805                         {
1806                                 get
1807                                 {
1808                                         return new SimpleClass ();
1809                                 }
1810                         }
1811
1812                         public int Count
1813                         {
1814                                 get { return _list.Count; }
1815                         }
1816
1817                         public bool IsSynchronized
1818                         {
1819                                 get { return _list.IsSynchronized; }
1820                         }
1821
1822                         public object SyncRoot
1823                         {
1824                                 get { return _list.SyncRoot; }
1825                         }
1826
1827                         public void CopyTo (Array array, int index)
1828                         {
1829                                 _list.CopyTo (array, index);
1830                         }
1831
1832                         public IEnumerator GetEnumerator ()
1833                         {
1834                                 return _list.GetEnumerator ();
1835                         }
1836
1837                         public void Add (object value)
1838                         {
1839                                 _list.Add (value);
1840                         }
1841
1842                         private ArrayList _list = new ArrayList ();
1843                 }
1844
1845                 public class SimpleClassCollection : ICollection
1846                 {
1847                         public SimpleClass this[int index]
1848                         {
1849                                 get
1850                                 {
1851                                         return (SimpleClass) _list[index];
1852                                 }
1853                         }
1854
1855                         public int Count
1856                         {
1857                                 get { return _list.Count; }
1858                         }
1859
1860                         public bool IsSynchronized
1861                         {
1862                                 get { return _list.IsSynchronized; }
1863                         }
1864
1865                         public object SyncRoot
1866                         {
1867                                 get { return _list.SyncRoot; }
1868                         }
1869
1870                         public void CopyTo (Array array, int index)
1871                         {
1872                                 _list.CopyTo (array, index);
1873                         }
1874
1875                         IEnumerator IEnumerable.GetEnumerator ()
1876                         {
1877                                 return GetEnumerator ();
1878                         }
1879
1880                         public SimpleClassEnumerator GetEnumerator ()
1881                         {
1882                                 return new SimpleClassEnumerator (_list);
1883                         }
1884
1885                         public void Add (SimpleClass value)
1886                         {
1887                                 _list.Add (value);
1888                         }
1889
1890                         private ArrayList _list = new ArrayList ();
1891                 }
1892
1893                 public class ObjectCollection : ICollection
1894                 {
1895                         public object this[int name]
1896                         {
1897                                 get
1898                                 {
1899                                         return new SimpleClass ();
1900                                 }
1901                         }
1902
1903                         public int Count
1904                         {
1905                                 get { return _list.Count; }
1906                         }
1907
1908                         public bool IsSynchronized
1909                         {
1910                                 get { return _list.IsSynchronized; }
1911                         }
1912
1913                         public object SyncRoot
1914                         {
1915                                 get { return _list.SyncRoot; }
1916                         }
1917
1918                         public void CopyTo (Array array, int index)
1919                         {
1920                                 _list.CopyTo (array, index);
1921                         }
1922
1923                         public IEnumerator GetEnumerator ()
1924                         {
1925                                 return _list.GetEnumerator ();
1926                         }
1927
1928                         public void Add (object value)
1929                         {
1930                                 _list.Add (value);
1931                         }
1932
1933                         private ArrayList _list = new ArrayList ();
1934                 }
1935
1936                 public class SimpleClassEnumerator : IEnumerator
1937                 {
1938                         internal SimpleClassEnumerator (ArrayList arguments)
1939                         {
1940                                 IEnumerable temp = (IEnumerable) (arguments);
1941                                 _baseEnumerator = temp.GetEnumerator ();
1942                         }
1943                         public SimpleClass Current
1944                         {
1945                                 get { return (SimpleClass) _baseEnumerator.Current; }
1946                         }
1947
1948                         object IEnumerator.Current
1949                         {
1950                                 get { return _baseEnumerator.Current; }
1951                         }
1952
1953                         public bool MoveNext ()
1954                         {
1955                                 return _baseEnumerator.MoveNext ();
1956                         }
1957
1958                         bool IEnumerator.MoveNext ()
1959                         {
1960                                 return _baseEnumerator.MoveNext ();
1961                         }
1962
1963                         public void Reset ()
1964                         {
1965                                 _baseEnumerator.Reset ();
1966                         }
1967
1968                         void IEnumerator.Reset ()
1969                         {
1970                                 _baseEnumerator.Reset ();
1971                         }
1972
1973                         private IEnumerator _baseEnumerator;
1974                 }
1975
1976                 public class NoCurrentEnumerator : IEnumerator
1977                 {
1978                         internal NoCurrentEnumerator (ArrayList arguments)
1979                         {
1980                                 IEnumerable temp = (IEnumerable) (arguments);
1981                                 _baseEnumerator = temp.GetEnumerator ();
1982                         }
1983
1984                         object IEnumerator.Current
1985                         {
1986                                 get { return _baseEnumerator.Current; }
1987                         }
1988
1989                         public bool MoveNext ()
1990                         {
1991                                 return _baseEnumerator.MoveNext ();
1992                         }
1993
1994                         bool IEnumerator.MoveNext ()
1995                         {
1996                                 return _baseEnumerator.MoveNext ();
1997                         }
1998
1999                         public void Reset ()
2000                         {
2001                                 _baseEnumerator.Reset ();
2002                         }
2003
2004                         void IEnumerator.Reset ()
2005                         {
2006                                 _baseEnumerator.Reset ();
2007                         }
2008
2009                         private IEnumerator _baseEnumerator;
2010                 }
2011
2012 #if NET_2_0
2013                 public class NullableContainer
2014                 {
2015                         [XmlElement (IsNullable = true)]
2016                         public int? NilInt;
2017                 }
2018 #endif
2019         }
2020 }
2021