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