* support-test-*.cs: Rename from test-*-p2.cs.
[mono.git] / mcs / class / System.XML / Test / System.Xml.Serialization / XmlSchemaExporterTests.cs
1 //
2 // System.Xml.Serialization.XmlSchemaExporterTests
3 //
4 // Author:
5 //   Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // (C) 2005 Novell
8 // 
9
10 using System;
11 using System.Collections;
12 using System.Globalization;
13 using System.IO;
14 using System.Xml;
15 using System.Xml.Schema;
16 using System.Xml.Serialization;
17
18 using NUnit.Framework;
19
20 using MonoTests.System.Xml.TestClasses;
21
22 namespace MonoTests.System.XmlSerialization
23 {
24         [TestFixture]
25         public class XmlSchemaExporterTests
26         {
27                 private XmlSchemas Export (Type type)
28                 {
29                         return Export (type, string.Empty);
30                 }
31
32                 private XmlSchemas Export (Type type, string defaultNamespace)
33                 {
34                         XmlReflectionImporter ri = new XmlReflectionImporter (defaultNamespace);
35                         XmlSchemas schemas = new XmlSchemas ();
36                         XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
37                         XmlTypeMapping tm = ri.ImportTypeMapping (type);
38                         sx.ExportTypeMapping (tm);
39                         return schemas;
40                 }
41
42                 private XmlSchemas Export (Type type, XmlAttributeOverrides overrides)
43                 {
44                         return Export (type, overrides, string.Empty);
45                 }
46
47                 private XmlSchemas Export (Type type, XmlAttributeOverrides overrides, string defaultNamespace)
48                 {
49                         XmlReflectionImporter ri = new XmlReflectionImporter (overrides, defaultNamespace);
50                         XmlSchemas schemas = new XmlSchemas ();
51                         XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
52                         XmlTypeMapping tm = ri.ImportTypeMapping (type);
53                         sx.ExportTypeMapping (tm);
54                         return schemas;
55                 }
56
57                 [Test]
58                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
59                 public void ExportStruct ()
60                 {
61                         XmlSchemas schemas = Export (typeof (TimeSpan), "NSTimeSpan");
62                         Assert.AreEqual (1, schemas.Count, "#1");
63
64                         StringWriter sw = new StringWriter ();
65                         schemas[0].Write (sw);
66
67                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
68                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
69                                 "<xs:schema xmlns:tns=\"NSTimeSpan\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpan\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
70                                 "  <xs:element name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
71                                 "  <xs:complexType name=\"TimeSpan\" />{0}" +
72                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
73
74                         schemas = Export (typeof (TimeSpan));
75                         Assert.AreEqual (1, schemas.Count, "#3");
76
77                         sw.GetStringBuilder ().Length = 0;
78                         schemas[0].Write (sw);
79
80                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
81                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
82                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
83                                 "  <xs:element name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
84                                 "  <xs:complexType name=\"TimeSpan\" />{0}" +
85                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
86                 }
87
88                 [Test]
89                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
90                 public void ExportStruct_Array ()
91                 {
92                         XmlSchemas schemas = Export (typeof (TimeSpan[]), "NSTimeSpanArray");
93                         Assert.AreEqual (1, schemas.Count, "#1");
94
95                         StringWriter sw = new StringWriter ();
96                         schemas[0].Write (sw);
97
98                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
99                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
100                                 "<xs:schema xmlns:tns=\"NSTimeSpanArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpanArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
101 #if MS // bug #77117
102                                 "  <xs:element name=\"ArrayOfTimeSpan\" nillable=\"true\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
103 #else
104                                 "  <xs:element name=\"ArrayOfTimeSpan\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
105 #endif
106                                 "  <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
107                                 "    <xs:sequence>{0}" +
108 #if MS // bug #77117
109                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
110 #else
111                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"tns:TimeSpan\" />{0}" +
112 #endif
113                                 "    </xs:sequence>{0}" +
114                                 "  </xs:complexType>{0}" +
115                                 "  <xs:complexType name=\"TimeSpan\" />{0}" +
116                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
117
118                         schemas = Export (typeof (TimeSpan[]));
119                         Assert.AreEqual (1, schemas.Count, "#3");
120
121                         sw.GetStringBuilder ().Length = 0;
122                         schemas[0].Write (sw);
123
124                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
125                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
126                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
127 #if MS // bug #77117
128                                 "  <xs:element name=\"ArrayOfTimeSpan\" nillable=\"true\" type=\"ArrayOfTimeSpan\" />{0}" +
129 #else
130                                 "  <xs:element name=\"ArrayOfTimeSpan\" type=\"ArrayOfTimeSpan\" />{0}" +
131 #endif
132                                 "  <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
133                                 "    <xs:sequence>{0}" +
134 #if MS // bug #77117
135                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
136 #else
137                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"TimeSpan\" />{0}" +
138 #endif
139                                 "    </xs:sequence>{0}" +
140                                 "  </xs:complexType>{0}" +
141                                 "  <xs:complexType name=\"TimeSpan\" />{0}" +
142                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
143                 }
144
145                 [Test]
146                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
147                 public void ExportClass_SimpleClass ()
148                 {
149                         XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
150                         XmlAttributes attr = new XmlAttributes ();
151                         XmlElementAttribute element = new XmlElementAttribute ();
152                         element.ElementName = "saying";
153                         element.IsNullable = true;
154                         attr.XmlElements.Add (element);
155                         overrides.Add (typeof (SimpleClass), "something", attr);
156
157                         XmlSchemas schemas = Export (typeof (SimpleClass), overrides, "NSSimpleClass");
158                         Assert.AreEqual (1, schemas.Count, "#1");
159
160                         StringWriter sw = new StringWriter ();
161                         schemas[0].Write (sw);
162
163                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
164                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
165                                 "<xs:schema xmlns:tns=\"NSSimpleClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
166 #if MS // bug #77117
167                                 "  <xs:element name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
168 #else
169                                 "  <xs:element name=\"SimpleClass\" type=\"tns:SimpleClass\" />{0}" +
170 #endif
171                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
172                                 "    <xs:sequence>{0}" +
173                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
174                                 "    </xs:sequence>{0}" +
175                                 "  </xs:complexType>{0}" +
176                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
177
178                         schemas = Export (typeof (SimpleClass), overrides);
179                         Assert.AreEqual (1, schemas.Count, "#3");
180
181                         sw.GetStringBuilder ().Length = 0;
182                         schemas[0].Write (sw);
183
184                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
185                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
186                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
187 #if MS // bug #77117
188                                 "  <xs:element name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
189 #else
190                                 "  <xs:element name=\"SimpleClass\" type=\"SimpleClass\" />{0}" +
191 #endif
192                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
193                                 "    <xs:sequence>{0}" +
194                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
195                                 "    </xs:sequence>{0}" +
196                                 "  </xs:complexType>{0}" +
197                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
198                 }
199
200                 [Test]
201                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
202                 public void ExportClass_StringCollection ()
203                 {
204                         XmlSchemas schemas = Export (typeof (StringCollection), "NSStringCollection");
205                         Assert.AreEqual (1, schemas.Count, "#1");
206
207                         StringWriter sw = new StringWriter ();
208                         schemas[0].Write (sw);
209
210                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
211                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
212                                 "<xs:schema xmlns:tns=\"NSStringCollection\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollection\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
213 #if MS // bug #77117
214                                 "  <xs:element name=\"ArrayOfString\" nillable=\"true\" type=\"tns:ArrayOfString\" />{0}" +
215 #else
216                                 "  <xs:element name=\"ArrayOfString\" type=\"tns:ArrayOfString\" />{0}" +
217 #endif
218                                 "  <xs:complexType name=\"ArrayOfString\">{0}" +
219                                 "    <xs:sequence>{0}" +
220                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
221                                 "    </xs:sequence>{0}" +
222                                 "  </xs:complexType>{0}" +
223                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
224
225                         schemas = Export (typeof (StringCollection));
226                         Assert.AreEqual (1, schemas.Count, "#3");
227
228                         sw.GetStringBuilder ().Length = 0;
229                         schemas[0].Write (sw);
230
231                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
232                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
233                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
234 #if MS // bug #77117
235                                 "  <xs:element name=\"ArrayOfString\" nillable=\"true\" type=\"ArrayOfString\" />{0}" +
236 #else
237                                 "  <xs:element name=\"ArrayOfString\" type=\"ArrayOfString\" />{0}" +
238 #endif
239                                 "  <xs:complexType name=\"ArrayOfString\">{0}" +
240                                 "    <xs:sequence>{0}" +
241                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
242                                 "    </xs:sequence>{0}" +
243                                 "  </xs:complexType>{0}" +
244                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
245                 }
246
247                 [Test]
248                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
249                 public void ExportClass_StringCollectionContainer ()
250                 {
251                         XmlSchemas schemas = Export (typeof (StringCollectionContainer), "NSStringCollectionContainer");
252                         Assert.AreEqual (1, schemas.Count, "#1");
253
254                         StringWriter sw = new StringWriter ();
255                         schemas[0].Write (sw);
256
257                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
258                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
259                                 "<xs:schema xmlns:tns=\"NSStringCollectionContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollectionContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
260 #if MS // bug #77117
261                                 "  <xs:element name=\"StringCollectionContainer\" nillable=\"true\" type=\"tns:StringCollectionContainer\" />{0}" +
262 #else
263                                 "  <xs:element name=\"StringCollectionContainer\" type=\"tns:StringCollectionContainer\" />{0}" +
264 #endif
265                                 "  <xs:complexType name=\"StringCollectionContainer\">{0}" +
266                                 "    <xs:sequence>{0}" +
267                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"tns:ArrayOfString\" />{0}" +
268                                 "    </xs:sequence>{0}" +
269                                 "  </xs:complexType>{0}" +
270                                 "  <xs:complexType name=\"ArrayOfString\">{0}" +
271                                 "    <xs:sequence>{0}" +
272                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
273                                 "    </xs:sequence>{0}" +
274                                 "  </xs:complexType>{0}" +
275                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
276
277                         schemas = Export (typeof (StringCollectionContainer));
278                         Assert.AreEqual (1, schemas.Count, "#3");
279
280                         sw.GetStringBuilder ().Length = 0;
281                         schemas[0].Write (sw);
282
283                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
284                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
285                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
286 #if MS // bug #77117
287                                 "  <xs:element name=\"StringCollectionContainer\" nillable=\"true\" type=\"StringCollectionContainer\" />{0}" +
288 #else
289                                 "  <xs:element name=\"StringCollectionContainer\" type=\"StringCollectionContainer\" />{0}" +
290 #endif
291                                 "  <xs:complexType name=\"StringCollectionContainer\">{0}" +
292                                 "    <xs:sequence>{0}" +
293                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"ArrayOfString\" />{0}" +
294                                 "    </xs:sequence>{0}" +
295                                 "  </xs:complexType>{0}" +
296                                 "  <xs:complexType name=\"ArrayOfString\">{0}" +
297                                 "    <xs:sequence>{0}" +
298                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
299                                 "    </xs:sequence>{0}" +
300                                 "  </xs:complexType>{0}" +
301                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
302                 }
303
304                 [Test]
305                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
306                 public void ExportClass_ArrayContainer ()
307                 {
308                         XmlSchemas schemas = Export (typeof (ArrayContainer), "NSArrayContainer");
309                         Assert.AreEqual (1, schemas.Count, "#1");
310
311                         StringWriter sw = new StringWriter ();
312                         schemas[0].Write (sw);
313
314                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
315                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
316                                 "<xs:schema xmlns:tns=\"NSArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
317 #if MS // bug #77117
318                                 "  <xs:element name=\"ArrayContainer\" nillable=\"true\" type=\"tns:ArrayContainer\" />{0}" +
319 #else
320                                 "  <xs:element name=\"ArrayContainer\" type=\"tns:ArrayContainer\" />{0}" +
321 #endif
322                                 "  <xs:complexType name=\"ArrayContainer\">{0}" +
323                                 "    <xs:sequence>{0}" +
324                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfAnyType\" />{0}" +
325                                 "    </xs:sequence>{0}" +
326                                 "  </xs:complexType>{0}" +
327                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
328                                 "    <xs:sequence>{0}" +
329                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
330                                 "    </xs:sequence>{0}" +
331                                 "  </xs:complexType>{0}" +
332                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
333
334                         schemas = Export (typeof (ArrayContainer));
335                         Assert.AreEqual (1, schemas.Count, "#3");
336
337                         sw.GetStringBuilder ().Length = 0;
338                         schemas[0].Write (sw);
339
340                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
341                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
342                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
343 #if MS // bug #77117
344                                 "  <xs:element name=\"ArrayContainer\" nillable=\"true\" type=\"ArrayContainer\" />{0}" +
345 #else
346                                 "  <xs:element name=\"ArrayContainer\" type=\"ArrayContainer\" />{0}" +
347 #endif
348                                 "  <xs:complexType name=\"ArrayContainer\">{0}" +
349                                 "    <xs:sequence>{0}" +
350                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfAnyType\" />{0}" +
351                                 "    </xs:sequence>{0}" +
352                                 "  </xs:complexType>{0}" +
353                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
354                                 "    <xs:sequence>{0}" +
355                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
356                                 "    </xs:sequence>{0}" +
357                                 "  </xs:complexType>{0}" +
358                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
359                 }
360
361                 [Test]
362                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
363                 public void ExportClass_ClassArrayContainer ()
364                 {
365                         XmlSchemas schemas = Export (typeof (ClassArrayContainer), "NSClassArrayContainer");
366                         Assert.AreEqual (1, schemas.Count, "#1");
367
368                         StringWriter sw = new StringWriter ();
369                         schemas[0].Write (sw);
370
371                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
372                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
373                                 "<xs:schema xmlns:tns=\"NSClassArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSClassArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
374 #if MS // bug #77117
375                                 "  <xs:element name=\"ClassArrayContainer\" nillable=\"true\" type=\"tns:ClassArrayContainer\" />{0}" +
376 #else
377                                 "  <xs:element name=\"ClassArrayContainer\" type=\"tns:ClassArrayContainer\" />{0}" +
378 #endif
379                                 "  <xs:complexType name=\"ClassArrayContainer\">{0}" +
380                                 "    <xs:sequence>{0}" +
381                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
382                                 "    </xs:sequence>{0}" +
383                                 "  </xs:complexType>{0}" +
384                                 "  <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
385                                 "    <xs:sequence>{0}" +
386                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
387                                 "    </xs:sequence>{0}" +
388                                 "  </xs:complexType>{0}" +
389                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
390                                 "    <xs:sequence>{0}" +
391                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
392                                 "    </xs:sequence>{0}" +
393                                 "  </xs:complexType>{0}" +
394                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
395
396                         schemas = Export (typeof (ClassArrayContainer));
397                         Assert.AreEqual (1, schemas.Count, "#3");
398
399                         sw.GetStringBuilder ().Length = 0;
400                         schemas[0].Write (sw);
401
402                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
403                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
404                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
405 #if MS // bug #77117
406                                 "  <xs:element name=\"ClassArrayContainer\" nillable=\"true\" type=\"ClassArrayContainer\" />{0}" +
407 #else
408                                 "  <xs:element name=\"ClassArrayContainer\" type=\"ClassArrayContainer\" />{0}" +
409 #endif
410                                 "  <xs:complexType name=\"ClassArrayContainer\">{0}" +
411                                 "    <xs:sequence>{0}" +
412                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfSimpleClass\" />{0}" +
413                                 "    </xs:sequence>{0}" +
414                                 "  </xs:complexType>{0}" +
415                                 "  <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
416                                 "    <xs:sequence>{0}" +
417                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
418                                 "    </xs:sequence>{0}" +
419                                 "  </xs:complexType>{0}" +
420                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
421                                 "    <xs:sequence>{0}" +
422                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
423                                 "    </xs:sequence>{0}" +
424                                 "  </xs:complexType>{0}" +
425                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
426                 }
427
428                 [Test]
429                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
430                 public void ExportClass_SimpleClassWithXmlAttributes ()
431                 {
432                         XmlSchemas schemas = Export (typeof (SimpleClassWithXmlAttributes), "NSSimpleClassWithXmlAttributes");
433                         Assert.AreEqual (1, schemas.Count, "#1");
434
435                         StringWriter sw = new StringWriter ();
436                         schemas[0].Write (sw);
437
438                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
439                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
440                                 "<xs:schema xmlns:tns=\"NSSimpleClassWithXmlAttributes\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassWithXmlAttributes\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
441 #if MS // bug #77117
442                                 "  <xs:element name=\"simple\" nillable=\"true\" type=\"tns:SimpleClassWithXmlAttributes\" />{0}" +
443 #else
444                                 "  <xs:element name=\"simple\" type=\"tns:SimpleClassWithXmlAttributes\" />{0}" +
445 #endif
446                                 "  <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
447                                 "    <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
448                                 "  </xs:complexType>{0}" +
449                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
450
451                         schemas = Export (typeof (SimpleClassWithXmlAttributes));
452                         Assert.AreEqual (1, schemas.Count, "#3");
453
454                         sw.GetStringBuilder ().Length = 0;
455                         schemas[0].Write (sw);
456
457                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
458                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
459                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
460 #if MS // bug #77117
461                                 "  <xs:element name=\"simple\" nillable=\"true\" type=\"SimpleClassWithXmlAttributes\" />{0}" +
462 #else
463                                 "  <xs:element name=\"simple\" type=\"SimpleClassWithXmlAttributes\" />{0}" +
464 #endif
465                                 "  <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
466                                 "    <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
467                                 "  </xs:complexType>{0}" +
468                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
469                 }
470
471                 [Test]
472                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
473                 public void ExportClass_Field ()
474                 {
475                         XmlSchemas schemas = Export (typeof (Field), "NSField");
476                         Assert.AreEqual (1, schemas.Count, "#1");
477
478                         StringWriter sw = new StringWriter ();
479                         schemas[0].Write (sw);
480
481                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
482                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
483                                 "<xs:schema xmlns:tns=\"NSField\" elementFormDefault=\"qualified\" targetNamespace=\"NSField\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
484 #if MS // bug #77117
485                                 "  <xs:element name=\"field\" nillable=\"true\" type=\"tns:Field\" />{0}" +
486 #else
487                                 "  <xs:element name=\"field\" type=\"tns:Field\" />{0}" +
488 #endif
489                                 "  <xs:complexType name=\"Field\">{0}" +
490                                 "    <xs:attribute name=\"modifiers\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
491                                 "    <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
492 #if MS // Mono does not yet translate default values to corresponding enum fields
493                                 "    <xs:attribute default=\"public\" name=\"modifiers3\" type=\"tns:MapModifiers\" />{0}" +
494                                 "    <xs:attribute default=\"public\" form=\"unqualified\" name=\"modifiers4\" type=\"tns:MapModifiers\" />{0}" +
495 #else
496                                 "    <xs:attribute default=\"0\" name=\"modifiers3\" type=\"tns:MapModifiers\" />{0}" +
497                                 "    <xs:attribute default=\"0\" form=\"unqualified\" name=\"modifiers4\" type=\"tns:MapModifiers\" />{0}" +
498 #endif
499                                 "    <xs:attribute name=\"names\">{0}" +
500                                 "      <xs:simpleType>{0}" +
501                                 "        <xs:list itemType=\"xs:string\" />{0}" +
502                                 "      </xs:simpleType>{0}" +
503                                 "    </xs:attribute>{0}" +
504                                 "    <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
505                                 "  </xs:complexType>{0}" +
506                                 "  <xs:simpleType name=\"MapModifiers\">{0}" +
507                                 "    <xs:list>{0}" +
508                                 "      <xs:simpleType>{0}" +
509                                 "        <xs:restriction base=\"xs:string\">{0}" +
510                                 "          <xs:enumeration value=\"public\" />{0}" +
511                                 "          <xs:enumeration value=\"protected\" />{0}" +
512                                 "        </xs:restriction>{0}" +
513                                 "      </xs:simpleType>{0}" +
514                                 "    </xs:list>{0}" +
515                                 "  </xs:simpleType>{0}" +
516                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
517
518                         schemas = Export (typeof (Field));
519                         Assert.AreEqual (1, schemas.Count, "#3");
520
521                         sw.GetStringBuilder ().Length = 0;
522                         schemas[0].Write (sw);
523
524                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
525                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
526                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
527 #if MS // bug #77117
528                                 "  <xs:element name=\"field\" nillable=\"true\" type=\"Field\" />{0}" +
529 #else
530                                 "  <xs:element name=\"field\" type=\"Field\" />{0}" +
531 #endif
532                                 "  <xs:complexType name=\"Field\">{0}" +
533                                 "    <xs:attribute name=\"modifiers\" type=\"MapModifiers\" use=\"required\" />{0}" +
534                                 "    <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"MapModifiers\" use=\"required\" />{0}" +
535 #if MS // Mono does not yet translate default values to corresponding enum fields
536                                 "    <xs:attribute default=\"public\" name=\"modifiers3\" type=\"MapModifiers\" />{0}" +
537                                 "    <xs:attribute default=\"public\" form=\"unqualified\" name=\"modifiers4\" type=\"MapModifiers\" />{0}" +
538 #else
539                                 "    <xs:attribute default=\"0\" name=\"modifiers3\" type=\"MapModifiers\" />{0}" +
540                                 "    <xs:attribute default=\"0\" form=\"unqualified\" name=\"modifiers4\" type=\"MapModifiers\" />{0}" +
541 #endif
542                                 "    <xs:attribute name=\"names\">{0}" +
543                                 "      <xs:simpleType>{0}" +
544                                 "        <xs:list itemType=\"xs:string\" />{0}" +
545                                 "      </xs:simpleType>{0}" +
546                                 "    </xs:attribute>{0}" +
547                                 "    <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
548                                 "  </xs:complexType>{0}" +
549                                 "  <xs:simpleType name=\"MapModifiers\">{0}" +
550                                 "    <xs:list>{0}" +
551                                 "      <xs:simpleType>{0}" +
552                                 "        <xs:restriction base=\"xs:string\">{0}" +
553                                 "          <xs:enumeration value=\"public\" />{0}" +
554                                 "          <xs:enumeration value=\"protected\" />{0}" +
555                                 "        </xs:restriction>{0}" +
556                                 "      </xs:simpleType>{0}" +
557                                 "    </xs:list>{0}" +
558                                 "  </xs:simpleType>{0}" +
559                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
560                 }
561
562                 [Test]
563                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
564                 public void ExportClass_MyList ()
565                 {
566                         XmlSchemas schemas = Export (typeof (MyList), "NSMyList");
567                         Assert.AreEqual (1, schemas.Count, "#1");
568
569                         StringWriter sw = new StringWriter ();
570                         schemas[0].Write (sw);
571
572                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
573                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
574                                 "<xs:schema xmlns:tns=\"NSMyList\" elementFormDefault=\"qualified\" targetNamespace=\"NSMyList\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
575 #if MS // bug #77117
576                                 "  <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"tns:ArrayOfAnyType\" />{0}" +
577 #else
578                                 "  <xs:element name=\"ArrayOfAnyType\" type=\"tns:ArrayOfAnyType\" />{0}" +
579 #endif
580                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
581                                 "    <xs:sequence>{0}" +
582                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
583                                 "    </xs:sequence>{0}" +
584                                 "  </xs:complexType>{0}" +
585                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
586
587                         schemas = Export (typeof (MyList));
588                         Assert.AreEqual (1, schemas.Count, "#3");
589
590                         sw.GetStringBuilder ().Length = 0;
591                         schemas[0].Write (sw);
592
593                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
594                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
595                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
596 #if MS // bug #77117
597                                 "  <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"ArrayOfAnyType\" />{0}" +
598 #else
599                                 "  <xs:element name=\"ArrayOfAnyType\" type=\"ArrayOfAnyType\" />{0}" +
600 #endif
601                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
602                                 "    <xs:sequence>{0}" +
603                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
604                                 "    </xs:sequence>{0}" +
605                                 "  </xs:complexType>{0}" +
606                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
607                 }
608
609                 [Test]
610                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
611                 public void ExportClass_Container ()
612                 {
613                         XmlSchemas schemas = Export (typeof (Container), "NSContainer");
614                         Assert.AreEqual (1, schemas.Count, "#1");
615
616                         StringWriter sw = new StringWriter ();
617                         schemas[0].Write (sw);
618
619                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
620                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
621                                 "<xs:schema xmlns:tns=\"NSContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
622 #if MS // bug #77117
623                                 "  <xs:element name=\"Container\" nillable=\"true\" type=\"tns:Container\" />{0}" +
624 #else
625                                 "  <xs:element name=\"Container\" type=\"tns:Container\" />{0}" +
626 #endif
627                                 "  <xs:complexType name=\"Container\">{0}" +
628                                 "    <xs:sequence>{0}" +
629                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
630                                 "    </xs:sequence>{0}" +
631                                 "  </xs:complexType>{0}" +
632                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
633                                 "    <xs:sequence>{0}" +
634                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
635                                 "    </xs:sequence>{0}" +
636                                 "  </xs:complexType>{0}" +
637                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
638
639                         schemas = Export (typeof (Container));
640                         Assert.AreEqual (1, schemas.Count, "#3");
641
642                         sw.GetStringBuilder ().Length = 0;
643                         schemas[0].Write (sw);
644
645                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
646                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
647                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
648 #if MS // bug #77117
649                                 "  <xs:element name=\"Container\" nillable=\"true\" type=\"Container\" />{0}" +
650 #else
651                                 "  <xs:element name=\"Container\" type=\"Container\" />{0}" +
652 #endif
653                                 "  <xs:complexType name=\"Container\">{0}" +
654                                 "    <xs:sequence>{0}" +
655                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
656                                 "    </xs:sequence>{0}" +
657                                 "  </xs:complexType>{0}" +
658                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
659                                 "    <xs:sequence>{0}" +
660                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
661                                 "    </xs:sequence>{0}" +
662                                 "  </xs:complexType>{0}" +
663                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
664                 }
665
666                 [Test]
667                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
668                 public void ExportClass_Container2 ()
669                 {
670                         XmlSchemas schemas = Export (typeof (Container2), "NSContainer2");
671                         Assert.AreEqual (1, schemas.Count, "#1");
672
673                         StringWriter sw = new StringWriter ();
674                         schemas[0].Write (sw);
675
676                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
677                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
678                                 "<xs:schema xmlns:tns=\"NSContainer2\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
679 #if MS // bug #77117
680                                 "  <xs:element name=\"Container2\" nillable=\"true\" type=\"tns:Container2\" />{0}" +
681 #else
682                                 "  <xs:element name=\"Container2\" type=\"tns:Container2\" />{0}" +
683 #endif
684                                 "  <xs:complexType name=\"Container2\">{0}" +
685                                 "    <xs:sequence>{0}" +
686                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
687                                 "    </xs:sequence>{0}" +
688                                 "  </xs:complexType>{0}" +
689                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
690                                 "    <xs:sequence>{0}" +
691                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
692                                 "    </xs:sequence>{0}" +
693                                 "  </xs:complexType>{0}" +
694                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
695
696                         schemas = Export (typeof (Container2));
697                         Assert.AreEqual (1, schemas.Count, "#3");
698
699                         sw.GetStringBuilder ().Length = 0;
700                         schemas[0].Write (sw);
701
702                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
703                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
704                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
705 #if MS // bug #77117
706                                 "  <xs:element name=\"Container2\" nillable=\"true\" type=\"Container2\" />{0}" +
707 #else
708                                 "  <xs:element name=\"Container2\" type=\"Container2\" />{0}" +
709 #endif
710                                 "  <xs:complexType name=\"Container2\">{0}" +
711                                 "    <xs:sequence>{0}" +
712                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
713                                 "    </xs:sequence>{0}" +
714                                 "  </xs:complexType>{0}" +
715                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
716                                 "    <xs:sequence>{0}" +
717                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
718                                 "    </xs:sequence>{0}" +
719                                 "  </xs:complexType>{0}" +
720                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
721                 }
722
723                 [Test]
724                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
725                 [ExpectedException (typeof (InvalidOperationException))] // Cannot use wildcards at the top level of a schema.
726                 public void ExportClass_MyElem ()
727                 {
728                         Export (typeof (MyElem), "NSMyElem");
729                 }
730
731                 [Test]
732                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
733                 public void ExportClass_CDataContainer ()
734                 {
735                         XmlSchemas schemas = Export (typeof (CDataContainer), "NSCDataContainer");
736                         Assert.AreEqual (1, schemas.Count, "#1");
737
738                         StringWriter sw = new StringWriter ();
739                         schemas[0].Write (sw);
740
741                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
742                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
743                                 "<xs:schema xmlns:tns=\"NSCDataContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSCDataContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
744 #if MS // bug #77117
745                                 "  <xs:element name=\"CDataContainer\" nillable=\"true\" type=\"tns:CDataContainer\" />{0}" +
746 #else
747                                 "  <xs:element name=\"CDataContainer\" type=\"tns:CDataContainer\" />{0}" +
748 #endif
749                                 "  <xs:complexType name=\"CDataContainer\">{0}" +
750                                 "    <xs:sequence>{0}" +
751                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
752                                 "        <xs:complexType mixed=\"true\">{0}" +
753                                 "          <xs:sequence>{0}" +
754                                 "            <xs:any />{0}" +
755                                 "          </xs:sequence>{0}" +
756                                 "        </xs:complexType>{0}" +
757                                 "      </xs:element>{0}" +
758                                 "    </xs:sequence>{0}" +
759                                 "  </xs:complexType>{0}" +
760                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
761
762                         schemas = Export (typeof (CDataContainer));
763                         Assert.AreEqual (1, schemas.Count, "#3");
764
765                         sw.GetStringBuilder ().Length = 0;
766                         schemas[0].Write (sw);
767
768                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
769                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
770                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
771 #if MS // bug #77117
772                                 "  <xs:element name=\"CDataContainer\" nillable=\"true\" type=\"CDataContainer\" />{0}" +
773 #else
774                                 "  <xs:element name=\"CDataContainer\" type=\"CDataContainer\" />{0}" +
775 #endif
776                                 "  <xs:complexType name=\"CDataContainer\">{0}" +
777                                 "    <xs:sequence>{0}" +
778                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
779                                 "        <xs:complexType mixed=\"true\">{0}" +
780                                 "          <xs:sequence>{0}" +
781                                 "            <xs:any />{0}" +
782                                 "          </xs:sequence>{0}" +
783                                 "        </xs:complexType>{0}" +
784                                 "      </xs:element>{0}" +
785                                 "    </xs:sequence>{0}" +
786                                 "  </xs:complexType>{0}" +
787                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
788                 }
789
790                 [Test]
791                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
792                 public void ExportClass_NodeContainer ()
793                 {
794                         XmlSchemas schemas = Export (typeof (NodeContainer), "NSNodeContainer");
795                         Assert.AreEqual (1, schemas.Count, "#1");
796
797                         StringWriter sw = new StringWriter ();
798                         schemas[0].Write (sw);
799
800                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
801                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
802                                 "<xs:schema xmlns:tns=\"NSNodeContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSNodeContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
803 #if MS // bug #77117
804                                 "  <xs:element name=\"NodeContainer\" nillable=\"true\" type=\"tns:NodeContainer\" />{0}" +
805 #else
806                                 "  <xs:element name=\"NodeContainer\" type=\"tns:NodeContainer\" />{0}" +
807 #endif
808                                 "  <xs:complexType name=\"NodeContainer\">{0}" +
809                                 "    <xs:sequence>{0}" +
810                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
811                                 "        <xs:complexType mixed=\"true\">{0}" +
812                                 "          <xs:sequence>{0}" +
813                                 "            <xs:any />{0}" +
814                                 "          </xs:sequence>{0}" +
815                                 "        </xs:complexType>{0}" +
816                                 "      </xs:element>{0}" +
817                                 "    </xs:sequence>{0}" +
818                                 "  </xs:complexType>{0}" +
819                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
820
821                         schemas = Export (typeof (NodeContainer));
822                         Assert.AreEqual (1, schemas.Count, "#3");
823
824                         sw.GetStringBuilder ().Length = 0;
825                         schemas[0].Write (sw);
826
827                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
828                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
829                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
830 #if MS // bug #77117
831                                 "  <xs:element name=\"NodeContainer\" nillable=\"true\" type=\"NodeContainer\" />{0}" +
832 #else
833                                 "  <xs:element name=\"NodeContainer\" type=\"NodeContainer\" />{0}" +
834 #endif
835                                 "  <xs:complexType name=\"NodeContainer\">{0}" +
836                                 "    <xs:sequence>{0}" +
837                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
838                                 "        <xs:complexType mixed=\"true\">{0}" +
839                                 "          <xs:sequence>{0}" +
840                                 "            <xs:any />{0}" +
841                                 "          </xs:sequence>{0}" +
842                                 "        </xs:complexType>{0}" +
843                                 "      </xs:element>{0}" +
844                                 "    </xs:sequence>{0}" +
845                                 "  </xs:complexType>{0}" +
846                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
847                 }
848
849                 [Test]
850                 [Category ("NotWorking")] // Mono does not generate the <xs:choice> node
851 #if NET_2_0
852                 [Category ("NotDotNet")] // MS.NET 2.0 randomly modifies the order of the elements!
853 #endif
854                 public void ExportClass_Choices ()
855                 {
856                         XmlSchemas schemas = Export (typeof (Choices), "NSChoices");
857                         Assert.AreEqual (1, schemas.Count, "#1");
858
859                         StringWriter sw = new StringWriter ();
860                         schemas[0].Write (sw);
861
862                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
863                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
864                                 "<xs:schema xmlns:tns=\"NSChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
865 #if MS // bug #77117
866                                 "  <xs:element name=\"Choices\" nillable=\"true\" type=\"tns:Choices\" />{0}" +
867 #else
868                                 "  <xs:element name=\"Choices\" type=\"tns:Choices\" />{0}" +
869 #endif
870                                 "  <xs:complexType name=\"Choices\">{0}" +
871                                 "    <xs:sequence>{0}" +
872                                 "      <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
873                                 "        <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
874                                 "        <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
875                                 "        <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
876                                 "      </xs:choice>{0}" +
877                                 "    </xs:sequence>{0}" +
878                                 "  </xs:complexType>{0}" +
879                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
880
881                         schemas = Export (typeof (Choices));
882                         Assert.AreEqual (1, schemas.Count, "#3");
883
884                         sw.GetStringBuilder ().Length = 0;
885                         schemas[0].Write (sw);
886
887                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
888                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
889                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
890 #if MS // bug #77117
891                                 "  <xs:element name=\"Choices\" nillable=\"true\" type=\"Choices\" />{0}" +
892 #else
893                                 "  <xs:element name=\"Choices\" type=\"Choices\" />{0}" +
894 #endif
895                                 "  <xs:complexType name=\"Choices\">{0}" +
896                                 "    <xs:sequence>{0}" +
897                                 "      <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
898                                 "        <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
899                                 "        <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
900                                 "        <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
901                                 "      </xs:choice>{0}" +
902                                 "    </xs:sequence>{0}" +
903                                 "  </xs:complexType>{0}" +
904                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
905                 }
906
907                 [Test]
908                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
909 #if ONLY_1_1
910                 [Category ("NotDotNet")] // MS.NET 1.x does not escape spaces in a type name, bug is fixed in .NET 2.0
911 #endif
912                 public void ExportClass_TestSpace ()
913                 {
914                         XmlSchemas schemas = Export (typeof (TestSpace), "NSTestSpace");
915                         Assert.AreEqual (1, schemas.Count, "#1");
916
917                         StringWriter sw = new StringWriter ();
918                         schemas[0].Write (sw);
919
920                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
921                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
922                                 "<xs:schema xmlns:tns=\"NSTestSpace\" elementFormDefault=\"qualified\" targetNamespace=\"NSTestSpace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
923 #if MS // bug #77117
924                                 "  <xs:element name=\"Type_x0020_with_x0020_space\" nillable=\"true\" type=\"tns:Type_x0020_with_x0020_space\" />{0}" +
925 #else
926                                 "  <xs:element name=\"Type_x0020_with_x0020_space\" type=\"tns:Type_x0020_with_x0020_space\" />{0}" +
927 #endif
928                                 "  <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
929                                 "    <xs:sequence>{0}" +
930                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
931                                 "    </xs:sequence>{0}" +
932                                 "    <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
933                                 "  </xs:complexType>{0}" +
934                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
935
936                         schemas = Export (typeof (TestSpace));
937                         Assert.AreEqual (1, schemas.Count, "#3");
938
939                         sw.GetStringBuilder ().Length = 0;
940                         schemas[0].Write (sw);
941
942                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
943                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
944                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
945 #if MS // bug #77117
946                                 "  <xs:element name=\"Type_x0020_with_x0020_space\" nillable=\"true\" type=\"Type_x0020_with_x0020_space\" />{0}" +
947 #else
948                                 "  <xs:element name=\"Type_x0020_with_x0020_space\" type=\"Type_x0020_with_x0020_space\" />{0}" +
949 #endif
950                                 "  <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
951                                 "    <xs:sequence>{0}" +
952                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
953                                 "    </xs:sequence>{0}" +
954                                 "    <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
955                                 "  </xs:complexType>{0}" +
956                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
957                 }
958
959                 [Test]
960                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
961                 public void ExportClass_ReadOnlyProperties ()
962                 {
963                         XmlSchemas schemas = Export (typeof (ReadOnlyProperties), "NSReadOnlyProperties");
964                         Assert.AreEqual (1, schemas.Count, "#1");
965
966                         StringWriter sw = new StringWriter ();
967                         schemas[0].Write (sw);
968
969                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
970                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
971                                 "<xs:schema xmlns:tns=\"NSReadOnlyProperties\" elementFormDefault=\"qualified\" targetNamespace=\"NSReadOnlyProperties\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
972 #if MS // bug #77117
973                                 "  <xs:element name=\"ReadOnlyProperties\" nillable=\"true\" type=\"tns:ReadOnlyProperties\" />{0}" +
974 #else
975                                 "  <xs:element name=\"ReadOnlyProperties\" type=\"tns:ReadOnlyProperties\" />{0}" +
976 #endif
977                                 "  <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
978                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
979
980                         schemas = Export (typeof (ReadOnlyProperties));
981                         Assert.AreEqual (1, schemas.Count, "#3");
982
983                         sw.GetStringBuilder ().Length = 0;
984                         schemas[0].Write (sw);
985
986                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
987                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
988                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
989 #if MS // bug #77117
990                                 "  <xs:element name=\"ReadOnlyProperties\" nillable=\"true\" type=\"ReadOnlyProperties\" />{0}" +
991 #else
992                                 "  <xs:element name=\"ReadOnlyProperties\" type=\"ReadOnlyProperties\" />{0}" +
993 #endif
994                                 "  <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
995                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
996                 }
997
998                 [Test]
999                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1000                 public void ExportClass_ListDefaults ()
1001                 {
1002                         XmlSchemas schemas = Export (typeof (ListDefaults), "NSListDefaults");
1003                         Assert.AreEqual (1, schemas.Count, "#1");
1004
1005                         StringWriter sw = new StringWriter ();
1006                         schemas[0].Write (sw);
1007
1008                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1009                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1010                                 "<xs:schema xmlns:tns=\"NSListDefaults\" elementFormDefault=\"qualified\" targetNamespace=\"NSListDefaults\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1011 #if MS // bug #77117
1012                                 "  <xs:element name=\"root\" nillable=\"true\" type=\"tns:ListDefaults\" />{0}" +
1013 #else
1014                                 "  <xs:element name=\"root\" type=\"tns:ListDefaults\" />{0}" +
1015 #endif
1016                                 "  <xs:complexType name=\"ListDefaults\">{0}" +
1017                                 "    <xs:sequence>{0}" +
1018                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"tns:ArrayOfAnyType\" />{0}" +
1019                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"tns:ArrayOfAnyType\" />{0}" +
1020                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"tns:ArrayOfString\" />{0}" +
1021                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"tns:SimpleClass\" />{0}" +
1022                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"tns:SimpleClass\" />{0}" +
1023                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
1024                                 "    </xs:sequence>{0}" +
1025                                 "  </xs:complexType>{0}" +
1026                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1027                                 "    <xs:sequence>{0}" +
1028                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1029                                 "    </xs:sequence>{0}" +
1030                                 "  </xs:complexType>{0}" +
1031                                 "  <xs:complexType name=\"ArrayOfString\">{0}" +
1032                                 "    <xs:sequence>{0}" +
1033                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
1034                                 "    </xs:sequence>{0}" +
1035                                 "  </xs:complexType>{0}" +
1036                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
1037                                 "    <xs:sequence>{0}" +
1038                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
1039                                 "    </xs:sequence>{0}" +
1040                                 "  </xs:complexType>{0}" +
1041                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1042
1043                         schemas = Export (typeof (ListDefaults));
1044                         Assert.AreEqual (1, schemas.Count, "#3");
1045
1046                         sw.GetStringBuilder ().Length = 0;
1047                         schemas[0].Write (sw);
1048
1049                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1050                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1051                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1052 #if MS // bug #77117
1053                                 "  <xs:element name=\"root\" nillable=\"true\" type=\"ListDefaults\" />{0}" +
1054 #else
1055                                 "  <xs:element name=\"root\" type=\"ListDefaults\" />{0}" +
1056 #endif
1057                                 "  <xs:complexType name=\"ListDefaults\">{0}" +
1058                                 "    <xs:sequence>{0}" +
1059                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"ArrayOfAnyType\" />{0}" +
1060                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"ArrayOfAnyType\" />{0}" +
1061                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"ArrayOfString\" />{0}" +
1062                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"SimpleClass\" />{0}" +
1063                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"SimpleClass\" />{0}" +
1064                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
1065                                 "    </xs:sequence>{0}" +
1066                                 "  </xs:complexType>{0}" +
1067                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1068                                 "    <xs:sequence>{0}" +
1069                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1070                                 "    </xs:sequence>{0}" +
1071                                 "  </xs:complexType>{0}" +
1072                                 "  <xs:complexType name=\"ArrayOfString\">{0}" +
1073                                 "    <xs:sequence>{0}" +
1074                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
1075                                 "    </xs:sequence>{0}" +
1076                                 "  </xs:complexType>{0}" +
1077                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
1078                                 "    <xs:sequence>{0}" +
1079                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
1080                                 "    </xs:sequence>{0}" +
1081                                 "  </xs:complexType>{0}" +
1082                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1083                 }
1084
1085                 [Test]
1086                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1087                 public void ExportClass_ClsPerson ()
1088                 {
1089                         XmlSchemas schemas = Export (typeof (clsPerson), "NSClsPerson");
1090                         Assert.AreEqual (1, schemas.Count, "#1");
1091
1092                         StringWriter sw = new StringWriter ();
1093                         schemas[0].Write (sw);
1094
1095                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1096                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1097                                 "<xs:schema xmlns:tns=\"NSClsPerson\" elementFormDefault=\"qualified\" targetNamespace=\"NSClsPerson\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1098 #if MS // bug #77117
1099                                 "  <xs:element name=\"clsPerson\" nillable=\"true\" type=\"tns:clsPerson\" />{0}" +
1100 #else
1101                                 "  <xs:element name=\"clsPerson\" type=\"tns:clsPerson\" />{0}" +
1102 #endif
1103                                 "  <xs:complexType name=\"clsPerson\">{0}" +
1104                                 "    <xs:sequence>{0}" +
1105                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"tns:ArrayOfAnyType\" />{0}" +
1106                                 "    </xs:sequence>{0}" +
1107                                 "  </xs:complexType>{0}" +
1108                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1109                                 "    <xs:sequence>{0}" +
1110                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1111                                 "    </xs:sequence>{0}" +
1112                                 "  </xs:complexType>{0}" +
1113                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1114
1115                         schemas = Export (typeof (clsPerson));
1116                         Assert.AreEqual (1, schemas.Count, "#3");
1117
1118                         sw.GetStringBuilder ().Length = 0;
1119                         schemas[0].Write (sw);
1120
1121                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1122                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1123                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1124 #if MS // bug #77117
1125                                 "  <xs:element name=\"clsPerson\" nillable=\"true\" type=\"clsPerson\" />{0}" +
1126 #else
1127                                 "  <xs:element name=\"clsPerson\" type=\"clsPerson\" />{0}" +
1128 #endif
1129                                 "  <xs:complexType name=\"clsPerson\">{0}" +
1130                                 "    <xs:sequence>{0}" +
1131                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"ArrayOfAnyType\" />{0}" +
1132                                 "    </xs:sequence>{0}" +
1133                                 "  </xs:complexType>{0}" +
1134                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1135                                 "    <xs:sequence>{0}" +
1136                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1137                                 "    </xs:sequence>{0}" +
1138                                 "  </xs:complexType>{0}" +
1139                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1140                 }
1141
1142                 [Test]
1143                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1144                 public void ExportClass_ArrayClass ()
1145                 {
1146                         XmlSchemas schemas = Export (typeof (ArrayClass), "NSArrayClass");
1147                         Assert.AreEqual (1, schemas.Count, "#1");
1148
1149                         StringWriter sw = new StringWriter ();
1150                         schemas[0].Write (sw);
1151
1152                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1153                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1154                                 "<xs:schema xmlns:tns=\"NSArrayClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1155 #if MS // bug #77117
1156                                 "  <xs:element name=\"ArrayClass\" nillable=\"true\" type=\"tns:ArrayClass\" />{0}" +
1157 #else
1158                                 "  <xs:element name=\"ArrayClass\" type=\"tns:ArrayClass\" />{0}" +
1159 #endif
1160                                 "  <xs:complexType name=\"ArrayClass\">{0}" +
1161                                 "    <xs:sequence>{0}" +
1162                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"names\" />{0}" +
1163                                 "    </xs:sequence>{0}" +
1164                                 "  </xs:complexType>{0}" +
1165                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1166
1167                         schemas = Export (typeof (ArrayClass));
1168                         Assert.AreEqual (1, schemas.Count, "#3");
1169
1170                         sw.GetStringBuilder ().Length = 0;
1171                         schemas[0].Write (sw);
1172
1173                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1174                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1175                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1176 #if MS // bug #77117
1177                                 "  <xs:element name=\"ArrayClass\" nillable=\"true\" type=\"ArrayClass\" />{0}" +
1178 #else
1179                                 "  <xs:element name=\"ArrayClass\" type=\"ArrayClass\" />{0}" +
1180 #endif
1181                                 "  <xs:complexType name=\"ArrayClass\">{0}" +
1182                                 "    <xs:sequence>{0}" +
1183                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"names\" />{0}" +
1184                                 "    </xs:sequence>{0}" +
1185                                 "  </xs:complexType>{0}" +
1186                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1187                 }
1188
1189                 [Test]
1190                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1191                 public void ExportClass_StructContainer ()
1192                 {
1193                         XmlSchemas schemas = Export (typeof (StructContainer), "NSStructContainer");
1194                         Assert.AreEqual (1, schemas.Count, "#1");
1195
1196                         StringWriter sw = new StringWriter ();
1197                         schemas[0].Write (sw);
1198
1199                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1200                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1201                                 "<xs:schema xmlns:tns=\"NSStructContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStructContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1202 #if MS // bug #77117
1203                                 "  <xs:element name=\"StructContainer\" nillable=\"true\" type=\"tns:StructContainer\" />{0}" +
1204 #else
1205                                 "  <xs:element name=\"StructContainer\" type=\"tns:StructContainer\" />{0}" +
1206 #endif
1207                                 "  <xs:complexType name=\"StructContainer\">{0}" +
1208                                 "    <xs:sequence>{0}" +
1209                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"tns:EnumDefaultValue\" />{0}" +
1210                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Times\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
1211                                 "    </xs:sequence>{0}" +
1212                                 "  </xs:complexType>{0}" +
1213                                 "  <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1214                                 "    <xs:list>{0}" +
1215                                 "      <xs:simpleType>{0}" +
1216                                 "        <xs:restriction base=\"xs:string\">{0}" +
1217                                 "          <xs:enumeration value=\"e1\" />{0}" +
1218                                 "          <xs:enumeration value=\"e2\" />{0}" +
1219                                 "          <xs:enumeration value=\"e3\" />{0}" +
1220                                 "        </xs:restriction>{0}" +
1221                                 "      </xs:simpleType>{0}" +
1222                                 "    </xs:list>{0}" +
1223                                 "  </xs:simpleType>{0}" +
1224                                 "  <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
1225                                 "    <xs:sequence>{0}" +
1226 #if MS // bug #77117
1227                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
1228 #else
1229                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"tns:TimeSpan\" />{0}" +
1230 #endif
1231                                 "    </xs:sequence>{0}" +
1232                                 "  </xs:complexType>{0}" +
1233                                 "  <xs:complexType name=\"TimeSpan\" />{0}" +
1234                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1235
1236                         schemas = Export (typeof (StructContainer));
1237                         Assert.AreEqual (1, schemas.Count, "#3");
1238
1239                         sw.GetStringBuilder ().Length = 0;
1240                         schemas[0].Write (sw);
1241
1242                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1243                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1244                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1245 #if MS // bug #77117
1246                                 "  <xs:element name=\"StructContainer\" nillable=\"true\" type=\"StructContainer\" />{0}" +
1247 #else
1248                                 "  <xs:element name=\"StructContainer\" type=\"StructContainer\" />{0}" +
1249 #endif
1250                                 "  <xs:complexType name=\"StructContainer\">{0}" +
1251                                 "    <xs:sequence>{0}" +
1252                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"EnumDefaultValue\" />{0}" +
1253                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Times\" type=\"ArrayOfTimeSpan\" />{0}" +
1254                                 "    </xs:sequence>{0}" +
1255                                 "  </xs:complexType>{0}" +
1256                                 "  <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1257                                 "    <xs:list>{0}" +
1258                                 "      <xs:simpleType>{0}" +
1259                                 "        <xs:restriction base=\"xs:string\">{0}" +
1260                                 "          <xs:enumeration value=\"e1\" />{0}" +
1261                                 "          <xs:enumeration value=\"e2\" />{0}" +
1262                                 "          <xs:enumeration value=\"e3\" />{0}" +
1263                                 "        </xs:restriction>{0}" +
1264                                 "      </xs:simpleType>{0}" +
1265                                 "    </xs:list>{0}" +
1266                                 "  </xs:simpleType>{0}" +
1267                                 "  <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
1268                                 "    <xs:sequence>{0}" +
1269 #if MS // bug #77117
1270                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
1271 #else
1272                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"TimeSpan\" />{0}" +
1273 #endif
1274                                 "    </xs:sequence>{0}" +
1275                                 "  </xs:complexType>{0}" +
1276                                 "  <xs:complexType name=\"TimeSpan\" />{0}" +
1277                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1278                 }
1279
1280                 [Test]
1281                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1282                 [ExpectedException (typeof (InvalidOperationException))] // Cannot use wildcards at the top level of a schema.
1283                 public void ExportClass_XmlElement ()
1284                 {
1285                         XmlSchemas schemas = Export (typeof (XmlElement), "NS1");
1286                 }
1287
1288                 [Test]
1289                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1290                 public void ExportClass_Array ()
1291                 {
1292                         XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
1293                         XmlAttributes attr = new XmlAttributes ();
1294                         XmlElementAttribute element = new XmlElementAttribute ();
1295                         element.ElementName = "saying";
1296                         element.IsNullable = true;
1297                         attr.XmlElements.Add (element);
1298                         overrides.Add (typeof (SimpleClass), "something", attr);
1299
1300                         XmlSchemas schemas = Export (typeof (SimpleClass[]), overrides, "NSSimpleClassArray");
1301                         Assert.AreEqual (1, schemas.Count, "#1");
1302
1303                         StringWriter sw = new StringWriter ();
1304                         schemas[0].Write (sw);
1305
1306                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1307                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1308                                 "<xs:schema xmlns:tns=\"NSSimpleClassArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1309 #if MS // bug #77117
1310                                 "  <xs:element name=\"ArrayOfSimpleClass\" nillable=\"true\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
1311 #else
1312                                 "  <xs:element name=\"ArrayOfSimpleClass\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
1313 #endif
1314                                 "  <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
1315                                 "    <xs:sequence>{0}" +
1316                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
1317                                 "    </xs:sequence>{0}" +
1318                                 "  </xs:complexType>{0}" +
1319                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
1320                                 "    <xs:sequence>{0}" +
1321                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
1322                                 "    </xs:sequence>{0}" +
1323                                 "  </xs:complexType>{0}" +
1324                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1325
1326                         schemas = Export (typeof (SimpleClass[]), overrides);
1327                         Assert.AreEqual (1, schemas.Count, "#3");
1328
1329                         sw.GetStringBuilder ().Length = 0;
1330                         schemas[0].Write (sw);
1331
1332                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1333                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1334                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1335 #if MS // bug #77117
1336                                 "  <xs:element name=\"ArrayOfSimpleClass\" nillable=\"true\" type=\"ArrayOfSimpleClass\" />{0}" +
1337 #else
1338                                 "  <xs:element name=\"ArrayOfSimpleClass\" type=\"ArrayOfSimpleClass\" />{0}" +
1339 #endif
1340                                 "  <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
1341                                 "    <xs:sequence>{0}" +
1342                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
1343                                 "    </xs:sequence>{0}" +
1344                                 "  </xs:complexType>{0}" +
1345                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
1346                                 "    <xs:sequence>{0}" +
1347                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
1348                                 "    </xs:sequence>{0}" +
1349                                 "  </xs:complexType>{0}" +
1350                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1351                 }
1352
1353                 [Test]
1354                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1355                 public void ExportEnum ()
1356                 {
1357                         XmlSchemas schemas = Export (typeof (EnumDefaultValue), "NSEnumDefaultValue");
1358                         Assert.AreEqual (1, schemas.Count, "#1");
1359
1360                         StringWriter sw = new StringWriter ();
1361                         schemas[0].Write (sw);
1362
1363                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1364                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1365                                 "<xs:schema xmlns:tns=\"NSEnumDefaultValue\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValue\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1366                                 "  <xs:element name=\"EnumDefaultValue\" type=\"tns:EnumDefaultValue\" />{0}" +
1367                                 "  <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1368                                 "    <xs:list>{0}" +
1369                                 "      <xs:simpleType>{0}" +
1370                                 "        <xs:restriction base=\"xs:string\">{0}" +
1371                                 "          <xs:enumeration value=\"e1\" />{0}" +
1372                                 "          <xs:enumeration value=\"e2\" />{0}" +
1373                                 "          <xs:enumeration value=\"e3\" />{0}" +
1374                                 "        </xs:restriction>{0}" +
1375                                 "      </xs:simpleType>{0}" +
1376                                 "    </xs:list>{0}" +
1377                                 "  </xs:simpleType>{0}" +
1378                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1379
1380                         schemas = Export (typeof (EnumDefaultValueNF), "NSEnumDefaultValueNF");
1381                         Assert.AreEqual (1, schemas.Count, "#3");
1382
1383                         sw.GetStringBuilder ().Length = 0; 
1384                         schemas[0].Write (sw);
1385
1386                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1387                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1388                                 "<xs:schema xmlns:tns=\"NSEnumDefaultValueNF\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValueNF\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1389                                 "  <xs:element name=\"EnumDefaultValueNF\" type=\"tns:EnumDefaultValueNF\" />{0}" +
1390                                 "  <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
1391                                 "    <xs:restriction base=\"xs:string\">{0}" +
1392                                 "      <xs:enumeration value=\"e1\" />{0}" +
1393                                 "      <xs:enumeration value=\"e2\" />{0}" +
1394                                 "      <xs:enumeration value=\"e3\" />{0}" +
1395                                 "    </xs:restriction>{0}" +
1396                                 "  </xs:simpleType>{0}" +
1397                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1398
1399                         schemas = Export (typeof (EnumDefaultValue));
1400                         Assert.AreEqual (1, schemas.Count, "#5");
1401
1402                         sw.GetStringBuilder ().Length = 0;
1403                         schemas[0].Write (sw);
1404
1405                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1406                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1407                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1408                                 "  <xs:element name=\"EnumDefaultValue\" type=\"EnumDefaultValue\" />{0}" +
1409                                 "  <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1410                                 "    <xs:list>{0}" +
1411                                 "      <xs:simpleType>{0}" +
1412                                 "        <xs:restriction base=\"xs:string\">{0}" +
1413                                 "          <xs:enumeration value=\"e1\" />{0}" +
1414                                 "          <xs:enumeration value=\"e2\" />{0}" +
1415                                 "          <xs:enumeration value=\"e3\" />{0}" +
1416                                 "        </xs:restriction>{0}" +
1417                                 "      </xs:simpleType>{0}" +
1418                                 "    </xs:list>{0}" +
1419                                 "  </xs:simpleType>{0}" +
1420                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
1421
1422                         schemas = Export (typeof (EnumDefaultValueNF));
1423                         Assert.AreEqual (1, schemas.Count, "#7");
1424
1425                         sw.GetStringBuilder ().Length = 0;
1426                         schemas[0].Write (sw);
1427
1428                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1429                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1430                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1431                                 "  <xs:element name=\"EnumDefaultValueNF\" type=\"EnumDefaultValueNF\" />{0}" +
1432                                 "  <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
1433                                 "    <xs:restriction base=\"xs:string\">{0}" +
1434                                 "      <xs:enumeration value=\"e1\" />{0}" +
1435                                 "      <xs:enumeration value=\"e2\" />{0}" +
1436                                 "      <xs:enumeration value=\"e3\" />{0}" +
1437                                 "    </xs:restriction>{0}" +
1438                                 "  </xs:simpleType>{0}" +
1439                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1440                 }
1441
1442                 [Test]
1443                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1444                 public void ExportXmlSerializable ()
1445                 {
1446                         XmlSchemas schemas = Export (typeof (Employee), "NSEmployee");
1447                         Assert.AreEqual (1, schemas.Count, "#1");
1448
1449                         StringWriter sw = new StringWriter ();
1450                         schemas[0].Write (sw);
1451
1452                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1453                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1454                                 "<xs:schema xmlns:tns=\"NSEmployee\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployee\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1455                                 "  <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1456 #if MS // bug #77117
1457                                 "  <xs:element name=\"Employee\" nillable=\"true\">{0}" +
1458 #else
1459                                 "  <xs:element name=\"Employee\">{0}" +
1460 #endif
1461                                 "    <xs:complexType>{0}" +
1462                                 "      <xs:sequence>{0}" +
1463                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1464                                 "        <xs:any />{0}" +
1465                                 "      </xs:sequence>{0}" +
1466                                 "    </xs:complexType>{0}" +
1467                                 "  </xs:element>{0}" +
1468                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1469
1470                         schemas = Export (typeof (Employee));
1471                         Assert.AreEqual (1, schemas.Count, "#3");
1472
1473                         sw.GetStringBuilder ().Length = 0;
1474                         schemas[0].Write (sw);
1475
1476                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1477                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1478                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1479                                 "  <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1480 #if MS // bug #77117
1481                                 "  <xs:element name=\"Employee\" nillable=\"true\">{0}" +
1482 #else
1483                                 "  <xs:element name=\"Employee\">{0}" +
1484 #endif
1485                                 "    <xs:complexType>{0}" +
1486                                 "      <xs:sequence>{0}" +
1487                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1488                                 "        <xs:any />{0}" +
1489                                 "      </xs:sequence>{0}" +
1490                                 "    </xs:complexType>{0}" +
1491                                 "  </xs:element>{0}" +
1492                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1493                 }
1494
1495                 [Test]
1496                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1497                 public void ExportXmlSerializable_Schema ()
1498                 {
1499                         XmlSchemas schemas = Export (typeof (EmployeeSchema), "NSEmployeeSchema");
1500                         Assert.AreEqual (2, schemas.Count, "#1");
1501
1502                         StringWriter sw = new StringWriter ();
1503                         schemas[0].Write (sw);
1504
1505                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1506                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1507                                 "<xs:schema xmlns:tns=\"NSEmployeeSchema\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1508 #if ONLY_1_1
1509                                 "  <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1510 #endif
1511 #if MS // bug #77117
1512                                 "  <xs:element name=\"EmployeeSchema\" nillable=\"true\">{0}" +
1513 #else
1514                                 "  <xs:element name=\"EmployeeSchema\">{0}" +
1515 #endif
1516                                 "    <xs:complexType>{0}" +
1517                                 "      <xs:sequence>{0}" +
1518                                 "        <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1519                                 "      </xs:sequence>{0}" +
1520                                 "    </xs:complexType>{0}" +
1521                                 "  </xs:element>{0}" +
1522                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1523
1524                         sw.GetStringBuilder ().Length = 0;
1525                         schemas[1].Write (sw);
1526
1527                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1528                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1529                                 "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1530                                 "  <xs:complexType name=\"employeeRoot\">{0}" +
1531                                 "    <xs:attribute name=\"firstName\" />{0}" +
1532                                 "    <xs:attribute name=\"lastName\" />{0}" +
1533                                 "    <xs:attribute name=\"address\" />{0}" +
1534                                 "  </xs:complexType>{0}" +
1535                                 "  <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1536                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
1537
1538                         schemas = Export (typeof (EmployeeSchema));
1539                         Assert.AreEqual (2, schemas.Count, "#4");
1540
1541                         sw.GetStringBuilder ().Length = 0;
1542                         schemas[0].Write (sw);
1543
1544                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1545                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1546                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1547 #if ONLY_1_1
1548                                 "  <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1549 #endif
1550 #if MS // bug #77117
1551                                  "  <xs:element name=\"EmployeeSchema\" nillable=\"true\">{0}" +
1552 #else
1553                                 "  <xs:element name=\"EmployeeSchema\">{0}" +
1554 #endif
1555                                 "    <xs:complexType>{0}" +
1556                                 "      <xs:sequence>{0}" +
1557                                 "        <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1558                                 "      </xs:sequence>{0}" +
1559                                 "    </xs:complexType>{0}" +
1560                                 "  </xs:element>{0}" +
1561                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
1562
1563                         sw.GetStringBuilder ().Length = 0;
1564                         schemas[1].Write (sw);
1565
1566                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1567                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1568                                 "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1569                                 "  <xs:complexType name=\"employeeRoot\">{0}" +
1570                                 "    <xs:attribute name=\"firstName\" />{0}" +
1571                                 "    <xs:attribute name=\"lastName\" />{0}" +
1572                                 "    <xs:attribute name=\"address\" />{0}" +
1573                                 "  </xs:complexType>{0}" +
1574                                 "  <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1575                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
1576
1577                         schemas = Export (typeof (PrimitiveSchema), "NSPrimitiveSchema");
1578                         Assert.AreEqual (2, schemas.Count, "#7");
1579
1580                         sw.GetStringBuilder ().Length = 0;
1581                         schemas[0].Write (sw);
1582
1583                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1584                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1585                                 "<xs:schema xmlns:tns=\"NSPrimitiveSchema\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimitiveSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1586 #if MS // bug #77117
1587                                 "  <xs:element name=\"PrimitiveSchema\" nillable=\"true\">{0}" +
1588 #else
1589                                 "  <xs:element name=\"PrimitiveSchema\">{0}" +
1590 #endif
1591                                 "    <xs:complexType>{0}" +
1592                                 "      <xs:sequence>{0}" +
1593                                 "        <xs:any namespace=\"\" />{0}" +
1594                                 "      </xs:sequence>{0}" +
1595                                 "    </xs:complexType>{0}" +
1596                                 "  </xs:element>{0}" +
1597                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1598
1599                         sw.GetStringBuilder ().Length = 0;
1600                         schemas[1].Write (sw);
1601
1602                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1603                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1604                                 "<xs:schema id=\"LuckyNumberSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1605                                 "  <xs:element name=\"LuckyNumber\" type=\"xs:int\" />{0}" +
1606                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#9");
1607                 }
1608
1609                 [Test]
1610                 [ExpectedException (typeof (InvalidOperationException))] // Schema Id is missing
1611                 public void ExportXmlSerializable_MissingID ()
1612                 {
1613                         Export (typeof (MissingIDSchema));
1614                 }
1615
1616                 [ExpectedException (typeof (InvalidOperationException))]
1617                 public void ExportXmlSerializable_DuplicateNamespace ()
1618                 {
1619                         try {
1620                                 Export (typeof (PrimitiveSchema));
1621                                 Assert.Fail ("#1");
1622                         } catch (InvalidOperationException) {
1623                                 // The namespace, , is a duplicate.
1624                         }
1625
1626                         try {
1627                                 Export (typeof (XmlSerializableContainer));
1628                                 Assert.Fail ("#2");
1629                         } catch (InvalidOperationException) {
1630                                 // The namespace, , is a duplicate.
1631                         }
1632                 }
1633
1634                 [Test]
1635                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1636 #if NET_2_0
1637                 [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
1638 #endif
1639                 public void ExportXmlSerializable_SchemaProvider ()
1640                 {
1641                         XmlSchemas schemas = Export (typeof (EmployeeSchemaProvider), "NSEmployeeSchemaProvider");
1642                         Assert.AreEqual (1, schemas.Count, "#1");
1643
1644                         StringWriter sw = new StringWriter ();
1645                         schemas[0].Write (sw);
1646
1647                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1648                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1649                                 "<xs:schema xmlns:tns=\"NSEmployeeSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployeeSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1650 #if NET_2_0
1651                                 "  <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1652                                 "  <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1653 #else
1654                                 "  <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1655 #if MS // bug #77117
1656                                 "  <xs:element name=\"EmployeeSchemaProvider\" nillable=\"true\">{0}" +
1657 #else
1658                                 "  <xs:element name=\"EmployeeSchemaProvider\">{0}" +
1659 #endif
1660                                 "    <xs:complexType>{0}" +
1661                                 "      <xs:sequence>{0}" +
1662                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1663                                 "        <xs:any />{0}" +
1664                                 "      </xs:sequence>{0}" +
1665                                 "    </xs:complexType>{0}" +
1666                                 "  </xs:element>{0}" +
1667 #endif
1668                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1669
1670                         schemas = Export (typeof (EmployeeSchemaProvider));
1671                         Assert.AreEqual (1, schemas.Count, "#3");
1672
1673                         sw.GetStringBuilder ().Length = 0;
1674                         schemas[0].Write (sw);
1675
1676                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1677                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1678                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1679 #if NET_2_0
1680                                 "  <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1681                                 "  <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1682 #else
1683                                 "  <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1684 #if MS // bug #77117
1685                                 "  <xs:element name=\"EmployeeSchemaProvider\" nillable=\"true\">{0}" +
1686 #else
1687                                 "  <xs:element name=\"EmployeeSchemaProvider\">{0}" +
1688 #endif
1689                                 "    <xs:complexType>{0}" +
1690                                 "      <xs:sequence>{0}" +
1691                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1692                                 "        <xs:any />{0}" +
1693                                 "      </xs:sequence>{0}" +
1694                                 "    </xs:complexType>{0}" +
1695                                 "  </xs:element>{0}" +
1696 #endif
1697                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1698
1699                         schemas = Export (typeof (PrimitiveSchemaProvider), "NSPrimitiveSchemaProvider");
1700                         Assert.AreEqual (1, schemas.Count, "#5");
1701
1702                         sw.GetStringBuilder ().Length = 0;
1703                         schemas[0].Write (sw);
1704
1705                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1706                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1707                                 "<xs:schema xmlns:tns=\"NSPrimitiveSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimitiveSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1708 #if NET_2_0
1709                                 "  <xs:import />{0}" +
1710                                 "  <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
1711 #else
1712                                 "  <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1713 #if MS // bug #77117
1714                                 "  <xs:element name=\"PrimitiveSchemaProvider\" nillable=\"true\">{0}" +
1715 #else
1716                                 "  <xs:element name=\"PrimitiveSchemaProvider\">{0}" +
1717 #endif
1718                                 "    <xs:complexType>{0}" +
1719                                 "      <xs:sequence>{0}" +
1720                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1721                                 "        <xs:any />{0}" +
1722                                 "      </xs:sequence>{0}" +
1723                                 "    </xs:complexType>{0}" +
1724                                 "  </xs:element>{0}" +
1725 #endif
1726                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
1727
1728                         schemas = Export (typeof (PrimitiveSchemaProvider));
1729                         Assert.AreEqual (1, schemas.Count, "#7");
1730
1731                         sw.GetStringBuilder ().Length = 0;
1732                         schemas[0].Write (sw);
1733
1734                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1735                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1736                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1737 #if NET_2_0
1738                                 "  <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
1739 #else
1740                                 "  <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1741 #if MS // bug #77117
1742                                 "  <xs:element name=\"PrimitiveSchemaProvider\" nillable=\"true\">{0}" +
1743 #else
1744                                 "  <xs:element name=\"PrimitiveSchemaProvider\">{0}" +
1745 #endif
1746                                 "    <xs:complexType>{0}" +
1747                                 "      <xs:sequence>{0}" +
1748                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1749                                 "        <xs:any />{0}" +
1750                                 "      </xs:sequence>{0}" +
1751                                 "    </xs:complexType>{0}" +
1752                                 "  </xs:element>{0}" +
1753 #endif
1754                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1755                 }
1756
1757                 [Test]
1758                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1759 #if NET_2_0
1760                 [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
1761 #endif
1762                 public void ExportXmlSerializable_Container ()
1763                 {
1764                         XmlSchemas schemas = Export (typeof (XmlSerializableContainer), "NSXmlSerializableContainer");
1765                         Assert.AreEqual (3, schemas.Count, "#1");
1766
1767                         StringWriter sw = new StringWriter ();
1768                         schemas[0].Write (sw);
1769
1770                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1771                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1772                                 "<xs:schema xmlns:tns=\"NSXmlSerializableContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSXmlSerializableContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1773                                 "  <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1774                                 "  <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1775 #if NET_2_0
1776                                 "  <xs:import />{0}" +
1777 #endif
1778 #if MS // bug #77117
1779                                 "  <xs:element name=\"XmlSerializableContainer\" nillable=\"true\" type=\"tns:XmlSerializableContainer\" />{0}" +
1780 #else
1781                                 "  <xs:element name=\"XmlSerializableContainer\" type=\"tns:XmlSerializableContainer\" />{0}" +
1782 #endif
1783                                 "  <xs:complexType name=\"XmlSerializableContainer\">{0}" +
1784                                 "    <xs:sequence>{0}" +
1785                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Slave\">{0}" +
1786                                 "        <xs:complexType>{0}" +
1787                                 "          <xs:sequence>{0}" +
1788                                 "            <xs:element ref=\"xs:schema\" />{0}" +
1789                                 "            <xs:any />{0}" +
1790                                 "          </xs:sequence>{0}" +
1791                                 "        </xs:complexType>{0}" +
1792                                 "      </xs:element>{0}" +
1793                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchema\">{0}" +
1794                                 "        <xs:complexType>{0}" +
1795                                 "          <xs:sequence>{0}" +
1796                                 "            <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1797                                 "          </xs:sequence>{0}" +
1798                                 "        </xs:complexType>{0}" +
1799                                 "      </xs:element>{0}" +
1800 #if NET_2_0
1801                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1802 #else
1803                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\">{0}" +
1804                                 "        <xs:complexType>{0}" +
1805                                 "          <xs:sequence>{0}" +
1806                                 "            <xs:element ref=\"xs:schema\" />{0}" +
1807                                 "            <xs:any />{0}" +
1808                                 "          </xs:sequence>{0}" +
1809                                 "        </xs:complexType>{0}" +
1810                                 "      </xs:element>{0}" +
1811 #endif
1812                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchema\">{0}" +
1813                                 "        <xs:complexType>{0}" +
1814                                 "          <xs:sequence>{0}" +
1815                                 "            <xs:any namespace=\"\" />{0}" +
1816                                 "          </xs:sequence>{0}" +
1817                                 "        </xs:complexType>{0}" +
1818                                 "      </xs:element>{0}" +
1819 #if NET_2_0
1820                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\" type=\"xs:int\" />{0}" +
1821                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveNamespace\" />{0}" +
1822                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaNamespace\" />{0}" +
1823                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:SlaveSchemaProviderNamespace\" />{0}" +
1824                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaNamespace\" />{0}" +
1825                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:NativeSchemaProviderNamespace\" />{0}" +
1826                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveNSOnly\" />{0}" +
1827                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaNSOnly\" />{0}" +
1828                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:SlaveSchemaProviderNSOnly\" />{0}" +
1829                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaNSOnly\" />{0}" +
1830                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q11=\"urn:types-devx-com\" ref=\"q11:NativeSchemaProviderNSOnly\" />{0}" +
1831 #else
1832                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\">{0}" +
1833                                 "        <xs:complexType>{0}" +
1834                                 "          <xs:sequence>{0}" +
1835                                 "            <xs:element ref=\"xs:schema\" />{0}" +
1836                                 "            <xs:any />{0}" +
1837                                 "          </xs:sequence>{0}" +
1838                                 "        </xs:complexType>{0}" +
1839                                 "      </xs:element>{0}" +
1840                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q1=\"urn:types-devx-com\" ref=\"q1:SlaveNamespace\" />{0}" +
1841                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveSchemaNamespace\" />{0}" +
1842                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaProviderNamespace\" />{0}" +
1843                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:NativeSchemaNamespace\" />{0}" +
1844                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaProviderNamespace\" />{0}" +
1845                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:SlaveNSOnly\" />{0}" +
1846                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveSchemaNSOnly\" />{0}" +
1847                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaProviderNSOnly\" />{0}" +
1848                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:NativeSchemaNSOnly\" />{0}" +
1849                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaProviderNSOnly\" />{0}" +
1850 #endif
1851                                 "    </xs:sequence>{0}" +
1852                                 "  </xs:complexType>{0}" +
1853                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1854
1855                         sw.GetStringBuilder ().Length = 0;
1856                         schemas[1].Write (sw);
1857
1858                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1859                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1860                                 "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1861                                 "  <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1862 #if NET_2_0
1863                                 "  <xs:import />{0}" +
1864 #endif
1865                                 "  <xs:complexType name=\"employeeRoot\">{0}" +
1866                                 "    <xs:attribute name=\"firstName\" />{0}" +
1867                                 "    <xs:attribute name=\"lastName\" />{0}" +
1868                                 "    <xs:attribute name=\"address\" />{0}" +
1869                                 "  </xs:complexType>{0}" +
1870                                 "  <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1871                                 "  <xs:element name=\"SlaveNamespace\">{0}" +
1872                                 "    <xs:complexType>{0}" +
1873                                 "      <xs:sequence>{0}" +
1874                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1875                                 "        <xs:any />{0}" +
1876                                 "      </xs:sequence>{0}" +
1877                                 "    </xs:complexType>{0}" +
1878                                 "  </xs:element>{0}" +
1879                                 "  <xs:element name=\"SlaveSchemaNamespace\">{0}" +
1880                                 "    <xs:complexType>{0}" +
1881                                 "      <xs:sequence>{0}" +
1882                                 "        <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1883                                 "      </xs:sequence>{0}" +
1884                                 "    </xs:complexType>{0}" +
1885                                 "  </xs:element>{0}" +
1886 #if NET_2_0
1887                                 "  <xs:element name=\"SlaveSchemaProviderNamespace\" type=\"tns:employeeRoot\" />{0}" +
1888 #else
1889                                 "  <xs:element name=\"SlaveSchemaProviderNamespace\">{0}" +
1890                                 "    <xs:complexType>{0}" +
1891                                 "      <xs:sequence>{0}" +
1892                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1893                                 "        <xs:any />{0}" +
1894                                 "      </xs:sequence>{0}" +
1895                                 "    </xs:complexType>{0}" +
1896                                 "  </xs:element>{0}" +
1897 #endif
1898                                 "  <xs:element name=\"NativeSchemaNamespace\">{0}" +
1899                                 "    <xs:complexType>{0}" +
1900                                 "      <xs:sequence>{0}" +
1901                                 "        <xs:any namespace=\"\" />{0}" +
1902                                 "      </xs:sequence>{0}" +
1903                                 "    </xs:complexType>{0}" +
1904                                 "  </xs:element>{0}" +
1905 #if NET_2_0
1906                                 "  <xs:element name=\"NativeSchemaProviderNamespace\" type=\"xs:int\" />{0}" +
1907 #else
1908                                 "  <xs:element name=\"NativeSchemaProviderNamespace\">{0}" +
1909                                 "    <xs:complexType>{0}" +
1910                                 "      <xs:sequence>{0}" +
1911                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1912                                 "        <xs:any />{0}" +
1913                                 "      </xs:sequence>{0}" +
1914                                 "    </xs:complexType>{0}" +
1915                                 "  </xs:element>{0}" +
1916 #endif
1917                                 "  <xs:element name=\"SlaveNSOnly\">{0}" +
1918                                 "    <xs:complexType>{0}" +
1919                                 "      <xs:sequence>{0}" +
1920                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1921                                 "        <xs:any />{0}" +
1922                                 "      </xs:sequence>{0}" +
1923                                 "    </xs:complexType>{0}" +
1924                                 "  </xs:element>{0}" +
1925                                 "  <xs:element name=\"SlaveSchemaNSOnly\">{0}" +
1926                                 "    <xs:complexType>{0}" +
1927                                 "      <xs:sequence>{0}" +
1928                                 "        <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1929                                 "      </xs:sequence>{0}" +
1930                                 "    </xs:complexType>{0}" +
1931                                 "  </xs:element>{0}" +
1932 #if NET_2_0
1933                                  "  <xs:element name=\"SlaveSchemaProviderNSOnly\" type=\"tns:employeeRoot\" />{0}" +
1934 #else
1935                                 "  <xs:element name=\"SlaveSchemaProviderNSOnly\">{0}" +
1936                                 "    <xs:complexType>{0}" +
1937                                 "      <xs:sequence>{0}" +
1938                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1939                                 "        <xs:any />{0}" +
1940                                 "      </xs:sequence>{0}" +
1941                                 "    </xs:complexType>{0}" +
1942                                 "  </xs:element>{0}" +
1943 #endif
1944                                 "  <xs:element name=\"NativeSchemaNSOnly\">{0}" +
1945                                 "    <xs:complexType>{0}" +
1946                                 "      <xs:sequence>{0}" +
1947                                 "        <xs:any namespace=\"\" />{0}" +
1948                                 "      </xs:sequence>{0}" +
1949                                 "    </xs:complexType>{0}" +
1950                                 "  </xs:element>{0}" +
1951 #if NET_2_0
1952                                 "  <xs:element name=\"NativeSchemaProviderNSOnly\" type=\"xs:int\" />{0}" +
1953 #else
1954                                 "  <xs:element name=\"NativeSchemaProviderNSOnly\">{0}" +
1955                                 "    <xs:complexType>{0}" +
1956                                 "      <xs:sequence>{0}" +
1957                                 "        <xs:element ref=\"xs:schema\" />{0}" +
1958                                 "        <xs:any />{0}" +
1959                                 "      </xs:sequence>{0}" +
1960                                 "    </xs:complexType>{0}" +
1961                                 "  </xs:element>{0}" +
1962 #endif
1963                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
1964
1965                         sw.GetStringBuilder ().Length = 0;
1966                         schemas[2].Write (sw);
1967
1968                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1969                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1970                                 "<xs:schema id=\"LuckyNumberSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1971                                 "  <xs:element name=\"LuckyNumber\" type=\"xs:int\" />{0}" +
1972                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1973                 }
1974
1975                 [Test]
1976                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1977                 public void ExportXsdPrimitive ()
1978                 {
1979                         ArrayList types = new ArrayList ();
1980                         types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte"));
1981                         types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte"));
1982                         types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean"));
1983                         types.Add (new TypeDescription (typeof (short), true, "short", "Short"));
1984                         types.Add (new TypeDescription (typeof (int), true, "int", "Int"));
1985                         types.Add (new TypeDescription (typeof (long), true, "long", "Long"));
1986                         types.Add (new TypeDescription (typeof (float), true, "float", "Float"));
1987                         types.Add (new TypeDescription (typeof (double), true, "double", "Double"));
1988                         types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal"));
1989                         types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort"));
1990                         types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt"));
1991                         types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong"));
1992                         types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime"));
1993 #if NET_2_0
1994                         types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true));
1995 #else
1996                         types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName"));
1997 #endif
1998                         types.Add (new TypeDescription (typeof (string), true, "string", "String", true));
1999
2000                         foreach (TypeDescription typeDesc in types) {
2001                                 XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
2002                                 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
2003
2004                                 StringWriter sw = new StringWriter ();
2005                                 schemas[0].Write (sw);
2006
2007                                 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2008                                         "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2009                                         "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2010                                         "  <xs:element name=\"{2}\" {3}type=\"xs:{2}\" />{0}" +
2011 #if MS // bug #77117
2012                                         "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.XmlType, typeDesc.IsNillable ? "nillable=\"true\" " : ""),
2013 #else
2014                                         "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.XmlType, ""),
2015 #endif
2016                                         sw.ToString (), typeDesc.Type.FullName + "#2");
2017
2018                                 schemas = Export (typeDesc.Type);
2019                                 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
2020
2021                                 sw.GetStringBuilder ().Length = 0;
2022                                 schemas[0].Write (sw);
2023
2024                                 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2025                                         "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2026                                         "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2027                                         "  <xs:element name=\"{1}\" {2}type=\"xs:{1}\" />{0}" +
2028 #if MS // bug #77117
2029                                         "</xs:schema>", Environment.NewLine, typeDesc.XmlType, typeDesc.IsNillable ? "nillable=\"true\" " : ""),
2030 #else
2031                                         "</xs:schema>", Environment.NewLine, typeDesc.XmlType, ""),
2032 #endif
2033                                         sw.ToString (), typeDesc.Type.FullName + "#4");
2034                         }
2035                 }
2036
2037                 [Test]
2038                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2039                 public void ExportXsdPrimitive_Object ()
2040                 {
2041                         XmlSchemas schemas = Export (typeof (object), "NSAnyType");
2042                         Assert.AreEqual (1, schemas.Count, "#1");
2043
2044                         StringWriter sw = new StringWriter ();
2045                         schemas[0].Write (sw);
2046
2047                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2048                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2049                                 "<xs:schema xmlns:tns=\"NSAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2050 #if MS // bug #77117
2051                                 "  <xs:element name=\"anyType\" nillable=\"true\" />{0}" +
2052 #else
2053                                 "  <xs:element name=\"anyType\" />{0}" +
2054 #endif
2055                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2056
2057                         schemas = Export (typeof (object));
2058                         Assert.AreEqual (1, schemas.Count, "#3");
2059
2060                         sw.GetStringBuilder ().Length = 0;
2061                         schemas[0].Write (sw);
2062
2063                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2064                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2065                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2066 #if MS // bug #77117
2067                                 "  <xs:element name=\"anyType\" nillable=\"true\" />{0}" +
2068 #else
2069                                 "  <xs:element name=\"anyType\" />{0}" +
2070 #endif
2071                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
2072                 }
2073
2074                 [Test]
2075                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2076                 public void ExportXsdPrimitive_ByteArray ()
2077                 {
2078                         XmlSchemas schemas = Export (typeof (byte[]), "NSByteArray");
2079                         Assert.AreEqual (1, schemas.Count, "#1");
2080
2081                         StringWriter sw = new StringWriter ();
2082                         schemas[0].Write (sw);
2083
2084                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2085                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2086                                 "<xs:schema xmlns:tns=\"NSByteArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSByteArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2087 #if MS // bug #77117
2088                                 "  <xs:element name=\"base64Binary\" nillable=\"true\" type=\"xs:base64Binary\" />{0}" +
2089 #else
2090                                 "  <xs:element name=\"base64Binary\" type=\"xs:base64Binary\" />{0}" +
2091 #endif
2092                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2093
2094                         schemas = Export (typeof (byte[]));
2095                         Assert.AreEqual (1, schemas.Count, "#3");
2096
2097                         sw.GetStringBuilder ().Length = 0;
2098                         schemas[0].Write (sw);
2099
2100                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2101                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2102                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2103 #if MS // bug #77117
2104                                 "  <xs:element name=\"base64Binary\" nillable=\"true\" type=\"xs:base64Binary\" />{0}" +
2105 #else
2106                                 "  <xs:element name=\"base64Binary\" type=\"xs:base64Binary\" />{0}" +
2107 #endif
2108                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
2109                 }
2110
2111                 [Test]
2112                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2113                 public void ExportXsdPrimitive_Arrays ()
2114                 {
2115                         ArrayList types = new ArrayList ();
2116                         types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte"));
2117                         types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean"));
2118                         types.Add (new TypeDescription (typeof (short[]), true, "short", "Short"));
2119                         types.Add (new TypeDescription (typeof (int[]), true, "int", "Int"));
2120                         types.Add (new TypeDescription (typeof (long[]), true, "long", "Long"));
2121                         types.Add (new TypeDescription (typeof (float[]), true, "float", "Float"));
2122                         types.Add (new TypeDescription (typeof (double[]), true, "double", "Double"));
2123                         types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal"));
2124                         types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort"));
2125                         types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt"));
2126                         types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong"));
2127                         types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime"));
2128 #if NET_2_0
2129                         types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true));
2130 #else
2131                         types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName"));
2132 #endif
2133                         types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true));
2134
2135                         foreach (TypeDescription typeDesc in types) {
2136                                 XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
2137                                 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
2138
2139                                 StringWriter sw = new StringWriter ();
2140                                 schemas[0].Write (sw);
2141
2142                                 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2143                                         "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2144                                         "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2145 #if MS // bug #77117
2146                                         "  <xs:element name=\"ArrayOf{2}\" nillable=\"true\" type=\"tns:ArrayOf{2}\" />{0}" +
2147 #else
2148                                         "  <xs:element name=\"ArrayOf{2}\" type=\"tns:ArrayOf{2}\" />{0}" +
2149 #endif
2150                                         "  <xs:complexType name=\"ArrayOf{2}\">{0}" +
2151                                         "    <xs:sequence>{0}" +
2152                                         "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{3}\" {5}type=\"{4}:{3}\" />{0}" +
2153                                         "    </xs:sequence>{0}" +
2154                                         "  </xs:complexType>{0}" +
2155                                         "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType, 
2156                                         typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
2157                                         sw.ToString (), typeDesc.Type.FullName + "#2");
2158
2159                                 schemas = Export (typeDesc.Type);
2160                                 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
2161
2162                                 sw.GetStringBuilder ().Length = 0;
2163                                 schemas[0].Write (sw);
2164
2165                                 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2166                                         "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2167                                         "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2168 #if MS // bug #77117
2169                                         "  <xs:element name=\"ArrayOf{1}\" nillable=\"true\" type=\"ArrayOf{1}\" />{0}" +
2170 #else
2171                                         "  <xs:element name=\"ArrayOf{1}\" type=\"ArrayOf{1}\" />{0}" +
2172 #endif
2173                                         "  <xs:complexType name=\"ArrayOf{1}\">{0}" +
2174                                         "    <xs:sequence>{0}" +
2175                                         "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{2}\" {4}type=\"{3}:{2}\" />{0}" +
2176                                         "    </xs:sequence>{0}" +
2177                                         "  </xs:complexType>{0}" +
2178                                         "</xs:schema>", Environment.NewLine, typeDesc.ArrayType, typeDesc.XmlType,
2179                                         typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
2180                                         sw.ToString (), typeDesc.Type.FullName + "#4");
2181                         }
2182                 }
2183
2184                 [Test]
2185                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2186                 public void ExportXsdPrimitive_Object_Arrays ()
2187                 {
2188                         XmlSchemas schemas = Export (typeof (object[]), "NSArrayOfAnyType");
2189                         Assert.AreEqual (1, schemas.Count, "#1");
2190
2191                         StringWriter sw = new StringWriter ();
2192                         schemas[0].Write (sw);
2193
2194                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2195                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2196                                 "<xs:schema xmlns:tns=\"NSArrayOfAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayOfAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2197 #if MS // bug #77117
2198                                 "  <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"tns:ArrayOfAnyType\" />{0}" +
2199 #else
2200                                 "  <xs:element name=\"ArrayOfAnyType\" type=\"tns:ArrayOfAnyType\" />{0}" +
2201 #endif
2202                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
2203                                 "    <xs:sequence>{0}" +
2204                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
2205                                 "    </xs:sequence>{0}" +
2206                                 "  </xs:complexType>{0}" +
2207                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2208
2209                         schemas = Export (typeof (object[]));
2210                         Assert.AreEqual (1, schemas.Count, "#3");
2211
2212                         sw.GetStringBuilder ().Length = 0;
2213                         schemas[0].Write (sw);
2214
2215                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2216                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2217                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2218 #if MS // bug #77117
2219                                 "  <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"ArrayOfAnyType\" />{0}" +
2220 #else
2221                                 "  <xs:element name=\"ArrayOfAnyType\" type=\"ArrayOfAnyType\" />{0}" +
2222 #endif
2223                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
2224                                 "    <xs:sequence>{0}" +
2225                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
2226                                 "    </xs:sequence>{0}" +
2227                                 "  </xs:complexType>{0}" +
2228                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
2229                 }
2230
2231                 [Test]
2232                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2233                 public void ExportNonXsdPrimitive_Guid ()
2234                 {
2235                         XmlSchemas schemas = Export (typeof (Guid), "NSPrimGuid");
2236                         Assert.AreEqual (2, schemas.Count, "#1");
2237
2238                         StringWriter sw = new StringWriter ();
2239                         schemas[0].Write (sw);
2240
2241                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2242                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2243                                 "<xs:schema xmlns:tns=\"NSPrimGuid\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimGuid\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2244                                 "  <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2245                                 "  <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
2246                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2247
2248                         sw.GetStringBuilder ().Length = 0;
2249                         schemas[1].Write (sw);
2250
2251                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2252                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2253                                 "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2254                                 "  <xs:simpleType name=\"guid\">{0}" +
2255                                 "    <xs:restriction base=\"xs:string\">{0}" +
2256                                 "      <xs:pattern value=\"[0-9a-fA-F]{{8}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{12}}\" />{0}" +
2257                                 "    </xs:restriction>{0}" +
2258                                 "  </xs:simpleType>{0}" +
2259                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
2260
2261                         schemas = Export (typeof (Guid));
2262                         Assert.AreEqual (2, schemas.Count, "#4");
2263
2264                         sw.GetStringBuilder ().Length = 0;
2265                         schemas[0].Write (sw);
2266
2267                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2268                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2269                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2270                                 "  <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2271                                 "  <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
2272                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
2273
2274                         sw.GetStringBuilder ().Length = 0;
2275                         schemas[1].Write (sw);
2276
2277                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2278                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2279                                 "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2280                                 "  <xs:simpleType name=\"guid\">{0}" +
2281                                 "    <xs:restriction base=\"xs:string\">{0}" +
2282                                 "      <xs:pattern value=\"[0-9a-fA-F]{{8}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{12}}\" />{0}" +
2283                                 "    </xs:restriction>{0}" +
2284                                 "  </xs:simpleType>{0}" +
2285                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
2286                 }
2287
2288                 [Test]
2289                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2290                 public void ExportNonXsdPrimitive_Char ()
2291                 {
2292                         XmlSchemas schemas = Export (typeof (char), "NSPrimChar");
2293                         Assert.AreEqual (2, schemas.Count, "#1");
2294
2295                         StringWriter sw = new StringWriter ();
2296                         schemas[0].Write (sw);
2297
2298                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2299                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2300                                 "<xs:schema xmlns:tns=\"NSPrimChar\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimChar\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2301                                 "  <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2302                                 "  <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
2303                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2304
2305                         sw.GetStringBuilder ().Length = 0;
2306                         schemas[1].Write (sw);
2307
2308                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2309                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2310                                 "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2311                                 "  <xs:simpleType name=\"char\">{0}" +
2312                                 "    <xs:restriction base=\"xs:unsignedShort\" />{0}" +
2313                                 "  </xs:simpleType>{0}" +
2314                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
2315
2316                         schemas = Export (typeof (char));
2317                         Assert.AreEqual (2, schemas.Count, "#4");
2318
2319                         sw.GetStringBuilder ().Length = 0;
2320                         schemas[0].Write (sw);
2321
2322                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2323                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2324                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2325                                 "  <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2326                                 "  <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
2327                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
2328
2329                         sw.GetStringBuilder ().Length = 0;
2330                         schemas[1].Write (sw);
2331
2332                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2333                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2334                                 "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2335                                 "  <xs:simpleType name=\"char\">{0}" +
2336                                 "    <xs:restriction base=\"xs:unsignedShort\" />{0}" +
2337                                 "  </xs:simpleType>{0}" +
2338                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
2339                 }
2340
2341                 public class Employee : IXmlSerializable
2342                 {
2343                         private string _firstName;
2344                         private string _lastName;
2345                         private string _address;
2346
2347                         public virtual XmlSchema GetSchema ()
2348                         {
2349                                 return null;
2350                         }
2351
2352                         public void WriteXml (XmlWriter writer)
2353                         {
2354                                 writer.WriteStartElement ("employee", "urn:devx-com");
2355                                 writer.WriteAttributeString ("firstName", _firstName);
2356                                 writer.WriteAttributeString ("lastName", _lastName);
2357                                 writer.WriteAttributeString ("address", _address);
2358                                 writer.WriteEndElement ();
2359                         }
2360
2361                         public void ReadXml (XmlReader reader)
2362                         {
2363                                 XmlNodeType type = reader.MoveToContent ();
2364                                 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2365                                         _firstName = reader["firstName"];
2366                                         _lastName = reader["lastName"];
2367                                         _address = reader["address"];
2368                                 }
2369                         }
2370                 }
2371
2372                 public class EmployeeSchema : IXmlSerializable
2373                 {
2374                         private string _firstName;
2375                         private string _lastName;
2376                         private string _address;
2377
2378                         public virtual XmlSchema GetSchema ()
2379                         {
2380                                 return CreateSchema ();
2381                         }
2382
2383                         public void WriteXml (XmlWriter writer)
2384                         {
2385                                 writer.WriteStartElement ("employee", "urn:devx-com");
2386                                 writer.WriteAttributeString ("firstName", _firstName);
2387                                 writer.WriteAttributeString ("lastName", _lastName);
2388                                 writer.WriteAttributeString ("address", _address);
2389                                 writer.WriteEndElement ();
2390                         }
2391
2392                         public void ReadXml (XmlReader reader)
2393                         {
2394                                 XmlNodeType type = reader.MoveToContent ();
2395                                 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2396                                         _firstName = reader["firstName"];
2397                                         _lastName = reader["lastName"];
2398                                         _address = reader["address"];
2399                                 }
2400                         }
2401
2402                         protected static XmlSchema CreateSchema ()
2403                         {
2404                                 XmlSchema schema = new XmlSchema ();
2405                                 schema.Id = "EmployeeSchema";
2406                                 schema.TargetNamespace = "urn:types-devx-com";
2407
2408                                 XmlSchemaComplexType type = new XmlSchemaComplexType ();
2409                                 type.Name = "employeeRoot";
2410                                 XmlSchemaAttribute firstNameAttr = new XmlSchemaAttribute ();
2411                                 firstNameAttr.Name = "firstName";
2412                                 type.Attributes.Add (firstNameAttr);
2413
2414                                 XmlSchemaAttribute lastNameAttr = new XmlSchemaAttribute ();
2415                                 lastNameAttr.Name = "lastName";
2416                                 type.Attributes.Add (lastNameAttr);
2417
2418                                 XmlSchemaAttribute addressAttr = new XmlSchemaAttribute ();
2419                                 addressAttr.Name = "address";
2420                                 type.Attributes.Add (addressAttr);
2421
2422                                 XmlSchemaElement employeeElement = new XmlSchemaElement ();
2423                                 employeeElement.Name = "employee";
2424                                 XmlQualifiedName name = new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
2425                                 employeeElement.SchemaTypeName = name;
2426
2427                                 schema.Items.Add (type);
2428                                 schema.Items.Add (employeeElement);
2429                                 return schema;
2430                         }
2431                 }
2432
2433                 public class PrimitiveSchema : IXmlSerializable
2434                 {
2435                         private string _firstName;
2436                         private string _lastName;
2437                         private string _address;
2438
2439                         public virtual XmlSchema GetSchema ()
2440                         {
2441                                 XmlSchema schema = new XmlSchema ();
2442                                 schema.Id = "LuckyNumberSchema";
2443                                 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2444                                 luckyNumberElement.Name = "LuckyNumber";
2445                                 luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
2446                                 schema.Items.Add (luckyNumberElement);
2447                                 return schema;
2448                         }
2449
2450                         public void WriteXml (XmlWriter writer)
2451                         {
2452                                 writer.WriteStartElement ("employee", "urn:devx-com");
2453                                 writer.WriteAttributeString ("firstName", _firstName);
2454                                 writer.WriteAttributeString ("lastName", _lastName);
2455                                 writer.WriteAttributeString ("address", _address);
2456                                 writer.WriteEndElement ();
2457                         }
2458
2459                         public void ReadXml (XmlReader reader)
2460                         {
2461                                 XmlNodeType type = reader.MoveToContent ();
2462                                 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2463                                         _firstName = reader["firstName"];
2464                                         _lastName = reader["lastName"];
2465                                         _address = reader["address"];
2466                                 }
2467                         }
2468                 }
2469
2470                 public class MissingIDSchema : IXmlSerializable
2471                 {
2472                         private string _firstName;
2473                         private string _lastName;
2474                         private string _address;
2475
2476                         public virtual XmlSchema GetSchema ()
2477                         {
2478                                 XmlSchema schema = new XmlSchema ();
2479                                 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2480                                 luckyNumberElement.Name = "LuckyNumber";
2481                                 luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
2482                                 return schema;
2483                         }
2484
2485                         public void WriteXml (XmlWriter writer)
2486                         {
2487                                 writer.WriteStartElement ("employee", "urn:devx-com");
2488                                 writer.WriteAttributeString ("firstName", _firstName);
2489                                 writer.WriteAttributeString ("lastName", _lastName);
2490                                 writer.WriteAttributeString ("address", _address);
2491                                 writer.WriteEndElement ();
2492                         }
2493
2494                         public void ReadXml (XmlReader reader)
2495                         {
2496                                 XmlNodeType type = reader.MoveToContent ();
2497                                 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2498                                         _firstName = reader["firstName"];
2499                                         _lastName = reader["lastName"];
2500                                         _address = reader["address"];
2501                                 }
2502                         }
2503                 }
2504
2505 #if NET_2_0
2506                 [XmlSchemaProvider ("CreateEmployeeSchema")]
2507 #endif
2508                 public class EmployeeSchemaProvider : EmployeeSchema
2509                 {
2510 #if NET_2_0
2511                         public static XmlQualifiedName CreateEmployeeSchema (XmlSchemaSet schemaSet)
2512                         {
2513                                 schemaSet.Add (CreateSchema ());
2514                                 return new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
2515                         }
2516 #else
2517                         public override XmlSchema GetSchema ()
2518                         {
2519                                 return null;
2520                         }
2521 #endif
2522                 }
2523
2524 #if NET_2_0
2525                 [XmlSchemaProvider ("CreateLuckyNumberSchema")]
2526 #endif
2527                 public class PrimitiveSchemaProvider : IXmlSerializable
2528                 {
2529 #if NET_2_0
2530                         public static XmlQualifiedName CreateLuckyNumberSchema (XmlSchemaSet schemaSet)
2531                         {
2532                                 XmlSchema schema = new XmlSchema ();
2533
2534                                 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2535                                 luckyNumberElement.Name = "LuckyNumber";
2536
2537                                 XmlQualifiedName typeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");
2538                                 luckyNumberElement.SchemaTypeName = typeName;
2539                                 schema.Items.Add (luckyNumberElement);
2540
2541                                 schemaSet.Add (schema);
2542                                 return typeName;
2543                         }
2544 #endif
2545
2546                         public XmlSchema GetSchema ()
2547                         {
2548                                 return null;
2549                         }
2550
2551                         public void WriteXml (XmlWriter writer)
2552                         {
2553                                 writer.WriteElementString ("LuckyNumber", "7");
2554                         }
2555
2556                         public void ReadXml (XmlReader reader)
2557                         {
2558                                 XmlNodeType type = reader.MoveToContent ();
2559                                 if (type == XmlNodeType.Element && reader.LocalName == "LuckyNumber") {
2560                                 }
2561                         }
2562                 }
2563
2564                 private class TypeDescription
2565                 {
2566                         public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType) : this (type, xsdType, xmlType, arrayType, false)
2567                         {
2568                         }
2569
2570                         public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable)
2571                         {
2572                                 _type = type;
2573                                 _xsdType = xsdType;
2574                                 _xmlType = xmlType;
2575                                 _arrayType = arrayType;
2576                                 _isNillable = isNillable;
2577                         }
2578
2579                         public Type Type {
2580                                 get { return _type; }
2581                         }
2582
2583                         public string XmlType {
2584                                 get { return _xmlType; }
2585                         }
2586
2587                         public string ArrayType {
2588                                 get { return _arrayType; }
2589                         }
2590
2591                         public bool XsdType {
2592                                 get { return _xsdType; }
2593                         }
2594
2595                         public bool IsNillable {
2596                                 get { return _isNillable; }
2597                         }
2598
2599                         private Type _type;
2600                         private bool _xsdType;
2601                         private string _xmlType;
2602                         private string _arrayType;
2603                         private bool _isNillable;
2604                 }
2605
2606                 public class StructContainer
2607                 {
2608                         public EnumDefaultValue Value;
2609                         public TimeSpan[] Times;
2610                 }
2611
2612                 public class XmlSerializableContainer
2613                 {
2614                         public Employee Slave;
2615                         public EmployeeSchema SlaveSchema;
2616                         public EmployeeSchemaProvider SlaveSchemaProvider;
2617                         public PrimitiveSchema NativeSchema;
2618                         public PrimitiveSchemaProvider NativeSchemaProvider;
2619
2620                         [XmlElement ("SlaveNamespace", Namespace = "urn:types-devx-com")]
2621                         public Employee SlaveNS;
2622                         [XmlElement ("SlaveSchemaNamespace", Namespace = "urn:types-devx-com")]
2623                         public EmployeeSchema SlaveSchemaNS;
2624                         [XmlElement ("SlaveSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
2625                         public EmployeeSchemaProvider SlaveSchemaProviderNS;
2626                         [XmlElement ("NativeSchemaNamespace", Namespace = "urn:types-devx-com")]
2627                         public PrimitiveSchema NativeSchemaNS;
2628                         [XmlElement ("NativeSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
2629                         public PrimitiveSchemaProvider NativeSchemaProviderNS;
2630
2631
2632                         [XmlElement (Namespace = "urn:types-devx-com")]
2633                         public Employee SlaveNSOnly;
2634                         [XmlElement (Namespace = "urn:types-devx-com")]
2635                         public EmployeeSchema SlaveSchemaNSOnly;
2636                         [XmlElement (Namespace = "urn:types-devx-com")]
2637                         public EmployeeSchemaProvider SlaveSchemaProviderNSOnly;
2638                         [XmlElement (Namespace = "urn:types-devx-com")]
2639                         public PrimitiveSchema NativeSchemaNSOnly;
2640                         [XmlElement (Namespace = "urn:types-devx-com")]
2641                         public PrimitiveSchemaProvider NativeSchemaProviderNSOnly;
2642                 }
2643         }
2644 }