2 // System.Xml.Serialization.XmlReflectionImporterTests
5 // Erik LeBel (eriklebel@yahoo.ca)
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?
14 using System.Collections;
17 using System.Xml.Schema;
18 using System.Xml.Serialization;
20 using NUnit.Framework;
22 using System.Collections.Generic;
25 using MonoTests.System.Xml.TestClasses;
27 namespace MonoTests.System.XmlSerialization
32 public static void Print(XmlTypeMapping tm)
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);
41 public static void Print(XmlMemberMapping mm)
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);
55 public class XmlReflectionImporterTests
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";
61 // these Map methods re-create the XmlReflectionImporter at every call.
63 private XmlTypeMapping Map(Type t)
65 XmlReflectionImporter ri = new XmlReflectionImporter();
66 XmlTypeMapping tm = ri.ImportTypeMapping(t);
72 private XmlTypeMapping Map(Type t, XmlRootAttribute root)
74 XmlReflectionImporter ri = new XmlReflectionImporter();
75 XmlTypeMapping tm = ri.ImportTypeMapping(t, root);
80 private XmlTypeMapping Map(Type t, string ns)
82 XmlReflectionImporter ri = new XmlReflectionImporter(ns);
83 XmlTypeMapping tm = ri.ImportTypeMapping(t);
89 private XmlTypeMapping Map (Type t, string ns, XmlRootAttribute root)
91 XmlReflectionImporter ri = new XmlReflectionImporter (ns);
92 XmlTypeMapping tm = ri.ImportTypeMapping (t, root);
97 private XmlTypeMapping Map(Type t, XmlAttributeOverrides overrides)
99 XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
100 XmlTypeMapping tm = ri.ImportTypeMapping(t);
106 private XmlMembersMapping MembersMap(Type t, XmlAttributeOverrides overrides,
107 XmlReflectionMember [] members, bool inContainer)
109 XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
110 XmlMembersMapping mm = ri.ImportMembersMapping(null, null, members, inContainer);
116 public void TestIntTypeMapping()
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");
127 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
129 public void TestIntTypeMapping_Array ()
131 XmlTypeMapping tm = Map(typeof(int[]));
132 Assert.AreEqual ("ArrayOfInt", tm.ElementName, "#A1");
133 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
135 Assert.AreEqual ("ArrayOfInt32", tm.TypeName, "#A3");
137 Assert.AreEqual ("Int32[]", tm.TypeName, "#A3");
139 Assert.AreEqual ("System.Int32[]", tm.TypeFullName, "#A4");
141 tm = Map (typeof (int[][]));
142 Assert.AreEqual ("ArrayOfArrayOfInt", tm.ElementName, "#B1");
143 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
145 Assert.AreEqual ("ArrayOfArrayOfInt32", tm.TypeName, "#B3");
147 Assert.AreEqual ("Int32[][]", tm.TypeName, "#B3");
149 Assert.AreEqual ("System.Int32[][]", tm.TypeFullName, "#B4");
151 tm = Map (typeof (int[][][]));
152 Assert.AreEqual ("ArrayOfArrayOfArrayOfInt", tm.ElementName, "#C1");
153 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
155 Assert.AreEqual ("ArrayOfArrayOfArrayOfInt32", tm.TypeName, "#C3");
157 Assert.AreEqual ("Int32[][][]", tm.TypeName, "#C3");
159 Assert.AreEqual ("System.Int32[][][]", tm.TypeFullName, "#C4");
163 public void TestStringTypeMapping()
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");
174 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
176 public void TestStringTypeMapping_Array ()
178 XmlTypeMapping tm = Map (typeof (string[]));
179 Assert.AreEqual ("ArrayOfString", tm.ElementName, "#A1");
180 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
182 Assert.AreEqual ("ArrayOfString", tm.TypeName, "#A3");
184 Assert.AreEqual ("String[]", tm.TypeName, "#A3");
186 Assert.AreEqual ("System.String[]", tm.TypeFullName, "#A4");
188 tm = Map (typeof (string[][]));
189 Assert.AreEqual ("ArrayOfArrayOfString", tm.ElementName, "#B1");
190 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
192 Assert.AreEqual ("ArrayOfArrayOfString", tm.TypeName, "#B3");
194 Assert.AreEqual ("String[][]", tm.TypeName, "#B3");
196 Assert.AreEqual ("System.String[][]", tm.TypeFullName, "#B4");
198 tm = Map (typeof (string[][][]));
199 Assert.AreEqual ("ArrayOfArrayOfArrayOfString", tm.ElementName, "#C1");
200 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
202 Assert.AreEqual ("ArrayOfArrayOfArrayOfString", tm.TypeName, "#C3");
204 Assert.AreEqual ("String[][][]", tm.TypeName, "#C3");
206 Assert.AreEqual ("System.String[][][]", tm.TypeFullName, "#C4");
210 public void TestObjectTypeMapping()
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");
221 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
223 public void TestObjectTypeMapping_Array ()
225 XmlTypeMapping tm = Map (typeof (object[]));
226 Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#A1");
227 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
229 Assert.AreEqual ("ArrayOfObject", tm.TypeName, "#A3");
231 Assert.AreEqual ("Object[]", tm.TypeName, "#A3");
233 Assert.AreEqual ("System.Object[]", tm.TypeFullName, "#A4");
235 tm = Map (typeof (object[][]));
236 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#B1");
237 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
239 Assert.AreEqual ("ArrayOfArrayOfObject", tm.TypeName, "#B3");
241 Assert.AreEqual ("Object[][]", tm.TypeName, "#B3");
243 Assert.AreEqual ("System.Object[][]", tm.TypeFullName, "#B4");
245 tm = Map (typeof (object[][][]));
246 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
247 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
249 Assert.AreEqual ("ArrayOfArrayOfArrayOfObject", tm.TypeName, "#C3");
251 Assert.AreEqual ("Object[][][]", tm.TypeName, "#C3");
253 Assert.AreEqual ("System.Object[][][]", tm.TypeFullName, "#C4");
257 public void TestByteTypeMapping()
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");
268 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
270 public void TestByteTypeMapping_Array ()
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");
278 tm = Map (typeof (byte[][]));
279 Assert.AreEqual ("ArrayOfBase64Binary", tm.ElementName, "#B1");
280 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
282 Assert.AreEqual ("ArrayOfArrayOfByte", tm.TypeName, "#B3");
284 Assert.AreEqual ("Byte[][]", tm.TypeName, "#B3");
286 Assert.AreEqual ("System.Byte[][]", tm.TypeFullName, "#B4");
288 tm = Map (typeof (byte[][][]));
289 Assert.AreEqual ("ArrayOfArrayOfBase64Binary", tm.ElementName, "#C1");
290 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
292 Assert.AreEqual ("ArrayOfArrayOfArrayOfByte", tm.TypeName, "#C3");
294 Assert.AreEqual ("Byte[][][]", tm.TypeName, "#C3");
296 Assert.AreEqual ("System.Byte[][][]", tm.TypeFullName, "#C4");
300 public void TestBoolTypeMapping()
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");
310 public void TestShortTypeMapping()
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");
320 public void TestUnsignedShortTypeMapping()
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");
330 public void TestUIntTypeMapping()
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");
340 public void TestLongTypeMapping()
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");
350 public void TestULongTypeMapping()
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");
360 public void TestFloatTypeMapping()
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");
370 public void TestDoubleTypeMapping()
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");
380 public void TestDateTimeTypeMapping()
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");
391 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
393 public void TestDateTimeTypeMapping_Array ()
395 XmlTypeMapping tm = Map (typeof (DateTime[]));
396 Assert.AreEqual ("ArrayOfDateTime", tm.ElementName, "#A1");
397 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
399 Assert.AreEqual ("ArrayOfDateTime", tm.TypeName, "#A3");
401 Assert.AreEqual ("DateTime[]", tm.TypeName, "#A3");
403 Assert.AreEqual ("System.DateTime[]", tm.TypeFullName, "#A4");
405 tm = Map (typeof (DateTime[][]));
406 Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.ElementName, "#B1");
407 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
409 Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.TypeName, "#B3");
411 Assert.AreEqual ("DateTime[][]", tm.TypeName, "#B3");
413 Assert.AreEqual ("System.DateTime[][]", tm.TypeFullName, "#B4");
415 tm = Map (typeof (DateTime[][][]));
416 Assert.AreEqual ("ArrayOfArrayOfArrayOfDateTime", tm.ElementName, "#C1");
417 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
419 Assert.AreEqual ("ArrayOfArrayOfArrayOfDateTime", tm.TypeName, "#C3");
421 Assert.AreEqual ("DateTime[][][]", tm.TypeName, "#C3");
423 Assert.AreEqual ("System.DateTime[][][]", tm.TypeFullName, "#C4");
427 public void TestGuidTypeMapping()
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");
438 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
440 public void TestGuidTypeMapping_Array ()
442 XmlTypeMapping tm = Map (typeof (Guid[]));
443 Assert.AreEqual ("ArrayOfGuid", tm.ElementName, "#A1");
444 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
446 Assert.AreEqual ("ArrayOfGuid", tm.TypeName, "#A3");
448 Assert.AreEqual ("Guid[]", tm.TypeName, "#A3");
450 Assert.AreEqual ("System.Guid[]", tm.TypeFullName, "#A4");
452 tm = Map (typeof (Guid[][]));
453 Assert.AreEqual ("ArrayOfArrayOfGuid", tm.ElementName, "#B1");
454 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
456 Assert.AreEqual ("ArrayOfArrayOfGuid", tm.TypeName, "#B3");
458 Assert.AreEqual ("Guid[][]", tm.TypeName, "#B3");
460 Assert.AreEqual ("System.Guid[][]", tm.TypeFullName, "#B4");
462 tm = Map (typeof (Guid[][][]));
463 Assert.AreEqual ("ArrayOfArrayOfArrayOfGuid", tm.ElementName, "#C1");
464 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
466 Assert.AreEqual ("ArrayOfArrayOfArrayOfGuid", tm.TypeName, "#C3");
468 Assert.AreEqual ("Guid[][][]", tm.TypeName, "#C3");
470 Assert.AreEqual ("System.Guid[][][]", tm.TypeFullName, "#C4");
474 public void TestDecimalTypeMapping()
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");
484 public void TestXmlQualifiedNameTypeMapping()
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");
494 public void TestSByteTypeMapping()
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");
505 public void TestCharTypeMapping()
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");
516 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
518 public void TestCharTypeMapping_Array ()
520 XmlTypeMapping tm = Map (typeof (char[]));
521 Assert.AreEqual ("ArrayOfChar", tm.ElementName, "#A1");
522 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
524 Assert.AreEqual ("ArrayOfChar", tm.TypeName, "#A3");
526 Assert.AreEqual ("Char[]", tm.TypeName, "#A3");
528 Assert.AreEqual ("System.Char[]", tm.TypeFullName, "#A4");
530 tm = Map (typeof (char[][]));
531 Assert.AreEqual ("ArrayOfArrayOfChar", tm.ElementName, "#B1");
532 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
534 Assert.AreEqual ("ArrayOfArrayOfChar", tm.TypeName, "#B3");
536 Assert.AreEqual ("Char[][]", tm.TypeName, "#B3");
538 Assert.AreEqual ("System.Char[][]", tm.TypeFullName, "#B4");
540 tm = Map (typeof (char[][][]));
541 Assert.AreEqual ("ArrayOfArrayOfArrayOfChar", tm.ElementName, "#C1");
542 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
544 Assert.AreEqual ("ArrayOfArrayOfArrayOfChar", tm.TypeName, "#C3");
546 Assert.AreEqual ("Char[][][]", tm.TypeName, "#C3");
548 Assert.AreEqual ("System.Char[][][]", tm.TypeFullName, "#C4");
552 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
553 public void TestXmlNodeTypeMapping ()
555 Type type = typeof (XmlNode);
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");
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");
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");
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");
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");
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");
598 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
599 public void TestXmlElementTypeMapping ()
601 Type type = typeof (XmlElement);
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");
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");
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");
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");
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");
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");
644 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
645 public void TestXmlNotationTypeMapping ()
647 Type type = typeof (XmlNotation);
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");
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");
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");
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");
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");
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");
690 public void TestXmlSerializableTypeMapping ()
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");
701 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
703 public void TestXmlSerializableTypeMapping_Array ()
705 XmlTypeMapping tm = Map (typeof (Employee[]));
706 Assert.AreEqual ("ArrayOfEmployee", tm.ElementName, "#A1");
707 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
709 Assert.AreEqual ("ArrayOfEmployee", tm.TypeName, "#A3");
711 Assert.AreEqual ("Employee[]", tm.TypeName, "#A3");
713 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[]", tm.TypeFullName, "#A4");
715 tm = Map (typeof (Employee[][]));
716 Assert.AreEqual ("ArrayOfArrayOfEmployee", tm.ElementName, "#B1");
717 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
719 Assert.AreEqual ("ArrayOfArrayOfEmployee", tm.TypeName, "#B3");
721 Assert.AreEqual ("Employee[][]", tm.TypeName, "#B3");
723 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[][]", tm.TypeFullName, "#B4");
725 tm = Map (typeof (Employee[][][]));
726 Assert.AreEqual ("ArrayOfArrayOfArrayOfEmployee", tm.ElementName, "#C1");
727 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
729 Assert.AreEqual ("ArrayOfArrayOfArrayOfEmployee", tm.TypeName, "#C3");
731 Assert.AreEqual ("Employee[][][]", tm.TypeName, "#C3");
733 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[][][]", tm.TypeFullName, "#C4");
737 public void TestClassTypeMapping_NestedStruct ()
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");
747 [ExpectedException (typeof (ArgumentNullException))]
748 public void TestNullTypeMapping()
754 public void TestIntTypeMappingWithDefaultNamespaces()
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");
764 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
765 public void TestStructTypeMapping ()
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");
775 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
776 public void TestStructTypeMapping_Array ()
778 XmlTypeMapping tm = Map (typeof (TimeSpan[]));
779 Assert.AreEqual ("ArrayOfTimeSpan", tm.ElementName, "#A1");
780 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
782 Assert.AreEqual ("ArrayOfTimeSpan", tm.TypeName, "#A3");
784 Assert.AreEqual ("TimeSpan[]", tm.TypeName, "#A3");
786 Assert.AreEqual ("System.TimeSpan[]", tm.TypeFullName, "#A4");
788 tm = Map (typeof (TimeSpan[][]));
789 Assert.AreEqual ("ArrayOfArrayOfTimeSpan", tm.ElementName, "#B1");
790 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
792 Assert.AreEqual ("ArrayOfArrayOfTimeSpan", tm.TypeName, "#B3");
794 Assert.AreEqual ("TimeSpan[][]", tm.TypeName, "#B3");
796 Assert.AreEqual ("System.TimeSpan[][]", tm.TypeFullName, "#B4");
798 tm = Map (typeof (TimeSpan[][][]));
799 Assert.AreEqual ("ArrayOfArrayOfArrayOfTimeSpan", tm.ElementName, "#C1");
800 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
802 Assert.AreEqual ("ArrayOfArrayOfArrayOfTimeSpan", tm.TypeName, "#C3");
804 Assert.AreEqual ("TimeSpan[][][]", tm.TypeName, "#C3");
806 Assert.AreEqual ("System.TimeSpan[][][]", tm.TypeFullName, "#C4");
810 public void TestEnumTypeMapping ()
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");
821 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
823 public void TestEnumTypeMapping_Array ()
825 XmlTypeMapping tm = Map (typeof (AttributeTargets[]));
826 Assert.AreEqual ("ArrayOfAttributeTargets", tm.ElementName, "#A1");
827 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
829 Assert.AreEqual ("ArrayOfAttributeTargets", tm.TypeName, "#A3");
831 Assert.AreEqual ("AttributeTargets[]", tm.TypeName, "#A3");
833 Assert.AreEqual ("System.AttributeTargets[]", tm.TypeFullName, "#A4");
835 tm = Map (typeof (AttributeTargets[][]));
836 Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.ElementName, "#B1");
837 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
839 Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.TypeName, "#B3");
841 Assert.AreEqual ("AttributeTargets[][]", tm.TypeName, "#B3");
843 Assert.AreEqual ("System.AttributeTargets[][]", tm.TypeFullName, "#B4");
845 tm = Map (typeof (AttributeTargets[][][]));
846 Assert.AreEqual ("ArrayOfArrayOfArrayOfAttributeTargets", tm.ElementName, "#C1");
847 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
849 Assert.AreEqual ("ArrayOfArrayOfArrayOfAttributeTargets", tm.TypeName, "#C3");
851 Assert.AreEqual ("AttributeTargets[][][]", tm.TypeName, "#C3");
853 Assert.AreEqual ("System.AttributeTargets[][][]", tm.TypeFullName, "#C4");
857 public void TestClassTypeMapping()
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");
868 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
870 public void TestClassTypeMapping_Array ()
872 XmlTypeMapping tm = Map (typeof (SimpleClass[]));
873 Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#A1");
874 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
876 Assert.AreEqual ("ArrayOfSimpleClass", tm.TypeName, "#A3");
878 Assert.AreEqual ("SimpleClass[]", tm.TypeName, "#A3");
880 Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[]", tm.TypeFullName, "#A4");
882 tm = Map (typeof (SimpleClass[][]));
883 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
884 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
886 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.TypeName, "#B3");
888 Assert.AreEqual ("SimpleClass[][]", tm.TypeName, "#B3");
890 Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][]", tm.TypeFullName, "#B4");
892 tm = Map (typeof (SimpleClass[][][]));
893 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
894 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
896 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.TypeName, "#C3");
898 Assert.AreEqual ("SimpleClass[][][]", tm.TypeName, "#C3");
900 Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][][]", tm.TypeFullName, "#C4");
904 [ExpectedException (typeof (NotSupportedException))]
905 public void TypeMapping_IDictionary ()
907 // The type MonoTests.System.Xml.TestClasses.DictionaryWithIndexer
908 // is not supported because it implements IDictionary.
909 Map (typeof (DictionaryWithIndexer));
914 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
916 public void TypeMapping_IEnumerable_SimpleClass ()
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");
924 tm = Map (typeof (SimpleClassEnumerable[]));
925 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
926 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
928 Assert.AreEqual ("ArrayOfSimpleClassEnumerable", tm.TypeName, "#A3");
930 Assert.AreEqual ("SimpleClassEnumerable[]", tm.TypeName, "#A3");
932 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[]", tm.TypeFullName, "#A4");
934 tm = Map (typeof (SimpleClassEnumerable[][]));
935 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
936 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
938 Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerable", tm.TypeName, "#B3");
940 Assert.AreEqual ("SimpleClassEnumerable[][]", tm.TypeName, "#B3");
942 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[][]", tm.TypeFullName, "#B4");
944 tm = Map (typeof (SimpleClassEnumerable[][][]));
945 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
946 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
948 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerable", tm.TypeName, "#C3");
950 Assert.AreEqual ("SimpleClassEnumerable[][][]", tm.TypeName, "#C3");
952 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[][][]", tm.TypeFullName, "#C4");
957 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
959 public void TypeMapping_IEnumerable_Object ()
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");
967 tm = Map (typeof (ObjectEnumerable[]));
968 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
969 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
971 Assert.AreEqual ("ArrayOfObjectEnumerable", tm.TypeName, "#A3");
973 Assert.AreEqual ("ObjectEnumerable[]", tm.TypeName, "#A3");
975 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[]", tm.TypeFullName, "#A4");
977 tm = Map (typeof (ObjectEnumerable[][]));
978 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
979 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
981 Assert.AreEqual ("ArrayOfArrayOfObjectEnumerable", tm.TypeName, "#B3");
983 Assert.AreEqual ("ObjectEnumerable[][]", tm.TypeName, "#B3");
985 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[][]", tm.TypeFullName, "#B4");
987 tm = Map (typeof (ObjectEnumerable[][][]));
988 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
989 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
991 Assert.AreEqual ("ArrayOfArrayOfArrayOfObjectEnumerable", tm.TypeName, "#C3");
993 Assert.AreEqual ("ObjectEnumerable[][][]", tm.TypeName, "#C3");
995 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[][][]", tm.TypeFullName, "#C4");
999 [ExpectedException (typeof (InvalidOperationException))]
1000 public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod ()
1002 Map (typeof (ObjectEnumerableNoMatchingAddMethod));
1006 [ExpectedException (typeof (InvalidOperationException))]
1007 public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod_Array ()
1009 Map (typeof (ObjectEnumerableNoMatchingAddMethod[]));
1014 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1016 public void TypeMapping_IEnumerable_SimpleClass_PrivateCurrent ()
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");
1024 tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[]));
1025 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
1026 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1028 Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#A3");
1030 Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[]", tm.TypeName, "#A3");
1032 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[]", tm.TypeFullName, "#A4");
1034 tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[][]));
1035 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
1036 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1038 Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#B3");
1040 Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[][]", tm.TypeName, "#B3");
1042 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[][]", tm.TypeFullName, "#B4");
1044 tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[][][]));
1045 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
1046 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1048 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#C3");
1050 Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[][][]", tm.TypeName, "#C3");
1052 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[][][]", tm.TypeFullName, "#C4");
1057 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1060 [Category ("NotDotNet")] // results in NullReferenceException in .NET 1.1 (SP1)
1062 public void TypeMapping_IEnumerable_SimpleClass_PrivateGetEnumerator ()
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");
1070 tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[]));
1071 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
1072 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1074 Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#A3");
1076 Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[]", tm.TypeName, "#A3");
1078 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[]", tm.TypeFullName, "#A4");
1080 tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[][]));
1081 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
1082 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1084 Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#B3");
1086 Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[][]", tm.TypeName, "#B3");
1088 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[][]", tm.TypeFullName, "#B4");
1090 tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[][][]));
1091 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
1092 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1094 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#C3");
1096 Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[][][]", tm.TypeName, "#C3");
1098 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[][][]", tm.TypeFullName, "#C4");
1102 [ExpectedException (typeof (InvalidOperationException))]
1103 public void TypeMapping_ICollection_Object_NoMatchingAddMethod ()
1105 Map (typeof (ObjectCollectionNoMatchingAddMethod));
1109 [ExpectedException (typeof (InvalidOperationException))]
1110 public void TypeMapping_ICollection_Object_NoMatchingAddMethod_Array ()
1112 Map (typeof (ObjectCollectionNoMatchingAddMethod[]));
1116 [ExpectedException (typeof (InvalidOperationException))]
1117 public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod ()
1119 Map (typeof (SimpleClassCollectionNoMatchingAddMethod));
1123 [ExpectedException (typeof (InvalidOperationException))]
1124 public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod_Array ()
1126 Map (typeof (SimpleClassCollectionNoMatchingAddMethod[]));
1131 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1133 public void TypeMapping_ICollection_SimpleClass ()
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");
1141 tm = Map (typeof (SimpleClassCollection[]));
1142 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
1143 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1145 Assert.AreEqual ("ArrayOfSimpleClassCollection", tm.TypeName, "#A3");
1147 Assert.AreEqual ("SimpleClassCollection[]", tm.TypeName, "#A3");
1149 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[]", tm.TypeFullName, "#A4");
1151 tm = Map (typeof (SimpleClassCollection[][]));
1152 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
1153 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1155 Assert.AreEqual ("ArrayOfArrayOfSimpleClassCollection", tm.TypeName, "#B3");
1157 Assert.AreEqual ("SimpleClassCollection[][]", tm.TypeName, "#B3");
1159 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[][]", tm.TypeFullName, "#B4");
1161 tm = Map (typeof (SimpleClassCollection[][][]));
1162 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
1163 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1165 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassCollection", tm.TypeName, "#C3");
1167 Assert.AreEqual ("SimpleClassCollection[][][]", tm.TypeName, "#C3");
1169 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[][][]", tm.TypeFullName, "#C4");
1174 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1176 public void TypeMapping_ICollection_Object ()
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");
1184 tm = Map (typeof (ObjectCollection[]));
1185 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
1186 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1188 Assert.AreEqual ("ArrayOfObjectCollection", tm.TypeName, "#A3");
1190 Assert.AreEqual ("ObjectCollection[]", tm.TypeName, "#A3");
1192 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[]", tm.TypeFullName, "#A4");
1194 tm = Map (typeof (ObjectCollection[][]));
1195 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
1196 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1198 Assert.AreEqual ("ArrayOfArrayOfObjectCollection", tm.TypeName, "#B3");
1200 Assert.AreEqual ("ObjectCollection[][]", tm.TypeName, "#B3");
1202 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[][]", tm.TypeFullName, "#B4");
1204 tm = Map (typeof (ObjectCollection[][][]));
1205 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
1206 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1208 Assert.AreEqual ("ArrayOfArrayOfArrayOfObjectCollection", tm.TypeName, "#C3");
1210 Assert.AreEqual ("ObjectCollection[][][]", tm.TypeName, "#C3");
1212 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[][][]", tm.TypeFullName, "#C4");
1216 [ExpectedException (typeof (InvalidOperationException))]
1217 public void TypeMapping_ICollection_Object_NoIntIndexer ()
1219 Map (typeof (ObjectCollectionNoIntIndexer));
1223 [ExpectedException (typeof (InvalidOperationException))]
1224 public void TypeMapping_ICollection_Object_NoIntIndexer_Array ()
1226 Map (typeof (ObjectCollectionNoIntIndexer[]));
1230 [ExpectedException (typeof (InvalidOperationException))]
1231 public void TypeMapping_ICollection_SimpleClass_NoIntIndexer ()
1233 Map (typeof (SimpleClassCollectionNoIntIndexer));
1237 [ExpectedException (typeof (InvalidOperationException))]
1238 public void TypeMapping_ICollection_SimpleClass_NoIntIndexer_Array ()
1240 Map (typeof (SimpleClassCollectionNoIntIndexer[]));
1244 public void TypeMapping_InvalidDefault ()
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);
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");
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");
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");
1275 attrs.XmlDefaultValue = "2"; // not of the same type as the underlying enum type (System.Int32)
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");
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");
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
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");
1303 attrs.XmlDefaultValue = EnumDefaultValueNF.e2; // other enum type
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");
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");
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");
1331 attrs.XmlDefaultValue = (MapModifiers) 20; // non-existing enum value
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");
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");
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");
1359 [ExpectedException (typeof (ArgumentNullException))]
1360 public void TypeMapping_Null ()
1366 [ExpectedException (typeof (NotSupportedException))]
1367 public void TypeMapping_Void ()
1369 Map (typeof (void));
1373 public void TypeMapping_WrongChoices ()
1376 Map (typeof (WrongChoices));
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");
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");
1389 // Type MonoTests.System.Xml.TestClasses.ItemChoiceType is missing
1390 // enumeration value 'StrangeOne' for element 'StrangeOne' from
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");
1399 [Test] // bug #77591
1400 public void TypeMapping_XmlText_PrimitiveTypes ()
1402 XmlAttributeOverrides overrides = null;
1403 XmlAttributes attrs = null;
1405 overrides = new XmlAttributeOverrides ();
1406 attrs = new XmlAttributes ();
1407 attrs.XmlText = new XmlTextAttribute (typeof (int));
1408 overrides.Add (typeof (Field), "Modifiers", attrs);
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");
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");
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");
1429 overrides = new XmlAttributeOverrides ();
1430 attrs = new XmlAttributes ();
1431 attrs.XmlText = new XmlTextAttribute (typeof (int));
1432 overrides.Add (typeof (Field), "Street", attrs);
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");
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");
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");
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);
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);
1467 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1468 public void TestImportMembersMapping()
1470 Type type = typeof(SimpleClass);
1471 XmlAttributes attrs = new XmlAttributes();
1472 XmlAttributeOverrides overrides = new XmlAttributeOverrides();
1473 overrides.Add(typeof(SimpleClass), attrs);
1475 XmlReflectionMember[] members = new XmlReflectionMember[0];
1476 XmlMembersMapping mm;
1479 mm = MembersMap(type, overrides, members, true);
1480 Assert.Fail("Should not be able to fetch an empty XmlMembersMapping");
1486 XmlReflectionMember rm = new XmlReflectionMember();
1487 rm.IsReturnValue = false;
1488 rm.MemberName = "something";
1489 rm.MemberType = typeof(string);
1490 members = new XmlReflectionMember[1];
1493 mm = MembersMap(type, overrides, members, false);
1495 Equals(mm.Count, 1);
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");
1505 Assert.AreEqual (XmlSchemaNamespace, smm.TypeNamespace, "#7");
1507 Assert.IsNull (smm.TypeNamespace, "#7");
1510 rm = new XmlReflectionMember();
1511 rm.IsReturnValue = false;
1512 rm.MemberName = "nothing";
1513 rm.MemberType = typeof(string);
1514 members = new XmlReflectionMember[1];
1517 mm = MembersMap(type, overrides, members, false);
1518 Assert.AreEqual (1, mm.Count, "#8");
1522 public void TestIntTypeMappingWithXmlRootAttribute()
1524 const string TheNamespace = "another:urn";
1525 XmlRootAttribute root = new XmlRootAttribute("price");
1526 root.Namespace = TheNamespace;
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");
1536 [ExpectedException (typeof (InvalidOperationException))]
1537 public void TestSerializeWrongChoice ()
1539 new XmlSerializer (typeof(WrongChoices));
1543 public void XmlArrayOnByteArray ()
1545 new XmlSerializer (typeof (XmlArrayOnByteArrayType));
1551 public void ImportNullableInt ()
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");
1566 public void ImportNullableContainer ()
1568 new XmlSerializer (typeof (NullableContainer));
1572 public void ImportNullableContainer2 ()
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);
1580 XmlSchema schema = schemas [0];
1581 XmlSchemaComplexType el = schema.Items [1] as XmlSchemaComplexType;
1583 XmlSchemaSequence s = el.Particle as XmlSchemaSequence;
1584 XmlSchemaElement el2 = s.Items [0] as XmlSchemaElement;
1585 Assert.IsTrue (el2.IsNillable);
1589 [ExpectedException (typeof (InvalidOperationException))]
1590 public void ImportGenericTypeDefinition ()
1592 new XmlSerializer (typeof (List<int>).GetGenericTypeDefinition ());
1596 [ExpectedException (typeof (InvalidOperationException))]
1597 public void XmlSchemaProviderMissingMethod ()
1599 new XmlSerializer (typeof (XmlSchemaProviderMissingMethodType));
1603 [ExpectedException (typeof (InvalidOperationException))]
1604 public void XmlSchemaProviderMethodNonStatic ()
1606 new XmlSerializer (typeof (XmlSchemaProviderNonStaticType));
1610 [ExpectedException (typeof (InvalidOperationException))]
1611 public void XmlSchemaProviderMethodIncorrectReturn ()
1613 new XmlSerializer (typeof (XmlSchemaProviderIncorrectReturnType));
1617 public void XmlSchemaProviderAndDefaultNamespace ()
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);
1627 public void ImportGenericICollectionWrapped ()
1629 new XmlSerializer (typeof (MyCollection));
1633 public void Bug704813Type ()
1635 var xs = new XmlSerializer (typeof (Bug704813Type));
1636 xs.Serialize (TextWriter.Null, new Bug704813Type ());
1640 public void Bug708178Type()
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);
1649 TextWriter WriteFileStream = new StreamWriter (file, false);
1650 xmlSerializer.Serialize (WriteFileStream, bugType);
1651 WriteFileStream.Close ();
1654 FileStream ReadFileStream = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.Read);
1655 Bug708178Type bugTypeReload = (Bug708178Type)xmlSerializer.Deserialize (ReadFileStream);
1657 //should have deserialized the relationship
1658 Assert.AreEqual(1, bugTypeReload.Foo.Count);
1662 public class Employee : IXmlSerializable
1664 private string _firstName;
1665 private string _lastName;
1666 private string _address;
1668 public XmlSchema GetSchema ()
1673 public void WriteXml (XmlWriter writer)
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 ();
1682 public void ReadXml (XmlReader reader)
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"];
1693 public class NestedStruct
1695 public TimeSpan Period = TimeSpan.MaxValue;
1698 public class ObjectEnumerable : IEnumerable
1700 public void Add (int value)
1704 public void Add (object value)
1708 public IEnumerator GetEnumerator ()
1710 return new ArrayList ().GetEnumerator ();
1714 public class SimpleClassEnumerable : IEnumerable
1716 public void Add (int value)
1720 public void Add (object value)
1724 IEnumerator IEnumerable.GetEnumerator ()
1726 return GetEnumerator ();
1729 public SimpleClassEnumerator GetEnumerator ()
1731 return new SimpleClassEnumerator (new ArrayList ());
1735 public class SimpleClassEnumerablePrivateGetEnumerator : IEnumerable
1737 public void Add (object value)
1741 IEnumerator IEnumerable.GetEnumerator ()
1743 return new ArrayList ().GetEnumerator ();
1747 public class SimpleClassEnumerablePrivateCurrent : IEnumerable
1749 public void Add (object value)
1753 IEnumerator IEnumerable.GetEnumerator ()
1755 return GetEnumerator ();
1758 public NoCurrentEnumerator GetEnumerator ()
1760 return new NoCurrentEnumerator (new ArrayList ());
1764 // GetEnumerator().Current returns object, but there's no corresponding
1765 // Add (System.Object) method
1766 public class ObjectEnumerableNoMatchingAddMethod : IEnumerable
1768 public void Add (int value)
1772 public IEnumerator GetEnumerator ()
1774 return new ArrayList ().GetEnumerator ();
1778 // GetEnumerator().Current returns SimpleClass, but there's no
1779 // corresponding Add (SimpleClass) method
1780 public class SimpleClassCollectionNoMatchingAddMethod : ICollection
1782 public SimpleClass this[int index]
1786 return (SimpleClass) _list[index];
1792 get { return _list.Count; }
1795 public bool IsSynchronized
1797 get { return _list.IsSynchronized; }
1800 public object SyncRoot
1802 get { return _list.SyncRoot; }
1805 public void CopyTo (Array array, int index)
1807 _list.CopyTo (array, index);
1810 IEnumerator IEnumerable.GetEnumerator ()
1812 return GetEnumerator ();
1815 public SimpleClassEnumerator GetEnumerator ()
1817 return new SimpleClassEnumerator (_list);
1820 private ArrayList _list = new ArrayList ();
1823 // GetEnumerator().Current returns object, but there's no corresponding
1824 // Add (System.Object) method
1825 public class ObjectCollectionNoMatchingAddMethod : ICollection
1827 public object this[int index]
1831 return _list[index];
1837 get { return _list.Count; }
1840 public bool IsSynchronized
1842 get { return _list.IsSynchronized; }
1845 public object SyncRoot
1847 get { return _list.SyncRoot; }
1850 public void CopyTo (Array array, int index)
1852 _list.CopyTo (array, index);
1855 IEnumerator IEnumerable.GetEnumerator ()
1857 return GetEnumerator ();
1860 public IEnumerator GetEnumerator ()
1862 return _list.GetEnumerator ();
1865 private ArrayList _list = new ArrayList ();
1868 // Does not have int indexer.
1869 public class SimpleClassCollectionNoIntIndexer : ICollection
1871 public SimpleClass this[string name]
1875 return new SimpleClass ();
1881 get { return _list.Count; }
1884 public bool IsSynchronized
1886 get { return _list.IsSynchronized; }
1889 public object SyncRoot
1891 get { return _list.SyncRoot; }
1894 public void CopyTo (Array array, int index)
1896 _list.CopyTo (array, index);
1899 IEnumerator IEnumerable.GetEnumerator ()
1901 return GetEnumerator ();
1904 public SimpleClassEnumerator GetEnumerator ()
1906 return new SimpleClassEnumerator (_list);
1909 public void Add (SimpleClass value)
1914 private ArrayList _list = new ArrayList ();
1917 // Does not have int indexer.
1918 public class ObjectCollectionNoIntIndexer : ICollection
1920 public object this[string name]
1924 return new SimpleClass ();
1930 get { return _list.Count; }
1933 public bool IsSynchronized
1935 get { return _list.IsSynchronized; }
1938 public object SyncRoot
1940 get { return _list.SyncRoot; }
1943 public void CopyTo (Array array, int index)
1945 _list.CopyTo (array, index);
1948 public IEnumerator GetEnumerator ()
1950 return _list.GetEnumerator ();
1953 public void Add (object value)
1958 private ArrayList _list = new ArrayList ();
1961 public class SimpleClassCollection : ICollection
1963 public SimpleClass this[int index]
1967 return (SimpleClass) _list[index];
1973 get { return _list.Count; }
1976 public bool IsSynchronized
1978 get { return _list.IsSynchronized; }
1981 public object SyncRoot
1983 get { return _list.SyncRoot; }
1986 public void CopyTo (Array array, int index)
1988 _list.CopyTo (array, index);
1991 IEnumerator IEnumerable.GetEnumerator ()
1993 return GetEnumerator ();
1996 public SimpleClassEnumerator GetEnumerator ()
1998 return new SimpleClassEnumerator (_list);
2001 public void Add (SimpleClass value)
2006 private ArrayList _list = new ArrayList ();
2009 public class ObjectCollection : ICollection
2011 public object this[int name]
2015 return new SimpleClass ();
2021 get { return _list.Count; }
2024 public bool IsSynchronized
2026 get { return _list.IsSynchronized; }
2029 public object SyncRoot
2031 get { return _list.SyncRoot; }
2034 public void CopyTo (Array array, int index)
2036 _list.CopyTo (array, index);
2039 public IEnumerator GetEnumerator ()
2041 return _list.GetEnumerator ();
2044 public void Add (object value)
2049 private ArrayList _list = new ArrayList ();
2052 public class SimpleClassEnumerator : IEnumerator
2054 internal SimpleClassEnumerator (ArrayList arguments)
2056 IEnumerable temp = (IEnumerable) (arguments);
2057 _baseEnumerator = temp.GetEnumerator ();
2059 public SimpleClass Current
2061 get { return (SimpleClass) _baseEnumerator.Current; }
2064 object IEnumerator.Current
2066 get { return _baseEnumerator.Current; }
2069 public bool MoveNext ()
2071 return _baseEnumerator.MoveNext ();
2074 bool IEnumerator.MoveNext ()
2076 return _baseEnumerator.MoveNext ();
2079 public void Reset ()
2081 _baseEnumerator.Reset ();
2084 void IEnumerator.Reset ()
2086 _baseEnumerator.Reset ();
2089 private IEnumerator _baseEnumerator;
2092 public class NoCurrentEnumerator : IEnumerator
2094 internal NoCurrentEnumerator (ArrayList arguments)
2096 IEnumerable temp = (IEnumerable) (arguments);
2097 _baseEnumerator = temp.GetEnumerator ();
2100 object IEnumerator.Current
2102 get { return _baseEnumerator.Current; }
2105 public bool MoveNext ()
2107 return _baseEnumerator.MoveNext ();
2110 bool IEnumerator.MoveNext ()
2112 return _baseEnumerator.MoveNext ();
2115 public void Reset ()
2117 _baseEnumerator.Reset ();
2120 void IEnumerator.Reset ()
2122 _baseEnumerator.Reset ();
2125 private IEnumerator _baseEnumerator;
2128 public class XmlArrayOnByteArrayType
2131 [XmlArrayItem ("Byte", IsNullable =false)]
2132 public byte [] Args;
2136 public class NullableContainer
2138 [XmlElement (IsNullable = true)]
2142 public class NullableContainer2
2146 public int? NullableInt {
2147 get { return value; }
2148 set { this.value = value; }
2152 [XmlSchemaProvider ("GetXsdType")]
2153 public class XmlSchemaProviderMissingMethodType : IXmlSerializable
2155 public void ReadXml (XmlReader reader)
2159 public void WriteXml (XmlWriter writer)
2163 public XmlSchema GetSchema ()
2169 [XmlSchemaProvider ("GetXsdType")]
2170 public class XmlSchemaProviderNonStaticType : IXmlSerializable
2172 public void ReadXml (XmlReader reader)
2176 public void WriteXml (XmlWriter writer)
2180 public XmlSchema GetSchema ()
2185 public object GetXsdType ()
2191 [XmlSchemaProvider ("GetXsdType")]
2192 public class XmlSchemaProviderIncorrectReturnType : IXmlSerializable
2194 public void ReadXml (XmlReader reader)
2198 public void WriteXml (XmlWriter writer)
2202 public XmlSchema GetSchema ()
2207 public static object GetXsdType ()
2213 [XmlSchemaProvider ("GetXsd")]
2214 public class XmlSchemaProviderAndDefaultNamespaceType : IXmlSerializable
2216 public static XmlQualifiedName GetXsd (XmlSchemaSet xss)
2218 XmlSchema xs = new XmlSchema ();
2219 xs.TargetNamespace = "urn:foo";
2220 XmlSchemaComplexType ct = new XmlSchemaComplexType ();
2224 return new XmlQualifiedName ("foo", "urn:foo");
2227 public void WriteXml (XmlWriter write)
2231 public void ReadXml (XmlReader reader)
2235 public XmlSchema GetSchema ()
2241 public class MyCollection : ICollection<string>
2243 public int Count { get { return 0; } }
2245 public bool IsReadOnly { get { return false; } }
2247 public void Add (string s)
2251 public void Clear ()
2255 public bool Contains (string item)
2260 public void CopyTo (string [] array, int arrayIndex)
2264 public IEnumerator<string> GetEnumerator ()
2266 throw new Exception ();
2269 IEnumerator IEnumerable.GetEnumerator ()
2271 return GetEnumerator ();
2274 public bool Remove (string item)
2281 public class Bug594490Class
2283 [XmlAttribute ("xml:lang")]
2284 public string GroupName;
2288 public void Bug594490_SerializationOfXmlLangAttribute ()
2290 var serializer = new XmlSerializer (typeof(Bug594490Class));
2292 using (var writer = new StringWriter ()) {
2293 var obj = new Bug594490Class ();
2295 obj.GroupName = "hello world";
2297 serializer.Serialize (writer, obj);
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"" />",
2303 "Novell bug #594490 (https://bugzilla.novell.com/show_bug.cgi?id=594490) not fixed.");