Fix to UriTemplate.Match to properly handle query parameters without a value. No...
[mono.git] / mcs / class / System.XML / Test / System.Xml.Serialization / SoapSchemaExporterTests.cs
1 //
2 // System.Xml.Serialization.SoapSchemaExporterTests
3 //
4 // Author:
5 //   Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // (C) 2005 Novell
8 // 
9
10 #if !MOBILE
11
12 using System;
13 using System.Collections;
14 using System.Globalization;
15 using System.IO;
16 using System.Xml;
17 using System.Xml.Schema;
18 using System.Xml.Serialization;
19
20 using NUnit.Framework;
21
22 using MonoTests.System.Xml.TestClasses;
23
24 namespace MonoTests.System.XmlSerialization
25 {
26         [TestFixture]
27         public class SoapSchemaExporterTests
28         {
29                 private XmlSchemas Export (Type type)
30                 {
31                         return Export (type, string.Empty);
32                 }
33
34                 private XmlSchemas Export (Type type, string defaultNamespace)
35                 {
36                         SoapReflectionImporter ri = new SoapReflectionImporter (defaultNamespace);
37                         XmlSchemas schemas = new XmlSchemas ();
38                         SoapSchemaExporter sx = new SoapSchemaExporter (schemas);
39                         XmlTypeMapping tm = ri.ImportTypeMapping (type);
40                         sx.ExportTypeMapping (tm);
41                         return schemas;
42                 }
43
44                 private XmlSchemas Export (Type type, SoapAttributeOverrides overrides)
45                 {
46                         return Export (type, overrides, string.Empty);
47                 }
48
49                 private XmlSchemas Export (Type type, SoapAttributeOverrides overrides, string defaultNamespace)
50                 {
51                         SoapReflectionImporter ri = new SoapReflectionImporter (overrides, defaultNamespace);
52                         XmlSchemas schemas = new XmlSchemas ();
53                         SoapSchemaExporter sx = new SoapSchemaExporter (schemas);
54                         XmlTypeMapping tm = ri.ImportTypeMapping (type);
55                         sx.ExportTypeMapping (tm);
56                         return schemas;
57                 }
58
59                 [Test]
60                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
61                 public void ExportStruct ()
62                 {
63                         XmlSchemas schemas = Export (typeof (TimeSpan), "NSTimeSpan");
64                         Assert.AreEqual (1, schemas.Count, "#1");
65
66                         StringWriter sw = new StringWriter ();
67                         schemas[0].Write (sw);
68
69                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
70                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
71                                 "<xs:schema xmlns:tns=\"NSTimeSpan\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpan\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
72                                 "  <xs:complexType name=\"TimeSpan\" />{0}" +
73                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
74
75                         schemas = Export (typeof (TimeSpan));
76                         Assert.AreEqual (1, schemas.Count, "#3");
77
78                         sw = new StringWriter ();
79                         schemas[0].Write (sw);
80
81                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
82                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
83                                 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{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 /*
91 #if NET_2_0
92                 [Category ("NotWorking")] // minOccurs is 1 on Mono
93 #endif
94 */
95                 public void ExportClass_SimpleClass ()
96                 {
97                         SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
98                         SoapAttributes attr = new SoapAttributes ();
99                         SoapElementAttribute element = new SoapElementAttribute ();
100                         element.ElementName = "saying";
101                         element.IsNullable = true;
102                         attr.SoapElement = element;
103                         overrides.Add (typeof (SimpleClass), "something", attr);
104
105                         XmlSchemas schemas = Export (typeof (SimpleClass), overrides, "NSSimpleClass");
106                         Assert.AreEqual (1, schemas.Count, "#1");
107
108                         StringWriter sw = new StringWriter ();
109                         schemas[0].Write (sw);
110
111                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
112                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
113                                 "<xs:schema xmlns:tns=\"NSSimpleClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
114                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
115                                 "    <xs:sequence>{0}" +
116                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
117                                 "    </xs:sequence>{0}" +
118                                 "  </xs:complexType>{0}" +
119                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
120                 }
121
122                 [Test]
123                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
124                 public void ExportClass_StringCollection ()
125                 {
126                         XmlSchemas schemas = Export (typeof (StringCollection), "NSStringCollection");
127                         Assert.AreEqual (1, schemas.Count, "#1");
128
129                         StringWriter sw = new StringWriter ();
130                         schemas[0].Write (sw);
131
132                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
133                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
134                                 "<xs:schema xmlns:tns=\"NSStringCollection\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollection\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
135                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
136                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
137                                 "  <xs:complexType name=\"ArrayOfString\">{0}" +
138                                 "    <xs:complexContent mixed=\"false\">{0}" +
139                                 "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
140                                 "        <xs:attribute d5p1:arrayType=\"xs:string[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
141                                 "      </xs:restriction>{0}" +
142                                 "    </xs:complexContent>{0}" +
143                                 "  </xs:complexType>{0}" +
144                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
145                 }
146
147                 [Test]
148                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
149                 public void ExportClass_StringCollectionContainer ()
150                 {
151                         XmlSchemas schemas = Export (typeof (StringCollectionContainer), "NSStringCollectionContainer");
152                         Assert.AreEqual (1, schemas.Count, "#1");
153
154                         StringWriter sw = new StringWriter ();
155                         schemas[0].Write (sw);
156
157                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
158                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
159                                 "<xs:schema xmlns:tns=\"NSStringCollectionContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollectionContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
160                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
161                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
162                                 "  <xs:complexType name=\"StringCollectionContainer\">{0}" +
163                                 "    <xs:sequence>{0}" +
164                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Messages\" type=\"tns:ArrayOfString\" />{0}" +
165                                 "    </xs:sequence>{0}" +
166                                 "  </xs:complexType>{0}" +
167                                 "  <xs:complexType name=\"ArrayOfString\">{0}" +
168                                 "    <xs:complexContent mixed=\"false\">{0}" +
169                                 "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
170                                 "        <xs:attribute d5p1:arrayType=\"xs:string[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
171                                 "      </xs:restriction>{0}" +
172                                 "    </xs:complexContent>{0}" +
173                                 "  </xs:complexType>{0}" +
174                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
175                 }
176
177                 [Test]
178                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
179                 public void ExportClass_ArrayContainer ()
180                 {
181                         XmlSchemas schemas = Export (typeof (ArrayContainer), "NSArrayContainer");
182                         Assert.AreEqual (1, schemas.Count, "#1");
183
184                         StringWriter sw = new StringWriter ();
185                         schemas[0].Write (sw);
186
187                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
188                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
189                                 "<xs:schema xmlns:tns=\"NSArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
190                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
191                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
192                                 "  <xs:complexType name=\"ArrayContainer\">{0}" +
193                                 "    <xs:sequence>{0}" +
194                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"items\" type=\"tns:ArrayOfAnyType\" />{0}" +
195                                 "    </xs:sequence>{0}" +
196                                 "  </xs:complexType>{0}" +
197                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
198                                 "    <xs:complexContent mixed=\"false\">{0}" +
199                                 "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
200                                 "        <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
201                                 "      </xs:restriction>{0}" +
202                                 "    </xs:complexContent>{0}" +
203                                 "  </xs:complexType>{0}" +
204                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
205                 }
206
207                 [Test]
208                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
209                 public void ExportClass_ClassArrayContainer ()
210                 {
211                         XmlSchemas schemas = Export (typeof (ClassArrayContainer), "NSClassArrayContainer");
212                         Assert.AreEqual (1, schemas.Count, "#1");
213
214                         StringWriter sw = new StringWriter ();
215                         schemas[0].Write (sw);
216
217                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
218                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
219                                 "<xs:schema xmlns:tns=\"NSClassArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSClassArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
220                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
221                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
222                                 "  <xs:complexType name=\"ClassArrayContainer\">{0}" +
223                                 "    <xs:sequence>{0}" +
224                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"items\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
225  "    </xs:sequence>{0}" +
226                                 "  </xs:complexType>{0}" +
227                                 "  <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
228                                 "    <xs:complexContent mixed=\"false\">{0}" +
229                                 "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
230                                 "        <xs:attribute d5p1:arrayType=\"tns:SimpleClass[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
231                                 "      </xs:restriction>{0}" +
232                                 "    </xs:complexContent>{0}" +
233                                 "  </xs:complexType>{0}" +
234                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
235                                 "    <xs:sequence>{0}" +
236                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"something\" type=\"xs:string\" />{0}" +
237                                 "    </xs:sequence>{0}" +
238                                 "  </xs:complexType>{0}" +
239                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
240                 }
241
242                 [Test]
243                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
244                 public void ExportClass_SimpleClassWithXmlAttributes ()
245                 {
246                         XmlSchemas schemas = Export (typeof (SimpleClassWithXmlAttributes), "NSSimpleClassWithXmlAttributes");
247                         Assert.AreEqual (1, schemas.Count, "#1");
248
249                         StringWriter sw = new StringWriter ();
250                         schemas[0].Write (sw);
251
252                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
253                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
254                                 "<xs:schema xmlns:tns=\"NSSimpleClassWithXmlAttributes\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassWithXmlAttributes\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
255                                 "  <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
256                                 "    <xs:sequence>{0}" +
257                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"something\" type=\"xs:string\" />{0}" +
258                                 "    </xs:sequence>{0}" +
259                                 "  </xs:complexType>{0}" +
260                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
261                 }
262
263                 [Test]
264                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
265                 public void ExportClass_Field ()
266                 {
267                         XmlSchemas schemas = Export (typeof (Field), "NSField");
268                         Assert.AreEqual (1, schemas.Count, "#1");
269
270                         StringWriter sw = new StringWriter ();
271                         schemas[0].Write (sw);
272
273                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
274                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
275                                 "<xs:schema xmlns:tns=\"NSField\" elementFormDefault=\"qualified\" targetNamespace=\"NSField\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
276                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
277                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
278                                 "  <xs:complexType name=\"Field\">{0}" +
279                                 "    <xs:sequence>{0}" +
280                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Flags1\" type=\"tns:FlagEnum\" />{0}" +
281                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Flags2\" type=\"tns:FlagEnum\" />{0}" +
282                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Flags3\" type=\"tns:FlagEnum\" />{0}" +
283                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Flags4\" type=\"tns:FlagEnum\" />{0}" +
284                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers\" type=\"tns:MapModifiers\" />{0}" +
285                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers2\" type=\"tns:MapModifiers\" />{0}" +
286                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers3\" type=\"tns:MapModifiers\" />{0}" +
287                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers4\" type=\"tns:MapModifiers\" />{0}" +
288                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers5\" type=\"tns:MapModifiers\" />{0}" +
289                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Names\" type=\"tns:ArrayOfString\" />{0}" +
290                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Street\" type=\"xs:string\" />{0}" +
291                                 "    </xs:sequence>{0}" +
292                                 "  </xs:complexType>{0}" +
293                                 "  <xs:simpleType name=\"FlagEnum\">{0}" +
294                                 "    <xs:list>{0}" +
295                                 "      <xs:simpleType>{0}" +
296                                 "        <xs:restriction base=\"xs:string\">{0}" +
297                                 "          <xs:enumeration value=\"e1\" />{0}" +
298                                 "          <xs:enumeration value=\"e2\" />{0}" +
299                                 "          <xs:enumeration value=\"e4\" />{0}" +
300                                 "        </xs:restriction>{0}" +
301                                 "      </xs:simpleType>{0}" +
302                                 "    </xs:list>{0}" +
303                                 "  </xs:simpleType>{0}" +
304                                 "  <xs:simpleType name=\"MapModifiers\">{0}" +
305                                 "    <xs:list>{0}" +
306                                 "      <xs:simpleType>{0}" +
307                                 "        <xs:restriction base=\"xs:string\">{0}" +
308                                 "          <xs:enumeration value=\"Public\" />{0}" +
309                                 "          <xs:enumeration value=\"Protected\" />{0}" +
310                                 "        </xs:restriction>{0}" +
311                                 "      </xs:simpleType>{0}" +
312                                 "    </xs:list>{0}" +
313                                 "  </xs:simpleType>{0}" +
314                                 "  <xs:complexType name=\"ArrayOfString\">{0}" +
315                                 "    <xs:complexContent mixed=\"false\">{0}" +
316                                 "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
317                                 "        <xs:attribute d5p1:arrayType=\"xs:string[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
318                                 "      </xs:restriction>{0}" +
319                                 "    </xs:complexContent>{0}" +
320                                 "  </xs:complexType>{0}" +
321                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
322                 }
323
324                 [Test]
325                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
326                 public void ExportClass_MyList ()
327                 {
328                         XmlSchemas schemas = Export (typeof (MyList), "NSMyList");
329                         Assert.AreEqual (1, schemas.Count, "#1");
330
331                         StringWriter sw = new StringWriter ();
332                         schemas[0].Write (sw);
333
334                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
335                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
336                                 "<xs:schema xmlns:tns=\"NSMyList\" elementFormDefault=\"qualified\" targetNamespace=\"NSMyList\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
337                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
338                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
339                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
340                                 "    <xs:complexContent mixed=\"false\">{0}" +
341                                 "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
342                                 "        <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
343                                 "      </xs:restriction>{0}" +
344                                 "    </xs:complexContent>{0}" +
345                                 "  </xs:complexType>{0}" +
346                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
347                 }
348
349                 [Test]
350                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
351                 public void ExportClass_Container ()
352                 {
353                         XmlSchemas schemas = Export (typeof (Container), "NSContainer");
354                         Assert.AreEqual (1, schemas.Count, "#1");
355
356                         StringWriter sw = new StringWriter ();
357                         schemas[0].Write (sw);
358
359                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
360                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
361                                 "<xs:schema xmlns:tns=\"NSContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
362                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
363                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
364                                 "  <xs:complexType name=\"Container\">{0}" +
365                                 "    <xs:sequence>{0}" +
366                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
367                                 "    </xs:sequence>{0}" +
368                                 "  </xs:complexType>{0}" +
369                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
370                                 "    <xs:complexContent mixed=\"false\">{0}" +
371                                 "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
372                                 "        <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
373                                 "      </xs:restriction>{0}" +
374                                 "    </xs:complexContent>{0}" +
375                                 "  </xs:complexType>{0}" +
376                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
377                 }
378
379                 [Test]
380                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
381                 public void ExportClass_Container2 ()
382                 {
383                         XmlSchemas schemas = Export (typeof (Container2), "NSContainer2");
384                         Assert.AreEqual (1, schemas.Count, "#1");
385
386                         StringWriter sw = new StringWriter ();
387                         schemas[0].Write (sw);
388
389                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
390                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
391                                 "<xs:schema xmlns:tns=\"NSContainer2\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
392                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
393                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
394                                 "  <xs:complexType name=\"Container2\">{0}" +
395                                 "    <xs:sequence>{0}" +
396                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
397                                 "    </xs:sequence>{0}" +
398                                 "  </xs:complexType>{0}" +
399                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
400                                 "    <xs:complexContent mixed=\"false\">{0}" +
401                                 "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
402                                 "        <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
403                                 "      </xs:restriction>{0}" +
404                                 "    </xs:complexContent>{0}" +
405                                 "  </xs:complexType>{0}" +
406                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
407                 }
408
409                 [Test]
410                 [ExpectedException (typeof (NotSupportedException))]
411                 public void ExportClass_MyElem ()
412                 {
413                         Export (typeof (MyElem), "NSMyElem");
414                 }
415
416                 [Test]
417                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
418                 [ExpectedException (typeof (NotSupportedException))] // The type System.Xml.XmlCDataSection may not be serialized with SOAP-encoded messages.
419                 public void ExportClass_CDataContainer ()
420                 {
421                         Export (typeof (CDataContainer), "NSCDataContainer");
422                 }
423
424                 [Test]
425                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
426                 [ExpectedException (typeof (NotSupportedException))] // The type System.Xml.XmlCDataSection may not be serialized with SOAP-encoded messages.
427                 public void ExportClass_NodeContainer ()
428                 {
429                         Export (typeof (NodeContainer), "NSNodeContainer");
430                 }
431
432                 [Test]
433                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
434                 public void ExportClass_Choices ()
435                 {
436                         XmlSchemas schemas = Export (typeof (Choices), "NSChoices");
437                         Assert.AreEqual (1, schemas.Count, "#1");
438
439                         StringWriter sw = new StringWriter ();
440                         schemas[0].Write (sw);
441
442                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
443                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
444                                 "<xs:schema xmlns:tns=\"NSChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
445                                 "  <xs:complexType name=\"Choices\">{0}" +
446                                 "    <xs:sequence>{0}" +
447                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"MyChoice\" type=\"xs:string\" />{0}" +
448                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"ItemType\" type=\"tns:ItemChoiceType\" />{0}" +
449                                 "    </xs:sequence>{0}" +
450                                 "  </xs:complexType>{0}" +
451                                 "  <xs:simpleType name=\"ItemChoiceType\">{0}" +
452                                 "    <xs:restriction base=\"xs:string\">{0}" +
453                                 "      <xs:enumeration value=\"ChoiceZero\" />{0}" +
454                                 "      <xs:enumeration value=\"StrangeOne\" />{0}" +
455                                 "      <xs:enumeration value=\"ChoiceTwo\" />{0}" +
456                                 "    </xs:restriction>{0}" +
457                                 "  </xs:simpleType>{0}" +
458                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
459                 }
460
461                 [Test]
462                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
463                 public void ExportClass_WrongChoices ()
464                 {
465                         XmlSchemas schemas = Export (typeof (WrongChoices), "NSWrongChoices");
466                         Assert.AreEqual (1, schemas.Count, "#1");
467
468                         StringWriter sw = new StringWriter ();
469                         schemas[0].Write (sw);
470
471                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
472                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
473                                 "<xs:schema xmlns:tns=\"NSWrongChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSWrongChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
474                                 "  <xs:complexType name=\"WrongChoices\">{0}" +
475                                 "    <xs:sequence>{0}" +
476                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"MyChoice\" type=\"xs:string\" />{0}" +
477                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"ItemType\" type=\"tns:ItemChoiceType\" />{0}" +
478                                 "    </xs:sequence>{0}" +
479                                 "  </xs:complexType>{0}" +
480                                 "  <xs:simpleType name=\"ItemChoiceType\">{0}" +
481                                 "    <xs:restriction base=\"xs:string\">{0}" +
482                                 "      <xs:enumeration value=\"ChoiceZero\" />{0}" +
483                                 "      <xs:enumeration value=\"StrangeOne\" />{0}" +
484                                 "      <xs:enumeration value=\"ChoiceTwo\" />{0}" +
485                                 "    </xs:restriction>{0}" +
486                                 "  </xs:simpleType>{0}" +
487                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
488                 }
489
490                 [Test]
491                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
492                 public void ExportClass_TestSpace ()
493                 {
494                         XmlSchemas schemas = Export (typeof (TestSpace), "NSTestSpace");
495                         Assert.AreEqual (1, schemas.Count, "#1");
496
497                         StringWriter sw = new StringWriter ();
498                         schemas[0].Write (sw);
499
500                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
501                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
502                                 "<xs:schema xmlns:tns=\"NSTestSpace\" elementFormDefault=\"qualified\" targetNamespace=\"NSTestSpace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
503                                 "  <xs:complexType name=\"TestSpace\">{0}" +
504                                 "    <xs:sequence>{0}" +
505                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"elem\" type=\"xs:int\" />{0}" +
506                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"attr\" type=\"xs:int\" />{0}" +
507                                 "    </xs:sequence>{0}" +
508                                 "  </xs:complexType>{0}" +
509                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
510                 }
511
512                 [Test]
513                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
514                 public void ExportClass_ReadOnlyProperties ()
515                 {
516                         XmlSchemas schemas = Export (typeof (ReadOnlyProperties), "NSReadOnlyProperties");
517                         Assert.AreEqual (1, schemas.Count, "#1");
518
519                         StringWriter sw = new StringWriter ();
520                         schemas[0].Write (sw);
521
522                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
523                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
524                                 "<xs:schema xmlns:tns=\"NSReadOnlyProperties\" elementFormDefault=\"qualified\" targetNamespace=\"NSReadOnlyProperties\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
525                                 "  <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
526                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
527                 }
528
529                 [Test]
530                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
531                 public void ExportClass_ListDefaults ()
532                 {
533                         XmlSchemas schemas = Export (typeof (ListDefaults), "NSListDefaults");
534                         Assert.AreEqual (1, schemas.Count, "#1");
535
536                         StringWriter sw = new StringWriter ();
537                         schemas[0].Write (sw);
538
539                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
540                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
541                                 "<xs:schema xmlns:tns=\"NSListDefaults\" elementFormDefault=\"qualified\" targetNamespace=\"NSListDefaults\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
542                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
543                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
544                                 "  <xs:complexType name=\"ListDefaults\">{0}" +
545                                 "    <xs:sequence>{0}" +
546                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list2\" type=\"tns:ArrayOfAnyType\" />{0}" +
547                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list3\" type=\"tns:ArrayOfAnyType\" />{0}" +
548                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list4\" type=\"tns:ArrayOfString\" />{0}" +
549                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list5\" type=\"tns:ArrayOfAnyType\" />{0}" +
550                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"ed\" type=\"tns:SimpleClass\" />{0}" +
551                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"str\" type=\"xs:string\" />{0}" +
552                                 "    </xs:sequence>{0}" +
553                                 "  </xs:complexType>{0}" +
554                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
555                                 "    <xs:complexContent mixed=\"false\">{0}" +
556                                 "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
557                                 "        <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
558                                 "      </xs:restriction>{0}" +
559                                 "    </xs:complexContent>{0}" +
560                                 "  </xs:complexType>{0}" +
561                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
562                                 "    <xs:sequence>{0}" +
563                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"something\" type=\"xs:string\" />{0}" +
564                                 "    </xs:sequence>{0}" +
565                                 "  </xs:complexType>{0}" +
566                                 "  <xs:complexType name=\"ArrayOfString\">{0}" +
567                                 "    <xs:complexContent mixed=\"false\">{0}" +
568                                 "      <xs:restriction xmlns:q2=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q2:Array\">{0}" +
569                                 "        <xs:attribute d5p1:arrayType=\"xs:string[]\" ref=\"q2:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
570                                 "      </xs:restriction>{0}" +
571                                 "    </xs:complexContent>{0}" +
572                                 "  </xs:complexType>{0}" +
573                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
574                 }
575
576                 [Test]
577                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
578                 public void ExportClass_ClsPerson ()
579                 {
580                         XmlSchemas schemas = Export (typeof (clsPerson), "NSClsPerson");
581                         Assert.AreEqual (1, schemas.Count, "#1");
582
583                         StringWriter sw = new StringWriter ();
584                         schemas[0].Write (sw);
585
586                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
587                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
588                                 "<xs:schema xmlns:tns=\"NSClsPerson\" elementFormDefault=\"qualified\" targetNamespace=\"NSClsPerson\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
589  "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
590                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
591                                 "  <xs:complexType name=\"clsPerson\">{0}" +
592                                 "    <xs:sequence>{0}" +
593                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"EmailAccounts\" type=\"tns:ArrayOfAnyType\" />{0}" +
594  "    </xs:sequence>{0}" +
595                                 "  </xs:complexType>{0}" +
596                                 "  <xs:complexType name=\"ArrayOfAnyType\">{0}" +
597                                 "    <xs:complexContent mixed=\"false\">{0}" +
598                                 "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
599                                 "        <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
600                                 "      </xs:restriction>{0}" +
601                                 "    </xs:complexContent>{0}" +
602                                 "  </xs:complexType>{0}" +
603                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
604                 }
605
606                 [Test]
607                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
608                 public void ExportClass_ArrayClass ()
609                 {
610                         XmlSchemas schemas = Export (typeof (ArrayClass), "NSArrayClass");
611                         Assert.AreEqual (1, schemas.Count, "#1");
612
613                         StringWriter sw = new StringWriter ();
614                         schemas[0].Write (sw);
615
616                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
617                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
618                                 "<xs:schema xmlns:tns=\"NSArrayClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
619                                 "  <xs:complexType name=\"ArrayClass\">{0}" +
620                                 "    <xs:sequence>{0}" +
621                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"names\" type=\"xs:anyType\" />{0}" +
622                                 "    </xs:sequence>{0}" +
623                                 "  </xs:complexType>{0}" +
624                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
625                 }
626
627                 [Test]
628                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
629                 public void ExportClass_StructContainer ()
630                 {
631                         XmlSchemas schemas = Export (typeof (StructContainer), "NSStructContainer");
632                         Assert.AreEqual (1, schemas.Count, "#1");
633
634                         StringWriter sw = new StringWriter ();
635                         schemas[0].Write (sw);
636
637                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
638                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
639                                 "<xs:schema xmlns:tns=\"NSStructContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStructContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
640                                 "  <xs:complexType name=\"StructContainer\">{0}" +
641                                 "    <xs:sequence>{0}" +
642                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Value\" type=\"tns:EnumDefaultValue\" />{0}" +
643                                 "    </xs:sequence>{0}" +
644                                 "  </xs:complexType>{0}" +
645                                 "  <xs:simpleType name=\"EnumDefaultValue\">{0}" +
646                                 "    <xs:list>{0}" +
647                                 "      <xs:simpleType>{0}" +
648                                 "        <xs:restriction base=\"xs:string\">{0}" +
649                                 "          <xs:enumeration value=\"e1\" />{0}" +
650                                 "          <xs:enumeration value=\"e2\" />{0}" +
651                                 "          <xs:enumeration value=\"e3\" />{0}" +
652                                 "        </xs:restriction>{0}" +
653                                 "      </xs:simpleType>{0}" +
654                                 "    </xs:list>{0}" +
655                                 "  </xs:simpleType>{0}" +
656                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
657                 }
658
659                 [Test]
660                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
661 /*
662 #if NET_2_0
663                 [Category ("NotWorking")] // minOccurs is 1 on Mono
664 #endif
665  */
666                 public void ExportClass_SimpleClass_Array ()
667                 {
668                         SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
669                         SoapAttributes attr = new SoapAttributes ();
670                         SoapElementAttribute element = new SoapElementAttribute ();
671                         element.ElementName = "saying";
672                         element.IsNullable = true;
673                         attr.SoapElement = element;
674                         overrides.Add (typeof (SimpleClass), "something", attr);
675
676                         SoapReflectionImporter ri = new SoapReflectionImporter (overrides, "NSSimpleClassArray");
677                         XmlSchemas schemas = new XmlSchemas ();
678                         SoapSchemaExporter sx = new SoapSchemaExporter (schemas);
679                         XmlTypeMapping tm = ri.ImportTypeMapping (typeof (SimpleClass[]));
680                         sx.ExportTypeMapping (tm);
681
682                         Assert.AreEqual (1, schemas.Count, "#1");
683
684                         StringWriter sw = new StringWriter ();
685                         schemas[0].Write (sw);
686
687                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
688                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
689                                 "<xs:schema xmlns:tns=\"NSSimpleClassArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
690                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
691                                 "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
692                                 "  <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
693                                 "    <xs:complexContent mixed=\"false\">{0}" +
694                                 "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
695                                 "        <xs:attribute d5p1:arrayType=\"tns:SimpleClass[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
696                                 "      </xs:restriction>{0}" +
697                                 "    </xs:complexContent>{0}" +
698                                 "  </xs:complexType>{0}" +
699                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
700                                 "    <xs:sequence>{0}" +
701                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
702                                 "    </xs:sequence>{0}" +
703                                 "  </xs:complexType>{0}" +
704                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
705                 }
706
707                 [Test]
708                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
709                 public void ExportEnum ()
710                 {
711                         XmlSchemas schemas = Export (typeof (EnumDefaultValue), "NSEnumDefaultValue");
712                         Assert.AreEqual (1, schemas.Count, "#1");
713
714                         StringWriter sw = new StringWriter ();
715                         schemas[0].Write (sw);
716
717                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
718                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
719                                 "<xs:schema xmlns:tns=\"NSEnumDefaultValue\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValue\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
720                                 "  <xs:simpleType name=\"EnumDefaultValue\">{0}" +
721                                 "    <xs:list>{0}" +
722                                 "      <xs:simpleType>{0}" +
723                                 "        <xs:restriction base=\"xs:string\">{0}" +
724                                 "          <xs:enumeration value=\"e1\" />{0}" +
725                                 "          <xs:enumeration value=\"e2\" />{0}" +
726                                 "          <xs:enumeration value=\"e3\" />{0}" +
727                                 "        </xs:restriction>{0}" +
728                                 "      </xs:simpleType>{0}" +
729                                 "    </xs:list>{0}" +
730                                 "  </xs:simpleType>{0}" +
731                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
732
733                         schemas = Export (typeof (EnumDefaultValueNF), "NSEnumDefaultValueNF");
734                         Assert.AreEqual (1, schemas.Count, "#3");
735
736                         sw = new StringWriter ();
737                         schemas[0].Write (sw);
738
739                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
740                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
741                                 "<xs:schema xmlns:tns=\"NSEnumDefaultValueNF\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValueNF\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
742                                 "  <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
743                                 "    <xs:restriction base=\"xs:string\">{0}" +
744                                 "      <xs:enumeration value=\"e1\" />{0}" +
745                                 "      <xs:enumeration value=\"e2\" />{0}" +
746                                 "      <xs:enumeration value=\"e3\" />{0}" +
747                                 "    </xs:restriction>{0}" +
748                                 "  </xs:simpleType>{0}" +
749                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
750                 }
751
752                 [Test]
753                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
754                 public void ExportXsdPrimitive ()
755                 {
756                         ArrayList types = new ArrayList ();
757                         types.Add (new TypeDescription (typeof (object), true, "anyType", "Object"));
758                         types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte"));
759                         types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte"));
760                         types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean"));
761                         types.Add (new TypeDescription (typeof (short), true, "short", "Short"));
762                         types.Add (new TypeDescription (typeof (int), true, "int", "Int"));
763                         types.Add (new TypeDescription (typeof (long), true, "long", "Long"));
764                         types.Add (new TypeDescription (typeof (float), true, "float", "Float"));
765                         types.Add (new TypeDescription (typeof (double), true, "double", "Double"));
766                         types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal"));
767                         types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort"));
768                         types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt"));
769                         types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong"));
770                         types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime"));
771                         types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true));
772                         types.Add (new TypeDescription (typeof (string), true, "string", "String", true));
773
774                         foreach (TypeDescription typeDesc in types) {
775                                 XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
776                                 Assert.AreEqual (0, schemas.Count, typeDesc.Type.FullName + "#1");
777                         }
778                 }
779
780                 [Test]
781                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
782                 public void ExportXsdPrimitive_ByteArray ()
783                 {
784                         XmlSchemas schemas = Export (typeof (byte[]), "ByteArray");
785                         Assert.AreEqual (0, schemas.Count, "#1");
786                 }
787
788                 [Test]
789                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
790                 public void ExportXsdPrimitive_Arrays ()
791                 {
792                         ArrayList types = new ArrayList ();
793                         types.Add (new TypeDescription (typeof (object[]), true, "anyType", "AnyType"));
794                         types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte"));
795                         types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean"));
796                         types.Add (new TypeDescription (typeof (short[]), true, "short", "Short"));
797                         types.Add (new TypeDescription (typeof (int[]), true, "int", "Int"));
798                         types.Add (new TypeDescription (typeof (long[]), true, "long", "Long"));
799                         types.Add (new TypeDescription (typeof (float[]), true, "float", "Float"));
800                         types.Add (new TypeDescription (typeof (double[]), true, "double", "Double"));
801                         types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal"));
802                         types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort"));
803                         types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt"));
804                         types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong"));
805                         types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime"));
806                         types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true));
807                         types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true));
808
809                         foreach (TypeDescription typeDesc in types) {
810                                 XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
811                                 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
812
813                                 StringWriter sw = new StringWriter ();
814                                 schemas[0].Write (sw);
815
816                                 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
817                                         "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
818                                         "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
819                                         "  <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
820                                         "  <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
821                                         "  <xs:complexType name=\"ArrayOf{2}\">{0}" +
822                                         "    <xs:complexContent mixed=\"false\">{0}" +
823                                         "      <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
824                                         "        <xs:attribute d5p1:arrayType=\"xs:{3}[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
825                                         "      </xs:restriction>{0}" +
826                                         "    </xs:complexContent>{0}" +
827                                         "  </xs:complexType>{0}" +
828                                         "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType, 
829                                         typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
830                                         sw.ToString (), typeDesc.Type.FullName + "#2");
831                         }
832                 }
833
834                 [Test]
835                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
836                 public void ExportNonXsdPrimitive_Guid ()
837                 {
838                         XmlSchemas schemas = Export (typeof (Guid), "NSPrimGuid");
839                         Assert.AreEqual (1, schemas.Count, "#1");
840
841                         StringWriter sw = new StringWriter ();
842                         schemas[0].Write (sw);
843
844                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
845                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
846                                 "<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}" +
847                                 "  <xs:simpleType name=\"guid\">{0}" +
848                                 "    <xs:restriction base=\"xs:string\">{0}" +
849                                 "      <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}" +
850                                 "    </xs:restriction>{0}" +
851                                 "  </xs:simpleType>{0}" +
852                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
853                 }
854
855                 [Test]
856                 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
857                 public void ExportNonXsdPrimitive_Char ()
858                 {
859                         XmlSchemas schemas = Export (typeof (Char), "NSPrimChar");
860                         Assert.AreEqual (1, schemas.Count, "#1");
861
862                         StringWriter sw = new StringWriter ();
863                         schemas[0].Write (sw);
864
865                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
866                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
867                                 "<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}" +
868                                 "  <xs:simpleType name=\"char\">{0}" +
869                                 "    <xs:restriction base=\"xs:unsignedShort\" />{0}" +
870                                 "  </xs:simpleType>{0}" +
871                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
872                 }
873
874                 public class Employee : IXmlSerializable
875                 {
876                         private string _firstName;
877                         private string _lastName;
878                         private string _address;
879
880                         public XmlSchema GetSchema ()
881                         {
882                                 return null;
883                         }
884
885                         public void WriteXml (XmlWriter writer)
886                         {
887                                 writer.WriteStartElement ("employee", "urn:devx-com");
888                                 writer.WriteAttributeString ("firstName", _firstName);
889                                 writer.WriteAttributeString ("lastName", _lastName);
890                                 writer.WriteAttributeString ("address", _address);
891                                 writer.WriteEndElement ();
892                         }
893
894                         public void ReadXml (XmlReader reader)
895                         {
896                                 XmlNodeType type = reader.MoveToContent ();
897                                 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
898                                         _firstName = reader["firstName"];
899                                         _lastName = reader["lastName"];
900                                         _address = reader["address"];
901                                 }
902                         }
903                 }
904
905                 public class StructContainer
906                 {
907                         public EnumDefaultValue Value;
908                 }
909
910                 private class TypeDescription
911                 {
912                         public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType)
913                                 : this (type, xsdType, xmlType, arrayType, false)
914                         {
915                         }
916
917                         public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable)
918                         {
919                                 _type = type;
920                                 _xsdType = xsdType;
921                                 _xmlType = xmlType;
922                                 _arrayType = arrayType;
923                                 _isNillable = isNillable;
924                         }
925
926                         public Type Type
927                         {
928                                 get { return _type; }
929                         }
930
931                         public string XmlType
932                         {
933                                 get { return _xmlType; }
934                         }
935
936                         public string ArrayType
937                         {
938                                 get { return _arrayType; }
939                         }
940
941                         public bool XsdType
942                         {
943                                 get { return _xsdType; }
944                         }
945
946                         public bool IsNillable
947                         {
948                                 get { return _isNillable; }
949                         }
950
951                         private Type _type;
952                         private bool _xsdType;
953                         private string _xmlType;
954                         private string _arrayType;
955                         private bool _isNillable;
956                 }
957         }
958 }
959
960 #endif