Merge pull request #1196 from tritao/master
[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) Gert Driesen (drieseng@users.sourceforge.net)
8 // (C) 2006 Novell
9 // 
10
11 #if !MOBILE
12
13 using System;
14 using System.CodeDom;
15 using System.CodeDom.Compiler;
16 using System.Collections;
17 using System.Globalization;
18 using System.IO;
19 #if NET_2_0
20 using System.Reflection;
21 #endif
22 using System.Xml;
23 using System.Xml.Schema;
24 using System.Xml.Serialization;
25
26 using Microsoft.CSharp;
27
28 using NUnit.Framework;
29
30 using MonoTests.System.Xml.TestClasses;
31
32 namespace MonoTests.System.XmlSerialization
33 {
34         [TestFixture]
35         public class XmlCodeExporterTests
36         {
37                 [Test]
38                 public void ExportTypeMapping_ArrayClass ()
39                 {
40                         CodeNamespace codeNamespace = ExportCode (typeof (ArrayClass));
41                         Assert.IsNotNull (codeNamespace, "#1");
42
43                         StringWriter sw = new StringWriter ();
44                         CodeDomProvider provider = new CSharpCodeProvider ();
45                         ICodeGenerator generator = provider.CreateGenerator ();
46                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
47
48                         Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
49                                 "{0}{0}" +
50                                 "/// <remarks/>{0}" +
51 #if NET_2_0
52                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
53                                 "[System.SerializableAttribute()]{0}" +
54                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
55                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
56                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
57                                 "public partial class ArrayClass {{{0}" +
58                                 "    {0}" +
59                                 "    private object namesField;{0}" +
60                                 "    {0}" +
61                                 "    /// <remarks/>{0}" +
62                                 "    public object names {{{0}" +
63                                 "        get {{{0}" +
64                                 "            return this.namesField;{0}" +
65                                 "        }}{0}" +
66                                 "        set {{{0}" +
67                                 "            this.namesField = value;{0}" +
68                                 "        }}{0}" +
69                                 "    }}{0}" +
70                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
71 #else
72                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
73                                 "public class ArrayClass {{{0}" +
74                                 "    {0}" +
75                                 "    /// <remarks/>{0}" +
76                                 "    public object names;{0}" +
77                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
78 #endif
79
80
81                         codeNamespace = ExportCode (typeof (ArrayClass[]));
82                         Assert.IsNotNull (codeNamespace, "#3");
83
84                         sw.GetStringBuilder ().Length = 0;
85                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
86
87                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
88                                 "{0}{0}" +
89                                 "/// <remarks/>{0}" +
90 #if NET_2_0
91                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
92                                 "[System.SerializableAttribute()]{0}" +
93                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
94                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
95                                 "public partial class ArrayClass {{{0}" +
96                                 "    {0}" +
97                                 "    private object namesField;{0}" +
98                                 "    {0}" +
99                                 "    /// <remarks/>{0}" +
100                                 "    public object names {{{0}" +
101                                 "        get {{{0}" +
102                                 "            return this.namesField;{0}" +
103                                 "        }}{0}" +
104                                 "        set {{{0}" +
105                                 "            this.namesField = value;{0}" +
106                                 "        }}{0}" +
107                                 "    }}{0}" +
108                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#4");
109 #else
110                                 "public class ArrayClass {{{0}" +
111                                 "    {0}" +
112                                 "    /// <remarks/>{0}" +
113                                 "    public object names;{0}" +
114                                 "}}{0}", Environment.NewLine), sw.ToString (), "#4");
115 #endif
116                 }
117
118                 [Test]
119                 public void ExportTypeMapping_ArrayContainer ()
120                 {
121                         CodeNamespace codeNamespace = ExportCode (typeof (ArrayContainer));
122                         Assert.IsNotNull (codeNamespace, "#1");
123
124                         StringWriter sw = new StringWriter ();
125                         CodeDomProvider provider = new CSharpCodeProvider ();
126                         ICodeGenerator generator = provider.CreateGenerator ();
127                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
128
129                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
130                                 "{0}{0}" +
131                                 "/// <remarks/>{0}" +
132 #if NET_2_0
133                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
134                                 "[System.SerializableAttribute()]{0}" +
135                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
136                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
137                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
138                                 "public partial class ArrayContainer {{{0}" +
139                                 "    {0}" +
140                                 "    private object[] itemsField;{0}" +
141                                 "    {0}" +
142                                 "    /// <remarks/>{0}" +
143                                 "    public object[] items {{{0}" +
144                                 "        get {{{0}" +
145                                 "            return this.itemsField;{0}" +
146                                 "        }}{0}" +
147                                 "        set {{{0}" +
148                                 "            this.itemsField = value;{0}" +
149                                 "        }}{0}" +
150                                 "    }}{0}" +
151                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
152 #else
153                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
154                                 "public class ArrayContainer {{{0}" +
155                                 "    {0}" +
156                                 "    /// <remarks/>{0}" +
157                                 "    public object[] items;{0}" +
158                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
159 #endif
160                 }
161
162                 [Test]
163                 public void ExportTypeMapping_CDataContainer ()
164                 {
165                         CodeNamespace codeNamespace = ExportCode (typeof (CDataContainer));
166                         Assert.IsNotNull (codeNamespace, "#1");
167
168                         StringWriter sw = new StringWriter ();
169                         CodeDomProvider provider = new CSharpCodeProvider ();
170                         ICodeGenerator generator = provider.CreateGenerator ();
171                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
172
173                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
174                                 "{0}{0}" +
175                                 "/// <remarks/>{0}" +
176 #if NET_2_0
177                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
178                                 "[System.SerializableAttribute()]{0}" +
179                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
180                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
181                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
182                                 "public partial class CDataContainer {{{0}" +
183                                 "    {0}" +
184                                 "    private System.Xml.XmlCDataSection cdataField;{0}" +
185                                 "    {0}" +
186                                 "    /// <remarks/>{0}" +
187                                 "    public System.Xml.XmlCDataSection cdata {{{0}" +
188                                 "        get {{{0}" +
189                                 "            return this.cdataField;{0}" +
190                                 "        }}{0}" +
191                                 "        set {{{0}" +
192                                 "            this.cdataField = value;{0}" +
193                                 "        }}{0}" +
194                                 "    }}{0}" +
195                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
196 #else
197                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
198                                 "public class CDataContainer {{{0}" +
199                                 "    {0}" +
200                                 "    /// <remarks/>{0}" +
201                                 "    public System.Xml.XmlCDataSection cdata;{0}" +
202                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
203 #endif
204                 }
205
206                 [Test]
207                 [Category ("NotWorking")] // order of XmlElementAttribute's does not match that of MSFT
208                 [Category ("NotDotNet")] // Mono bug ##77117 and MS.NET randomly modifies the order of the elements!
209                 public void ExportTypeMapping_Choices ()
210                 {
211                         CodeNamespace codeNamespace = ExportCode (typeof (Choices));
212                         Assert.IsNotNull (codeNamespace, "#1");
213
214                         StringWriter sw = new StringWriter ();
215                         CodeDomProvider provider = new CSharpCodeProvider ();
216                         ICodeGenerator generator = provider.CreateGenerator ();
217                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
218
219                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
220                                 "{0}{0}" +
221                                 "/// <remarks/>{0}" +
222 #if NET_2_0
223                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
224                                 "[System.SerializableAttribute()]{0}" +
225                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
226                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
227                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
228                                 "public partial class Choices {{{0}" +
229                                 "    {0}" +
230                                 "    private string myChoiceField;{0}" +
231                                 "    {0}" +
232                                 "    /// <remarks/>{0}" +
233                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceZero\", typeof(string))]{0}" +
234                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceOne\", typeof(string))]{0}" +
235                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceTwo\", typeof(string))]{0}" +
236                                 "    [System.Xml.Serialization.XmlChoiceIdentifierAttribute(\"ItemType\")]{0}" +
237                                 "    public string MyChoice {{{0}" +
238                                 "        get {{{0}" +
239                                 "            return this.myChoiceField;{0}" +
240                                 "        }}{0}" +
241                                 "        set {{{0}" +
242                                 "            this.myChoiceField = value;{0}" +
243                                 "        }}{0}" +
244                                 "    }}{0}" +
245                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
246 #else
247                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
248                                 "public class Choices {{{0}" +
249                                 "    {0}" +
250                                 "    /// <remarks/>{0}" +
251                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceZero\", typeof(string))]{0}" +
252                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceTwo\", typeof(string))]{0}" +
253                                 "    [System.Xml.Serialization.XmlElementAttribute(\"ChoiceOne\", typeof(string))]{0}" +
254                                 "    [System.Xml.Serialization.XmlChoiceIdentifierAttribute(\"ItemType\")]{0}" +
255                                 "    public string MyChoice;{0}" +
256                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
257 #endif
258                 }
259
260                 [Test]
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;{0}" +
284                                 "    {0}" +
285                                 "    private MonoTests.System.Xml.TestClasses.FlagEnum flags2Field;{0}" +
286                                 "    {0}" +
287                                 "    private MonoTests.System.Xml.TestClasses.FlagEnum flags3Field;{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;{0}" +
296                                 "    {0}" +
297                                 "    private MonoTests.System.Xml.TestClasses.MapModifiers modifiers4Field;{0}" +
298                                 "    {0}" +
299                                 "    private MonoTests.System.Xml.TestClasses.MapModifiers modifiers5Field;{0}" +
300                                 "    {0}" +
301                                 "    private string[] namesField;{0}" +
302                                 "    {0}" +
303                                 "    private string streetField;{0}" +
304                                 "    {0}" +
305                                 "    public Field() {{{0}" +
306                                 "        this.flags1Field = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
307                                 "        this.flags2Field = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
308                                 "        this.flags3Field = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2);{0}" +
309                                 "        this.modifiers3Field = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
310                                 "        this.modifiers4Field = MonoTests.System.Xml.TestClasses.MapModifiers.Protected;{0}" +
311                                 "        this.modifiers5Field = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
312                                 "    }}{0}" +
313                                 "    {0}" +
314                                 "    /// <remarks/>{0}" +
315                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag1\")]{0}" +
316                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags1 {{{0}" +
317                                 "        get {{{0}" +
318                                 "            return this.flags1Field;{0}" +
319                                 "        }}{0}" +
320                                 "        set {{{0}" +
321                                 "            this.flags1Field = value;{0}" +
322                                 "        }}{0}" +
323                                 "    }}{0}" +
324                                 "    {0}" +
325                                 "    /// <remarks/>{0}" +
326                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag2\")]{0}" +
327                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags2 {{{0}" +
328                                 "        get {{{0}" +
329                                 "            return this.flags2Field;{0}" +
330                                 "        }}{0}" +
331                                 "        set {{{0}" +
332                                 "            this.flags2Field = value;{0}" +
333                                 "        }}{0}" +
334                                 "    }}{0}" +
335                                 "    {0}" +
336                                 "    /// <remarks/>{0}" +
337                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag3\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
338                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags3 {{{0}" +
339                                 "        get {{{0}" +
340                                 "            return this.flags3Field;{0}" +
341                                 "        }}{0}" +
342                                 "        set {{{0}" +
343                                 "            this.flags3Field = value;{0}" +
344                                 "        }}{0}" +
345                                 "    }}{0}" +
346                                 "    {0}" +
347                                 "    /// <remarks/>{0}" +
348                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag4\")]{0}" +
349                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags4 {{{0}" +
350                                 "        get {{{0}" +
351                                 "            return this.flags4Field;{0}" +
352                                 "        }}{0}" +
353                                 "        set {{{0}" +
354                                 "            this.flags4Field = value;{0}" +
355                                 "        }}{0}" +
356                                 "    }}{0}" +
357                                 "    {0}" +
358                                 "    /// <remarks/>{0}" +
359                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers\")]{0}" +
360                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers {{{0}" +
361                                 "        get {{{0}" +
362                                 "            return this.modifiersField;{0}" +
363                                 "        }}{0}" +
364                                 "        set {{{0}" +
365                                 "            this.modifiersField = value;{0}" +
366                                 "        }}{0}" +
367                                 "    }}{0}" +
368                                 "    {0}" +
369                                 "    /// <remarks/>{0}" +
370                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers2\")]{0}" +
371                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers2 {{{0}" +
372                                 "        get {{{0}" +
373                                 "            return this.modifiers2Field;{0}" +
374                                 "        }}{0}" +
375                                 "        set {{{0}" +
376                                 "            this.modifiers2Field = value;{0}" +
377                                 "        }}{0}" +
378                                 "    }}{0}" +
379                                 "    {0}" +
380                                 "    /// <remarks/>{0}" +
381                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers3\")]{0}" +
382                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers3 {{{0}" +
383                                 "        get {{{0}" +
384                                 "            return this.modifiers3Field;{0}" +
385                                 "        }}{0}" +
386                                 "        set {{{0}" +
387                                 "            this.modifiers3Field = value;{0}" +
388                                 "        }}{0}" +
389                                 "    }}{0}" +
390                                 "    {0}" +
391                                 "    /// <remarks/>{0}" +
392                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers4\")]{0}" +
393                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers4 {{{0}" +
394                                 "        get {{{0}" +
395                                 "            return this.modifiers4Field;{0}" +
396                                 "        }}{0}" +
397                                 "        set {{{0}" +
398                                 "            this.modifiers4Field = value;{0}" +
399                                 "        }}{0}" +
400                                 "    }}{0}" +
401                                 "    {0}" +
402                                 "    /// <remarks/>{0}" +
403                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers5\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
404                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers5 {{{0}" +
405                                 "        get {{{0}" +
406                                 "            return this.modifiers5Field;{0}" +
407                                 "        }}{0}" +
408                                 "        set {{{0}" +
409                                 "            this.modifiers5Field = value;{0}" +
410                                 "        }}{0}" +
411                                 "    }}{0}" +
412                                 "    {0}" +
413                                 "    /// <remarks/>{0}" +
414                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"names\")]{0}" +
415                                 "    public string[] Names {{{0}" +
416                                 "        get {{{0}" +
417                                 "            return this.namesField;{0}" +
418                                 "        }}{0}" +
419                                 "        set {{{0}" +
420                                 "            this.namesField = value;{0}" +
421                                 "        }}{0}" +
422                                 "    }}{0}" +
423                                 "    {0}" +
424                                 "    /// <remarks/>{0}" +
425                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"street\")]{0}" +
426                                 "    public string Street {{{0}" +
427                                 "        get {{{0}" +
428                                 "            return this.streetField;{0}" +
429                                 "        }}{0}" +
430                                 "        set {{{0}" +
431                                 "            this.streetField = value;{0}" +
432                                 "        }}{0}" +
433                                 "    }}{0}" +
434 #else
435                                 "[System.Xml.Serialization.XmlRootAttribute(\"field\", Namespace=\"\", IsNullable=true)]{0}" +
436                                 "public class Field {{{0}" +
437                                 "    {0}" +
438                                 "    /// <remarks/>{0}" +
439                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag1\")]{0}" +
440                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
441                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags1 = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
442                                 "    {0}" +
443                                 "    /// <remarks/>{0}" +
444                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag2\")]{0}" +
445                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
446                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags2 = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
447                                 "    {0}" +
448                                 "    /// <remarks/>{0}" +
449                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag3\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
450                                 "    [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2))]{0}" +
451                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags3 = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e2);{0}" +
452                                 "    {0}" +
453                                 "    /// <remarks/>{0}" +
454                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"flag4\")]{0}" +
455                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags4;{0}" +
456                                 "    {0}" +
457                                 "    /// <remarks/>{0}" +
458                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers\")]{0}" +
459                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers;{0}" +
460                                 "    {0}" +
461                                 "    /// <remarks/>{0}" +
462                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers2\")]{0}" +
463                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers2;{0}" +
464                                 "    {0}" +
465                                 "    /// <remarks/>{0}" +
466                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers3\")]{0}" +
467                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
468                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers3 = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
469                                 "    {0}" +
470                                 "    /// <remarks/>{0}" +
471                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers4\")]{0}" +
472                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Protected)]{0}" +
473                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers4 = MonoTests.System.Xml.TestClasses.MapModifiers.Protected;{0}" +
474                                 "    {0}" +
475                                 "    /// <remarks/>{0}" +
476                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"modifiers5\", Form=System.Xml.Schema.XmlSchemaForm.Qualified)]{0}" +
477                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.MapModifiers.Public)]{0}" +
478                                 "    public MonoTests.System.Xml.TestClasses.MapModifiers Modifiers5 = MonoTests.System.Xml.TestClasses.MapModifiers.Public;{0}" +
479                                 "    {0}" +
480                                 "    /// <remarks/>{0}" +
481                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"names\")]{0}" +
482                                 "    public string[] Names;{0}" +
483                                 "    {0}" +
484                                 "    /// <remarks/>{0}" +
485                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"street\")]{0}" +
486                                 "    public string Street;{0}" +
487 #endif
488                                 "}}{0}" +
489                                 "{0}" +
490                                 "/// <remarks/>{0}" +
491                                 "[System.FlagsAttribute()]{0}" +
492 #if NET_2_0
493                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
494                                 "[System.SerializableAttribute()]{0}" +
495 #endif
496                                 "public enum FlagEnum {{{0}" +
497                                 "    {0}" +
498                                 "    /// <remarks/>{0}" +
499                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
500                                 "    e1 = 1,{0}" +
501                                 "    {0}" +
502                                 "    /// <remarks/>{0}" +
503                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
504                                 "    e2 = 2,{0}" +
505                                 "    {0}" +
506                                 "    /// <remarks/>{0}" +
507                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
508                                 "    e4 = 4,{0}" +
509                                 "}}{0}" +
510                                 "{0}" +
511                                 "/// <remarks/>{0}" +
512                                 "[System.FlagsAttribute()]{0}" +
513 #if NET_2_0
514                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
515                                 "[System.SerializableAttribute()]{0}" +
516 #endif
517                                 "public enum MapModifiers {{{0}" +
518                                 "    {0}" +
519                                 "    /// <remarks/>{0}" +
520                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"public\")]{0}" +
521                                 "    Public = 1,{0}" +
522                                 "    {0}" +
523                                 "    /// <remarks/>{0}" +
524                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"protected\")]{0}" +
525                                 "    Protected = 2,{0}" +
526 #if NET_2_0
527                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
528 #else
529                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
530 #endif
531                 }
532
533                 [Test]
534                 public void ExportTypeMapping_ItemChoiceType ()
535                 {
536                         CodeNamespace codeNamespace = ExportCode (typeof (ItemChoiceType));
537                         Assert.IsNotNull (codeNamespace, "#1");
538
539                         StringWriter sw = new StringWriter ();
540                         CodeDomProvider provider = new CSharpCodeProvider ();
541                         ICodeGenerator generator = provider.CreateGenerator ();
542                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
543
544                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
545                                 "{0}{0}" +
546                                 "/// <remarks/>{0}" +
547 #if NET_2_0
548                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
549                                 "[System.SerializableAttribute()]{0}" +
550 #endif
551                                 "[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]{0}" +
552                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=false)]{0}" +
553                                 "public enum ItemChoiceType {{{0}" +
554                                 "    {0}" +
555                                 "    /// <remarks/>{0}" +
556                                 "    ChoiceZero,{0}" +
557                                 "    {0}" +
558                                 "    /// <remarks/>{0}" +
559                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"ChoiceOne\")]{0}" +
560                                 "    StrangeOne,{0}" +
561                                 "    {0}" +
562                                 "    /// <remarks/>{0}" +
563                                 "    ChoiceTwo,{0}" +
564 #if NET_2_0
565                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
566 #else
567                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
568 #endif
569
570                         codeNamespace = ExportCode (typeof (ItemChoiceType[]));
571                         Assert.IsNotNull (codeNamespace, "#3");
572
573                         sw.GetStringBuilder ().Length = 0;
574                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
575
576                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
577                                 "{0}{0}" +
578                                 "/// <remarks/>{0}" +
579 #if NET_2_0
580                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
581                                 "[System.SerializableAttribute()]{0}" +
582 #endif
583                                 "[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]{0}" +
584                                 "public enum ItemChoiceType {{{0}" +
585                                 "    {0}" +
586                                 "    /// <remarks/>{0}" +
587                                 "    ChoiceZero,{0}" +
588                                 "    {0}" +
589                                 "    /// <remarks/>{0}" +
590                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"ChoiceOne\")]{0}" +
591                                 "    StrangeOne,{0}" +
592                                 "    {0}" +
593                                 "    /// <remarks/>{0}" +
594                                 "    ChoiceTwo,{0}" +
595 #if NET_2_0
596                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#4");
597 #else
598                                 "}}{0}", Environment.NewLine), sw.ToString (), "#4");
599 #endif
600                 }
601
602                 [Test]
603                 public void ExportTypeMapping_ClassArrayContainer ()
604                 {
605                         CodeNamespace codeNamespace = ExportCode (typeof (ClassArrayContainer));
606                         Assert.IsNotNull (codeNamespace, "#1");
607
608                         StringWriter sw = new StringWriter ();
609                         CodeDomProvider provider = new CSharpCodeProvider ();
610                         ICodeGenerator generator = provider.CreateGenerator ();
611                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
612
613                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
614                                 "{0}{0}" +
615                                 "/// <remarks/>{0}" +
616 #if NET_2_0
617                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
618                                 "[System.SerializableAttribute()]{0}" +
619                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
620                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
621                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
622                                 "public partial class ClassArrayContainer {{{0}" +
623                                 "    {0}" +
624                                 "    private MonoTests.System.Xml.TestClasses.SimpleClass[] itemsField;{0}" +
625                                 "    {0}" +
626                                 "    /// <remarks/>{0}" +
627                                 "    public MonoTests.System.Xml.TestClasses.SimpleClass[] items {{{0}" +
628                                 "        get {{{0}" +
629                                 "            return this.itemsField;{0}" +
630                                 "        }}{0}" +
631                                 "        set {{{0}" +
632                                 "            this.itemsField = value;{0}" +
633                                 "        }}{0}" +
634                                 "    }}{0}" +
635                                 "}}{0}" +
636                                 "{0}" +
637                                 "/// <remarks/>{0}" +
638                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
639                                 "[System.SerializableAttribute()]{0}" +
640                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
641                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
642                                 "public partial class SimpleClass {{{0}" +
643                                 "    {0}" +
644                                 "    private string somethingField;{0}" +
645                                 "    {0}" +
646                                 "    /// <remarks/>{0}" +
647                                 "    public string something {{{0}" +
648                                 "        get {{{0}" +
649                                 "            return this.somethingField;{0}" +
650                                 "        }}{0}" +
651                                 "        set {{{0}" +
652                                 "            this.somethingField = value;{0}" +
653                                 "        }}{0}" +
654                                 "    }}{0}" +
655                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
656 #else
657                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=true)]{0}" +
658                                 "public class ClassArrayContainer {{{0}" +
659                                 "    {0}" +
660                                 "    /// <remarks/>{0}" +
661                                 "    public MonoTests.System.Xml.TestClasses.SimpleClass[] items;{0}" +
662                                 "}}{0}" +
663                                 "{0}" +
664                                 "/// <remarks/>{0}" +
665                                 "public class SimpleClass {{{0}" +
666                                 "    {0}" +
667                                 "    /// <remarks/>{0}" +
668                                 "    public string something;{0}" +
669                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
670 #endif
671                 }
672
673                 [Test]
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 #if NET_2_0
689                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
690                                 "[System.SerializableAttribute()]{0}" +
691                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
692                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
693                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:aNS\")]{0}" +
694                                 "[System.Xml.Serialization.XmlRootAttribute(\"root\", Namespace=\"urn:aNS\", IsNullable=false)]{0}" +
695                                 "public partial class Root {{{0}" +
696                                 "    {0}" +
697                                 "    private MonoTests.System.Xml.TestClasses.OptionalValueTypeContainer optionalValueField;{0}" +
698                                 "    {0}" +
699                                 "    private MonoTests.System.Xml.TestClasses.TestDefault defaultField;{0}" +
700                                 "    {0}" +
701                                 "    /// <remarks/>{0}" +
702                                 "    public MonoTests.System.Xml.TestClasses.OptionalValueTypeContainer OptionalValue {{{0}" +
703                                 "        get {{{0}" +
704                                 "            return this.optionalValueField;{0}" +
705                                 "        }}{0}" +
706                                 "        set {{{0}" +
707                                 "            this.optionalValueField = value;{0}" +
708                                 "        }}{0}" +
709                                 "    }}{0}" +
710                                 "    {0}" +
711                                 "    /// <remarks/>{0}" +
712                                 "    public MonoTests.System.Xml.TestClasses.TestDefault Default {{{0}" +
713                                 "        get {{{0}" +
714                                 "            return this.defaultField;{0}" +
715                                 "        }}{0}" +
716                                 "        set {{{0}" +
717                                 "            this.defaultField = value;{0}" +
718                                 "        }}{0}" +
719                                 "    }}{0}" +
720                                 "}}{0}" +
721                                 "{0}" +
722                                 "/// <remarks/>{0}" +
723                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
724                                 "[System.SerializableAttribute()]{0}" +
725                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
726                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
727                                 "[System.Xml.Serialization.XmlTypeAttribute(TypeName=\"optionalValueType\", Namespace=\"some:urn\")]{0}" +
728                                 "public partial class OptionalValueTypeContainer {{{0}" +
729                                 "    {0}" +
730                                 "    private MonoTests.System.Xml.TestClasses.FlagEnum attributesField;{0}" +
731                                 "    {0}" +
732                                 "    private MonoTests.System.Xml.TestClasses.FlagEnum flagsField;{0}" +
733                                 "    {0}" +
734                                 "    private bool flagsFieldSpecified;{0}" +
735                                 "    {0}" +
736                                 "    private bool isEmptyField;{0}" +
737                                 "    {0}" +
738                                 "    private bool isEmptyFieldSpecified;{0}" +
739                                 "    {0}" +
740                                 "    private bool isNullField;{0}" +
741                                 "    {0}" +
742                                 "    public OptionalValueTypeContainer() {{{0}" +
743                                 "        this.attributesField = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
744                                 "        this.flagsField = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
745                                 "    }}{0}" +
746                                 "    {0}" +
747                                 "    /// <remarks/>{0}" +
748                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Attributes {{{0}" +
749                                 "        get {{{0}" +
750                                 "            return this.attributesField;{0}" +
751                                 "        }}{0}" +
752                                 "        set {{{0}" +
753                                 "            this.attributesField = value;{0}" +
754                                 "        }}{0}" +
755                                 "    }}{0}" +
756                                 "    {0}" +
757                                 "    /// <remarks/>{0}" +
758                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags {{{0}" +
759                                 "        get {{{0}" +
760                                 "            return this.flagsField;{0}" +
761                                 "        }}{0}" +
762                                 "        set {{{0}" +
763                                 "            this.flagsField = value;{0}" +
764                                 "        }}{0}" +
765                                 "    }}{0}" +
766                                 "    {0}" +
767                                 "    /// <remarks/>{0}" +
768                                 "    [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
769                                 "    public bool FlagsSpecified {{{0}" +
770                                 "        get {{{0}" +
771                                 "            return this.flagsFieldSpecified;{0}" +
772                                 "        }}{0}" +
773                                 "        set {{{0}" +
774                                 "            this.flagsFieldSpecified = value;{0}" +
775                                 "        }}{0}" +
776                                 "    }}{0}" +
777                                 "    {0}" +
778                                 "    /// <remarks/>{0}" +
779                                 "    public bool IsEmpty {{{0}" +
780                                 "        get {{{0}" +
781                                 "            return this.isEmptyField;{0}" +
782                                 "        }}{0}" +
783                                 "        set {{{0}" +
784                                 "            this.isEmptyField = value;{0}" +
785                                 "        }}{0}" +
786                                 "    }}{0}" +
787                                 "    {0}" +
788                                 "    /// <remarks/>{0}" +
789                                 "    [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
790                                 "    public bool IsEmptySpecified {{{0}" +
791                                 "        get {{{0}" +
792                                 "            return this.isEmptyFieldSpecified;{0}" +
793                                 "        }}{0}" +
794                                 "        set {{{0}" +
795                                 "            this.isEmptyFieldSpecified = value;{0}" +
796                                 "        }}{0}" +
797                                 "    }}{0}" +
798                                 "    {0}" +
799                                 "    /// <remarks/>{0}" +
800                                 "    public bool IsNull {{{0}" +
801                                 "        get {{{0}" +
802                                 "            return this.isNullField;{0}" +
803                                 "        }}{0}" +
804                                 "        set {{{0}" +
805                                 "            this.isNullField = value;{0}" +
806                                 "        }}{0}" +
807                                 "    }}{0}" +
808                                 "}}{0}" +
809                                 "{0}" +
810                                 "/// <remarks/>{0}" +
811                                 "[System.FlagsAttribute()]{0}" +
812                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
813                                 "[System.SerializableAttribute()]{0}" +
814                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"some:urn\")]{0}" +
815                                 "public enum FlagEnum {{{0}" +
816                                 "    {0}" +
817                                 "    /// <remarks/>{0}" +
818                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
819                                 "    e1 = 1,{0}" +
820                                 "    {0}" +
821                                 "    /// <remarks/>{0}" +
822                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
823                                 "    e2 = 2,{0}" +
824                                 "    {0}" +
825                                 "    /// <remarks/>{0}" +
826                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
827                                 "    e4 = 4,{0}" +
828                                 "}}{0}" +
829                                 "{0}" +
830                                 "/// <remarks/>{0}" +
831                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
832                                 "[System.SerializableAttribute()]{0}" +
833                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
834                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
835                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
836                                 "public partial class TestDefault {{{0}" +
837                                 "    {0}" +
838                                 "    private string strField;{0}" +
839                                 "    {0}" +
840                                 "    private string strDefaultField;{0}" +
841                                 "    {0}" +
842                                 "    private bool boolTField;{0}" +
843                                 "    {0}" +
844                                 "    private bool boolFField;{0}" +
845                                 "    {0}" +
846                                 "    private decimal decimalvalField;{0}" +
847                                 "    {0}" +
848                                 "    private MonoTests.System.Xml.TestClasses.FlagEnum flagField;{0}" +
849                                 "    {0}" +
850                                 "    private MonoTests.System.Xml.TestClasses.FlagEnum_Encoded flagencodedField;{0}" +
851                                 "    {0}" +
852                                 "    public TestDefault() {{{0}" +
853                                 "        this.strDefaultField = \"Default Value\";{0}" +
854                                 "        this.flagField = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
855                                 "        this.flagencodedField = (MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1 | MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4);{0}" +
856                                 "    }}{0}" +
857                                 "    {0}" +
858                                 "    /// <remarks/>{0}" +
859                                 "    public string str {{{0}" +
860                                 "        get {{{0}" +
861                                 "            return this.strField;{0}" +
862                                 "        }}{0}" +
863                                 "        set {{{0}" +
864                                 "            this.strField = value;{0}" +
865                                 "        }}{0}" +
866                                 "    }}{0}" +
867                                 "    {0}" +
868                                 "    /// <remarks/>{0}" +
869                                 "    public string strDefault {{{0}" +
870                                 "        get {{{0}" +
871                                 "            return this.strDefaultField;{0}" +
872                                 "        }}{0}" +
873                                 "        set {{{0}" +
874                                 "            this.strDefaultField = value;{0}" +
875                                 "        }}{0}" +
876                                 "    }}{0}" +
877                                 "    {0}" +
878                                 "    /// <remarks/>{0}" +
879                                 "    public bool boolT {{{0}" +
880                                 "        get {{{0}" +
881                                 "            return this.boolTField;{0}" +
882                                 "        }}{0}" +
883                                 "        set {{{0}" +
884                                 "            this.boolTField = value;{0}" +
885                                 "        }}{0}" +
886                                 "    }}{0}" +
887                                 "    {0}" +
888                                 "    /// <remarks/>{0}" +
889                                 "    public bool boolF {{{0}" +
890                                 "        get {{{0}" +
891                                 "            return this.boolFField;{0}" +
892                                 "        }}{0}" +
893                                 "        set {{{0}" +
894                                 "            this.boolFField = value;{0}" +
895                                 "        }}{0}" +
896                                 "    }}{0}" +
897                                 "    {0}" +
898                                 "    /// <remarks/>{0}" +
899                                 "    public decimal decimalval {{{0}" +
900                                 "        get {{{0}" +
901                                 "            return this.decimalvalField;{0}" +
902                                 "        }}{0}" +
903                                 "        set {{{0}" +
904                                 "            this.decimalvalField = value;{0}" +
905                                 "        }}{0}" +
906                                 "    }}{0}" +
907                                 "    {0}" +
908                                 "    /// <remarks/>{0}" +
909                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum flag {{{0}" +
910                                 "        get {{{0}" +
911                                 "            return this.flagField;{0}" +
912                                 "        }}{0}" +
913                                 "        set {{{0}" +
914                                 "            this.flagField = value;{0}" +
915                                 "        }}{0}" +
916                                 "    }}{0}" +
917                                 "    {0}" +
918                                 "    /// <remarks/>{0}" +
919                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum_Encoded flagencoded {{{0}" +
920                                 "        get {{{0}" +
921                                 "            return this.flagencodedField;{0}" +
922                                 "        }}{0}" +
923                                 "        set {{{0}" +
924                                 "            this.flagencodedField = value;{0}" +
925                                 "        }}{0}" +
926                                 "    }}{0}" +
927                                 "}}{0}" +
928                                 "{0}" +
929                                 "/// <remarks/>{0}" +
930                                 "[System.FlagsAttribute()]{0}" +
931                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
932                                 "[System.SerializableAttribute()]{0}" +
933                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
934                                 "public enum FlagEnum {{{0}" +
935                                 "    {0}" +
936                                 "    /// <remarks/>{0}" +
937                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
938                                 "    e1 = 1,{0}" +
939                                 "    {0}" +
940                                 "    /// <remarks/>{0}" +
941                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
942                                 "    e2 = 2,{0}" +
943                                 "    {0}" +
944                                 "    /// <remarks/>{0}" +
945                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
946                                 "    e4 = 4,{0}" +
947                                 "}}{0}" +
948                                 "{0}" +
949                                 "/// <remarks/>{0}" +
950                                 "[System.FlagsAttribute()]{0}" +
951                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
952                                 "[System.SerializableAttribute()]{0}" +
953                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
954                                 "public enum FlagEnum_Encoded {{{0}" +
955                                 "    {0}" +
956                                 "    /// <remarks/>{0}" +
957                                 "    e1 = 1,{0}" +
958                                 "    {0}" +
959                                 "    /// <remarks/>{0}" +
960                                 "    e2 = 2,{0}" +
961                                 "    {0}" +
962                                 "    /// <remarks/>{0}" +
963                                 "    e4 = 4,{0}" +
964                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
965 #else
966                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:aNS\")]{0}" +
967                                 "[System.Xml.Serialization.XmlRootAttribute(\"root\", Namespace=\"urn:aNS\", IsNullable=false)]{0}" +
968                                 "public class Root {{{0}" +
969                                 "    {0}" +
970                                 "    /// <remarks/>{0}" +
971                                 "    public MonoTests.System.Xml.TestClasses.OptionalValueTypeContainer OptionalValue;{0}" +
972                                 "    {0}" +
973                                 "    /// <remarks/>{0}" +
974                                 "    public MonoTests.System.Xml.TestClasses.TestDefault Default;{0}" +
975                                 "}}{0}" +
976                                 "{0}" +
977                                 "/// <remarks/>{0}" +
978                                 "[System.Xml.Serialization.XmlTypeAttribute(TypeName=\"optionalValueType\", Namespace=\"some:urn\")]{0}" +
979                                 "public class OptionalValueTypeContainer {{{0}" +
980                                 "    {0}" +
981                                 "    /// <remarks/>{0}" +
982                                 "    [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4))]{0}" +
983                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Attributes = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
984                                 "    {0}" +
985                                 "    /// <remarks/>{0}" +
986                                 "    [System.ComponentModel.DefaultValueAttribute(MonoTests.System.Xml.TestClasses.FlagEnum.e1)]{0}" +
987                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum Flags = MonoTests.System.Xml.TestClasses.FlagEnum.e1;{0}" +
988                                 "    {0}" +
989                                 "    /// <remarks/>{0}" +
990                                 "    [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
991                                 "    public bool FlagsSpecified;{0}" +
992                                 "    {0}" +
993                                 "    /// <remarks/>{0}" +
994                                 "    [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
995                                 "    public bool IsEmpty = false;{0}" +
996                                 "    {0}" +
997                                 "    /// <remarks/>{0}" +
998                                 "    [System.Xml.Serialization.XmlIgnoreAttribute()]{0}" +
999                                 "    public bool IsEmptySpecified;{0}" +
1000                                 "    {0}" +
1001                                 "    /// <remarks/>{0}" +
1002                                 "    [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
1003                                 "    public bool IsNull = false;{0}" +
1004                                 "}}{0}" +
1005                                 "{0}" +
1006                                 "/// <remarks/>{0}" +
1007                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"some:urn\")]{0}" +
1008                                 "[System.FlagsAttribute()]{0}" +
1009                                 "public enum FlagEnum {{{0}" +
1010                                 "    {0}" +
1011                                 "    /// <remarks/>{0}" +
1012                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
1013                                 "    e1 = 1,{0}" +
1014                                 "    {0}" +
1015                                 "    /// <remarks/>{0}" +
1016                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
1017                                 "    e2 = 2,{0}" +
1018                                 "    {0}" +
1019                                 "    /// <remarks/>{0}" +
1020                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
1021                                 "    e4 = 4,{0}" +
1022                                 "}}{0}" +
1023                                 "{0}" +
1024                                 "/// <remarks/>{0}" +
1025                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
1026                                 "public class TestDefault {{{0}" +
1027                                 "    {0}" +
1028                                 "    /// <remarks/>{0}" +
1029                                 "    public string str;{0}" +
1030                                 "    {0}" +
1031                                 "    /// <remarks/>{0}" +
1032                                 "    [System.ComponentModel.DefaultValueAttribute(\"Default Value\")]{0}" +
1033                                 "    public string strDefault = \"Default Value\";{0}" +
1034                                 "    {0}" +
1035                                 "    /// <remarks/>{0}" +
1036                                 "    [System.ComponentModel.DefaultValueAttribute(true)]{0}" +
1037                                 "    public bool boolT = true;{0}" +
1038                                 "    {0}" +
1039                                 "    /// <remarks/>{0}" +
1040                                 "    [System.ComponentModel.DefaultValueAttribute(false)]{0}" +
1041                                 "    public bool boolF = false;{0}" +
1042                                 "    {0}" +
1043                                 "    /// <remarks/>{0}" +
1044                                 "    [System.ComponentModel.DefaultValueAttribute(typeof(System.Decimal), \"10\")]{0}" +
1045                                 "    public System.Decimal decimalval = ((System.Decimal)(10m));{0}" +
1046                                 "    {0}" +
1047                                 "    /// <remarks/>{0}" +
1048                                 "    [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4))]{0}" +
1049                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum flag = (MonoTests.System.Xml.TestClasses.FlagEnum.e1 | MonoTests.System.Xml.TestClasses.FlagEnum.e4);{0}" +
1050                                 "    {0}" +
1051                                 "    /// <remarks/>{0}" +
1052                                 "    [System.ComponentModel.DefaultValueAttribute((MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1 | MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4))]{0}" +
1053                                 "    public MonoTests.System.Xml.TestClasses.FlagEnum_Encoded flagencoded = (MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e1 | MonoTests.System.Xml.TestClasses.FlagEnum_Encoded.e4);{0}" +
1054                                 "}}{0}" +
1055                                 "{0}" +
1056                                 "/// <remarks/>{0}" +
1057                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
1058                                 "[System.FlagsAttribute()]{0}" +
1059                                 "public enum FlagEnum {{{0}" +
1060                                 "    {0}" +
1061                                 "    /// <remarks/>{0}" +
1062                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"one\")]{0}" +
1063                                 "    e1 = 1,{0}" +
1064                                 "    {0}" +
1065                                 "    /// <remarks/>{0}" +
1066                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"two\")]{0}" +
1067                                 "    e2 = 2,{0}" +
1068                                 "    {0}" +
1069                                 "    /// <remarks/>{0}" +
1070                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"four\")]{0}" +
1071                                 "    e4 = 4,{0}" +
1072                                 "}}{0}" +
1073                                 "{0}" +
1074                                 "/// <remarks/>{0}" +
1075                                 "[System.Xml.Serialization.XmlTypeAttribute(Namespace=\"urn:myNS\")]{0}" +
1076                                 "[System.FlagsAttribute()]{0}" +
1077                                 "public enum FlagEnum_Encoded {{{0}" +
1078                                 "    {0}" +
1079                                 "    /// <remarks/>{0}" +
1080                                 "    e1 = 1,{0}" +
1081                                 "    {0}" +
1082                                 "    /// <remarks/>{0}" +
1083                                 "    e2 = 2,{0}" +
1084                                 "    {0}" +
1085                                 "    /// <remarks/>{0}" +
1086                                 "    e4 = 4,{0}" +
1087                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
1088 #endif
1089                 }
1090
1091                 [Test]
1092                 public void ExportTypeMapping_SimpleClassWithXmlAttributes ()
1093                 {
1094                         CodeNamespace codeNamespace = ExportCode (typeof (SimpleClassWithXmlAttributes));
1095                         Assert.IsNotNull (codeNamespace, "#1");
1096
1097                         StringWriter sw = new StringWriter ();
1098                         CodeDomProvider provider = new CSharpCodeProvider ();
1099                         ICodeGenerator generator = provider.CreateGenerator ();
1100                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
1101
1102                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1103                                 "{0}{0}" +
1104                                 "/// <remarks/>{0}" +
1105 #if NET_2_0
1106                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
1107                                 "[System.SerializableAttribute()]{0}" +
1108                                 "[System.Diagnostics.DebuggerStepThroughAttribute()]{0}" +
1109                                 "[System.ComponentModel.DesignerCategoryAttribute(\"code\")]{0}" +
1110                                 "[System.Xml.Serialization.XmlRootAttribute(\"simple\", Namespace=\"\", IsNullable=true)]{0}" +
1111                                 "public partial class SimpleClassWithXmlAttributes {{{0}" +
1112                                 "    {0}" +
1113                                 "    private string somethingField;{0}" +
1114                                 "    {0}" +
1115                                 "    /// <remarks/>{0}" +
1116                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"member\")]{0}" +
1117                                 "    public string something {{{0}" +
1118                                 "        get {{{0}" +
1119                                 "            return this.somethingField;{0}" +
1120                                 "        }}{0}" +
1121                                 "        set {{{0}" +
1122                                 "            this.somethingField = value;{0}" +
1123                                 "        }}{0}" +
1124                                 "    }}{0}" +
1125                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
1126 #else
1127                                 "[System.Xml.Serialization.XmlRootAttribute(\"simple\", Namespace=\"\", IsNullable=true)]{0}" +
1128                                 "public class SimpleClassWithXmlAttributes {{{0}" +
1129                                 "    {0}" +
1130                                 "    /// <remarks/>{0}" +
1131                                 "    [System.Xml.Serialization.XmlAttributeAttribute(\"member\")]{0}" +
1132                                 "    public string something;{0}" +
1133                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
1134 #endif
1135                 }
1136
1137                 [Test]
1138                 public void ExportTypeMapping_XsdPrimitive_Arrays ()
1139                 {
1140                         ArrayList types = new ArrayList ();
1141                         types.Add (typeof (sbyte[]));
1142                         types.Add (typeof (bool[]));
1143                         types.Add (typeof (short[]));
1144                         types.Add (typeof (int[]));
1145                         types.Add (typeof (long[]));
1146                         types.Add (typeof (float[]));
1147                         types.Add (typeof (double[]));
1148                         types.Add (typeof (decimal[]));
1149                         types.Add (typeof (ushort[]));
1150                         types.Add (typeof (uint[]));
1151                         types.Add (typeof (ulong[]));
1152                         types.Add (typeof (DateTime[]));
1153                         types.Add (typeof (XmlQualifiedName[]));
1154                         types.Add (typeof (string[]));
1155
1156                         StringWriter sw = new StringWriter ();
1157                         CodeDomProvider provider = new CSharpCodeProvider ();
1158                         ICodeGenerator generator = provider.CreateGenerator ();
1159
1160                         foreach (Type type in types) {
1161                                 CodeNamespace codeNamespace = ExportCode (type);
1162                                 Assert.IsNotNull (codeNamespace, type.FullName + "#1");
1163
1164                                 generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
1165
1166                                 Assert.AreEqual (Environment.NewLine, sw.ToString (), 
1167                                         type.FullName + "#2");
1168
1169                                 sw.GetStringBuilder ().Length = 0;
1170                         }
1171                 }
1172
1173                 [Test]
1174                 public void ExportTypeMapping_ZeroFlagEnum ()
1175                 {
1176                         CodeNamespace codeNamespace = ExportCode (typeof (ZeroFlagEnum));
1177                         Assert.IsNotNull (codeNamespace, "#1");
1178
1179                         StringWriter sw = new StringWriter ();
1180                         CodeDomProvider provider = new CSharpCodeProvider ();
1181                         ICodeGenerator generator = provider.CreateGenerator ();
1182                         generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
1183
1184                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1185                                 "{0}{0}" +
1186                                 "/// <remarks/>{0}" +
1187                                 "[System.FlagsAttribute()]{0}" +
1188 #if NET_2_0
1189                                 "[System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Xml\", \"{1}\")]{0}" +
1190                                 "[System.SerializableAttribute()]{0}" +
1191 #endif
1192                                 "[System.Xml.Serialization.XmlRootAttribute(Namespace=\"\", IsNullable=false)]{0}" +
1193                                 "public enum ZeroFlagEnum {{{0}" +
1194                                 "    {0}" +
1195                                 "    /// <remarks/>{0}" +
1196                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"zero\")]{0}" +
1197                                 "    e0 = 1,{0}" +
1198                                 "    {0}" +
1199                                 "    /// <remarks/>{0}" +
1200                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"o<n>e\")]{0}" +
1201                                 "    e1 = 2,{0}" +
1202                                 "    {0}" +
1203                                 "    /// <remarks/>{0}" +
1204                                 "    [System.Xml.Serialization.XmlEnumAttribute(\"tns:t<w>o\")]{0}" +
1205                                 "    e2 = 4,{0}" +
1206 #if NET_2_0
1207                                 "}}{0}", Environment.NewLine, XmlFileVersion), sw.ToString (), "#2");
1208 #else
1209                                 "}}{0}", Environment.NewLine), sw.ToString (), "#2");
1210 #endif
1211                 }
1212
1213                 [Test]
1214                 public void DuplicateIdentifiers ()
1215                 {
1216                         XmlSchema xs = XmlSchema.Read (File.OpenText ("Test/XmlFiles/xsd/82078.xsd"), null);
1217
1218                         XmlSchemas xss = new XmlSchemas ();
1219                         xss.Add (xs);
1220                         XmlSchemaImporter imp = new XmlSchemaImporter (xss);
1221                         CodeNamespace cns = new CodeNamespace ();
1222                         XmlCodeExporter exp = new XmlCodeExporter (cns);
1223                         XmlQualifiedName qname = new XmlQualifiedName (
1224                                 "Operation", "http://tempuri.org/");
1225                         exp.ExportTypeMapping (imp.ImportTypeMapping (qname));
1226                         CodeCompileUnit ccu = new CodeCompileUnit ();
1227                         ccu.Namespaces.Add (cns);
1228
1229                         CodeDomProvider provider = new CSharpCodeProvider ();
1230                         ICodeCompiler compiler = provider.CreateCompiler ();
1231
1232                         CompilerParameters options = new CompilerParameters ();
1233                         options.ReferencedAssemblies.Add ("System.dll");
1234                         options.ReferencedAssemblies.Add ("System.Xml.dll");
1235                         options.GenerateInMemory = true;
1236
1237                         CompilerResults result = compiler.CompileAssemblyFromDom (options, ccu);
1238                         Assert.AreEqual (0, result.Errors.Count, "#1");
1239                         Assert.IsNotNull (result.CompiledAssembly, "#2");
1240                 }
1241
1242                 [Test]
1243                 public void ExportSimpleContentExtensionEnum ()
1244                 {
1245                         string xsd = @"
1246 <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:b='urn:bar' targetNamespace='urn:bar'>
1247   <xs:element name='Foo' type='b:DayOfWeek' />
1248   <xs:complexType name='DayOfWeek'>
1249     <xs:simpleContent>
1250       <xs:extension base='b:WeekDay' />
1251     </xs:simpleContent>
1252   </xs:complexType>
1253   <xs:simpleType name='WeekDay'>
1254     <xs:restriction base='xs:string'>
1255       <xs:enumeration value='Sunday'/>
1256       <xs:enumeration value='Monday'/>
1257       <xs:enumeration value='Tuesday'/>
1258       <xs:enumeration value='Wednesday'/>
1259       <xs:enumeration value='Thursday'/>
1260       <xs:enumeration value='Friday'/>
1261       <xs:enumeration value='Saturday'/>
1262     </xs:restriction>
1263   </xs:simpleType>
1264 </xs:schema>";
1265                         XmlSchema xs = XmlSchema.Read (new StringReader (xsd), null);
1266                         XmlSchemas xss = new XmlSchemas ();
1267                         xss.Add (xs);
1268                         XmlSchemaImporter imp = new XmlSchemaImporter (xss);
1269                         XmlTypeMapping m = imp.ImportTypeMapping (new XmlQualifiedName ("Foo", "urn:bar"));
1270                         CodeNamespace cns = new CodeNamespace ();
1271                         XmlCodeExporter exp = new XmlCodeExporter (cns);
1272                         exp.ExportTypeMapping (m);
1273                         CodeTypeDeclaration enumType = null;
1274                         foreach (CodeTypeDeclaration ctd in cns.Types)
1275                                 if (ctd.Name == "WeekDay")
1276                                         enumType = ctd;
1277                         Assert.IsNotNull (enumType);
1278                 }
1279
1280                 CodeNamespace ExportCode (Type type)
1281                 {
1282                         XmlReflectionImporter imp = new XmlReflectionImporter ();
1283                         XmlTypeMapping map = imp.ImportTypeMapping (type);
1284                         CodeNamespace codeNamespace = new CodeNamespace ();
1285                         XmlCodeExporter exp = new XmlCodeExporter (codeNamespace);
1286                         exp.ExportTypeMapping (map);
1287                         return codeNamespace;
1288                 }
1289
1290 #if NET_2_0
1291                 string XmlFileVersion {
1292                         get {
1293                                 Assembly xmlAsm = typeof (XmlDocument).Assembly;
1294                                 AssemblyFileVersionAttribute afv = (AssemblyFileVersionAttribute)
1295                                         Attribute.GetCustomAttribute (xmlAsm, typeof (AssemblyFileVersionAttribute));
1296                                 return afv.Version;
1297                         }
1298                 }
1299 #endif
1300
1301                 [XmlRootAttribute ("root", Namespace="urn:aNS", IsNullable=false)]
1302                 public class Root
1303                 {
1304                         public OptionalValueTypeContainer OptionalValue;
1305                         public TestDefault Default;
1306                 }
1307         }
1308 }
1309
1310 #endif