[bcl] Remove ONLY_1_1 defines from class libs
[mono-project.git] / mcs / class / System.XML / Test / System.Xml.Serialization / XmlReflectionImporterTests.cs
blobf4103f14d7d31269148b0a142f05f97e0b136b5d
1 //
2 // System.Xml.Serialization.XmlReflectionImporterTests
3 //
4 // Author:
5 // Erik LeBel (eriklebel@yahoo.ca)
6 //
7 // (C) 2003 Erik LeBel
8 //
9 // FIXME test some of these with Xml Attributes attached to some members:
10 // do the names get carried over to Element for XmlAttributeAttribute and XmlElementAttribute?
11 //
13 using System;
14 using System.Collections;
15 using System.IO;
16 using System.Xml;
17 using System.Xml.Schema;
18 using System.Xml.Serialization;
20 using NUnit.Framework;
21 using System.Collections.Generic;
23 using MonoTests.System.Xml.TestClasses;
25 namespace MonoTests.System.XmlSerialization
27 // debugging class
28 internal class Debug
30 public static void Print(XmlTypeMapping tm)
32 Console.WriteLine("/XmlTypeMapping:");
33 Console.WriteLine("ElementName: {0} ", tm.ElementName);
34 Console.WriteLine("Namespace: {0} ", tm.Namespace);
35 Console.WriteLine("TypeName: {0} ", tm.TypeName);
36 Console.WriteLine("FullTypeName: {0} ", tm.TypeFullName);
39 public static void Print(XmlMemberMapping mm)
41 Console.WriteLine("/XmlMemberMapping:");
42 Console.WriteLine("Any: {0} ", mm.Any);
43 Console.WriteLine("ElementName: {0} ", mm.ElementName);
44 Console.WriteLine("MemberName: {0} ", mm.MemberName);
45 Console.WriteLine("Namespace: {0} ", mm.Namespace);
46 Console.WriteLine("TypeFullName: {0} ", mm.TypeFullName);
47 Console.WriteLine("TypeName: {0} ", mm.TypeName);
48 Console.WriteLine("TypeNamespace: {0} ", mm.TypeNamespace);
52 [TestFixture]
53 public class XmlReflectionImporterTests
55 private const string SomeNamespace = "some:urn";
56 private const string AnotherNamespace = "another:urn";
57 private const string XmlSchemaNamespace = "http://www.w3.org/2001/XMLSchema";
59 // these Map methods re-create the XmlReflectionImporter at every call.
61 private XmlTypeMapping Map(Type t)
63 XmlReflectionImporter ri = new XmlReflectionImporter();
64 XmlTypeMapping tm = ri.ImportTypeMapping(t);
65 //Debug.Print(tm);
67 return tm;
70 private XmlTypeMapping Map(Type t, XmlRootAttribute root)
72 XmlReflectionImporter ri = new XmlReflectionImporter();
73 XmlTypeMapping tm = ri.ImportTypeMapping(t, root);
75 return tm;
78 private XmlTypeMapping Map(Type t, string ns)
80 XmlReflectionImporter ri = new XmlReflectionImporter(ns);
81 XmlTypeMapping tm = ri.ImportTypeMapping(t);
82 //Debug.Print(tm);
84 return tm;
87 private XmlTypeMapping Map (Type t, string ns, XmlRootAttribute root)
89 XmlReflectionImporter ri = new XmlReflectionImporter (ns);
90 XmlTypeMapping tm = ri.ImportTypeMapping (t, root);
92 return tm;
95 private XmlTypeMapping Map(Type t, XmlAttributeOverrides overrides)
97 XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
98 XmlTypeMapping tm = ri.ImportTypeMapping(t);
99 //Debug.Print(tm);
101 return tm;
104 private XmlMembersMapping MembersMap(Type t, XmlAttributeOverrides overrides,
105 XmlReflectionMember [] members, bool inContainer)
107 XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
108 XmlMembersMapping mm = ri.ImportMembersMapping(null, null, members, inContainer);
110 return mm;
113 [Test]
114 public void TestIntTypeMapping()
116 XmlTypeMapping tm = Map(typeof(int));
117 Assert.AreEqual ("int", tm.ElementName, "#1");
118 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
119 Assert.AreEqual ("Int32", tm.TypeName, "#3");
120 Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
123 [Test]
124 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
125 public void TestIntTypeMapping_Array ()
127 XmlTypeMapping tm = Map(typeof(int[]));
128 Assert.AreEqual ("ArrayOfInt", tm.ElementName, "#A1");
129 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
130 Assert.AreEqual ("ArrayOfInt32", tm.TypeName, "#A3");
131 Assert.AreEqual ("System.Int32[]", tm.TypeFullName, "#A4");
133 tm = Map (typeof (int[][]));
134 Assert.AreEqual ("ArrayOfArrayOfInt", tm.ElementName, "#B1");
135 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
136 Assert.AreEqual ("ArrayOfArrayOfInt32", tm.TypeName, "#B3");
137 Assert.AreEqual ("System.Int32[][]", tm.TypeFullName, "#B4");
139 tm = Map (typeof (int[][][]));
140 Assert.AreEqual ("ArrayOfArrayOfArrayOfInt", tm.ElementName, "#C1");
141 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
142 Assert.AreEqual ("ArrayOfArrayOfArrayOfInt32", tm.TypeName, "#C3");
143 Assert.AreEqual ("System.Int32[][][]", tm.TypeFullName, "#C4");
146 [Test]
147 public void TestStringTypeMapping()
149 XmlTypeMapping tm = Map(typeof(string));
150 Assert.AreEqual ("string", tm.ElementName, "#1");
151 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
152 Assert.AreEqual ("String", tm.TypeName, "#3");
153 Assert.AreEqual ("System.String", tm.TypeFullName, "#4");
156 [Test]
157 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
158 public void TestStringTypeMapping_Array ()
160 XmlTypeMapping tm = Map (typeof (string[]));
161 Assert.AreEqual ("ArrayOfString", tm.ElementName, "#A1");
162 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
163 Assert.AreEqual ("ArrayOfString", tm.TypeName, "#A3");
164 Assert.AreEqual ("System.String[]", tm.TypeFullName, "#A4");
166 tm = Map (typeof (string[][]));
167 Assert.AreEqual ("ArrayOfArrayOfString", tm.ElementName, "#B1");
168 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
169 Assert.AreEqual ("ArrayOfArrayOfString", tm.TypeName, "#B3");
170 Assert.AreEqual ("System.String[][]", tm.TypeFullName, "#B4");
172 tm = Map (typeof (string[][][]));
173 Assert.AreEqual ("ArrayOfArrayOfArrayOfString", tm.ElementName, "#C1");
174 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
175 Assert.AreEqual ("ArrayOfArrayOfArrayOfString", tm.TypeName, "#C3");
176 Assert.AreEqual ("System.String[][][]", tm.TypeFullName, "#C4");
179 [Test]
180 public void TestObjectTypeMapping()
182 XmlTypeMapping tm = Map(typeof(object));
183 Assert.AreEqual ("anyType", tm.ElementName, "#1");
184 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
185 Assert.AreEqual ("Object", tm.TypeName, "#3");
186 Assert.AreEqual ("System.Object", tm.TypeFullName, "#4");
189 [Test]
190 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
191 public void TestObjectTypeMapping_Array ()
193 XmlTypeMapping tm = Map (typeof (object[]));
194 Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#A1");
195 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
196 Assert.AreEqual ("ArrayOfObject", tm.TypeName, "#A3");
197 Assert.AreEqual ("System.Object[]", tm.TypeFullName, "#A4");
199 tm = Map (typeof (object[][]));
200 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#B1");
201 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
202 Assert.AreEqual ("ArrayOfArrayOfObject", tm.TypeName, "#B3");
203 Assert.AreEqual ("System.Object[][]", tm.TypeFullName, "#B4");
205 tm = Map (typeof (object[][][]));
206 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
207 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
208 Assert.AreEqual ("ArrayOfArrayOfArrayOfObject", tm.TypeName, "#C3");
209 Assert.AreEqual ("System.Object[][][]", tm.TypeFullName, "#C4");
212 [Test]
213 public void TestByteTypeMapping()
215 XmlTypeMapping tm = Map(typeof(byte));
216 Assert.AreEqual ("unsignedByte", tm.ElementName, "#1");
217 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
218 Assert.AreEqual ("Byte", tm.TypeName, "#3");
219 Assert.AreEqual ("System.Byte", tm.TypeFullName, "#4");
222 [Test]
223 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
224 public void TestByteTypeMapping_Array ()
226 XmlTypeMapping tm = Map(typeof(byte[]));
227 Assert.AreEqual ("base64Binary", tm.ElementName, "#A1");
228 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
229 Assert.AreEqual ("Byte[]", tm.TypeName, "#A3");
230 Assert.AreEqual ("System.Byte[]", tm.TypeFullName, "#A4");
232 tm = Map (typeof (byte[][]));
233 Assert.AreEqual ("ArrayOfBase64Binary", tm.ElementName, "#B1");
234 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
235 Assert.AreEqual ("ArrayOfArrayOfByte", tm.TypeName, "#B3");
236 Assert.AreEqual ("System.Byte[][]", tm.TypeFullName, "#B4");
238 tm = Map (typeof (byte[][][]));
239 Assert.AreEqual ("ArrayOfArrayOfBase64Binary", tm.ElementName, "#C1");
240 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
241 Assert.AreEqual ("ArrayOfArrayOfArrayOfByte", tm.TypeName, "#C3");
242 Assert.AreEqual ("System.Byte[][][]", tm.TypeFullName, "#C4");
245 [Test]
246 public void TestBoolTypeMapping()
248 XmlTypeMapping tm = Map(typeof(bool));
249 Assert.AreEqual ("boolean", tm.ElementName, "#1");
250 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
251 Assert.AreEqual ("Boolean", tm.TypeName, "#3");
252 Assert.AreEqual ("System.Boolean", tm.TypeFullName, "#4");
255 [Test]
256 public void TestShortTypeMapping()
258 XmlTypeMapping tm = Map(typeof(short));
259 Assert.AreEqual ("short", tm.ElementName, "#1");
260 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
261 Assert.AreEqual ("Int16", tm.TypeName, "#3");
262 Assert.AreEqual ("System.Int16", tm.TypeFullName, "#4");
265 [Test]
266 public void TestUnsignedShortTypeMapping()
268 XmlTypeMapping tm = Map(typeof(ushort));
269 Assert.AreEqual ("unsignedShort", tm.ElementName, "#1");
270 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
271 Assert.AreEqual ("UInt16", tm.TypeName, "#3");
272 Assert.AreEqual ("System.UInt16", tm.TypeFullName, "#4");
275 [Test]
276 public void TestUIntTypeMapping()
278 XmlTypeMapping tm = Map(typeof(uint));
279 Assert.AreEqual ("unsignedInt", tm.ElementName, "#1");
280 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
281 Assert.AreEqual ("UInt32", tm.TypeName, "#3");
282 Assert.AreEqual ("System.UInt32", tm.TypeFullName, "#4");
285 [Test]
286 public void TestLongTypeMapping()
288 XmlTypeMapping tm = Map(typeof(long));
289 Assert.AreEqual ("long", tm.ElementName, "#1");
290 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
291 Assert.AreEqual ("Int64", tm.TypeName, "#3");
292 Assert.AreEqual ("System.Int64", tm.TypeFullName, "#4");
295 [Test]
296 public void TestULongTypeMapping()
298 XmlTypeMapping tm = Map(typeof(ulong));
299 Assert.AreEqual ("unsignedLong", tm.ElementName, "#1");
300 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
301 Assert.AreEqual ("UInt64", tm.TypeName, "#3");
302 Assert.AreEqual ("System.UInt64", tm.TypeFullName, "#4");
305 [Test]
306 public void TestFloatTypeMapping()
308 XmlTypeMapping tm = Map(typeof(float));
309 Assert.AreEqual ("float", tm.ElementName, "#1");
310 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
311 Assert.AreEqual ("Single", tm.TypeName, "#3");
312 Assert.AreEqual ("System.Single", tm.TypeFullName, "#4");
315 [Test]
316 public void TestDoubleTypeMapping()
318 XmlTypeMapping tm = Map(typeof(double));
319 Assert.AreEqual ("double", tm.ElementName, "#1");
320 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
321 Assert.AreEqual ("Double", tm.TypeName, "#3");
322 Assert.AreEqual ("System.Double", tm.TypeFullName, "#4");
325 [Test]
326 public void TestDateTimeTypeMapping()
328 XmlTypeMapping tm = Map(typeof(DateTime));
329 Assert.AreEqual ("dateTime", tm.ElementName, "#1");
330 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
331 Assert.AreEqual ("DateTime", tm.TypeName, "#3");
332 Assert.AreEqual ("System.DateTime", tm.TypeFullName, "#4");
335 [Test]
336 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
337 public void TestDateTimeTypeMapping_Array ()
339 XmlTypeMapping tm = Map (typeof (DateTime[]));
340 Assert.AreEqual ("ArrayOfDateTime", tm.ElementName, "#A1");
341 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
342 Assert.AreEqual ("ArrayOfDateTime", tm.TypeName, "#A3");
343 Assert.AreEqual ("System.DateTime[]", tm.TypeFullName, "#A4");
345 tm = Map (typeof (DateTime[][]));
346 Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.ElementName, "#B1");
347 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
348 Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.TypeName, "#B3");
349 Assert.AreEqual ("System.DateTime[][]", tm.TypeFullName, "#B4");
351 tm = Map (typeof (DateTime[][][]));
352 Assert.AreEqual ("ArrayOfArrayOfArrayOfDateTime", tm.ElementName, "#C1");
353 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
354 Assert.AreEqual ("ArrayOfArrayOfArrayOfDateTime", tm.TypeName, "#C3");
355 Assert.AreEqual ("System.DateTime[][][]", tm.TypeFullName, "#C4");
358 [Test]
359 public void TestGuidTypeMapping()
361 XmlTypeMapping tm = Map(typeof(Guid));
362 Assert.AreEqual ("guid", tm.ElementName, "#1");
363 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
364 Assert.AreEqual ("Guid", tm.TypeName, "#3");
365 Assert.AreEqual ("System.Guid", tm.TypeFullName, "#4");
368 [Test]
369 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
370 public void TestGuidTypeMapping_Array ()
372 XmlTypeMapping tm = Map (typeof (Guid[]));
373 Assert.AreEqual ("ArrayOfGuid", tm.ElementName, "#A1");
374 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
375 Assert.AreEqual ("ArrayOfGuid", tm.TypeName, "#A3");
376 Assert.AreEqual ("System.Guid[]", tm.TypeFullName, "#A4");
378 tm = Map (typeof (Guid[][]));
379 Assert.AreEqual ("ArrayOfArrayOfGuid", tm.ElementName, "#B1");
380 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
381 Assert.AreEqual ("ArrayOfArrayOfGuid", tm.TypeName, "#B3");
382 Assert.AreEqual ("System.Guid[][]", tm.TypeFullName, "#B4");
384 tm = Map (typeof (Guid[][][]));
385 Assert.AreEqual ("ArrayOfArrayOfArrayOfGuid", tm.ElementName, "#C1");
386 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
387 Assert.AreEqual ("ArrayOfArrayOfArrayOfGuid", tm.TypeName, "#C3");
388 Assert.AreEqual ("System.Guid[][][]", tm.TypeFullName, "#C4");
391 [Test]
392 public void TestDecimalTypeMapping()
394 XmlTypeMapping tm = Map(typeof(decimal));
395 Assert.AreEqual ("decimal", tm.ElementName, "#1");
396 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
397 Assert.AreEqual ("Decimal", tm.TypeName, "#3");
398 Assert.AreEqual ("System.Decimal", tm.TypeFullName, "#4");
401 [Test]
402 public void TestXmlQualifiedNameTypeMapping()
404 XmlTypeMapping tm = Map(typeof(XmlQualifiedName));
405 Assert.AreEqual ("QName", tm.ElementName, "#1");
406 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
407 Assert.AreEqual ("XmlQualifiedName", tm.TypeName, "#3");
408 Assert.AreEqual ("System.Xml.XmlQualifiedName", tm.TypeFullName, "#4");
411 [Test]
412 public void TestSByteTypeMapping()
414 XmlTypeMapping tm = Map(typeof(sbyte));
415 Assert.AreEqual ("byte", tm.ElementName, "#1");
416 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
417 Assert.AreEqual ("SByte", tm.TypeName, "#3");
418 Assert.AreEqual ("System.SByte", tm.TypeFullName, "#4");
422 [Test]
423 public void TestCharTypeMapping()
425 XmlTypeMapping tm = Map(typeof(char));
426 Assert.AreEqual ("char", tm.ElementName, "#1");
427 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
428 Assert.AreEqual ("Char", tm.TypeName, "#3");
429 Assert.AreEqual ("System.Char", tm.TypeFullName, "#4");
432 [Test]
433 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
434 public void TestCharTypeMapping_Array ()
436 XmlTypeMapping tm = Map (typeof (char[]));
437 Assert.AreEqual ("ArrayOfChar", tm.ElementName, "#A1");
438 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
439 Assert.AreEqual ("ArrayOfChar", tm.TypeName, "#A3");
440 Assert.AreEqual ("System.Char[]", tm.TypeFullName, "#A4");
442 tm = Map (typeof (char[][]));
443 Assert.AreEqual ("ArrayOfArrayOfChar", tm.ElementName, "#B1");
444 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
445 Assert.AreEqual ("ArrayOfArrayOfChar", tm.TypeName, "#B3");
446 Assert.AreEqual ("System.Char[][]", tm.TypeFullName, "#B4");
448 tm = Map (typeof (char[][][]));
449 Assert.AreEqual ("ArrayOfArrayOfArrayOfChar", tm.ElementName, "#C1");
450 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
451 Assert.AreEqual ("ArrayOfArrayOfArrayOfChar", tm.TypeName, "#C3");
452 Assert.AreEqual ("System.Char[][][]", tm.TypeFullName, "#C4");
455 [Test]
456 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
457 public void TestXmlNodeTypeMapping ()
459 Type type = typeof (XmlNode);
461 XmlTypeMapping tm = Map (type);
462 Assert.AreEqual (string.Empty, tm.ElementName, "#A1");
463 Assert.IsNull (tm.Namespace, "#A2");
464 Assert.AreEqual ("XmlNode", tm.TypeName, "#A3");
465 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#A4");
467 tm = Map (type, AnotherNamespace);
468 Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
469 Assert.IsNull (tm.Namespace, "#B2");
470 Assert.AreEqual ("XmlNode", tm.TypeName, "#B3");
471 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#B4");
473 XmlRootAttribute root = new XmlRootAttribute ("somename");
474 root.Namespace = SomeNamespace;
475 tm = Map (type, root);
476 Assert.AreEqual ("somename", tm.ElementName, "#C1");
477 Assert.IsNull (tm.Namespace, "#C2");
478 Assert.AreEqual ("XmlNode", tm.TypeName, "#C3");
479 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#C4");
481 tm = Map (type, AnotherNamespace, root);
482 Assert.AreEqual ("somename", tm.ElementName, "#D1");
483 Assert.IsNull (tm.Namespace, "#D2");
484 Assert.AreEqual ("XmlNode", tm.TypeName, "#D3");
485 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#D4");
487 root.Namespace = null;
488 tm = Map (type, root);
489 Assert.AreEqual ("somename", tm.ElementName, "#E1");
490 Assert.IsNull (tm.Namespace, "#E2");
491 Assert.AreEqual ("XmlNode", tm.TypeName, "#E3");
492 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#E4");
494 tm = Map (type, AnotherNamespace, root);
495 Assert.AreEqual ("somename", tm.ElementName, "#F1");
496 Assert.IsNull (tm.Namespace, "#F2");
497 Assert.AreEqual ("XmlNode", tm.TypeName, "#F3");
498 Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#F4");
501 [Test]
502 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
503 public void TestXmlElementTypeMapping ()
505 Type type = typeof (XmlElement);
507 XmlTypeMapping tm = Map (type);
508 Assert.AreEqual (string.Empty, tm.ElementName, "#1");
509 Assert.IsNull (tm.Namespace, "#2");
510 Assert.AreEqual ("XmlElement", tm.TypeName, "#3");
511 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#4");
513 tm = Map (type, AnotherNamespace);
514 Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
515 Assert.IsNull (tm.Namespace, "#B2");
516 Assert.AreEqual ("XmlElement", tm.TypeName, "#B3");
517 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#B4");
519 XmlRootAttribute root = new XmlRootAttribute ("somename");
520 root.Namespace = SomeNamespace;
521 tm = Map (type, root);
522 Assert.AreEqual ("somename", tm.ElementName, "#C1");
523 Assert.IsNull (tm.Namespace, "#C2");
524 Assert.AreEqual ("XmlElement", tm.TypeName, "#C3");
525 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#C4");
527 tm = Map (type, AnotherNamespace, root);
528 Assert.AreEqual ("somename", tm.ElementName, "#D1");
529 Assert.IsNull (tm.Namespace, "#D2");
530 Assert.AreEqual ("XmlElement", tm.TypeName, "#D3");
531 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#D4");
533 root.Namespace = null;
534 tm = Map (type, root);
535 Assert.AreEqual ("somename", tm.ElementName, "#E1");
536 Assert.IsNull (tm.Namespace, "#E2");
537 Assert.AreEqual ("XmlElement", tm.TypeName, "#E3");
538 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#E4");
540 tm = Map (type, AnotherNamespace, root);
541 Assert.AreEqual ("somename", tm.ElementName, "#F1");
542 Assert.IsNull (tm.Namespace, "#F2");
543 Assert.AreEqual ("XmlElement", tm.TypeName, "#F3");
544 Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#F4");
547 [Test]
548 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
549 public void TestXmlNotationTypeMapping ()
551 Type type = typeof (XmlNotation);
553 XmlTypeMapping tm = Map (type);
554 Assert.AreEqual (string.Empty, tm.ElementName, "#1");
555 Assert.IsNull (tm.Namespace, "#2");
556 Assert.AreEqual ("XmlNotation", tm.TypeName, "#3");
557 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#4");
559 tm = Map (type, AnotherNamespace);
560 Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
561 Assert.IsNull (tm.Namespace, "#B2");
562 Assert.AreEqual ("XmlNotation", tm.TypeName, "#B3");
563 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#B4");
565 XmlRootAttribute root = new XmlRootAttribute ("somename");
566 root.Namespace = SomeNamespace;
567 tm = Map (type, root);
568 Assert.AreEqual ("somename", tm.ElementName, "#C1");
569 Assert.IsNull (tm.Namespace, "#C2");
570 Assert.AreEqual ("XmlNotation", tm.TypeName, "#C3");
571 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#C4");
573 tm = Map (type, AnotherNamespace, root);
574 Assert.AreEqual ("somename", tm.ElementName, "#D1");
575 Assert.IsNull (tm.Namespace, "#D2");
576 Assert.AreEqual ("XmlNotation", tm.TypeName, "#D3");
577 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#D4");
579 root.Namespace = null;
580 tm = Map (type, root);
581 Assert.AreEqual ("somename", tm.ElementName, "#E1");
582 Assert.IsNull (tm.Namespace, "#E2");
583 Assert.AreEqual ("XmlNotation", tm.TypeName, "#E3");
584 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#E4");
586 tm = Map (type, AnotherNamespace, root);
587 Assert.AreEqual ("somename", tm.ElementName, "#F1");
588 Assert.IsNull (tm.Namespace, "#F2");
589 Assert.AreEqual ("XmlNotation", tm.TypeName, "#F3");
590 Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#F4");
593 [Test]
594 public void TestXmlSerializableTypeMapping ()
596 XmlTypeMapping tm = Map (typeof (Employee));
597 Assert.AreEqual ("Employee", tm.ElementName, "#1");
598 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
599 Assert.AreEqual ("Employee", tm.TypeName, "#3");
600 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee", tm.TypeFullName, "#4");
603 [Test]
604 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
605 public void TestXmlSerializableTypeMapping_Array ()
607 XmlTypeMapping tm = Map (typeof (Employee[]));
608 Assert.AreEqual ("ArrayOfEmployee", tm.ElementName, "#A1");
609 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
610 Assert.AreEqual ("ArrayOfEmployee", tm.TypeName, "#A3");
611 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[]", tm.TypeFullName, "#A4");
613 tm = Map (typeof (Employee[][]));
614 Assert.AreEqual ("ArrayOfArrayOfEmployee", tm.ElementName, "#B1");
615 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
616 Assert.AreEqual ("ArrayOfArrayOfEmployee", tm.TypeName, "#B3");
617 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[][]", tm.TypeFullName, "#B4");
619 tm = Map (typeof (Employee[][][]));
620 Assert.AreEqual ("ArrayOfArrayOfArrayOfEmployee", tm.ElementName, "#C1");
621 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
622 Assert.AreEqual ("ArrayOfArrayOfArrayOfEmployee", tm.TypeName, "#C3");
623 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[][][]", tm.TypeFullName, "#C4");
626 [Test]
627 public void TestClassTypeMapping_NestedStruct ()
629 XmlTypeMapping tm = Map (typeof (NestedStruct));
630 Assert.AreEqual ("NestedStruct", tm.ElementName, "#1");
631 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
632 Assert.AreEqual ("NestedStruct", tm.TypeName, "#3");
633 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.NestedStruct", tm.TypeFullName, "#4");
636 [Test]
637 [ExpectedException (typeof (ArgumentNullException))]
638 public void TestNullTypeMapping()
640 Map(null);
643 [Test]
644 public void TestIntTypeMappingWithDefaultNamespaces()
646 XmlTypeMapping tm = Map(typeof(int), SomeNamespace);
647 Assert.AreEqual ("int", tm.ElementName, "#1");
648 Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
649 Assert.AreEqual ("Int32", tm.TypeName, "#3");
650 Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
653 [Test]
654 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
655 public void TestStructTypeMapping ()
657 XmlTypeMapping tm = Map (typeof (TimeSpan));
658 Assert.AreEqual ("TimeSpan", tm.ElementName, "#1");
659 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
660 Assert.AreEqual ("TimeSpan", tm.TypeName, "#3");
661 Assert.AreEqual ("System.TimeSpan", tm.TypeFullName, "#4");
664 [Test]
665 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
666 public void TestStructTypeMapping_Array ()
668 XmlTypeMapping tm = Map (typeof (TimeSpan[]));
669 Assert.AreEqual ("ArrayOfTimeSpan", tm.ElementName, "#A1");
670 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
671 Assert.AreEqual ("ArrayOfTimeSpan", tm.TypeName, "#A3");
672 Assert.AreEqual ("System.TimeSpan[]", tm.TypeFullName, "#A4");
674 tm = Map (typeof (TimeSpan[][]));
675 Assert.AreEqual ("ArrayOfArrayOfTimeSpan", tm.ElementName, "#B1");
676 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
677 Assert.AreEqual ("ArrayOfArrayOfTimeSpan", tm.TypeName, "#B3");
678 Assert.AreEqual ("System.TimeSpan[][]", tm.TypeFullName, "#B4");
680 tm = Map (typeof (TimeSpan[][][]));
681 Assert.AreEqual ("ArrayOfArrayOfArrayOfTimeSpan", tm.ElementName, "#C1");
682 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
683 Assert.AreEqual ("ArrayOfArrayOfArrayOfTimeSpan", tm.TypeName, "#C3");
684 Assert.AreEqual ("System.TimeSpan[][][]", tm.TypeFullName, "#C4");
687 [Test]
688 public void TestEnumTypeMapping ()
690 XmlTypeMapping tm = Map (typeof (AttributeTargets));
691 Assert.AreEqual ("AttributeTargets", tm.ElementName, "#1");
692 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
693 Assert.AreEqual ("AttributeTargets", tm.TypeName, "#3");
694 Assert.AreEqual ("System.AttributeTargets", tm.TypeFullName, "#4");
697 [Test]
698 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
699 public void TestEnumTypeMapping_Array ()
701 XmlTypeMapping tm = Map (typeof (AttributeTargets[]));
702 Assert.AreEqual ("ArrayOfAttributeTargets", tm.ElementName, "#A1");
703 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
704 Assert.AreEqual ("ArrayOfAttributeTargets", tm.TypeName, "#A3");
705 Assert.AreEqual ("System.AttributeTargets[]", tm.TypeFullName, "#A4");
707 tm = Map (typeof (AttributeTargets[][]));
708 Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.ElementName, "#B1");
709 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
710 Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.TypeName, "#B3");
711 Assert.AreEqual ("System.AttributeTargets[][]", tm.TypeFullName, "#B4");
713 tm = Map (typeof (AttributeTargets[][][]));
714 Assert.AreEqual ("ArrayOfArrayOfArrayOfAttributeTargets", tm.ElementName, "#C1");
715 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
716 Assert.AreEqual ("ArrayOfArrayOfArrayOfAttributeTargets", tm.TypeName, "#C3");
717 Assert.AreEqual ("System.AttributeTargets[][][]", tm.TypeFullName, "#C4");
720 [Test]
721 public void TestClassTypeMapping()
723 XmlTypeMapping tm = Map (typeof (SimpleClass));
724 Assert.AreEqual ("SimpleClass", tm.ElementName, "#1");
725 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
726 Assert.AreEqual ("SimpleClass", tm.TypeName, "#3");
727 Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass", tm.TypeFullName, "#4");
730 [Test]
731 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
732 public void TestClassTypeMapping_Array ()
734 XmlTypeMapping tm = Map (typeof (SimpleClass[]));
735 Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#A1");
736 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
737 Assert.AreEqual ("ArrayOfSimpleClass", tm.TypeName, "#A3");
738 Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[]", tm.TypeFullName, "#A4");
740 tm = Map (typeof (SimpleClass[][]));
741 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
742 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
743 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.TypeName, "#B3");
744 Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][]", tm.TypeFullName, "#B4");
746 tm = Map (typeof (SimpleClass[][][]));
747 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
748 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
749 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.TypeName, "#C3");
750 Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][][]", tm.TypeFullName, "#C4");
753 [Test]
754 [ExpectedException (typeof (NotSupportedException))]
755 public void TypeMapping_IDictionary ()
757 // The type MonoTests.System.Xml.TestClasses.DictionaryWithIndexer
758 // is not supported because it implements IDictionary.
759 Map (typeof (DictionaryWithIndexer));
762 [Test]
763 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
764 public void TypeMapping_IEnumerable_SimpleClass ()
766 XmlTypeMapping tm = Map (typeof (SimpleClassEnumerable));
767 Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#1");
768 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
769 Assert.AreEqual ("SimpleClassEnumerable", tm.TypeName, "#3");
770 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable", tm.TypeFullName, "#4");
772 tm = Map (typeof (SimpleClassEnumerable[]));
773 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
774 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
775 Assert.AreEqual ("ArrayOfSimpleClassEnumerable", tm.TypeName, "#A3");
776 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[]", tm.TypeFullName, "#A4");
778 tm = Map (typeof (SimpleClassEnumerable[][]));
779 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
780 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
781 Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerable", tm.TypeName, "#B3");
782 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[][]", tm.TypeFullName, "#B4");
784 tm = Map (typeof (SimpleClassEnumerable[][][]));
785 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
786 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
787 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerable", tm.TypeName, "#C3");
788 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[][][]", tm.TypeFullName, "#C4");
791 [Test]
792 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
793 public void TypeMapping_IEnumerable_Object ()
795 XmlTypeMapping tm = Map (typeof (ObjectEnumerable));
796 Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
797 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
798 Assert.AreEqual ("ObjectEnumerable", tm.TypeName, "#3");
799 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable", tm.TypeFullName, "#4");
801 tm = Map (typeof (ObjectEnumerable[]));
802 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
803 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
804 Assert.AreEqual ("ArrayOfObjectEnumerable", tm.TypeName, "#A3");
805 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[]", tm.TypeFullName, "#A4");
807 tm = Map (typeof (ObjectEnumerable[][]));
808 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
809 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
810 Assert.AreEqual ("ArrayOfArrayOfObjectEnumerable", tm.TypeName, "#B3");
811 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[][]", tm.TypeFullName, "#B4");
813 tm = Map (typeof (ObjectEnumerable[][][]));
814 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
815 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
816 Assert.AreEqual ("ArrayOfArrayOfArrayOfObjectEnumerable", tm.TypeName, "#C3");
817 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[][][]", tm.TypeFullName, "#C4");
820 [Test]
821 [ExpectedException (typeof (InvalidOperationException))]
822 public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod ()
824 Map (typeof (ObjectEnumerableNoMatchingAddMethod));
827 [Test]
828 [ExpectedException (typeof (InvalidOperationException))]
829 public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod_Array ()
831 Map (typeof (ObjectEnumerableNoMatchingAddMethod[]));
834 [Test]
835 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
836 public void TypeMapping_IEnumerable_SimpleClass_PrivateCurrent ()
838 XmlTypeMapping tm = Map (typeof (SimpleClassEnumerablePrivateCurrent));
839 Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
840 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
841 Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent", tm.TypeName, "#3");
842 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent", tm.TypeFullName, "#4");
844 tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[]));
845 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
846 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
847 Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#A3");
848 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[]", tm.TypeFullName, "#A4");
850 tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[][]));
851 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
852 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
853 Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#B3");
854 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[][]", tm.TypeFullName, "#B4");
856 tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[][][]));
857 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
858 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
859 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#C3");
860 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[][][]", tm.TypeFullName, "#C4");
863 [Test]
864 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
865 public void TypeMapping_IEnumerable_SimpleClass_PrivateGetEnumerator ()
867 XmlTypeMapping tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator));
868 Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
869 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
870 Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#3");
871 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator", tm.TypeFullName, "#4");
873 tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[]));
874 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
875 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
876 Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#A3");
877 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[]", tm.TypeFullName, "#A4");
879 tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[][]));
880 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
881 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
882 Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#B3");
883 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[][]", tm.TypeFullName, "#B4");
885 tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[][][]));
886 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
887 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
888 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#C3");
889 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[][][]", tm.TypeFullName, "#C4");
892 [Test]
893 [ExpectedException (typeof (InvalidOperationException))]
894 public void TypeMapping_ICollection_Object_NoMatchingAddMethod ()
896 Map (typeof (ObjectCollectionNoMatchingAddMethod));
899 [Test]
900 [ExpectedException (typeof (InvalidOperationException))]
901 public void TypeMapping_ICollection_Object_NoMatchingAddMethod_Array ()
903 Map (typeof (ObjectCollectionNoMatchingAddMethod[]));
906 [Test]
907 [ExpectedException (typeof (InvalidOperationException))]
908 public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod ()
910 Map (typeof (SimpleClassCollectionNoMatchingAddMethod));
913 [Test]
914 [ExpectedException (typeof (InvalidOperationException))]
915 public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod_Array ()
917 Map (typeof (SimpleClassCollectionNoMatchingAddMethod[]));
920 [Test]
921 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
922 public void TypeMapping_ICollection_SimpleClass ()
924 XmlTypeMapping tm = Map (typeof (SimpleClassCollection));
925 Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#1");
926 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
927 Assert.AreEqual ("SimpleClassCollection", tm.TypeName, "#3");
928 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection", tm.TypeFullName, "#4");
930 tm = Map (typeof (SimpleClassCollection[]));
931 Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
932 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
933 Assert.AreEqual ("ArrayOfSimpleClassCollection", tm.TypeName, "#A3");
934 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[]", tm.TypeFullName, "#A4");
936 tm = Map (typeof (SimpleClassCollection[][]));
937 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
938 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
939 Assert.AreEqual ("ArrayOfArrayOfSimpleClassCollection", tm.TypeName, "#B3");
940 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[][]", tm.TypeFullName, "#B4");
942 tm = Map (typeof (SimpleClassCollection[][][]));
943 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
944 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
945 Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassCollection", tm.TypeName, "#C3");
946 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[][][]", tm.TypeFullName, "#C4");
949 [Test]
950 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
951 public void TypeMapping_ICollection_Object ()
953 XmlTypeMapping tm = Map (typeof (ObjectCollection));
954 Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
955 Assert.AreEqual (string.Empty, tm.Namespace, "#2");
956 Assert.AreEqual ("ObjectCollection", tm.TypeName, "#3");
957 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection", tm.TypeFullName, "#4");
959 tm = Map (typeof (ObjectCollection[]));
960 Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
961 Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
962 Assert.AreEqual ("ArrayOfObjectCollection", tm.TypeName, "#A3");
963 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[]", tm.TypeFullName, "#A4");
965 tm = Map (typeof (ObjectCollection[][]));
966 Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
967 Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
968 Assert.AreEqual ("ArrayOfArrayOfObjectCollection", tm.TypeName, "#B3");
969 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[][]", tm.TypeFullName, "#B4");
971 tm = Map (typeof (ObjectCollection[][][]));
972 Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
973 Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
974 Assert.AreEqual ("ArrayOfArrayOfArrayOfObjectCollection", tm.TypeName, "#C3");
975 Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[][][]", tm.TypeFullName, "#C4");
978 [Test]
979 [ExpectedException (typeof (InvalidOperationException))]
980 public void TypeMapping_ICollection_Object_NoIntIndexer ()
982 Map (typeof (ObjectCollectionNoIntIndexer));
985 [Test]
986 [ExpectedException (typeof (InvalidOperationException))]
987 public void TypeMapping_ICollection_Object_NoIntIndexer_Array ()
989 Map (typeof (ObjectCollectionNoIntIndexer[]));
992 [Test]
993 [ExpectedException (typeof (InvalidOperationException))]
994 public void TypeMapping_ICollection_SimpleClass_NoIntIndexer ()
996 Map (typeof (SimpleClassCollectionNoIntIndexer));
999 [Test]
1000 [ExpectedException (typeof (InvalidOperationException))]
1001 public void TypeMapping_ICollection_SimpleClass_NoIntIndexer_Array ()
1003 Map (typeof (SimpleClassCollectionNoIntIndexer[]));
1006 [Test]
1007 public void TypeMapping_InvalidDefault ()
1009 XmlAttributes attrs = new XmlAttributes (typeof (Field).GetMember ("Modifiers") [0]);
1010 attrs.XmlDefaultValue = 2; // not a defined enum value
1011 XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
1012 overrides.Add (typeof (Field), "Modifiers", attrs);
1014 try {
1015 Map (typeof (Field), overrides);
1016 Assert.Fail ("#A1");
1017 } catch (InvalidOperationException ex) {
1018 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1019 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1020 Assert.IsNotNull (ex.Message, "#A3");
1021 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#A4");
1022 Assert.IsNotNull (ex.InnerException, "#A5");
1024 // There was an error reflecting field 'Modifiers'
1025 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#A6");
1026 Assert.IsNotNull (ex.InnerException.Message, "#A7");
1027 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#A8");
1028 Assert.IsNotNull (ex.InnerException.InnerException, "#A9");
1030 // Value '2' cannot be converted to System.Int32
1031 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.InnerException.GetType (), "#A10");
1032 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#A11");
1033 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'2'") != -1, "#A12");
1034 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (int).FullName) != -1, "#A13");
1035 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#A14");
1038 attrs.XmlDefaultValue = "2"; // not of the same type as the underlying enum type (System.Int32)
1040 try {
1041 Map (typeof (Field), overrides);
1042 Assert.Fail ("#B1");
1043 } catch (InvalidOperationException ex) {
1044 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1045 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
1046 Assert.IsNotNull (ex.Message, "#B3");
1047 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#B4");
1048 Assert.IsNotNull (ex.InnerException, "#B5");
1050 // There was an error reflecting field 'Modifiers'
1051 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#B6");
1052 Assert.IsNotNull (ex.InnerException.Message, "#B7");
1053 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#B8");
1054 Assert.IsNotNull (ex.InnerException.InnerException, "#B9");
1056 // Enum underlying type and the object must be same type or object.
1057 // Type passed in was 'System.String'; the enum underlying type was
1058 // 'System.Int32'.
1059 Assert.AreEqual (typeof (ArgumentException), ex.InnerException.InnerException.GetType (), "#B10");
1060 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#B11");
1061 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (string).FullName) != -1, "#B12");
1062 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (int).FullName) != -1, "#B13");
1063 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#B14");
1066 attrs.XmlDefaultValue = EnumDefaultValueNF.e2; // other enum type
1068 try {
1069 Map (typeof (Field), overrides);
1070 Assert.Fail ("#C1");
1071 } catch (InvalidOperationException ex) {
1072 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1073 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
1074 Assert.IsNotNull (ex.Message, "#C3");
1075 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#C4");
1076 Assert.IsNotNull (ex.InnerException, "#C5");
1078 // There was an error reflecting field 'Modifiers'
1079 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#C6");
1080 Assert.IsNotNull (ex.InnerException.Message, "#C7");
1081 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#C8");
1082 Assert.IsNotNull (ex.InnerException.InnerException, "#C9");
1084 // Object must be the same type as the enum. The type passed in
1085 // was MonoTests.System.Xml.TestClasses.EnumDefaultValueNF; the
1086 // enum type was MonoTests.System.Xml.TestClasses.MapModifiers
1087 Assert.AreEqual (typeof (ArgumentException), ex.InnerException.InnerException.GetType (), "#C10");
1088 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#C11");
1089 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (EnumDefaultValueNF).FullName) != -1, "#C12");
1090 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#C13");
1091 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#C14");
1094 attrs.XmlDefaultValue = (MapModifiers) 20; // non-existing enum value
1096 try {
1097 Map (typeof (Field), overrides);
1098 Assert.Fail ("#D1");
1099 } catch (InvalidOperationException ex) {
1100 // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
1101 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
1102 Assert.IsNotNull (ex.Message, "#D3");
1103 Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#D4");
1104 Assert.IsNotNull (ex.InnerException, "#D5");
1106 // There was an error reflecting field 'Modifiers'
1107 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#D6");
1108 Assert.IsNotNull (ex.InnerException.Message, "#D7");
1109 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#D8");
1110 Assert.IsNotNull (ex.InnerException.InnerException, "#D9");
1112 // Value '20' cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
1113 Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.InnerException.GetType (), "#D10");
1114 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#D11");
1115 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'20'") != -1, "#D12");
1116 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#D13");
1117 Assert.IsNull (ex.InnerException.InnerException.InnerException, "#D14");
1121 [Test]
1122 [ExpectedException (typeof (ArgumentNullException))]
1123 public void TypeMapping_Null ()
1125 Map ((Type) null);
1128 [Test]
1129 [ExpectedException (typeof (NotSupportedException))]
1130 public void TypeMapping_Void ()
1132 Map (typeof (void));
1135 [Test]
1136 public void TypeMapping_WrongChoices ()
1138 try {
1139 Map (typeof (WrongChoices));
1140 Assert.Fail ("#1");
1141 } catch (InvalidOperationException ex) {
1142 // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.WrongChoices'
1143 Assert.IsNotNull (ex.Message, "#2");
1144 Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (WrongChoices).FullName + "'") != -1, "#3");
1145 Assert.IsNotNull (ex.InnerException, "#4");
1147 // There was an error reflecting field 'MyChoice'
1148 Assert.IsNotNull (ex.InnerException.Message, "#5");
1149 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'MyChoice'") != -1, "#6");
1150 Assert.IsNotNull (ex.InnerException.InnerException, "#7");
1152 // Type MonoTests.System.Xml.TestClasses.ItemChoiceType is missing
1153 // enumeration value 'StrangeOne' for element 'StrangeOne' from
1154 // namespace ''.
1155 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#8");
1156 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (ItemChoiceType).FullName) != -1, "#9");
1157 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'StrangeOne'") != -1, "#10");
1158 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("''") != -1, "#11");
1162 [Test] // bug #77591
1163 public void TypeMapping_XmlText_PrimitiveTypes ()
1165 XmlAttributeOverrides overrides = null;
1166 XmlAttributes attrs = null;
1168 overrides = new XmlAttributeOverrides ();
1169 attrs = new XmlAttributes ();
1170 attrs.XmlText = new XmlTextAttribute (typeof (int));
1171 overrides.Add (typeof (Field), "Modifiers", attrs);
1173 try {
1174 Map (typeof (Field), overrides);
1175 Assert.Fail ("#A1");
1176 } catch (InvalidOperationException ex) {
1177 // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.Field'
1178 Assert.IsNotNull (ex.Message, "#A2");
1179 Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (Field).FullName + "'") != -1, "#A3");
1180 Assert.IsNotNull (ex.InnerException, "#A4");
1182 // There was an error reflecting field 'Modifiers'
1183 Assert.IsNotNull (ex.InnerException.Message, "#A5");
1184 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#A6");
1185 Assert.IsNotNull (ex.InnerException.InnerException, "#A7");
1187 // The type for XmlText may not be specified for primitive types
1188 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#A8");
1189 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("XmlText") != -1, "#A9");
1192 overrides = new XmlAttributeOverrides ();
1193 attrs = new XmlAttributes ();
1194 attrs.XmlText = new XmlTextAttribute (typeof (int));
1195 overrides.Add (typeof (Field), "Street", attrs);
1197 try {
1198 Map (typeof (Field), overrides);
1199 Assert.Fail ("#B1");
1200 } catch (InvalidOperationException ex) {
1201 // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.Field'
1202 Assert.IsNotNull (ex.Message, "#B2");
1203 Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (Field).FullName + "'") != -1, "#B3");
1204 Assert.IsNotNull (ex.InnerException, "#B4");
1206 // There was an error reflecting field 'Street'
1207 Assert.IsNotNull (ex.InnerException.Message, "#B5");
1208 Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Street'") != -1, "#B6");
1209 Assert.IsNotNull (ex.InnerException.InnerException, "#B7");
1211 // The type for XmlText may not be specified for primitive types
1212 Assert.IsNotNull (ex.InnerException.InnerException.Message, "#B8");
1213 Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("XmlText") != -1, "#B9");
1216 overrides = new XmlAttributeOverrides ();
1217 attrs = new XmlAttributes ();
1218 attrs.XmlText = new XmlTextAttribute (typeof (MapModifiers));
1219 overrides.Add (typeof (Field), "Modifiers", attrs);
1220 Map (typeof (Field), overrides);
1222 overrides = new XmlAttributeOverrides ();
1223 attrs = new XmlAttributes ();
1224 attrs.XmlText = new XmlTextAttribute (typeof (string));
1225 overrides.Add (typeof (Field), "Street", attrs);
1226 Map (typeof (Field), overrides);
1229 [Test]
1230 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1231 public void TestImportMembersMapping()
1233 Type type = typeof(SimpleClass);
1234 XmlAttributes attrs = new XmlAttributes();
1235 XmlAttributeOverrides overrides = new XmlAttributeOverrides();
1236 overrides.Add(typeof(SimpleClass), attrs);
1238 XmlReflectionMember[] members = new XmlReflectionMember[0];
1239 XmlMembersMapping mm;
1242 mm = MembersMap(type, overrides, members, true);
1243 Assert.Fail("Should not be able to fetch an empty XmlMembersMapping");
1245 catch (Exception)
1249 XmlReflectionMember rm = new XmlReflectionMember();
1250 rm.IsReturnValue = false;
1251 rm.MemberName = "something";
1252 rm.MemberType = typeof(string);
1253 members = new XmlReflectionMember[1];
1254 members[0] = rm;
1256 mm = MembersMap(type, overrides, members, false);
1258 Equals(mm.Count, 1);
1260 XmlMemberMapping smm = mm[0];
1261 Assert.IsFalse (smm.Any, "#1");
1262 Assert.AreEqual ("something", smm.ElementName, "#2");
1263 Assert.AreEqual ("something", smm.MemberName, "#3");
1264 Assert.IsNull (smm.Namespace, "#4");
1265 Assert.AreEqual ("System.String", smm.TypeFullName, "#5");
1266 Assert.AreEqual ("string", smm.TypeName, "#6");
1267 Assert.AreEqual (XmlSchemaNamespace, smm.TypeNamespace, "#7");
1269 rm = new XmlReflectionMember();
1270 rm.IsReturnValue = false;
1271 rm.MemberName = "nothing";
1272 rm.MemberType = typeof(string);
1273 members = new XmlReflectionMember[1];
1274 members[0] = rm;
1276 mm = MembersMap(type, overrides, members, false);
1277 Assert.AreEqual (1, mm.Count, "#8");
1280 [Test]
1281 public void TestIntTypeMappingWithXmlRootAttribute()
1283 const string TheNamespace = "another:urn";
1284 XmlRootAttribute root = new XmlRootAttribute("price");
1285 root.Namespace = TheNamespace;
1287 XmlTypeMapping tm = Map(typeof(int), root);
1288 Assert.AreEqual ("price", tm.ElementName, "#1");
1289 Assert.AreEqual (TheNamespace, tm.Namespace, "#2");
1290 Assert.AreEqual ("Int32", tm.TypeName, "#3");
1291 Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
1294 [Test]
1295 [ExpectedException (typeof (InvalidOperationException))]
1296 public void TestSerializeWrongChoice ()
1298 new XmlSerializer (typeof(WrongChoices));
1301 [Test]
1302 public void XmlArrayOnByteArray ()
1304 new XmlSerializer (typeof (XmlArrayOnByteArrayType));
1308 [Test]
1309 public void ImportNullableInt ()
1311 XmlReflectionImporter imp = new XmlReflectionImporter ();
1312 XmlTypeMapping map = imp.ImportTypeMapping (typeof (int?));
1313 XmlSchemas schemas = new XmlSchemas ();
1314 XmlSchemaExporter exp = new XmlSchemaExporter (schemas);
1315 exp.ExportTypeMapping (map);
1316 XmlSchema schema = schemas [0];
1317 XmlSchemaElement el = schema.Items [0] as XmlSchemaElement;
1318 Assert.AreEqual ("int", el.Name, "#1");
1319 Assert.AreEqual (new XmlQualifiedName ("int", XmlSchema.Namespace), el.SchemaTypeName, "#2");
1320 Assert.AreEqual (true, el.IsNillable, "#3");
1323 [Test]
1324 public void ImportNullableContainer ()
1326 new XmlSerializer (typeof (NullableContainer));
1329 [Test]
1330 public void ImportNullableContainer2 ()
1332 XmlReflectionImporter imp = new XmlReflectionImporter ();
1333 XmlTypeMapping map = imp.ImportTypeMapping (typeof (NullableContainer2));
1334 XmlSchemas schemas = new XmlSchemas ();
1335 XmlSchemaExporter exp = new XmlSchemaExporter (schemas);
1336 exp.ExportTypeMapping (map);
1338 XmlSchema schema = schemas [0];
1339 XmlSchemaComplexType el = schema.Items [1] as XmlSchemaComplexType;
1341 XmlSchemaSequence s = el.Particle as XmlSchemaSequence;
1342 XmlSchemaElement el2 = s.Items [0] as XmlSchemaElement;
1343 Assert.IsTrue (el2.IsNillable);
1346 [Test]
1347 [ExpectedException (typeof (InvalidOperationException))]
1348 public void ImportGenericTypeDefinition ()
1350 new XmlSerializer (typeof (List<int>).GetGenericTypeDefinition ());
1353 [Test]
1354 [ExpectedException (typeof (InvalidOperationException))]
1355 public void XmlSchemaProviderMissingMethod ()
1357 new XmlSerializer (typeof (XmlSchemaProviderMissingMethodType));
1360 [Test]
1361 [ExpectedException (typeof (InvalidOperationException))]
1362 public void XmlSchemaProviderMethodNonStatic ()
1364 new XmlSerializer (typeof (XmlSchemaProviderNonStaticType));
1367 [Test]
1368 [ExpectedException (typeof (InvalidOperationException))]
1369 public void XmlSchemaProviderMethodIncorrectReturn ()
1371 new XmlSerializer (typeof (XmlSchemaProviderIncorrectReturnType));
1374 [Test]
1375 public void XmlSchemaProviderAndDefaultNamespace ()
1377 XmlTypeMapping tm = new XmlReflectionImporter ("urn:bar").ImportTypeMapping (typeof (XmlSchemaProviderAndDefaultNamespaceType));
1378 Assert.AreEqual ("foo", tm.ElementName, "#1");
1379 Assert.AreEqual ("foo", tm.XsdTypeName, "#2");
1380 Assert.AreEqual ("urn:bar", tm.Namespace, "#3");
1381 Assert.AreEqual ("urn:foo", tm.XsdTypeNamespace);
1384 [Test]
1385 public void ImportGenericICollectionWrapped ()
1387 new XmlSerializer (typeof (MyCollection));
1390 [Test]
1391 public void Bug704813Type ()
1393 var xs = new XmlSerializer (typeof (Bug704813Type));
1394 xs.Serialize (TextWriter.Null, new Bug704813Type ());
1397 [Test]
1398 public void Bug708178Type()
1400 string file = Path.Combine (Path.GetTempPath (), "Bug708178Type.xml");
1401 XmlSerializer xmlSerializer = new XmlSerializer (typeof(Bug708178Type));
1402 Bug708178Type bugType = new Bug708178Type ();
1403 bugType.Foo.Add ("test");
1404 Assert.AreEqual (1, bugType.Foo.Count);
1406 //xml Serialize
1407 TextWriter WriteFileStream = new StreamWriter (file, false);
1408 xmlSerializer.Serialize (WriteFileStream, bugType);
1409 WriteFileStream.Close ();
1411 //xml Deserialize
1412 FileStream ReadFileStream = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.Read);
1413 Bug708178Type bugTypeReload = (Bug708178Type)xmlSerializer.Deserialize (ReadFileStream);
1415 //should have deserialized the relationship
1416 Assert.AreEqual(1, bugTypeReload.Foo.Count);
1419 public class Employee : IXmlSerializable
1421 private string _firstName;
1422 private string _lastName;
1423 private string _address;
1425 public XmlSchema GetSchema ()
1427 return null;
1430 public void WriteXml (XmlWriter writer)
1432 writer.WriteStartElement ("employee", "urn:devx-com");
1433 writer.WriteAttributeString ("firstName", _firstName);
1434 writer.WriteAttributeString ("lastName", _lastName);
1435 writer.WriteAttributeString ("address", _address);
1436 writer.WriteEndElement ();
1439 public void ReadXml (XmlReader reader)
1441 XmlNodeType type = reader.MoveToContent ();
1442 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
1443 _firstName = reader["firstName"];
1444 _lastName = reader["lastName"];
1445 _address = reader["address"];
1450 public class NestedStruct
1452 public TimeSpan Period = TimeSpan.MaxValue;
1455 public class ObjectEnumerable : IEnumerable
1457 public void Add (int value)
1461 public void Add (object value)
1465 public IEnumerator GetEnumerator ()
1467 return new ArrayList ().GetEnumerator ();
1471 public class SimpleClassEnumerable : IEnumerable
1473 public void Add (int value)
1477 public void Add (object value)
1481 IEnumerator IEnumerable.GetEnumerator ()
1483 return GetEnumerator ();
1486 public SimpleClassEnumerator GetEnumerator ()
1488 return new SimpleClassEnumerator (new ArrayList ());
1492 public class SimpleClassEnumerablePrivateGetEnumerator : IEnumerable
1494 public void Add (object value)
1498 IEnumerator IEnumerable.GetEnumerator ()
1500 return new ArrayList ().GetEnumerator ();
1504 public class SimpleClassEnumerablePrivateCurrent : IEnumerable
1506 public void Add (object value)
1510 IEnumerator IEnumerable.GetEnumerator ()
1512 return GetEnumerator ();
1515 public NoCurrentEnumerator GetEnumerator ()
1517 return new NoCurrentEnumerator (new ArrayList ());
1521 // GetEnumerator().Current returns object, but there's no corresponding
1522 // Add (System.Object) method
1523 public class ObjectEnumerableNoMatchingAddMethod : IEnumerable
1525 public void Add (int value)
1529 public IEnumerator GetEnumerator ()
1531 return new ArrayList ().GetEnumerator ();
1535 // GetEnumerator().Current returns SimpleClass, but there's no
1536 // corresponding Add (SimpleClass) method
1537 public class SimpleClassCollectionNoMatchingAddMethod : ICollection
1539 public SimpleClass this[int index]
1543 return (SimpleClass) _list[index];
1547 public int Count
1549 get { return _list.Count; }
1552 public bool IsSynchronized
1554 get { return _list.IsSynchronized; }
1557 public object SyncRoot
1559 get { return _list.SyncRoot; }
1562 public void CopyTo (Array array, int index)
1564 _list.CopyTo (array, index);
1567 IEnumerator IEnumerable.GetEnumerator ()
1569 return GetEnumerator ();
1572 public SimpleClassEnumerator GetEnumerator ()
1574 return new SimpleClassEnumerator (_list);
1577 private ArrayList _list = new ArrayList ();
1580 // GetEnumerator().Current returns object, but there's no corresponding
1581 // Add (System.Object) method
1582 public class ObjectCollectionNoMatchingAddMethod : ICollection
1584 public object this[int index]
1588 return _list[index];
1592 public int Count
1594 get { return _list.Count; }
1597 public bool IsSynchronized
1599 get { return _list.IsSynchronized; }
1602 public object SyncRoot
1604 get { return _list.SyncRoot; }
1607 public void CopyTo (Array array, int index)
1609 _list.CopyTo (array, index);
1612 IEnumerator IEnumerable.GetEnumerator ()
1614 return GetEnumerator ();
1617 public IEnumerator GetEnumerator ()
1619 return _list.GetEnumerator ();
1622 private ArrayList _list = new ArrayList ();
1625 // Does not have int indexer.
1626 public class SimpleClassCollectionNoIntIndexer : ICollection
1628 public SimpleClass this[string name]
1632 return new SimpleClass ();
1636 public int Count
1638 get { return _list.Count; }
1641 public bool IsSynchronized
1643 get { return _list.IsSynchronized; }
1646 public object SyncRoot
1648 get { return _list.SyncRoot; }
1651 public void CopyTo (Array array, int index)
1653 _list.CopyTo (array, index);
1656 IEnumerator IEnumerable.GetEnumerator ()
1658 return GetEnumerator ();
1661 public SimpleClassEnumerator GetEnumerator ()
1663 return new SimpleClassEnumerator (_list);
1666 public void Add (SimpleClass value)
1668 _list.Add (value);
1671 private ArrayList _list = new ArrayList ();
1674 // Does not have int indexer.
1675 public class ObjectCollectionNoIntIndexer : ICollection
1677 public object this[string name]
1681 return new SimpleClass ();
1685 public int Count
1687 get { return _list.Count; }
1690 public bool IsSynchronized
1692 get { return _list.IsSynchronized; }
1695 public object SyncRoot
1697 get { return _list.SyncRoot; }
1700 public void CopyTo (Array array, int index)
1702 _list.CopyTo (array, index);
1705 public IEnumerator GetEnumerator ()
1707 return _list.GetEnumerator ();
1710 public void Add (object value)
1712 _list.Add (value);
1715 private ArrayList _list = new ArrayList ();
1718 public class SimpleClassCollection : ICollection
1720 public SimpleClass this[int index]
1724 return (SimpleClass) _list[index];
1728 public int Count
1730 get { return _list.Count; }
1733 public bool IsSynchronized
1735 get { return _list.IsSynchronized; }
1738 public object SyncRoot
1740 get { return _list.SyncRoot; }
1743 public void CopyTo (Array array, int index)
1745 _list.CopyTo (array, index);
1748 IEnumerator IEnumerable.GetEnumerator ()
1750 return GetEnumerator ();
1753 public SimpleClassEnumerator GetEnumerator ()
1755 return new SimpleClassEnumerator (_list);
1758 public void Add (SimpleClass value)
1760 _list.Add (value);
1763 private ArrayList _list = new ArrayList ();
1766 public class ObjectCollection : ICollection
1768 public object this[int name]
1772 return new SimpleClass ();
1776 public int Count
1778 get { return _list.Count; }
1781 public bool IsSynchronized
1783 get { return _list.IsSynchronized; }
1786 public object SyncRoot
1788 get { return _list.SyncRoot; }
1791 public void CopyTo (Array array, int index)
1793 _list.CopyTo (array, index);
1796 public IEnumerator GetEnumerator ()
1798 return _list.GetEnumerator ();
1801 public void Add (object value)
1803 _list.Add (value);
1806 private ArrayList _list = new ArrayList ();
1809 public class SimpleClassEnumerator : IEnumerator
1811 internal SimpleClassEnumerator (ArrayList arguments)
1813 IEnumerable temp = (IEnumerable) (arguments);
1814 _baseEnumerator = temp.GetEnumerator ();
1816 public SimpleClass Current
1818 get { return (SimpleClass) _baseEnumerator.Current; }
1821 object IEnumerator.Current
1823 get { return _baseEnumerator.Current; }
1826 public bool MoveNext ()
1828 return _baseEnumerator.MoveNext ();
1831 bool IEnumerator.MoveNext ()
1833 return _baseEnumerator.MoveNext ();
1836 public void Reset ()
1838 _baseEnumerator.Reset ();
1841 void IEnumerator.Reset ()
1843 _baseEnumerator.Reset ();
1846 private IEnumerator _baseEnumerator;
1849 public class NoCurrentEnumerator : IEnumerator
1851 internal NoCurrentEnumerator (ArrayList arguments)
1853 IEnumerable temp = (IEnumerable) (arguments);
1854 _baseEnumerator = temp.GetEnumerator ();
1857 object IEnumerator.Current
1859 get { return _baseEnumerator.Current; }
1862 public bool MoveNext ()
1864 return _baseEnumerator.MoveNext ();
1867 bool IEnumerator.MoveNext ()
1869 return _baseEnumerator.MoveNext ();
1872 public void Reset ()
1874 _baseEnumerator.Reset ();
1877 void IEnumerator.Reset ()
1879 _baseEnumerator.Reset ();
1882 private IEnumerator _baseEnumerator;
1885 public class XmlArrayOnByteArrayType
1887 [XmlArray]
1888 [XmlArrayItem ("Byte", IsNullable =false)]
1889 public byte [] Args;
1892 public class NullableContainer
1894 [XmlElement (IsNullable = true)]
1895 public int? NilInt;
1898 public class NullableContainer2
1900 int? value;
1902 public int? NullableInt {
1903 get { return value; }
1904 set { this.value = value; }
1908 [XmlSchemaProvider ("GetXsdType")]
1909 public class XmlSchemaProviderMissingMethodType : IXmlSerializable
1911 public void ReadXml (XmlReader reader)
1915 public void WriteXml (XmlWriter writer)
1919 public XmlSchema GetSchema ()
1921 return null;
1925 [XmlSchemaProvider ("GetXsdType")]
1926 public class XmlSchemaProviderNonStaticType : IXmlSerializable
1928 public void ReadXml (XmlReader reader)
1932 public void WriteXml (XmlWriter writer)
1936 public XmlSchema GetSchema ()
1938 return null;
1941 public object GetXsdType ()
1943 return null;
1947 [XmlSchemaProvider ("GetXsdType")]
1948 public class XmlSchemaProviderIncorrectReturnType : IXmlSerializable
1950 public void ReadXml (XmlReader reader)
1954 public void WriteXml (XmlWriter writer)
1958 public XmlSchema GetSchema ()
1960 return null;
1963 public static object GetXsdType ()
1965 return null;
1969 [XmlSchemaProvider ("GetXsd")]
1970 public class XmlSchemaProviderAndDefaultNamespaceType : IXmlSerializable
1972 public static XmlQualifiedName GetXsd (XmlSchemaSet xss)
1974 XmlSchema xs = new XmlSchema ();
1975 xs.TargetNamespace = "urn:foo";
1976 XmlSchemaComplexType ct = new XmlSchemaComplexType ();
1977 ct.Name = "foo";
1978 xs.Items.Add (ct);
1979 xss.Add (xs);
1980 return new XmlQualifiedName ("foo", "urn:foo");
1983 public void WriteXml (XmlWriter write)
1987 public void ReadXml (XmlReader reader)
1991 public XmlSchema GetSchema ()
1993 return null;
1997 public class MyCollection : ICollection<string>
1999 public int Count { get { return 0; } }
2001 public bool IsReadOnly { get { return false; } }
2003 public void Add (string s)
2007 public void Clear ()
2011 public bool Contains (string item)
2013 return false;
2016 public void CopyTo (string [] array, int arrayIndex)
2020 public IEnumerator<string> GetEnumerator ()
2022 throw new Exception ();
2025 IEnumerator IEnumerable.GetEnumerator ()
2027 return GetEnumerator ();
2030 public bool Remove (string item)
2032 return false;
2036 public class Bug594490Class
2038 [XmlAttribute ("xml:lang")]
2039 public string GroupName;
2042 [Test]
2043 public void Bug594490_SerializationOfXmlLangAttribute ()
2045 var serializer = new XmlSerializer (typeof(Bug594490Class));
2047 using (var writer = new StringWriter ()) {
2048 var obj = new Bug594490Class ();
2050 obj.GroupName = "hello world";
2052 serializer.Serialize (writer, obj);
2053 writer.Close ();
2055 Assert.AreEqual (@"<?xml version=""1.0"" encoding=""utf-16""?>
2056 <Bug594490Class xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xml:lang=""hello world"" />",
2057 writer.ToString (),
2058 "Novell bug #594490 (https://bugzilla.novell.com/show_bug.cgi?id=594490) not fixed.");
2063 * The following code was generated from Microsoft's xsd.exe with the /classes switch.
2064 * It only includes the relevent details but was based on the following namespaces:
2065 * urn:oasis:names:tc:SAML:2.0:protocol
2066 * urn:oasis:names:tc:SAML:2.0:assertion
2067 * http://www.w3.org/2000/09/xmldsig#
2068 * http://www.w3.org/2001/04/xmlenc
2071 [XmlTypeAttribute (Namespace = "urn:oasis:names:tc:SAML:2.0:protocol")]
2072 [XmlRootAttribute ("RequestedAuthnContext", Namespace = "urn:oasis:names:tc:SAML:2.0:protocol", IsNullable = false)]
2073 public class RequestedAuthnContext
2075 string[] items;
2076 ItemsChoice7[] itemsElementName;
2078 [XmlElementAttribute ("AuthnContextClassRef", typeof (string), Namespace = "urn:oasis:names:tc:SAML:2.0:assertion", DataType = "anyURI")]
2079 [XmlElementAttribute ("AuthnContextDeclRef", typeof (string), Namespace = "urn:oasis:names:tc:SAML:2.0:assertion", DataType = "anyURI")]
2080 [XmlChoiceIdentifierAttribute ("ItemsElementName")]
2081 public string[] Items {
2082 get { return this.items; }
2083 set { this.items = value; }
2086 [XmlElementAttribute ("ItemsElementName")]
2087 [XmlIgnoreAttribute ()]
2088 public ItemsChoice7[] ItemsElementName {
2089 get { return this.itemsElementName; }
2090 set { this.itemsElementName = value; }
2094 [XmlTypeAttribute (Namespace = "urn:oasis:names:tc:SAML:2.0:protocol", IncludeInSchema = false)]
2095 public enum ItemsChoice7 {
2096 [XmlEnumAttribute ("urn:oasis:names:tc:SAML:2.0:assertion:AuthnContextClassRef")]
2097 AuthnContextClassRef,
2098 [XmlEnumAttribute ("urn:oasis:names:tc:SAML:2.0:assertion:AuthnContextDeclRef")]
2099 AuthnContextDeclRef,
2101 // End snippet from xsd.exe
2103 [Test]
2104 public void FullyQualifiedName_XmlEnumAttribute ()
2106 var serializer = new XmlSerializer (typeof (RequestedAuthnContext));