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;
16 using System.Xml.Schema;
17 using System.Xml.Serialization;
19 using NUnit.Framework;
21 using System.Collections.Generic;
24 using MonoTests.System.Xml.TestClasses;
26 namespace MonoTests.System.XmlSerialization
31 public static void Print(XmlTypeMapping tm)
33 Console.WriteLine("/XmlTypeMapping:");
34 Console.WriteLine("ElementName: {0} ", tm.ElementName);
35 Console.WriteLine("Namespace: {0} ", tm.Namespace);
36 Console.WriteLine("TypeName: {0} ", tm.TypeName);
37 Console.WriteLine("FullTypeName: {0} ", tm.TypeFullName);
40 public static void Print(XmlMemberMapping mm)
42 Console.WriteLine("/XmlMemberMapping:");
43 Console.WriteLine("Any: {0} ", mm.Any);
44 Console.WriteLine("ElementName: {0} ", mm.ElementName);
45 Console.WriteLine("MemberName: {0} ", mm.MemberName);
46 Console.WriteLine("Namespace: {0} ", mm.Namespace);
47 Console.WriteLine("TypeFullName: {0} ", mm.TypeFullName);
48 Console.WriteLine("TypeName: {0} ", mm.TypeName);
49 Console.WriteLine("TypeNamespace: {0} ", mm.TypeNamespace);
54 public class XmlReflectionImporterTests
56 private const string SomeNamespace = "some:urn";
57 private const string AnotherNamespace = "another:urn";
58 private const string XmlSchemaNamespace = "http://www.w3.org/2001/XMLSchema";
60 // these Map methods re-create the XmlReflectionImporter at every call.
62 private XmlTypeMapping Map(Type t)
64 XmlReflectionImporter ri = new XmlReflectionImporter();
65 XmlTypeMapping tm = ri.ImportTypeMapping(t);
71 private XmlTypeMapping Map(Type t, XmlRootAttribute root)
73 XmlReflectionImporter ri = new XmlReflectionImporter();
74 XmlTypeMapping tm = ri.ImportTypeMapping(t, root);
79 private XmlTypeMapping Map(Type t, string ns)
81 XmlReflectionImporter ri = new XmlReflectionImporter(ns);
82 XmlTypeMapping tm = ri.ImportTypeMapping(t);
88 private XmlTypeMapping Map (Type t, string ns, XmlRootAttribute root)
90 XmlReflectionImporter ri = new XmlReflectionImporter (ns);
91 XmlTypeMapping tm = ri.ImportTypeMapping (t, root);
96 private XmlTypeMapping Map(Type t, XmlAttributeOverrides overrides)
98 XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
99 XmlTypeMapping tm = ri.ImportTypeMapping(t);
105 private XmlMembersMapping MembersMap(Type t, XmlAttributeOverrides overrides,
106 XmlReflectionMember [] members, bool inContainer)
108 XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
109 XmlMembersMapping mm = ri.ImportMembersMapping(null, null, members, inContainer);
115 public void TestIntTypeMapping()
117 XmlTypeMapping tm = Map(typeof(int));
118 Assert.AreEqual ("int", tm.ElementName, "#1");
119 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
120 Assert.AreEqual ("Int32", tm.TypeName, "#3");
121 Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
126 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
128 public void TestIntTypeMapping_Array ()
130 XmlTypeMapping tm = Map(typeof(int[]));
131 Assert.AreEqual ("ArrayOfInt", tm.ElementName, "#A1");
132 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
134 Assert.AreEqual ("ArrayOfInt32", tm.TypeName, "#A3");
136 Assert.AreEqual ("Int32[]", tm.TypeName, "#A3");
138 Assert.AreEqual ("System.Int32[]", tm.TypeFullName, "#A4");
140 tm = Map (typeof (int[][]));
141 Assert.AreEqual ("ArrayOfArrayOfInt", tm.ElementName, "#B1");
142 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
144 Assert.AreEqual ("ArrayOfArrayOfInt32", tm.TypeName, "#B3");
146 Assert.AreEqual ("Int32[][]", tm.TypeName, "#B3");
148 Assert.AreEqual ("System.Int32[][]", tm.TypeFullName, "#B4");
150 tm = Map (typeof (int[][][]));
151 Assert.AreEqual ("ArrayOfArrayOfArrayOfInt", tm.ElementName, "#C1");
152 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
154 Assert.AreEqual ("ArrayOfArrayOfArrayOfInt32", tm.TypeName, "#C3");
156 Assert.AreEqual ("Int32[][][]", tm.TypeName, "#C3");
158 Assert.AreEqual ("System.Int32[][][]", tm.TypeFullName, "#C4");
162 public void TestStringTypeMapping()
164 XmlTypeMapping tm = Map(typeof(string));
165 Assert.AreEqual ("string", tm.ElementName, "#1");
166 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
167 Assert.AreEqual ("String", tm.TypeName, "#3");
168 Assert.AreEqual ("System.String", tm.TypeFullName, "#4");
173 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
175 public void TestStringTypeMapping_Array ()
177 XmlTypeMapping tm = Map (typeof (string[]));
178 Assert.AreEqual ("ArrayOfString", tm.ElementName, "#A1");
179 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
181 Assert.AreEqual ("ArrayOfString", tm.TypeName, "#A3");
183 Assert.AreEqual ("String[]", tm.TypeName, "#A3");
185 Assert.AreEqual ("System.String[]", tm.TypeFullName, "#A4");
187 tm = Map (typeof (string[][]));
188 Assert.AreEqual ("ArrayOfArrayOfString", tm.ElementName, "#B1");
189 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
191 Assert.AreEqual ("ArrayOfArrayOfString", tm.TypeName, "#B3");
193 Assert.AreEqual ("String[][]", tm.TypeName, "#B3");
195 Assert.AreEqual ("System.String[][]", tm.TypeFullName, "#B4");
197 tm = Map (typeof (string[][][]));
198 Assert.AreEqual ("ArrayOfArrayOfArrayOfString", tm.ElementName, "#C1");
199 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
201 Assert.AreEqual ("ArrayOfArrayOfArrayOfString", tm.TypeName, "#C3");
203 Assert.AreEqual ("String[][][]", tm.TypeName, "#C3");
205 Assert.AreEqual ("System.String[][][]", tm.TypeFullName, "#C4");
209 public void TestObjectTypeMapping()
211 XmlTypeMapping tm = Map(typeof(object));
212 Assert.AreEqual ("anyType", tm.ElementName, "#1");
213 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
214 Assert.AreEqual ("Object", tm.TypeName, "#3");
215 Assert.AreEqual ("System.Object", tm.TypeFullName, "#4");
220 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
222 public void TestObjectTypeMapping_Array ()
224 XmlTypeMapping tm = Map (typeof (object[]));
225 Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#A1");
226 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
228 Assert.AreEqual ("ArrayOfObject", tm.TypeName, "#A3");
230 Assert.AreEqual ("Object[]", tm.TypeName, "#A3");
232 Assert.AreEqual ("System.Object[]", tm.TypeFullName, "#A4");
234 tm = Map (typeof (object[][]));
235 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#B1");
236 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
238 Assert.AreEqual ("ArrayOfArrayOfObject", tm.TypeName, "#B3");
240 Assert.AreEqual ("Object[][]", tm.TypeName, "#B3");
242 Assert.AreEqual ("System.Object[][]", tm.TypeFullName, "#B4");
244 tm = Map (typeof (object[][][]));
245 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
246 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
248 Assert.AreEqual ("ArrayOfArrayOfArrayOfObject", tm.TypeName, "#C3");
250 Assert.AreEqual ("Object[][][]", tm.TypeName, "#C3");
252 Assert.AreEqual ("System.Object[][][]", tm.TypeFullName, "#C4");
256 public void TestByteTypeMapping()
258 XmlTypeMapping tm = Map(typeof(byte));
259 Assert.AreEqual ("unsignedByte", tm.ElementName, "#1");
260 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
261 Assert.AreEqual ("Byte", tm.TypeName, "#3");
262 Assert.AreEqual ("System.Byte", tm.TypeFullName, "#4");
267 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
269 public void TestByteTypeMapping_Array ()
271 XmlTypeMapping tm = Map(typeof(byte[]));
272 Assert.AreEqual ("base64Binary", tm.ElementName, "#A1");
273 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
274 Assert.AreEqual ("Byte[]", tm.TypeName, "#A3");
275 Assert.AreEqual ("System.Byte[]", tm.TypeFullName, "#A4");
277 tm = Map (typeof (byte[][]));
278 Assert.AreEqual ("ArrayOfBase64Binary", tm.ElementName, "#B1");
279 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
281 Assert.AreEqual ("ArrayOfArrayOfByte", tm.TypeName, "#B3");
283 Assert.AreEqual ("Byte[][]", tm.TypeName, "#B3");
285 Assert.AreEqual ("System.Byte[][]", tm.TypeFullName, "#B4");
287 tm = Map (typeof (byte[][][]));
288 Assert.AreEqual ("ArrayOfArrayOfBase64Binary", tm.ElementName, "#C1");
289 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
291 Assert.AreEqual ("ArrayOfArrayOfArrayOfByte", tm.TypeName, "#C3");
293 Assert.AreEqual ("Byte[][][]", tm.TypeName, "#C3");
295 Assert.AreEqual ("System.Byte[][][]", tm.TypeFullName, "#C4");
299 public void TestBoolTypeMapping()
301 XmlTypeMapping tm = Map(typeof(bool));
302 Assert.AreEqual ("boolean", tm.ElementName, "#1");
303 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
304 Assert.AreEqual ("Boolean", tm.TypeName, "#3");
305 Assert.AreEqual ("System.Boolean", tm.TypeFullName, "#4");
309 public void TestShortTypeMapping()
311 XmlTypeMapping tm = Map(typeof(short));
312 Assert.AreEqual ("short", tm.ElementName, "#1");
313 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
314 Assert.AreEqual ("Int16", tm.TypeName, "#3");
315 Assert.AreEqual ("System.Int16", tm.TypeFullName, "#4");
319 public void TestUnsignedShortTypeMapping()
321 XmlTypeMapping tm = Map(typeof(ushort));
322 Assert.AreEqual ("unsignedShort", tm.ElementName, "#1");
323 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
324 Assert.AreEqual ("UInt16", tm.TypeName, "#3");
325 Assert.AreEqual ("System.UInt16", tm.TypeFullName, "#4");
329 public void TestUIntTypeMapping()
331 XmlTypeMapping tm = Map(typeof(uint));
332 Assert.AreEqual ("unsignedInt", tm.ElementName, "#1");
333 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
334 Assert.AreEqual ("UInt32", tm.TypeName, "#3");
335 Assert.AreEqual ("System.UInt32", tm.TypeFullName, "#4");
339 public void TestLongTypeMapping()
341 XmlTypeMapping tm = Map(typeof(long));
342 Assert.AreEqual ("long", tm.ElementName, "#1");
343 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
344 Assert.AreEqual ("Int64", tm.TypeName, "#3");
345 Assert.AreEqual ("System.Int64", tm.TypeFullName, "#4");
349 public void TestULongTypeMapping()
351 XmlTypeMapping tm = Map(typeof(ulong));
352 Assert.AreEqual ("unsignedLong", tm.ElementName, "#1");
353 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
354 Assert.AreEqual ("UInt64", tm.TypeName, "#3");
355 Assert.AreEqual ("System.UInt64", tm.TypeFullName, "#4");
359 public void TestFloatTypeMapping()
361 XmlTypeMapping tm = Map(typeof(float));
362 Assert.AreEqual ("float", tm.ElementName, "#1");
363 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
364 Assert.AreEqual ("Single", tm.TypeName, "#3");
365 Assert.AreEqual ("System.Single", tm.TypeFullName, "#4");
369 public void TestDoubleTypeMapping()
371 XmlTypeMapping tm = Map(typeof(double));
372 Assert.AreEqual ("double", tm.ElementName, "#1");
373 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
374 Assert.AreEqual ("Double", tm.TypeName, "#3");
375 Assert.AreEqual ("System.Double", tm.TypeFullName, "#4");
379 public void TestDateTimeTypeMapping()
381 XmlTypeMapping tm = Map(typeof(DateTime));
382 Assert.AreEqual ("dateTime", tm.ElementName, "#1");
383 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
384 Assert.AreEqual ("DateTime", tm.TypeName, "#3");
385 Assert.AreEqual ("System.DateTime", tm.TypeFullName, "#4");
390 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
392 public void TestDateTimeTypeMapping_Array ()
394 XmlTypeMapping tm = Map (typeof (DateTime[]));
395 Assert.AreEqual ("ArrayOfDateTime", tm.ElementName, "#A1");
396 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
398 Assert.AreEqual ("ArrayOfDateTime", tm.TypeName, "#A3");
400 Assert.AreEqual ("DateTime[]", tm.TypeName, "#A3");
402 Assert.AreEqual ("System.DateTime[]", tm.TypeFullName, "#A4");
404 tm = Map (typeof (DateTime[][]));
405 Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.ElementName, "#B1");
406 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
408 Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.TypeName, "#B3");
410 Assert.AreEqual ("DateTime[][]", tm.TypeName, "#B3");
412 Assert.AreEqual ("System.DateTime[][]", tm.TypeFullName, "#B4");
414 tm = Map (typeof (DateTime[][][]));
415 Assert.AreEqual ("ArrayOfArrayOfArrayOfDateTime", tm.ElementName, "#C1");
416 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
418 Assert.AreEqual ("ArrayOfArrayOfArrayOfDateTime", tm.TypeName, "#C3");
420 Assert.AreEqual ("DateTime[][][]", tm.TypeName, "#C3");
422 Assert.AreEqual ("System.DateTime[][][]", tm.TypeFullName, "#C4");
426 public void TestGuidTypeMapping()
428 XmlTypeMapping tm = Map(typeof(Guid));
429 Assert.AreEqual ("guid", tm.ElementName, "#1");
430 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
431 Assert.AreEqual ("Guid", tm.TypeName, "#3");
432 Assert.AreEqual ("System.Guid", tm.TypeFullName, "#4");
437 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
439 public void TestGuidTypeMapping_Array ()
441 XmlTypeMapping tm = Map (typeof (Guid[]));
442 Assert.AreEqual ("ArrayOfGuid", tm.ElementName, "#A1");
443 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
445 Assert.AreEqual ("ArrayOfGuid", tm.TypeName, "#A3");
447 Assert.AreEqual ("Guid[]", tm.TypeName, "#A3");
449 Assert.AreEqual ("System.Guid[]", tm.TypeFullName, "#A4");
451 tm = Map (typeof (Guid[][]));
452 Assert.AreEqual ("ArrayOfArrayOfGuid", tm.ElementName, "#B1");
453 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
455 Assert.AreEqual ("ArrayOfArrayOfGuid", tm.TypeName, "#B3");
457 Assert.AreEqual ("Guid[][]", tm.TypeName, "#B3");
459 Assert.AreEqual ("System.Guid[][]", tm.TypeFullName, "#B4");
461 tm = Map (typeof (Guid[][][]));
462 Assert.AreEqual ("ArrayOfArrayOfArrayOfGuid", tm.ElementName, "#C1");
463 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
465 Assert.AreEqual ("ArrayOfArrayOfArrayOfGuid", tm.TypeName, "#C3");
467 Assert.AreEqual ("Guid[][][]", tm.TypeName, "#C3");
469 Assert.AreEqual ("System.Guid[][][]", tm.TypeFullName, "#C4");
473 public void TestDecimalTypeMapping()
475 XmlTypeMapping tm = Map(typeof(decimal));
476 Assert.AreEqual ("decimal", tm.ElementName, "#1");
477 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
478 Assert.AreEqual ("Decimal", tm.TypeName, "#3");
479 Assert.AreEqual ("System.Decimal", tm.TypeFullName, "#4");
483 public void TestXmlQualifiedNameTypeMapping()
485 XmlTypeMapping tm = Map(typeof(XmlQualifiedName));
486 Assert.AreEqual ("QName", tm.ElementName, "#1");
487 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
488 Assert.AreEqual ("XmlQualifiedName", tm.TypeName, "#3");
489 Assert.AreEqual ("System.Xml.XmlQualifiedName", tm.TypeFullName, "#4");
493 public void TestSByteTypeMapping()
495 XmlTypeMapping tm = Map(typeof(sbyte));
496 Assert.AreEqual ("byte", tm.ElementName, "#1");
497 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
498 Assert.AreEqual ("SByte", tm.TypeName, "#3");
499 Assert.AreEqual ("System.SByte", tm.TypeFullName, "#4");
504 public void TestCharTypeMapping()
506 XmlTypeMapping tm = Map(typeof(char));
507 Assert.AreEqual ("char", tm.ElementName, "#1");
508 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
509 Assert.AreEqual ("Char", tm.TypeName, "#3");
510 Assert.AreEqual ("System.Char", tm.TypeFullName, "#4");
515 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
517 public void TestCharTypeMapping_Array ()
519 XmlTypeMapping tm = Map (typeof (char[]));
520 Assert.AreEqual ("ArrayOfChar", tm.ElementName, "#A1");
521 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
523 Assert.AreEqual ("ArrayOfChar", tm.TypeName, "#A3");
525 Assert.AreEqual ("Char[]", tm.TypeName, "#A3");
527 Assert.AreEqual ("System.Char[]", tm.TypeFullName, "#A4");
529 tm = Map (typeof (char[][]));
530 Assert.AreEqual ("ArrayOfArrayOfChar", tm.ElementName, "#B1");
531 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
533 Assert.AreEqual ("ArrayOfArrayOfChar", tm.TypeName, "#B3");
535 Assert.AreEqual ("Char[][]", tm.TypeName, "#B3");
537 Assert.AreEqual ("System.Char[][]", tm.TypeFullName, "#B4");
539 tm = Map (typeof (char[][][]));
540 Assert.AreEqual ("ArrayOfArrayOfArrayOfChar", tm.ElementName, "#C1");
541 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
543 Assert.AreEqual ("ArrayOfArrayOfArrayOfChar", tm.TypeName, "#C3");
545 Assert.AreEqual ("Char[][][]", tm.TypeName, "#C3");
547 Assert.AreEqual ("System.Char[][][]", tm.TypeFullName, "#C4");
551 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
552 public void TestXmlNodeTypeMapping ()
554 Type type = typeof (XmlNode);
556 XmlTypeMapping tm = Map (type);
557 Assert.AreEqual (string.Empty, tm.ElementName, "#A1");
558 Assert.IsNull (tm.Namespace, "#A2");
559 Assert.AreEqual ("XmlNode", tm.TypeName, "#A3");
560 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#A4");
562 tm = Map (type, AnotherNamespace);
563 Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
564 Assert.IsNull (tm.Namespace, "#B2");
565 Assert.AreEqual ("XmlNode", tm.TypeName, "#B3");
566 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#B4");
568 XmlRootAttribute root = new XmlRootAttribute ("somename");
569 root.Namespace = SomeNamespace;
570 tm = Map (type, root);
571 Assert.AreEqual ("somename", tm.ElementName, "#C1");
572 Assert.IsNull (tm.Namespace, "#C2");
573 Assert.AreEqual ("XmlNode", tm.TypeName, "#C3");
574 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#C4");
576 tm = Map (type, AnotherNamespace, root);
577 Assert.AreEqual ("somename", tm.ElementName, "#D1");
578 Assert.IsNull (tm.Namespace, "#D2");
579 Assert.AreEqual ("XmlNode", tm.TypeName, "#D3");
580 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#D4");
582 root.Namespace = null;
583 tm = Map (type, root);
584 Assert.AreEqual ("somename", tm.ElementName, "#E1");
585 Assert.IsNull (tm.Namespace, "#E2");
586 Assert.AreEqual ("XmlNode", tm.TypeName, "#E3");
587 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#E4");
589 tm = Map (type, AnotherNamespace, root);
590 Assert.AreEqual ("somename", tm.ElementName, "#F1");
591 Assert.IsNull (tm.Namespace, "#F2");
592 Assert.AreEqual ("XmlNode", tm.TypeName, "#F3");
593 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#F4");
597 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
598 public void TestXmlElementTypeMapping ()
600 Type type = typeof (XmlElement);
602 XmlTypeMapping tm = Map (type);
603 Assert.AreEqual (string.Empty, tm.ElementName, "#1");
604 Assert.IsNull (tm.Namespace, "#2");
605 Assert.AreEqual ("XmlElement", tm.TypeName, "#3");
606 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#4");
608 tm = Map (type, AnotherNamespace);
609 Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
610 Assert.IsNull (tm.Namespace, "#B2");
611 Assert.AreEqual ("XmlElement", tm.TypeName, "#B3");
612 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#B4");
614 XmlRootAttribute root = new XmlRootAttribute ("somename");
615 root.Namespace = SomeNamespace;
616 tm = Map (type, root);
617 Assert.AreEqual ("somename", tm.ElementName, "#C1");
618 Assert.IsNull (tm.Namespace, "#C2");
619 Assert.AreEqual ("XmlElement", tm.TypeName, "#C3");
620 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#C4");
622 tm = Map (type, AnotherNamespace, root);
623 Assert.AreEqual ("somename", tm.ElementName, "#D1");
624 Assert.IsNull (tm.Namespace, "#D2");
625 Assert.AreEqual ("XmlElement", tm.TypeName, "#D3");
626 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#D4");
628 root.Namespace = null;
629 tm = Map (type, root);
630 Assert.AreEqual ("somename", tm.ElementName, "#E1");
631 Assert.IsNull (tm.Namespace, "#E2");
632 Assert.AreEqual ("XmlElement", tm.TypeName, "#E3");
633 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#E4");
635 tm = Map (type, AnotherNamespace, root);
636 Assert.AreEqual ("somename", tm.ElementName, "#F1");
637 Assert.IsNull (tm.Namespace, "#F2");
638 Assert.AreEqual ("XmlElement", tm.TypeName, "#F3");
639 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#F4");
643 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
644 public void TestXmlNotationTypeMapping ()
646 Type type = typeof (XmlNotation);
648 XmlTypeMapping tm = Map (type);
649 Assert.AreEqual (string.Empty, tm.ElementName, "#1");
650 Assert.IsNull (tm.Namespace, "#2");
651 Assert.AreEqual ("XmlNotation", tm.TypeName, "#3");
652 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#4");
654 tm = Map (type, AnotherNamespace);
655 Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
656 Assert.IsNull (tm.Namespace, "#B2");
657 Assert.AreEqual ("XmlNotation", tm.TypeName, "#B3");
658 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#B4");
660 XmlRootAttribute root = new XmlRootAttribute ("somename");
661 root.Namespace = SomeNamespace;
662 tm = Map (type, root);
663 Assert.AreEqual ("somename", tm.ElementName, "#C1");
664 Assert.IsNull (tm.Namespace, "#C2");
665 Assert.AreEqual ("XmlNotation", tm.TypeName, "#C3");
666 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#C4");
668 tm = Map (type, AnotherNamespace, root);
669 Assert.AreEqual ("somename", tm.ElementName, "#D1");
670 Assert.IsNull (tm.Namespace, "#D2");
671 Assert.AreEqual ("XmlNotation", tm.TypeName, "#D3");
672 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#D4");
674 root.Namespace = null;
675 tm = Map (type, root);
676 Assert.AreEqual ("somename", tm.ElementName, "#E1");
677 Assert.IsNull (tm.Namespace, "#E2");
678 Assert.AreEqual ("XmlNotation", tm.TypeName, "#E3");
679 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#E4");
681 tm = Map (type, AnotherNamespace, root);
682 Assert.AreEqual ("somename", tm.ElementName, "#F1");
683 Assert.IsNull (tm.Namespace, "#F2");
684 Assert.AreEqual ("XmlNotation", tm.TypeName, "#F3");
685 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#F4");
689 public void TestXmlSerializableTypeMapping ()
691 XmlTypeMapping tm = Map (typeof (Employee));
692 Assert.AreEqual ("Employee", tm.ElementName, "#1");
693 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
694 Assert.AreEqual ("Employee", tm.TypeName, "#3");
695 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee", tm.TypeFullName, "#4");
700 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
702 public void TestXmlSerializableTypeMapping_Array ()
704 XmlTypeMapping tm = Map (typeof (Employee[]));
705 Assert.AreEqual ("ArrayOfEmployee", tm.ElementName, "#A1");
706 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
708 Assert.AreEqual ("ArrayOfEmployee", tm.TypeName, "#A3");
710 Assert.AreEqual ("Employee[]", tm.TypeName, "#A3");
712 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[]", tm.TypeFullName, "#A4");
714 tm = Map (typeof (Employee[][]));
715 Assert.AreEqual ("ArrayOfArrayOfEmployee", tm.ElementName, "#B1");
716 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
718 Assert.AreEqual ("ArrayOfArrayOfEmployee", tm.TypeName, "#B3");
720 Assert.AreEqual ("Employee[][]", tm.TypeName, "#B3");
722 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[][]", tm.TypeFullName, "#B4");
724 tm = Map (typeof (Employee[][][]));
725 Assert.AreEqual ("ArrayOfArrayOfArrayOfEmployee", tm.ElementName, "#C1");
726 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
728 Assert.AreEqual ("ArrayOfArrayOfArrayOfEmployee", tm.TypeName, "#C3");
730 Assert.AreEqual ("Employee[][][]", tm.TypeName, "#C3");
732 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[][][]", tm.TypeFullName, "#C4");
736 public void TestClassTypeMapping_NestedStruct ()
738 XmlTypeMapping tm = Map (typeof (NestedStruct));
739 Assert.AreEqual ("NestedStruct", tm.ElementName, "#1");
740 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
741 Assert.AreEqual ("NestedStruct", tm.TypeName, "#3");
742 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.NestedStruct", tm.TypeFullName, "#4");
746 [ExpectedException (typeof (ArgumentNullException))]
747 public void TestNullTypeMapping()
753 public void TestIntTypeMappingWithDefaultNamespaces()
755 XmlTypeMapping tm = Map(typeof(int), SomeNamespace);
756 Assert.AreEqual ("int", tm.ElementName, "#1");
757 Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
758 Assert.AreEqual ("Int32", tm.TypeName, "#3");
759 Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
763 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
764 public void TestStructTypeMapping ()
766 XmlTypeMapping tm = Map (typeof (TimeSpan));
767 Assert.AreEqual ("TimeSpan", tm.ElementName, "#1");
768 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
769 Assert.AreEqual ("TimeSpan", tm.TypeName, "#3");
770 Assert.AreEqual ("System.TimeSpan", tm.TypeFullName, "#4");
774 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
775 public void TestStructTypeMapping_Array ()
777 XmlTypeMapping tm = Map (typeof (TimeSpan[]));
778 Assert.AreEqual ("ArrayOfTimeSpan", tm.ElementName, "#A1");
779 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
781 Assert.AreEqual ("ArrayOfTimeSpan", tm.TypeName, "#A3");
783 Assert.AreEqual ("TimeSpan[]", tm.TypeName, "#A3");
785 Assert.AreEqual ("System.TimeSpan[]", tm.TypeFullName, "#A4");
787 tm = Map (typeof (TimeSpan[][]));
788 Assert.AreEqual ("ArrayOfArrayOfTimeSpan", tm.ElementName, "#B1");
789 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
791 Assert.AreEqual ("ArrayOfArrayOfTimeSpan", tm.TypeName, "#B3");
793 Assert.AreEqual ("TimeSpan[][]", tm.TypeName, "#B3");
795 Assert.AreEqual ("System.TimeSpan[][]", tm.TypeFullName, "#B4");
797 tm = Map (typeof (TimeSpan[][][]));
798 Assert.AreEqual ("ArrayOfArrayOfArrayOfTimeSpan", tm.ElementName, "#C1");
799 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
801 Assert.AreEqual ("ArrayOfArrayOfArrayOfTimeSpan", tm.TypeName, "#C3");
803 Assert.AreEqual ("TimeSpan[][][]", tm.TypeName, "#C3");
805 Assert.AreEqual ("System.TimeSpan[][][]", tm.TypeFullName, "#C4");
809 public void TestEnumTypeMapping ()
811 XmlTypeMapping tm = Map (typeof (AttributeTargets));
812 Assert.AreEqual ("AttributeTargets", tm.ElementName, "#1");
813 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
814 Assert.AreEqual ("AttributeTargets", tm.TypeName, "#3");
815 Assert.AreEqual ("System.AttributeTargets", tm.TypeFullName, "#4");
820 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
822 public void TestEnumTypeMapping_Array ()
824 XmlTypeMapping tm = Map (typeof (AttributeTargets[]));
825 Assert.AreEqual ("ArrayOfAttributeTargets", tm.ElementName, "#A1");
826 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
828 Assert.AreEqual ("ArrayOfAttributeTargets", tm.TypeName, "#A3");
830 Assert.AreEqual ("AttributeTargets[]", tm.TypeName, "#A3");
832 Assert.AreEqual ("System.AttributeTargets[]", tm.TypeFullName, "#A4");
834 tm = Map (typeof (AttributeTargets[][]));
835 Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.ElementName, "#B1");
836 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
838 Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.TypeName, "#B3");
840 Assert.AreEqual ("AttributeTargets[][]", tm.TypeName, "#B3");
842 Assert.AreEqual ("System.AttributeTargets[][]", tm.TypeFullName, "#B4");
844 tm = Map (typeof (AttributeTargets[][][]));
845 Assert.AreEqual ("ArrayOfArrayOfArrayOfAttributeTargets", tm.ElementName, "#C1");
846 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
848 Assert.AreEqual ("ArrayOfArrayOfArrayOfAttributeTargets", tm.TypeName, "#C3");
850 Assert.AreEqual ("AttributeTargets[][][]", tm.TypeName, "#C3");
852 Assert.AreEqual ("System.AttributeTargets[][][]", tm.TypeFullName, "#C4");
856 public void TestClassTypeMapping()
858 XmlTypeMapping tm = Map (typeof (SimpleClass));
859 Assert.AreEqual ("SimpleClass", tm.ElementName, "#1");
860 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
861 Assert.AreEqual ("SimpleClass", tm.TypeName, "#3");
862 Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass", tm.TypeFullName, "#4");
867 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
869 public void TestClassTypeMapping_Array ()
871 XmlTypeMapping tm = Map (typeof (SimpleClass[]));
872 Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#A1");
873 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
875 Assert.AreEqual ("ArrayOfSimpleClass", tm.TypeName, "#A3");
877 Assert.AreEqual ("SimpleClass[]", tm.TypeName, "#A3");
879 Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[]", tm.TypeFullName, "#A4");
881 tm = Map (typeof (SimpleClass[][]));
882 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
883 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
885 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.TypeName, "#B3");
887 Assert.AreEqual ("SimpleClass[][]", tm.TypeName, "#B3");
889 Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][]", tm.TypeFullName, "#B4");
891 tm = Map (typeof (SimpleClass[][][]));
892 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
893 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
895 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.TypeName, "#C3");
897 Assert.AreEqual ("SimpleClass[][][]", tm.TypeName, "#C3");
899 Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][][]", tm.TypeFullName, "#C4");
903 [ExpectedException (typeof (NotSupportedException))]
904 public void TypeMapping_IDictionary ()
906 // The type MonoTests.System.Xml.TestClasses.DictionaryWithIndexer
907 // is not supported because it implements IDictionary.
908 Map (typeof (DictionaryWithIndexer));
913 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
915 public void TypeMapping_IEnumerable_SimpleClass ()
917 XmlTypeMapping tm = Map (typeof (SimpleClassEnumerable));
918 Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#1");
919 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
920 Assert.AreEqual ("SimpleClassEnumerable", tm.TypeName, "#3");
921 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable", tm.TypeFullName, "#4");
923 tm = Map (typeof (SimpleClassEnumerable[]));
924 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
925 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
927 Assert.AreEqual ("ArrayOfSimpleClassEnumerable", tm.TypeName, "#A3");
929 Assert.AreEqual ("SimpleClassEnumerable[]", tm.TypeName, "#A3");
931 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[]", tm.TypeFullName, "#A4");
933 tm = Map (typeof (SimpleClassEnumerable[][]));
934 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
935 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
937 Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerable", tm.TypeName, "#B3");
939 Assert.AreEqual ("SimpleClassEnumerable[][]", tm.TypeName, "#B3");
941 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[][]", tm.TypeFullName, "#B4");
943 tm = Map (typeof (SimpleClassEnumerable[][][]));
944 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
945 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
947 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerable", tm.TypeName, "#C3");
949 Assert.AreEqual ("SimpleClassEnumerable[][][]", tm.TypeName, "#C3");
951 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[][][]", tm.TypeFullName, "#C4");
956 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
958 public void TypeMapping_IEnumerable_Object ()
960 XmlTypeMapping tm = Map (typeof (ObjectEnumerable));
961 Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
962 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
963 Assert.AreEqual ("ObjectEnumerable", tm.TypeName, "#3");
964 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable", tm.TypeFullName, "#4");
966 tm = Map (typeof (ObjectEnumerable[]));
967 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
968 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
970 Assert.AreEqual ("ArrayOfObjectEnumerable", tm.TypeName, "#A3");
972 Assert.AreEqual ("ObjectEnumerable[]", tm.TypeName, "#A3");
974 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[]", tm.TypeFullName, "#A4");
976 tm = Map (typeof (ObjectEnumerable[][]));
977 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
978 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
980 Assert.AreEqual ("ArrayOfArrayOfObjectEnumerable", tm.TypeName, "#B3");
982 Assert.AreEqual ("ObjectEnumerable[][]", tm.TypeName, "#B3");
984 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[][]", tm.TypeFullName, "#B4");
986 tm = Map (typeof (ObjectEnumerable[][][]));
987 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
988 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
990 Assert.AreEqual ("ArrayOfArrayOfArrayOfObjectEnumerable", tm.TypeName, "#C3");
992 Assert.AreEqual ("ObjectEnumerable[][][]", tm.TypeName, "#C3");
994 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[][][]", tm.TypeFullName, "#C4");
998 [ExpectedException (typeof (InvalidOperationException))]
999 public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod ()
1001 Map (typeof (ObjectEnumerableNoMatchingAddMethod));
1005 [ExpectedException (typeof (InvalidOperationException))]
1006 public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod_Array ()
1008 Map (typeof (ObjectEnumerableNoMatchingAddMethod[]));
1013 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1015 public void TypeMapping_IEnumerable_SimpleClass_PrivateCurrent ()
1017 XmlTypeMapping tm = Map (typeof (SimpleClassEnumerablePrivateCurrent));
1018 Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
1019 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
1020 Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent", tm.TypeName, "#3");
1021 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent", tm.TypeFullName, "#4");
1023 tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[]));
1024 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
1025 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1027 Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#A3");
1029 Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[]", tm.TypeName, "#A3");
1031 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[]", tm.TypeFullName, "#A4");
1033 tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[][]));
1034 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
1035 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1037 Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#B3");
1039 Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[][]", tm.TypeName, "#B3");
1041 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[][]", tm.TypeFullName, "#B4");
1043 tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[][][]));
1044 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
1045 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1047 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#C3");
1049 Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[][][]", tm.TypeName, "#C3");
1051 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[][][]", tm.TypeFullName, "#C4");
1056 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1059 [Category ("NotDotNet")] // results in NullReferenceException in .NET 1.1 (SP1)
1061 public void TypeMapping_IEnumerable_SimpleClass_PrivateGetEnumerator ()
1063 XmlTypeMapping tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator));
1064 Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
1065 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
1066 Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#3");
1067 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator", tm.TypeFullName, "#4");
1069 tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[]));
1070 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
1071 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1073 Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#A3");
1075 Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[]", tm.TypeName, "#A3");
1077 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[]", tm.TypeFullName, "#A4");
1079 tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[][]));
1080 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
1081 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1083 Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#B3");
1085 Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[][]", tm.TypeName, "#B3");
1087 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[][]", tm.TypeFullName, "#B4");
1089 tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[][][]));
1090 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
1091 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1093 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#C3");
1095 Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[][][]", tm.TypeName, "#C3");
1097 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[][][]", tm.TypeFullName, "#C4");
1101 [ExpectedException (typeof (InvalidOperationException))]
1102 public void TypeMapping_ICollection_Object_NoMatchingAddMethod ()
1104 Map (typeof (ObjectCollectionNoMatchingAddMethod));
1108 [ExpectedException (typeof (InvalidOperationException))]
1109 public void TypeMapping_ICollection_Object_NoMatchingAddMethod_Array ()
1111 Map (typeof (ObjectCollectionNoMatchingAddMethod[]));
1115 [ExpectedException (typeof (InvalidOperationException))]
1116 public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod ()
1118 Map (typeof (SimpleClassCollectionNoMatchingAddMethod));
1122 [ExpectedException (typeof (InvalidOperationException))]
1123 public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod_Array ()
1125 Map (typeof (SimpleClassCollectionNoMatchingAddMethod[]));
1130 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1132 public void TypeMapping_ICollection_SimpleClass ()
1134 XmlTypeMapping tm = Map (typeof (SimpleClassCollection));
1135 Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#1");
1136 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
1137 Assert.AreEqual ("SimpleClassCollection", tm.TypeName, "#3");
1138 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection", tm.TypeFullName, "#4");
1140 tm = Map (typeof (SimpleClassCollection[]));
1141 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
1142 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1144 Assert.AreEqual ("ArrayOfSimpleClassCollection", tm.TypeName, "#A3");
1146 Assert.AreEqual ("SimpleClassCollection[]", tm.TypeName, "#A3");
1148 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[]", tm.TypeFullName, "#A4");
1150 tm = Map (typeof (SimpleClassCollection[][]));
1151 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
1152 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1154 Assert.AreEqual ("ArrayOfArrayOfSimpleClassCollection", tm.TypeName, "#B3");
1156 Assert.AreEqual ("SimpleClassCollection[][]", tm.TypeName, "#B3");
1158 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[][]", tm.TypeFullName, "#B4");
1160 tm = Map (typeof (SimpleClassCollection[][][]));
1161 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
1162 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1164 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassCollection", tm.TypeName, "#C3");
1166 Assert.AreEqual ("SimpleClassCollection[][][]", tm.TypeName, "#C3");
1168 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[][][]", tm.TypeFullName, "#C4");
1173 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1175 public void TypeMapping_ICollection_Object ()
1177 XmlTypeMapping tm = Map (typeof (ObjectCollection));
1178 Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
1179 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
1180 Assert.AreEqual ("ObjectCollection", tm.TypeName, "#3");
1181 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection", tm.TypeFullName, "#4");
1183 tm = Map (typeof (ObjectCollection[]));
1184 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
1185 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
1187 Assert.AreEqual ("ArrayOfObjectCollection", tm.TypeName, "#A3");
1189 Assert.AreEqual ("ObjectCollection[]", tm.TypeName, "#A3");
1191 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[]", tm.TypeFullName, "#A4");
1193 tm = Map (typeof (ObjectCollection[][]));
1194 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
1195 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
1197 Assert.AreEqual ("ArrayOfArrayOfObjectCollection", tm.TypeName, "#B3");
1199 Assert.AreEqual ("ObjectCollection[][]", tm.TypeName, "#B3");
1201 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[][]", tm.TypeFullName, "#B4");
1203 tm = Map (typeof (ObjectCollection[][][]));
1204 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
1205 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
1207 Assert.AreEqual ("ArrayOfArrayOfArrayOfObjectCollection", tm.TypeName, "#C3");
1209 Assert.AreEqual ("ObjectCollection[][][]", tm.TypeName, "#C3");
1211 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[][][]", tm.TypeFullName, "#C4");
1215 [ExpectedException (typeof (InvalidOperationException))]
1216 public void TypeMapping_ICollection_Object_NoIntIndexer ()
1218 Map (typeof (ObjectCollectionNoIntIndexer));
1222 [ExpectedException (typeof (InvalidOperationException))]
1223 public void TypeMapping_ICollection_Object_NoIntIndexer_Array ()
1225 Map (typeof (ObjectCollectionNoIntIndexer[]));
1229 [ExpectedException (typeof (InvalidOperationException))]
1230 public void TypeMapping_ICollection_SimpleClass_NoIntIndexer ()
1232 Map (typeof (SimpleClassCollectionNoIntIndexer));
1236 [ExpectedException (typeof (InvalidOperationException))]
1237 public void TypeMapping_ICollection_SimpleClass_NoIntIndexer_Array ()
1239 Map (typeof (SimpleClassCollectionNoIntIndexer[]));
1243 public void TypeMapping_InvalidDefault ()
1245 XmlAttributes attrs = new XmlAttributes (typeof (Field).GetMember ("Modifiers") [0]);
1246 attrs.XmlDefaultValue = 2; // not a defined enum value
1247 XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
1248 overrides.Add (typeof (Field), "Modifiers", attrs);
1251 Map (typeof (Field), overrides);
1252 Assert.Fail ("#A1");
1253 } catch (InvalidOperationException ex) {
1254 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1255 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1256 Assert.IsNotNull (ex.Message, "#A3");
1257 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#A4");
1258 Assert.IsNotNull (ex.InnerException, "#A5");
1260 // There was an error reflecting field 'Modifiers'
1261 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#A6");
1262 Assert.IsNotNull (ex.InnerException.Message, "#A7");
1263 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#A8");
1264 Assert.IsNotNull (ex.InnerException.InnerException, "#A9");
1266 // Value '2' cannot be converted to System.Int32
1267 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.InnerException.GetType (), "#A10");
1268 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#A11");
1269 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'2'") != -1, "#A12");
1270 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (int).FullName) != -1, "#A13");
1271 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#A14");
1274 attrs.XmlDefaultValue = "2"; // not of the same type as the underlying enum type (System.Int32)
1277 Map (typeof (Field), overrides);
1278 Assert.Fail ("#B1");
1279 } catch (InvalidOperationException ex) {
1280 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1281 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
1282 Assert.IsNotNull (ex.Message, "#B3");
1283 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#B4");
1284 Assert.IsNotNull (ex.InnerException, "#B5");
1286 // There was an error reflecting field 'Modifiers'
1287 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#B6");
1288 Assert.IsNotNull (ex.InnerException.Message, "#B7");
1289 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#B8");
1290 Assert.IsNotNull (ex.InnerException.InnerException, "#B9");
1292 // Enum underlying type and the object must be same type or object.
1293 // Type passed in was 'System.String'; the enum underlying type was
1295 Assert.AreEqual (typeof (ArgumentException), ex.InnerException.InnerException.GetType (), "#B10");
1296 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#B11");
1297 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (string).FullName) != -1, "#B12");
1298 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (int).FullName) != -1, "#B13");
1299 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#B14");
1302 attrs.XmlDefaultValue = EnumDefaultValueNF.e2; // other enum type
1305 Map (typeof (Field), overrides);
1306 Assert.Fail ("#C1");
1307 } catch (InvalidOperationException ex) {
1308 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1309 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
1310 Assert.IsNotNull (ex.Message, "#C3");
1311 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#C4");
1312 Assert.IsNotNull (ex.InnerException, "#C5");
1314 // There was an error reflecting field 'Modifiers'
1315 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#C6");
1316 Assert.IsNotNull (ex.InnerException.Message, "#C7");
1317 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#C8");
1318 Assert.IsNotNull (ex.InnerException.InnerException, "#C9");
1320 // Object must be the same type as the enum. The type passed in
1321 // was MonoTests.System.Xml.TestClasses.EnumDefaultValueNF; the
1322 // enum type was MonoTests.System.Xml.TestClasses.MapModifiers
1323 Assert.AreEqual (typeof (ArgumentException), ex.InnerException.InnerException.GetType (), "#C10");
1324 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#C11");
1325 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (EnumDefaultValueNF).FullName) != -1, "#C12");
1326 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#C13");
1327 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#C14");
1330 attrs.XmlDefaultValue = (MapModifiers) 20; // non-existing enum value
1333 Map (typeof (Field), overrides);
1334 Assert.Fail ("#D1");
1335 } catch (InvalidOperationException ex) {
1336 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1337 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1338 Assert.IsNotNull (ex.Message, "#D3");
1339 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#D4");
1340 Assert.IsNotNull (ex.InnerException, "#D5");
1342 // There was an error reflecting field 'Modifiers'
1343 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#D6");
1344 Assert.IsNotNull (ex.InnerException.Message, "#D7");
1345 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#D8");
1346 Assert.IsNotNull (ex.InnerException.InnerException, "#D9");
1348 // Value '20' cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
1349 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.InnerException.GetType (), "#D10");
1350 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#D11");
1351 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'20'") != -1, "#D12");
1352 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#D13");
1353 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#D14");
1358 [ExpectedException (typeof (ArgumentNullException))]
1359 public void TypeMapping_Null ()
1365 [ExpectedException (typeof (NotSupportedException))]
1366 public void TypeMapping_Void ()
1368 Map (typeof (void));
1372 public void TypeMapping_WrongChoices ()
1375 Map (typeof (WrongChoices));
1377 } catch (InvalidOperationException ex) {
1378 // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.WrongChoices'
1379 Assert.IsNotNull (ex.Message, "#2");
1380 Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (WrongChoices).FullName + "'") != -1, "#3");
1381 Assert.IsNotNull (ex.InnerException, "#4");
1383 // There was an error reflecting field 'MyChoice'
1384 Assert.IsNotNull (ex.InnerException.Message, "#5");
1385 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'MyChoice'") != -1, "#6");
1386 Assert.IsNotNull (ex.InnerException.InnerException, "#7");
1388 // Type MonoTests.System.Xml.TestClasses.ItemChoiceType is missing
1389 // enumeration value 'StrangeOne' for element 'StrangeOne' from
1391 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#8");
1392 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (ItemChoiceType).FullName) != -1, "#9");
1393 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'StrangeOne'") != -1, "#10");
1394 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("''") != -1, "#11");
1398 [Test] // bug #77591
1399 public void TypeMapping_XmlText_PrimitiveTypes ()
1401 XmlAttributeOverrides overrides = null;
1402 XmlAttributes attrs = null;
1404 overrides = new XmlAttributeOverrides ();
1405 attrs = new XmlAttributes ();
1406 attrs.XmlText = new XmlTextAttribute (typeof (int));
1407 overrides.Add (typeof (Field), "Modifiers", attrs);
1410 Map (typeof (Field), overrides);
1411 Assert.Fail ("#A1");
1412 } catch (InvalidOperationException ex) {
1413 // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.Field'
1414 Assert.IsNotNull (ex.Message, "#A2");
1415 Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (Field).FullName + "'") != -1, "#A3");
1416 Assert.IsNotNull (ex.InnerException, "#A4");
1418 // There was an error reflecting field 'Modifiers'
1419 Assert.IsNotNull (ex.InnerException.Message, "#A5");
1420 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#A6");
1421 Assert.IsNotNull (ex.InnerException.InnerException, "#A7");
1423 // The type for XmlText may not be specified for primitive types
1424 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#A8");
1425 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("XmlText") != -1, "#A9");
1428 overrides = new XmlAttributeOverrides ();
1429 attrs = new XmlAttributes ();
1430 attrs.XmlText = new XmlTextAttribute (typeof (int));
1431 overrides.Add (typeof (Field), "Street", attrs);
1434 Map (typeof (Field), overrides);
1435 Assert.Fail ("#B1");
1436 } catch (InvalidOperationException ex) {
1437 // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.Field'
1438 Assert.IsNotNull (ex.Message, "#B2");
1439 Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (Field).FullName + "'") != -1, "#B3");
1440 Assert.IsNotNull (ex.InnerException, "#B4");
1442 // There was an error reflecting field 'Street'
1443 Assert.IsNotNull (ex.InnerException.Message, "#B5");
1444 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Street'") != -1, "#B6");
1445 Assert.IsNotNull (ex.InnerException.InnerException, "#B7");
1447 // The type for XmlText may not be specified for primitive types
1448 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#B8");
1449 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("XmlText") != -1, "#B9");
1452 overrides = new XmlAttributeOverrides ();
1453 attrs = new XmlAttributes ();
1454 attrs.XmlText = new XmlTextAttribute (typeof (MapModifiers));
1455 overrides.Add (typeof (Field), "Modifiers", attrs);
1456 Map (typeof (Field), overrides);
1458 overrides = new XmlAttributeOverrides ();
1459 attrs = new XmlAttributes ();
1460 attrs.XmlText = new XmlTextAttribute (typeof (string));
1461 overrides.Add (typeof (Field), "Street", attrs);
1462 Map (typeof (Field), overrides);
1466 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1467 public void TestImportMembersMapping()
1469 Type type = typeof(SimpleClass);
1470 XmlAttributes attrs = new XmlAttributes();
1471 XmlAttributeOverrides overrides = new XmlAttributeOverrides();
1472 overrides.Add(typeof(SimpleClass), attrs);
1474 XmlReflectionMember[] members = new XmlReflectionMember[0];
1475 XmlMembersMapping mm;
1478 mm = MembersMap(type, overrides, members, true);
1479 Assert.Fail("Should not be able to fetch an empty XmlMembersMapping");
1485 XmlReflectionMember rm = new XmlReflectionMember();
1486 rm.IsReturnValue = false;
1487 rm.MemberName = "something";
1488 rm.MemberType = typeof(string);
1489 members = new XmlReflectionMember[1];
1492 mm = MembersMap(type, overrides, members, false);
1494 Equals(mm.Count, 1);
1496 XmlMemberMapping smm = mm[0];
1497 Assert.IsFalse (smm.Any, "#1");
1498 Assert.AreEqual ("something", smm.ElementName, "#2");
1499 Assert.AreEqual ("something", smm.MemberName, "#3");
1500 Assert.IsNull (smm.Namespace, "#4");
1501 Assert.AreEqual ("System.String", smm.TypeFullName, "#5");
1502 Assert.AreEqual ("string", smm.TypeName, "#6");
1504 Assert.AreEqual (XmlSchemaNamespace, smm.TypeNamespace, "#7");
1506 Assert.IsNull (smm.TypeNamespace, "#7");
1509 rm = new XmlReflectionMember();
1510 rm.IsReturnValue = false;
1511 rm.MemberName = "nothing";
1512 rm.MemberType = typeof(string);
1513 members = new XmlReflectionMember[1];
1516 mm = MembersMap(type, overrides, members, false);
1517 Assert.AreEqual (1, mm.Count, "#8");
1521 public void TestIntTypeMappingWithXmlRootAttribute()
1523 const string TheNamespace = "another:urn";
1524 XmlRootAttribute root = new XmlRootAttribute("price");
1525 root.Namespace = TheNamespace;
1527 XmlTypeMapping tm = Map(typeof(int), root);
1528 Assert.AreEqual ("price", tm.ElementName, "#1");
1529 Assert.AreEqual (TheNamespace, tm.Namespace, "#2");
1530 Assert.AreEqual ("Int32", tm.TypeName, "#3");
1531 Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
1535 [ExpectedException (typeof (InvalidOperationException))]
1536 public void TestSerializeWrongChoice ()
1538 new XmlSerializer (typeof(WrongChoices));
1542 public void XmlArrayOnByteArray ()
1544 new XmlSerializer (typeof (XmlArrayOnByteArrayType));
1550 public void ImportNullableInt ()
1552 XmlReflectionImporter imp = new XmlReflectionImporter ();
1553 XmlTypeMapping map = imp.ImportTypeMapping (typeof (int?));
1554 XmlSchemas schemas = new XmlSchemas ();
1555 XmlSchemaExporter exp = new XmlSchemaExporter (schemas);
1556 exp.ExportTypeMapping (map);
1557 XmlSchema schema = schemas [0];
1558 XmlSchemaElement el = schema.Items [0] as XmlSchemaElement;
1559 Assert.AreEqual ("int", el.Name, "#1");
1560 Assert.AreEqual (new XmlQualifiedName ("int", XmlSchema.Namespace), el.SchemaTypeName, "#2");
1561 Assert.AreEqual (true, el.IsNillable, "#3");
1565 public void ImportNullableContainer ()
1567 new XmlSerializer (typeof (NullableContainer));
1571 public void ImportNullableContainer2 ()
1573 XmlReflectionImporter imp = new XmlReflectionImporter ();
1574 XmlTypeMapping map = imp.ImportTypeMapping (typeof (NullableContainer2));
1575 XmlSchemas schemas = new XmlSchemas ();
1576 XmlSchemaExporter exp = new XmlSchemaExporter (schemas);
1577 exp.ExportTypeMapping (map);
1579 XmlSchema schema = schemas [0];
1580 XmlSchemaComplexType el = schema.Items [1] as XmlSchemaComplexType;
1582 XmlSchemaSequence s = el.Particle as XmlSchemaSequence;
1583 XmlSchemaElement el2 = s.Items [0] as XmlSchemaElement;
1584 Assert.IsTrue (el2.IsNillable);
1588 [ExpectedException (typeof (InvalidOperationException))]
1589 public void ImportGenericTypeDefinition ()
1591 new XmlSerializer (typeof (List<int>).GetGenericTypeDefinition ());
1595 [ExpectedException (typeof (InvalidOperationException))]
1596 public void XmlSchemaProviderMissingMethod ()
1598 new XmlSerializer (typeof (XmlSchemaProviderMissingMethodType));
1602 [ExpectedException (typeof (InvalidOperationException))]
1603 public void XmlSchemaProviderMethodNonStatic ()
1605 new XmlSerializer (typeof (XmlSchemaProviderNonStaticType));
1609 [ExpectedException (typeof (InvalidOperationException))]
1610 public void XmlSchemaProviderMethodIncorrectReturn ()
1612 new XmlSerializer (typeof (XmlSchemaProviderIncorrectReturnType));
1616 public void XmlSchemaProviderAndDefaultNamespace ()
1618 XmlTypeMapping tm = new XmlReflectionImporter ("urn:bar").ImportTypeMapping (typeof (XmlSchemaProviderAndDefaultNamespaceType));
1619 Assert.AreEqual ("foo", tm.ElementName, "#1");
1620 Assert.AreEqual ("foo", tm.XsdTypeName, "#2");
1621 Assert.AreEqual ("urn:bar", tm.Namespace, "#3");
1622 Assert.AreEqual ("urn:foo", tm.XsdTypeNamespace);
1626 public void ImportGenericICollectionWrapped ()
1628 new XmlSerializer (typeof (MyCollection));
1632 public class Employee : IXmlSerializable
1634 private string _firstName;
1635 private string _lastName;
1636 private string _address;
1638 public XmlSchema GetSchema ()
1643 public void WriteXml (XmlWriter writer)
1645 writer.WriteStartElement ("employee", "urn:devx-com");
1646 writer.WriteAttributeString ("firstName", _firstName);
1647 writer.WriteAttributeString ("lastName", _lastName);
1648 writer.WriteAttributeString ("address", _address);
1649 writer.WriteEndElement ();
1652 public void ReadXml (XmlReader reader)
1654 XmlNodeType type = reader.MoveToContent ();
1655 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
1656 _firstName = reader["firstName"];
1657 _lastName = reader["lastName"];
1658 _address = reader["address"];
1663 public class NestedStruct
1665 public TimeSpan Period = TimeSpan.MaxValue;
1668 public class ObjectEnumerable : IEnumerable
1670 public void Add (int value)
1674 public void Add (object value)
1678 public IEnumerator GetEnumerator ()
1680 return new ArrayList ().GetEnumerator ();
1684 public class SimpleClassEnumerable : IEnumerable
1686 public void Add (int value)
1690 public void Add (object value)
1694 IEnumerator IEnumerable.GetEnumerator ()
1696 return GetEnumerator ();
1699 public SimpleClassEnumerator GetEnumerator ()
1701 return new SimpleClassEnumerator (new ArrayList ());
1705 public class SimpleClassEnumerablePrivateGetEnumerator : IEnumerable
1707 public void Add (object value)
1711 IEnumerator IEnumerable.GetEnumerator ()
1713 return new ArrayList ().GetEnumerator ();
1717 public class SimpleClassEnumerablePrivateCurrent : IEnumerable
1719 public void Add (object value)
1723 IEnumerator IEnumerable.GetEnumerator ()
1725 return GetEnumerator ();
1728 public NoCurrentEnumerator GetEnumerator ()
1730 return new NoCurrentEnumerator (new ArrayList ());
1734 // GetEnumerator().Current returns object, but there's no corresponding
1735 // Add (System.Object) method
1736 public class ObjectEnumerableNoMatchingAddMethod : IEnumerable
1738 public void Add (int value)
1742 public IEnumerator GetEnumerator ()
1744 return new ArrayList ().GetEnumerator ();
1748 // GetEnumerator().Current returns SimpleClass, but there's no
1749 // corresponding Add (SimpleClass) method
1750 public class SimpleClassCollectionNoMatchingAddMethod : ICollection
1752 public SimpleClass this[int index]
1756 return (SimpleClass) _list[index];
1762 get { return _list.Count; }
1765 public bool IsSynchronized
1767 get { return _list.IsSynchronized; }
1770 public object SyncRoot
1772 get { return _list.SyncRoot; }
1775 public void CopyTo (Array array, int index)
1777 _list.CopyTo (array, index);
1780 IEnumerator IEnumerable.GetEnumerator ()
1782 return GetEnumerator ();
1785 public SimpleClassEnumerator GetEnumerator ()
1787 return new SimpleClassEnumerator (_list);
1790 private ArrayList _list = new ArrayList ();
1793 // GetEnumerator().Current returns object, but there's no corresponding
1794 // Add (System.Object) method
1795 public class ObjectCollectionNoMatchingAddMethod : ICollection
1797 public object this[int index]
1801 return _list[index];
1807 get { return _list.Count; }
1810 public bool IsSynchronized
1812 get { return _list.IsSynchronized; }
1815 public object SyncRoot
1817 get { return _list.SyncRoot; }
1820 public void CopyTo (Array array, int index)
1822 _list.CopyTo (array, index);
1825 IEnumerator IEnumerable.GetEnumerator ()
1827 return GetEnumerator ();
1830 public IEnumerator GetEnumerator ()
1832 return _list.GetEnumerator ();
1835 private ArrayList _list = new ArrayList ();
1838 // Does not have int indexer.
1839 public class SimpleClassCollectionNoIntIndexer : ICollection
1841 public SimpleClass this[string name]
1845 return new SimpleClass ();
1851 get { return _list.Count; }
1854 public bool IsSynchronized
1856 get { return _list.IsSynchronized; }
1859 public object SyncRoot
1861 get { return _list.SyncRoot; }
1864 public void CopyTo (Array array, int index)
1866 _list.CopyTo (array, index);
1869 IEnumerator IEnumerable.GetEnumerator ()
1871 return GetEnumerator ();
1874 public SimpleClassEnumerator GetEnumerator ()
1876 return new SimpleClassEnumerator (_list);
1879 public void Add (SimpleClass value)
1884 private ArrayList _list = new ArrayList ();
1887 // Does not have int indexer.
1888 public class ObjectCollectionNoIntIndexer : ICollection
1890 public object this[string name]
1894 return new SimpleClass ();
1900 get { return _list.Count; }
1903 public bool IsSynchronized
1905 get { return _list.IsSynchronized; }
1908 public object SyncRoot
1910 get { return _list.SyncRoot; }
1913 public void CopyTo (Array array, int index)
1915 _list.CopyTo (array, index);
1918 public IEnumerator GetEnumerator ()
1920 return _list.GetEnumerator ();
1923 public void Add (object value)
1928 private ArrayList _list = new ArrayList ();
1931 public class SimpleClassCollection : ICollection
1933 public SimpleClass this[int index]
1937 return (SimpleClass) _list[index];
1943 get { return _list.Count; }
1946 public bool IsSynchronized
1948 get { return _list.IsSynchronized; }
1951 public object SyncRoot
1953 get { return _list.SyncRoot; }
1956 public void CopyTo (Array array, int index)
1958 _list.CopyTo (array, index);
1961 IEnumerator IEnumerable.GetEnumerator ()
1963 return GetEnumerator ();
1966 public SimpleClassEnumerator GetEnumerator ()
1968 return new SimpleClassEnumerator (_list);
1971 public void Add (SimpleClass value)
1976 private ArrayList _list = new ArrayList ();
1979 public class ObjectCollection : ICollection
1981 public object this[int name]
1985 return new SimpleClass ();
1991 get { return _list.Count; }
1994 public bool IsSynchronized
1996 get { return _list.IsSynchronized; }
1999 public object SyncRoot
2001 get { return _list.SyncRoot; }
2004 public void CopyTo (Array array, int index)
2006 _list.CopyTo (array, index);
2009 public IEnumerator GetEnumerator ()
2011 return _list.GetEnumerator ();
2014 public void Add (object value)
2019 private ArrayList _list = new ArrayList ();
2022 public class SimpleClassEnumerator : IEnumerator
2024 internal SimpleClassEnumerator (ArrayList arguments)
2026 IEnumerable temp = (IEnumerable) (arguments);
2027 _baseEnumerator = temp.GetEnumerator ();
2029 public SimpleClass Current
2031 get { return (SimpleClass) _baseEnumerator.Current; }
2034 object IEnumerator.Current
2036 get { return _baseEnumerator.Current; }
2039 public bool MoveNext ()
2041 return _baseEnumerator.MoveNext ();
2044 bool IEnumerator.MoveNext ()
2046 return _baseEnumerator.MoveNext ();
2049 public void Reset ()
2051 _baseEnumerator.Reset ();
2054 void IEnumerator.Reset ()
2056 _baseEnumerator.Reset ();
2059 private IEnumerator _baseEnumerator;
2062 public class NoCurrentEnumerator : IEnumerator
2064 internal NoCurrentEnumerator (ArrayList arguments)
2066 IEnumerable temp = (IEnumerable) (arguments);
2067 _baseEnumerator = temp.GetEnumerator ();
2070 object IEnumerator.Current
2072 get { return _baseEnumerator.Current; }
2075 public bool MoveNext ()
2077 return _baseEnumerator.MoveNext ();
2080 bool IEnumerator.MoveNext ()
2082 return _baseEnumerator.MoveNext ();
2085 public void Reset ()
2087 _baseEnumerator.Reset ();
2090 void IEnumerator.Reset ()
2092 _baseEnumerator.Reset ();
2095 private IEnumerator _baseEnumerator;
2098 public class XmlArrayOnByteArrayType
2101 [XmlArrayItem ("Byte", IsNullable =false)]
2102 public byte [] Args;
2106 public class NullableContainer
2108 [XmlElement (IsNullable = true)]
2112 public class NullableContainer2
2116 public int? NullableInt {
2117 get { return value; }
2118 set { this.value = value; }
2122 [XmlSchemaProvider ("GetXsdType")]
2123 public class XmlSchemaProviderMissingMethodType : IXmlSerializable
2125 public void ReadXml (XmlReader reader)
2129 public void WriteXml (XmlWriter writer)
2133 public XmlSchema GetSchema ()
2139 [XmlSchemaProvider ("GetXsdType")]
2140 public class XmlSchemaProviderNonStaticType : IXmlSerializable
2142 public void ReadXml (XmlReader reader)
2146 public void WriteXml (XmlWriter writer)
2150 public XmlSchema GetSchema ()
2155 public object GetXsdType ()
2161 [XmlSchemaProvider ("GetXsdType")]
2162 public class XmlSchemaProviderIncorrectReturnType : IXmlSerializable
2164 public void ReadXml (XmlReader reader)
2168 public void WriteXml (XmlWriter writer)
2172 public XmlSchema GetSchema ()
2177 public static object GetXsdType ()
2183 [XmlSchemaProvider ("GetXsd")]
2184 public class XmlSchemaProviderAndDefaultNamespaceType : IXmlSerializable
2186 public static XmlQualifiedName GetXsd (XmlSchemaSet xss)
2188 XmlSchema xs = new XmlSchema ();
2189 xs.TargetNamespace = "urn:foo";
2190 XmlSchemaComplexType ct = new XmlSchemaComplexType ();
2194 return new XmlQualifiedName ("foo", "urn:foo");
2197 public void WriteXml (XmlWriter write)
2201 public void ReadXml (XmlReader reader)
2205 public XmlSchema GetSchema ()
2211 public class MyCollection : ICollection<string>
2213 public int Count { get { return 0; } }
2215 public bool IsReadOnly { get { return false; } }
2217 public void Add (string s)
2221 public void Clear ()
2225 public bool Contains (string item)
2230 public void CopyTo (string [] array, int arrayIndex)
2234 public IEnumerator<string> GetEnumerator ()
2236 throw new Exception ();
2239 IEnumerator IEnumerable.GetEnumerator ()
2241 return GetEnumerator ();
2244 public bool Remove (string item)