In corlib/System.Runtime.InteropServices:
[mono.git] / mcs / class / System.XML / Test / System.Xml.Serialization / XmlCodeExporterTests.cs
1 //
2 // System.Xml.Serialization.XmlCodeExporterTests
3 //
4 // Author:
5 //   Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // (C) 2006 Novell
8 // 
9
10 using System;
11 using System.CodeDom;
12 using System.CodeDom.Compiler;
13 using System.Collections;
14 using System.Globalization;
15 using System.IO;
16 #if NET_2_0
17 using System.Reflection;
18 #endif
19 using System.Xml;
20 using System.Xml.Schema;
21 using System.Xml.Serialization;
22
23 using Microsoft.CSharp;
24
25 using NUnit.Framework;
26
27 using MonoTests.System.Xml.TestClasses;
28
29 namespace MonoTests.System.XmlSerialization
30 {
31         [TestFixture]
32         public class XmlCodeExporterTests
33         {
34                 [Test]
35                 public void ExportTypeMapping_ArrayClass ()
36                 {
37                         CodeNamespace codeNamespace = ExportCode (typeof (ArrayClass));
38                         Assert.IsNotNull (codeNamespace, "#1");
39
40                         StringWriter sw = new StringWriter ();
41                         CodeDomProvider provider = new CSharpCodeProvider ();
42                         ICodeGenerator generator = provider.CreateGenerator ();
43                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
44
45                         Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
46                                 "{0}{0}" +
47                                 "/// <remarks/>{0}" +
48 #if NET_2_0
49                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
50                                 "[System.SerializableAttribute()]{0}" +
51                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
52                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
53                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
54                                 "public partial class ArrayClass {{{0}" +
55                                 "    {0}" +
56                                 "    private object namesField;{0}" +
57                                 "    {0}" +
58                                 "    /// <remarks/>{0}" +
59                                 "    public object names {{{0}" +
60                                 "        get {{{0}" +
61                                 "            return this.namesField;{0}" +
62                                 "        }}{0}" +
63                                 "        set {{{0}" +
64                                 "            this.namesField = value;{0}" +
65                                 "        }}{0}" +
66                                 "    }}{0}" +
67                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
68 #else
69                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
70                                 "public class ArrayClass {{{0}" +
71                                 "    {0}" +
72                                 "    /// <remarks/>{0}" +
73                                 "    public object names;{0}" +
74                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
75 #endif
76
77
78                         codeNamespace = ExportCode (typeof (ArrayClass[]));
79                         Assert.IsNotNull (codeNamespace, "#3");
80
81                         sw.GetStringBuilder ().Length = 0;
82                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
83
84                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
85                                 "{0}{0}" +
86                                 "/// <remarks/>{0}" +
87 #if NET_2_0
88                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
89                                 "[System.SerializableAttribute()]{0}" +
90                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
91                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
92                                 "public partial class ArrayClass {{{0}" +
93                                 "    {0}" +
94                                 "    private object namesField;{0}" +
95                                 "    {0}" +
96                                 "    /// <remarks/>{0}" +
97                                 "    public object names {{{0}" +
98                                 "        get {{{0}" +
99                                 "            return this.namesField;{0}" +
100                                 "        }}{0}" +
101                                 "        set {{{0}" +
102                                 "            this.namesField = value;{0}" +
103                                 "        }}{0}" +
104                                 "    }}{0}" +
105                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#4");
106 #else
107                                 "public class ArrayClass {{{0}" +
108                                 "    {0}" +
109                                 "    /// <remarks/>{0}" +
110                                 "    public object names;{0}" +
111                                 "}}{0}", Environment.NewLine), sw.ToString (), "#4");
112 #endif
113                 }
114
115                 [Test]
116                 public void ExportTypeMapping_ArrayContainer ()
117                 {
118                         CodeNamespace codeNamespace = ExportCode (typeof (ArrayContainer));
119                         Assert.IsNotNull (codeNamespace, "#1");
120
121                         StringWriter sw = new StringWriter ();
122                         CodeDomProvider provider = new CSharpCodeProvider ();
123                         ICodeGenerator generator = provider.CreateGenerator ();
124                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
125
126                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
127                                 "{0}{0}" +
128                                 "/// <remarks/>{0}" +
129 #if NET_2_0
130                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
131                                 "[System.SerializableAttribute()]{0}" +
132                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
133                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
134                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
135                                 "public partial class ArrayContainer {{{0}" +
136                                 "    {0}" +
137                                 "    private object[] itemsField;{0}" +
138                                 "    {0}" +
139                                 "    /// <remarks/>{0}" +
140                                 "    public object[] items {{{0}" +
141                                 "        get {{{0}" +
142                                 "            return this.itemsField;{0}" +
143                                 "        }}{0}" +
144                                 "        set {{{0}" +
145                                 "            this.itemsField = value;{0}" +
146                                 "        }}{0}" +
147                                 "    }}{0}" +
148                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
149 #else
150                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
151                                 "public class ArrayContainer {{{0}" +
152                                 "    {0}" +
153                                 "    /// <remarks/>{0}" +
154                                 "    public object[] items;{0}" +
155                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
156 #endif
157                 }
158
159                 [Test]
160                 public void ExportTypeMapping_CDataContainer ()
161                 {
162                         CodeNamespace codeNamespace = ExportCode (typeof (CDataContainer));
163                         Assert.IsNotNull (codeNamespace, "#1");
164
165                         StringWriter sw = new StringWriter ();
166                         CodeDomProvider provider = new CSharpCodeProvider ();
167                         ICodeGenerator generator = provider.CreateGenerator ();
168                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
169
170                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
171                                 "{0}{0}" +
172                                 "/// <remarks/>{0}" +
173 #if NET_2_0
174                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
175                                 "[System.SerializableAttribute()]{0}" +
176                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
177                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
178                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
179                                 "public partial class CDataContainer {{{0}" +
180                                 "    {0}" +
181                                 "    private System.Xml.XmlCDataSection cdataField;{0}" +
182                                 "    {0}" +
183                                 "    /// <remarks/>{0}" +
184                                 "    public System.Xml.XmlCDataSection cdata {{{0}" +
185                                 "        get {{{0}" +
186                                 "            return this.cdataField;{0}" +
187                                 "        }}{0}" +
188                                 "        set {{{0}" +
189                                 "            this.cdataField = value;{0}" +
190                                 "        }}{0}" +
191                                 "    }}{0}" +
192                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
193 #else
194                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
195                                 "public class CDataContainer {{{0}" +
196                                 "    {0}" +
197                                 "    /// <remarks/>{0}" +
198                                 "    public System.Xml.XmlCDataSection cdata;{0}" +
199                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
200 #endif
201                 }
202
203                 [Test]
204                 [Category ("NotWorking")] // order of XmlElementAttribute's does not match that of MSFT
205                 [Category ("NotDotNet")] // Mono bug ##77117 and MS.NET randomly modifies the order of the elements!
206                 public void ExportTypeMapping_Choices ()
207                 {
208                         CodeNamespace codeNamespace = ExportCode (typeof (Choices));
209                         Assert.IsNotNull (codeNamespace, "#1");
210
211                         StringWriter sw = new StringWriter ();
212                         CodeDomProvider provider = new CSharpCodeProvider ();
213                         ICodeGenerator generator = provider.CreateGenerator ();
214                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
215
216                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
217                                 "{0}{0}" +
218                                 "/// <remarks/>{0}" +
219 #if NET_2_0
220                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
221                                 "[System.SerializableAttribute()]{0}" +
222                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
223                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
224                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
225                                 "public partial class Choices {{{0}" +
226                                 "    {0}" +
227                                 "    private string myChoiceField;{0}" +
228                                 "    {0}" +
229                                 "    /// <remarks/>{0}" +
230                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceZero\", typeof(string))]{0}" +
231                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceOne\", typeof(string))]{0}" +
232                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceTwo\", typeof(string))]{0}" +
233                                 "    [System.Xml.Serialization.XmlChoiceIdentifierAttribute(\"ItemType\")]{0}" +
234                                 "    public string MyChoice {{{0}" +
235                                 "        get {{{0}" +
236                                 "            return this.myChoiceField;{0}" +
237                                 "        }}{0}" +
238                                 "        set {{{0}" +
239                                 "            this.myChoiceField = value;{0}" +
240                                 "        }}{0}" +
241                                 "    }}{0}" +
242                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
243 #else
244                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
245                                 "public class Choices {{{0}" +
246                                 "    {0}" +
247                                 "    /// <remarks/>{0}" +
248                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceZero\", typeof(string))]{0}" +
249                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceTwo\", typeof(string))]{0}" +
250                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceOne\", typeof(string))]{0}" +
251                                 "    [System.Xml.Serialization.XmlChoiceIdentifierAttribute(\"ItemType\")]{0}" +
252                                 "    public string MyChoice;{0}" +
253                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
254 #endif
255                 }
256
257                 [Test]
258 #if NET_2_0
259                 [Category ("NotDotNet")] // regression in MS.NET 2.0
260 #endif
261                 [Category ("NotWorking")] // TODO: order of DefaultValueAttribute, ...
262                 public void ExportTypeMapping_Field ()
263                 {
264                         CodeNamespace codeNamespace = ExportCode (typeof (Field));
265                         Assert.IsNotNull (codeNamespace, "#1");
266
267                         StringWriter sw = new StringWriter ();
268                         CodeDomProvider provider = new CSharpCodeProvider ();
269                         ICodeGenerator generator = provider.CreateGenerator ();
270                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
271
272                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
273                                 "{0}{0}" +
274                                 "/// <remarks/>{0}" +
275 #if NET_2_0
276                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
277                                 "[System.SerializableAttribute()]{0}" +
278                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
279                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
280                                 "[System.Xml.Serialization.XmlRootAttribute(\"field\", Namespace=\"\", IsNullable=true)]{0}" +
281                                 "public partial class Field {{{0}" +
282                                 "    {0}" +
283                                 "    private MonoTests.System.Xml.TestClasses.FlagEnum flags1Field = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
284                                 "    {0}" +
285                                 "    private MonoTests.System.Xml.TestClasses.FlagEnum flags2Field = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
286                                 "    {0}" +
287                                 "    private MonoTests.System.Xml.TestClasses.FlagEnum flags3Field = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2);{0}" +
288                                 "    {0}" +
289                                 "    private MonoTests.System.Xml.TestClasses.FlagEnum flags4Field;{0}" +
290                                 "    {0}" +
291                                 "    private MonoTests.System.Xml.TestClasses.MapModifiers modifiersField;{0}" +
292                                 "    {0}" +
293                                 "    private MonoTests.System.Xml.TestClasses.MapModifiers modifiers2Field;{0}" +
294                                 "    {0}" +
295                                 "    private MonoTests.System.Xml.TestClasses.MapModifiers modifiers3Field = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
296                                 "    {0}" +
297                                 "    private MonoTests.System.Xml.TestClasses.MapModifiers modifiers4Field = MonoTests.System.Xml.TestClasses.MapModifiers.Protected;{0}" +
298                                 "    {0}" +
299                                 "    private MonoTests.System.Xml.TestClasses.MapModifiers modifiers5Field = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
300                                 "    {0}" +
301                                 "    private string[] namesField;{0}" +
302                                 "    {0}" +
303                                 "    private string streetField;{0}" +
304                                 "    {0}" +
305                                 "    /// <remarks/>{0}" +
306                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag1\")]{0}" +
307                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
308                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags1 {{{0}" +
309                                 "        get {{{0}" +
310                                 "            return this.flags1Field;{0}" +
311                                 "        }}{0}" +
312                                 "        set {{{0}" +
313                                 "            this.flags1Field = value;{0}" +
314                                 "        }}{0}" +
315                                 "    }}{0}" +
316                                 "    {0}" +
317                                 "    /// <remarks/>{0}" +
318                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag2\")]{0}" +
319                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
320                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags2 {{{0}" +
321                                 "        get {{{0}" +
322                                 "            return this.flags2Field;{0}" +
323                                 "        }}{0}" +
324                                 "        set {{{0}" +
325                                 "            this.flags2Field = value;{0}" +
326                                 "        }}{0}" +
327                                 "    }}{0}" +
328                                 "    {0}" +
329                                 "    /// <remarks/>{0}" +
330                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag3\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
331                                 "    [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2))]{0}" +
332                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags3 {{{0}" +
333                                 "        get {{{0}" +
334                                 "            return this.flags3Field;{0}" +
335                                 "        }}{0}" +
336                                 "        set {{{0}" +
337                                 "            this.flags3Field = value;{0}" +
338                                 "        }}{0}" +
339                                 "    }}{0}" +
340                                 "    {0}" +
341                                 "    /// <remarks/>{0}" +
342                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag4\")]{0}" +
343                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags4 {{{0}" +
344                                 "        get {{{0}" +
345                                 "            return this.flags4Field;{0}" +
346                                 "        }}{0}" +
347                                 "        set {{{0}" +
348                                 "            this.flags4Field = value;{0}" +
349                                 "        }}{0}" +
350                                 "    }}{0}" +
351                                 "    {0}" +
352                                 "    /// <remarks/>{0}" +
353                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers\")]{0}" +
354                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers {{{0}" +
355                                 "        get {{{0}" +
356                                 "            return this.modifiersField;{0}" +
357                                 "        }}{0}" +
358                                 "        set {{{0}" +
359                                 "            this.modifiersField = value;{0}" +
360                                 "        }}{0}" +
361                                 "    }}{0}" +
362                                 "    {0}" +
363                                 "    /// <remarks/>{0}" +
364                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers2\")]{0}" +
365                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers2 {{{0}" +
366                                 "        get {{{0}" +
367                                 "            return this.modifiers2Field;{0}" +
368                                 "        }}{0}" +
369                                 "        set {{{0}" +
370                                 "            this.modifiers2Field = value;{0}" +
371                                 "        }}{0}" +
372                                 "    }}{0}" +
373                                 "    {0}" +
374                                 "    /// <remarks/>{0}" +
375                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers3\")]{0}" +
376                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
377                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers3 {{{0}" +
378                                 "        get {{{0}" +
379                                 "            return this.modifiers3Field;{0}" +
380                                 "        }}{0}" +
381                                 "        set {{{0}" +
382                                 "            this.modifiers3Field = value;{0}" +
383                                 "        }}{0}" +
384                                 "    }}{0}" +
385                                 "    {0}" +
386                                 "    /// <remarks/>{0}" +
387                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers4\")]{0}" +
388                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Protected)]{0}" +
389                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers4 {{{0}" +
390                                 "        get {{{0}" +
391                                 "            return this.modifiers4Field;{0}" +
392                                 "        }}{0}" +
393                                 "        set {{{0}" +
394                                 "            this.modifiers4Field = value;{0}" +
395                                 "        }}{0}" +
396                                 "    }}{0}" +
397                                 "    {0}" +
398                                 "    /// <remarks/>{0}" +
399                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers5\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
400                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
401                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers5 {{{0}" +
402                                 "        get {{{0}" +
403                                 "            return this.modifiers5Field;{0}" +
404                                 "        }}{0}" +
405                                 "        set {{{0}" +
406                                 "            this.modifiers5Field = value;{0}" +
407                                 "        }}{0}" +
408                                 "    }}{0}" +
409                                 "    {0}" +
410                                 "    /// <remarks/>{0}" +
411                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"names\")]{0}" +
412                                 "    public string[] Names {{{0}" +
413                                 "        get {{{0}" +
414                                 "            return this.namesField;{0}" +
415                                 "        }}{0}" +
416                                 "        set {{{0}" +
417                                 "            this.namesField = value;{0}" +
418                                 "        }}{0}" +
419                                 "    }}{0}" +
420                                 "    {0}" +
421                                 "    /// <remarks/>{0}" +
422                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"street\")]{0}" +
423                                 "    public string Street {{{0}" +
424                                 "        get {{{0}" +
425                                 "            return this.streetField;{0}" +
426                                 "        }}{0}" +
427                                 "        set {{{0}" +
428                                 "            this.streetField = value;{0}" +
429                                 "        }}{0}" +
430                                 "    }}{0}" +
431 #else
432                                 "[System.Xml.Serialization.XmlRootAttribute(\"field\", Namespace=\"\", IsNullable=true)]{0}" +
433                                 "public class Field {{{0}" +
434                                 "    {0}" +
435                                 "    /// <remarks/>{0}" +
436                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag1\")]{0}" +
437                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
438                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags1 = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
439                                 "    {0}" +
440                                 "    /// <remarks/>{0}" +
441                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag2\")]{0}" +
442                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
443                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags2 = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
444                                 "    {0}" +
445                                 "    /// <remarks/>{0}" +
446                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag3\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
447                                 "    [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2))]{0}" +
448                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags3 = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2);{0}" +
449                                 "    {0}" +
450                                 "    /// <remarks/>{0}" +
451                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag4\")]{0}" +
452                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags4;{0}" +
453                                 "    {0}" +
454                                 "    /// <remarks/>{0}" +
455                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers\")]{0}" +
456                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers;{0}" +
457                                 "    {0}" +
458                                 "    /// <remarks/>{0}" +
459                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers2\")]{0}" +
460                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers2;{0}" +
461                                 "    {0}" +
462                                 "    /// <remarks/>{0}" +
463                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers3\")]{0}" +
464                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
465                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers3 = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
466                                 "    {0}" +
467                                 "    /// <remarks/>{0}" +
468                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers4\")]{0}" +
469                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Protected)]{0}" +
470                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers4 = MonoTests.System.Xml.TestClasses.MapModifiers.Protected;{0}" +
471                                 "    {0}" +
472                                 "    /// <remarks/>{0}" +
473                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers5\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
474                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
475                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers5 = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
476                                 "    {0}" +
477                                 "    /// <remarks/>{0}" +
478                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"names\")]{0}" +
479                                 "    public string[] Names;{0}" +
480                                 "    {0}" +
481                                 "    /// <remarks/>{0}" +
482                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"street\")]{0}" +
483                                 "    public string Street;{0}" +
484 #endif
485                                 "}}{0}" +
486                                 "{0}" +
487                                 "/// <remarks/>{0}" +
488                                 "[System.FlagsAttribute()]{0}" +
489 #if NET_2_0
490                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
491                                 "[System.SerializableAttribute()]{0}" +
492 #endif
493                                 "public enum FlagEnum {{{0}" +
494                                 "    {0}" +
495                                 "    /// <remarks/>{0}" +
496                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
497                                 "    e1 = 1,{0}" +
498                                 "    {0}" +
499                                 "    /// <remarks/>{0}" +
500                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
501                                 "    e2 = 2,{0}" +
502                                 "    {0}" +
503                                 "    /// <remarks/>{0}" +
504                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
505                                 "    e4 = 4,{0}" +
506                                 "}}{0}" +
507                                 "{0}" +
508                                 "/// <remarks/>{0}" +
509                                 "[System.FlagsAttribute()]{0}" +
510 #if NET_2_0
511                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
512                                 "[System.SerializableAttribute()]{0}" +
513 #endif
514                                 "public enum MapModifiers {{{0}" +
515                                 "    {0}" +
516                                 "    /// <remarks/>{0}" +
517                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"public\")]{0}" +
518                                 "    Public = 1,{0}" +
519                                 "    {0}" +
520                                 "    /// <remarks/>{0}" +
521                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"protected\")]{0}" +
522                                 "    Protected = 2,{0}" +
523 #if NET_2_0
524                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
525 #else
526                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
527 #endif
528                 }
529
530                 [Test]
531                 public void ExportTypeMapping_ItemChoiceType ()
532                 {
533                         CodeNamespace codeNamespace = ExportCode (typeof (ItemChoiceType));
534                         Assert.IsNotNull (codeNamespace, "#1");
535
536                         StringWriter sw = new StringWriter ();
537                         CodeDomProvider provider = new CSharpCodeProvider ();
538                         ICodeGenerator generator = provider.CreateGenerator ();
539                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
540
541                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
542                                 "{0}{0}" +
543                                 "/// <remarks/>{0}" +
544 #if NET_2_0
545                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
546                                 "[System.SerializableAttribute()]{0}" +
547 #endif
548                                 "[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]{0}" +
549                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=false)]{0}" +
550                                 "public enum ItemChoiceType {{{0}" +
551                                 "    {0}" +
552                                 "    /// <remarks/>{0}" +
553                                 "    ChoiceZero,{0}" +
554                                 "    {0}" +
555                                 "    /// <remarks/>{0}" +
556                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"ChoiceOne\")]{0}" +
557                                 "    StrangeOne,{0}" +
558                                 "    {0}" +
559                                 "    /// <remarks/>{0}" +
560                                 "    ChoiceTwo,{0}" +
561 #if NET_2_0
562                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
563 #else
564                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
565 #endif
566
567                         codeNamespace = ExportCode (typeof (ItemChoiceType[]));
568                         Assert.IsNotNull (codeNamespace, "#3");
569
570                         sw.GetStringBuilder ().Length = 0;
571                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
572
573                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
574                                 "{0}{0}" +
575                                 "/// <remarks/>{0}" +
576 #if NET_2_0
577                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
578                                 "[System.SerializableAttribute()]{0}" +
579 #endif
580                                 "[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]{0}" +
581                                 "public enum ItemChoiceType {{{0}" +
582                                 "    {0}" +
583                                 "    /// <remarks/>{0}" +
584                                 "    ChoiceZero,{0}" +
585                                 "    {0}" +
586                                 "    /// <remarks/>{0}" +
587                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"ChoiceOne\")]{0}" +
588                                 "    StrangeOne,{0}" +
589                                 "    {0}" +
590                                 "    /// <remarks/>{0}" +
591                                 "    ChoiceTwo,{0}" +
592 #if NET_2_0
593                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#4");
594 #else
595                                 "}}{0}", Environment.NewLine), sw.ToString (), "#4");
596 #endif
597                 }
598
599                 [Test]
600                 public void ExportTypeMapping_ClassArrayContainer ()
601                 {
602                         CodeNamespace codeNamespace = ExportCode (typeof (ClassArrayContainer));
603                         Assert.IsNotNull (codeNamespace, "#1");
604
605                         StringWriter sw = new StringWriter ();
606                         CodeDomProvider provider = new CSharpCodeProvider ();
607                         ICodeGenerator generator = provider.CreateGenerator ();
608                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
609
610                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
611                                 "{0}{0}" +
612                                 "/// <remarks/>{0}" +
613 #if NET_2_0
614                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
615                                 "[System.SerializableAttribute()]{0}" +
616                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
617                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
618                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
619                                 "public partial class ClassArrayContainer {{{0}" +
620                                 "    {0}" +
621                                 "    private MonoTests.System.Xml.TestClasses.SimpleClass[] itemsField;{0}" +
622                                 "    {0}" +
623                                 "    /// <remarks/>{0}" +
624                                 "    public MonoTests.System.Xml.TestClasses.SimpleClass[] items {{{0}" +
625                                 "        get {{{0}" +
626                                 "            return this.itemsField;{0}" +
627                                 "        }}{0}" +
628                                 "        set {{{0}" +
629                                 "            this.itemsField = value;{0}" +
630                                 "        }}{0}" +
631                                 "    }}{0}" +
632                                 "}}{0}" +
633                                 "{0}" +
634                                 "/// <remarks/>{0}" +
635                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
636                                 "[System.SerializableAttribute()]{0}" +
637                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
638                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
639                                 "public partial class SimpleClass {{{0}" +
640                                 "    {0}" +
641                                 "    private string somethingField;{0}" +
642                                 "    {0}" +
643                                 "    /// <remarks/>{0}" +
644                                 "    public string something {{{0}" +
645                                 "        get {{{0}" +
646                                 "            return this.somethingField;{0}" +
647                                 "        }}{0}" +
648                                 "        set {{{0}" +
649                                 "            this.somethingField = value;{0}" +
650                                 "        }}{0}" +
651                                 "    }}{0}" +
652                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
653 #else
654                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
655                                 "public class ClassArrayContainer {{{0}" +
656                                 "    {0}" +
657                                 "    /// <remarks/>{0}" +
658                                 "    public MonoTests.System.Xml.TestClasses.SimpleClass[] items;{0}" +
659                                 "}}{0}" +
660                                 "{0}" +
661                                 "/// <remarks/>{0}" +
662                                 "public class SimpleClass {{{0}" +
663                                 "    {0}" +
664                                 "    /// <remarks/>{0}" +
665                                 "    public string something;{0}" +
666                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
667 #endif
668                 }
669
670                 [Test]
671 #if NET_2_0
672                 [Category ("NotDotNet")] // regression in MS.NET 2.0
673 #endif
674                 [Category ("NotWorking")] // bug #78214
675                 public void ExportTypeMapping_Root ()
676                 {
677                         CodeNamespace codeNamespace = ExportCode (typeof (Root));
678                         Assert.IsNotNull (codeNamespace, "#1");
679
680                         StringWriter sw = new StringWriter ();
681                         CodeDomProvider provider = new CSharpCodeProvider ();
682                         ICodeGenerator generator = provider.CreateGenerator ();
683                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
684
685                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
686                                 "{0}{0}" +
687                                 "/// <remarks/>{0}" +
688                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:aNS\")]{0}" +
689                                 "[System.Xml.Serialization.XmlRootAttribute(\"root\", Namespace=\"urn:aNS\", IsNullable=false)]{0}" +
690                                 "public class Root {{{0}" +
691                                 "    {0}" +
692                                 "    /// <remarks/>{0}" +
693                                 "    public MonoTests.System.Xml.TestClasses.OptionalValueTypeContainer OptionalValue;{0}" +
694                                 "    {0}" +
695                                 "    /// <remarks/>{0}" +
696                                 "    public MonoTests.System.Xml.TestClasses.TestDefault Default;{0}" +
697                                 "}}{0}" +
698                                 "{0}" +
699                                 "/// <remarks/>{0}" +
700                                 "[System.Xml.Serialization.XmlTypeAttribute(TypeName=\"optionalValueType\", Namespace=\"some:urn\")]{0}" +
701                                 "public class OptionalValueTypeContainer {{{0}" +
702                                 "    {0}" +
703                                 "    /// <remarks/>{0}" +
704                                 "    [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4))]{0}" +
705                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Attributes = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
706                                 "    {0}" +
707                                 "    /// <remarks/>{0}" +
708                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
709                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
710                                 "    {0}" +
711                                 "    /// <remarks/>{0}" +
712                                 "    [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
713                                 "    public bool FlagsSpecified;{0}" +
714                                 "    {0}" +
715                                 "    /// <remarks/>{0}" +
716                                 "    [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
717                                 "    public bool IsEmpty = false;{0}" +
718                                 "    {0}" +
719                                 "    /// <remarks/>{0}" +
720                                 "    [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
721                                 "    public bool IsEmptySpecified;{0}" +
722                                 "    {0}" +
723                                 "    /// <remarks/>{0}" +
724                                 "    [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
725                                 "    public bool IsNull = false;{0}" +
726                                 "}}{0}" +
727                                 "{0}" +
728                                 "/// <remarks/>{0}" +
729                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"some:urn\")]{0}" +
730                                 "[System.FlagsAttribute()]{0}" +
731                                 "public enum FlagEnum {{{0}" +
732                                 "    {0}" +
733                                 "    /// <remarks/>{0}" +
734                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
735                                 "    e1 = 1,{0}" +
736                                 "    {0}" +
737                                 "    /// <remarks/>{0}" +
738                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
739                                 "    e2 = 2,{0}" +
740                                 "    {0}" +
741                                 "    /// <remarks/>{0}" +
742                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
743                                 "    e4 = 4,{0}" +
744                                 "}}{0}" +
745                                 "{0}" +
746                                 "/// <remarks/>{0}" +
747                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
748                                 "public class TestDefault {{{0}" +
749                                 "    {0}" +
750                                 "    /// <remarks/>{0}" +
751                                 "    public string str;{0}" +
752                                 "    {0}" +
753                                 "    /// <remarks/>{0}" +
754                                 "    [System.ComponentModel.DefaultValueAttribute(\"Default Value\")]{0}" +
755                                 "    public string strDefault = \"Default Value\";{0}" +
756                                 "    {0}" +
757                                 "    /// <remarks/>{0}" +
758                                 "    [System.ComponentModel.DefaultValueAttribute(true)]{0}" +
759                                 "    public bool boolT = true;{0}" +
760                                 "    {0}" +
761                                 "    /// <remarks/>{0}" +
762                                 "    [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
763                                 "    public bool boolF = false;{0}" +
764                                 "    {0}" +
765                                 "    /// <remarks/>{0}" +
766                                 "    [System.ComponentModel.DefaultValueAttribute(typeof(System.Decimal), \"10\")]{0}" +
767                                 "    public System.Decimal decimalval = ((System.Decimal)(10m));{0}" +
768                                 "    {0}" +
769                                 "    /// <remarks/>{0}" +
770                                 "    [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4))]{0}" +
771                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum flag = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
772                                 "    {0}" +
773                                 "    /// <remarks/>{0}" +
774                                 "    [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1 | MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4))]{0}" +
775                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum_Encoded flagencoded = (MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1 | MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4);{0}" +
776                                 "}}{0}" +
777                                 "{0}" +
778                                 "/// <remarks/>{0}" +
779                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
780                                 "[System.FlagsAttribute()]{0}" +
781                                 "public enum FlagEnum {{{0}" +
782                                 "    {0}" +
783                                 "    /// <remarks/>{0}" +
784                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
785                                 "    e1 = 1,{0}" +
786                                 "    {0}" +
787                                 "    /// <remarks/>{0}" +
788                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
789                                 "    e2 = 2,{0}" +
790                                 "    {0}" +
791                                 "    /// <remarks/>{0}" +
792                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
793                                 "    e4 = 4,{0}" +
794                                 "}}{0}" +
795                                 "{0}" +
796                                 "/// <remarks/>{0}" +
797                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
798                                 "[System.FlagsAttribute()]{0}" +
799                                 "public enum FlagEnum_Encoded {{{0}" +
800                                 "    {0}" +
801                                 "    /// <remarks/>{0}" +
802                                 "    e1 = 1,{0}" +
803                                 "    {0}" +
804                                 "    /// <remarks/>{0}" +
805                                 "    e2 = 2,{0}" +
806                                 "    {0}" +
807                                 "    /// <remarks/>{0}" +
808                                 "    e4 = 4,{0}" +
809                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
810                 }
811
812                 [Test]
813                 public void ExportTypeMapping_SimpleClassWithXmlAttributes ()
814                 {
815                         CodeNamespace codeNamespace = ExportCode (typeof (SimpleClassWithXmlAttributes));
816                         Assert.IsNotNull (codeNamespace, "#1");
817
818                         StringWriter sw = new StringWriter ();
819                         CodeDomProvider provider = new CSharpCodeProvider ();
820                         ICodeGenerator generator = provider.CreateGenerator ();
821                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
822
823                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
824                                 "{0}{0}" +
825                                 "/// <remarks/>{0}" +
826 #if NET_2_0
827                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
828                                 "[System.SerializableAttribute()]{0}" +
829                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
830                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
831                                 "[System.Xml.Serialization.XmlRootAttribute(\"simple\", Namespace=\"\", IsNullable=true)]{0}" +
832                                 "public partial class SimpleClassWithXmlAttributes {{{0}" +
833                                 "    {0}" +
834                                 "    private string somethingField;{0}" +
835                                 "    {0}" +
836                                 "    /// <remarks/>{0}" +
837                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"member\")]{0}" +
838                                 "    public string something {{{0}" +
839                                 "        get {{{0}" +
840                                 "            return this.somethingField;{0}" +
841                                 "        }}{0}" +
842                                 "        set {{{0}" +
843                                 "            this.somethingField = value;{0}" +
844                                 "        }}{0}" +
845                                 "    }}{0}" +
846                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
847 #else
848                                 "[System.Xml.Serialization.XmlRootAttribute(\"simple\", Namespace=\"\", IsNullable=true)]{0}" +
849                                 "public class SimpleClassWithXmlAttributes {{{0}" +
850                                 "    {0}" +
851                                 "    /// <remarks/>{0}" +
852                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"member\")]{0}" +
853                                 "    public string something;{0}" +
854                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
855 #endif
856                 }
857
858                 [Test]
859                 public void ExportTypeMapping_XsdPrimitive_Arrays ()
860                 {
861                         ArrayList types = new ArrayList ();
862                         types.Add (typeof (sbyte[]));
863                         types.Add (typeof (bool[]));
864                         types.Add (typeof (short[]));
865                         types.Add (typeof (int[]));
866                         types.Add (typeof (long[]));
867                         types.Add (typeof (float[]));
868                         types.Add (typeof (double[]));
869                         types.Add (typeof (decimal[]));
870                         types.Add (typeof (ushort[]));
871                         types.Add (typeof (uint[]));
872                         types.Add (typeof (ulong[]));
873                         types.Add (typeof (DateTime[]));
874                         types.Add (typeof (XmlQualifiedName[]));
875                         types.Add (typeof (string[]));
876
877                         StringWriter sw = new StringWriter ();
878                         CodeDomProvider provider = new CSharpCodeProvider ();
879                         ICodeGenerator generator = provider.CreateGenerator ();
880
881                         foreach (Type type in types) {
882                                 CodeNamespace codeNamespace = ExportCode (type);
883                                 Assert.IsNotNull (codeNamespace, type.FullName + "#1");
884
885                                 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
886
887                                 Assert.AreEqual (Environment.NewLine, sw.ToString (), 
888                                         type.FullName + "#2");
889
890                                 sw.GetStringBuilder ().Length = 0;
891                         }
892                 }
893
894                 [Test]
895                 public void ExportTypeMapping_ZeroFlagEnum ()
896                 {
897                         CodeNamespace codeNamespace = ExportCode (typeof (ZeroFlagEnum));
898                         Assert.IsNotNull (codeNamespace, "#1");
899
900                         StringWriter sw = new StringWriter ();
901                         CodeDomProvider provider = new CSharpCodeProvider ();
902                         ICodeGenerator generator = provider.CreateGenerator ();
903                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
904
905                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
906                                 "{0}{0}" +
907                                 "/// <remarks/>{0}" +
908                                 "[System.FlagsAttribute()]{0}" +
909 #if NET_2_0
910                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
911                                 "[System.SerializableAttribute()]{0}" +
912 #endif
913                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=false)]{0}" +
914                                 "public enum ZeroFlagEnum {{{0}" +
915                                 "    {0}" +
916                                 "    /// <remarks/>{0}" +
917                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"zero\")]{0}" +
918                                 "    e0 = 1,{0}" +
919                                 "    {0}" +
920                                 "    /// <remarks/>{0}" +
921                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"o<n>e\")]{0}" +
922                                 "    e1 = 2,{0}" +
923                                 "    {0}" +
924                                 "    /// <remarks/>{0}" +
925                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"tns:t<w>o\")]{0}" +
926                                 "    e2 = 4,{0}" +
927 #if NET_2_0
928                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
929 #else
930                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
931 #endif
932                 }
933
934                 CodeNamespace ExportCode (Type type)
935                 {
936                         XmlReflectionImporter imp = new XmlReflectionImporter ();
937                         XmlTypeMapping map = imp.ImportTypeMapping (type);
938                         CodeNamespace codeNamespace = new CodeNamespace ();
939                         XmlCodeExporter exp = new XmlCodeExporter (codeNamespace);
940                         exp.ExportTypeMapping (map);
941                         return codeNamespace;
942                 }
943
944 #if NET_2_0
945                 string XmlFileVersion {
946                         get {
947                                 Assembly xmlAsm = typeof (XmlDocument).Assembly;
948                                 AssemblyFileVersionAttribute afv = (AssemblyFileVersionAttribute)
949                                         Attribute.GetCustomAttribute (xmlAsm, typeof (AssemblyFileVersionAttribute));
950                                 return afv.Version;
951                         }
952                 }
953 #endif
954
955                 [XmlRootAttribute ("root", Namespace="urn:aNS", IsNullable=false)]
956                 public class Root
957                 {
958                         public OptionalValueTypeContainer OptionalValue;
959                         public TestDefault Default;
960                 }
961         }
962 }