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