* XmlSchemaExporterTests.cs: Added tests for exporting structs, and
[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                 [Test]
28                 [Category ("NotWorking")] // on Mono, element is output before type
29                 public void ExportStruct ()
30                 {
31                         XmlReflectionImporter ri = new XmlReflectionImporter ("NSTimeSpan");
32                         XmlSchemas schemas = new XmlSchemas ();
33                         XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
34                         XmlTypeMapping tm = ri.ImportTypeMapping (typeof (TimeSpan));
35                         sx.ExportTypeMapping (tm);
36
37                         Assert.AreEqual (1, schemas.Count, "#1");
38
39                         StringWriter sw = new StringWriter ();
40                         schemas[0].Write (sw);
41
42                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
43                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
44                                 "<xs:schema xmlns:tns=\"NSTimeSpan\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpan\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
45                                 "  <xs:element name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
46                                 "  <xs:complexType name=\"TimeSpan\" />{0}" +
47                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
48                 }
49
50                 [Test]
51                 [Category ("NotWorking")] // on Mono, element is output before type
52                 public void ExportStruct_Array ()
53                 {
54                         XmlReflectionImporter ri = new XmlReflectionImporter ("NSTimeSpanArray");
55                         XmlSchemas schemas = new XmlSchemas ();
56                         XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
57                         XmlTypeMapping tm = ri.ImportTypeMapping (typeof (TimeSpan[]));
58                         sx.ExportTypeMapping (tm);
59
60                         Assert.AreEqual (1, schemas.Count, "#1");
61
62                         StringWriter sw = new StringWriter ();
63                         schemas[0].Write (sw);
64
65                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
66                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
67                                 "<xs:schema xmlns:tns=\"NSTimeSpanArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpanArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
68                                 "  <xs:element name=\"ArrayOfTimeSpan\" nillable=\"true\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
69                                 "  <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
70                                 "    <xs:sequence>{0}" +
71                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
72                                 "    </xs:sequence>{0}" +
73                                 "  </xs:complexType>{0}" +
74                                 "  <xs:complexType name=\"TimeSpan\" />{0}" +
75                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
76                 }
77
78                 [Test]
79                 [Category ("NotWorking")] // on Mono, element is output before type
80                 public void ExportClass ()
81                 {
82                         XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
83                         XmlAttributes attr = new XmlAttributes ();
84                         XmlElementAttribute element = new XmlElementAttribute ();
85                         element.ElementName = "saying";
86                         element.IsNullable = true;
87                         attr.XmlElements.Add (element);
88                         overrides.Add (typeof (SimpleClass), "something", attr);
89
90                         XmlReflectionImporter ri = new XmlReflectionImporter (overrides, "NS1");
91                         XmlSchemas schemas = new XmlSchemas ();
92                         XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
93                         XmlTypeMapping tm = ri.ImportTypeMapping (typeof (SimpleClass));
94                         sx.ExportTypeMapping (tm);
95
96                         Assert.AreEqual (1, schemas.Count, "#1");
97
98                         StringWriter sw = new StringWriter ();
99                         schemas[0].Write (sw);
100
101                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
102                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
103                                 "<xs:schema xmlns:tns=\"NS1\" elementFormDefault=\"qualified\" targetNamespace=\"NS1\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
104                                 "  <xs:element name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
105                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
106                                 "    <xs:sequence>{0}" +
107                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
108                                 "    </xs:sequence>{0}" +
109                                 "  </xs:complexType>{0}" +
110                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
111                 }
112
113                 [Test]
114                 [Category ("NotWorking")] // on Mono, element is output before type
115                 public void ExportClass_Array ()
116                 {
117                         XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
118                         XmlAttributes attr = new XmlAttributes ();
119                         XmlElementAttribute element = new XmlElementAttribute ();
120                         element.ElementName = "saying";
121                         element.IsNullable = true;
122                         attr.XmlElements.Add (element);
123                         overrides.Add (typeof (SimpleClass), "something", attr);
124
125                         XmlReflectionImporter ri = new XmlReflectionImporter (overrides, "NSSimpleClassArray");
126                         XmlSchemas schemas = new XmlSchemas ();
127                         XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
128                         XmlTypeMapping tm = ri.ImportTypeMapping (typeof (SimpleClass[]));
129                         sx.ExportTypeMapping (tm);
130
131                         Assert.AreEqual (1, schemas.Count, "#1");
132
133                         StringWriter sw = new StringWriter ();
134                         schemas[0].Write (sw);
135
136                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
137                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
138                                 "<xs:schema xmlns:tns=\"NSSimpleClassArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
139                                 "  <xs:element name=\"ArrayOfSimpleClass\" nillable=\"true\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
140                                 "  <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
141                                 "    <xs:sequence>{0}" +
142                                 "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
143                                 "    </xs:sequence>{0}" +
144                                 "  </xs:complexType>{0}" +
145                                 "  <xs:complexType name=\"SimpleClass\">{0}" +
146                                 "    <xs:sequence>{0}" +
147                                 "      <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
148                                 "    </xs:sequence>{0}" +
149                                 "  </xs:complexType>{0}" +
150                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
151                 }
152
153                 [Test]
154                 [Category ("NotWorking")] // on Mono, element is output before type
155                 public void ExportEnum ()
156                 {
157                         XmlReflectionImporter ri = new XmlReflectionImporter ("NS2");
158                         XmlSchemas schemas = new XmlSchemas ();
159                         XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
160                         XmlTypeMapping tm = ri.ImportTypeMapping (typeof (EnumDefaultValue));
161                         sx.ExportTypeMapping (tm);
162
163                         Assert.AreEqual (1, schemas.Count, "#1");
164
165                         StringWriter sw = new StringWriter ();
166                         schemas[0].Write (sw);
167
168                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
169                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
170                                 "<xs:schema xmlns:tns=\"NS2\" elementFormDefault=\"qualified\" targetNamespace=\"NS2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
171                                 "  <xs:element name=\"EnumDefaultValue\" type=\"tns:EnumDefaultValue\" />{0}" +
172                                 "  <xs:simpleType name=\"EnumDefaultValue\">{0}" +
173                                 "    <xs:list>{0}" +
174                                 "      <xs:simpleType>{0}" +
175                                 "        <xs:restriction base=\"xs:string\">{0}" +
176                                 "          <xs:enumeration value=\"e1\" />{0}" +
177                                 "          <xs:enumeration value=\"e2\" />{0}" +
178                                 "          <xs:enumeration value=\"e3\" />{0}" +
179                                 "        </xs:restriction>{0}" +
180                                 "      </xs:simpleType>{0}" +
181                                 "    </xs:list>{0}" +
182                                 "  </xs:simpleType>{0}" +
183                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
184                 }
185
186                 [Test]
187                 [Category ("NotWorking")] // on Mono, element is output before type
188                 public void ExportXmlSerializable ()
189                 {
190                         XmlReflectionImporter ri = new XmlReflectionImporter ("NS3");
191                         XmlSchemas schemas = new XmlSchemas ();
192                         XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
193                         XmlTypeMapping tm = ri.ImportTypeMapping (typeof (Employee));
194                         sx.ExportTypeMapping (tm);
195
196                         Assert.AreEqual (1, schemas.Count, "#1");
197
198                         StringWriter sw = new StringWriter ();
199                         schemas[0].Write (sw);
200
201                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
202                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
203                                 "<xs:schema xmlns:tns=\"NS3\" elementFormDefault=\"qualified\" targetNamespace=\"NS3\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
204                                 "  <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
205                                 "  <xs:element name=\"Employee\" nillable=\"true\">{0}" +
206                                 "    <xs:complexType>{0}" +
207                                 "      <xs:sequence>{0}" +
208                                 "        <xs:element ref=\"xs:schema\" />{0}" +
209                                 "        <xs:any />{0}" +
210                                 "      </xs:sequence>{0}" +
211                                 "    </xs:complexType>{0}" +
212                                 "  </xs:element>{0}" +
213                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
214
215                         ri = new XmlReflectionImporter ("NS4");
216
217                         schemas = new XmlSchemas ();
218                         sx = new XmlSchemaExporter (schemas);
219                         tm = ri.ImportTypeMapping (typeof (EmployeeSchema));
220                         sx.ExportTypeMapping (tm);
221
222                         Assert.AreEqual (1, schemas.Count, "#3");
223
224                         sw = new StringWriter ();
225                         schemas[0].Write (sw);
226
227                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
228                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
229                                 "<xs:schema xmlns:tns=\"NS4\" elementFormDefault=\"qualified\" targetNamespace=\"NS4\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
230 #if NET_2_0
231                                 "  <xs:import namespace=\"urn:types-devx-com\" />{0}" +
232                                 "  <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
233 #else
234                                 "  <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
235                                 "  <xs:element name=\"EmployeeSchema\" nillable=\"true\">{0}" +
236                                 "    <xs:complexType>{0}" +
237                                 "      <xs:sequence>{0}" +
238                                 "        <xs:element ref=\"xs:schema\" />{0}" +
239                                 "        <xs:any />{0}" +
240                                 "      </xs:sequence>{0}" +
241                                 "    </xs:complexType>{0}" +
242                                 "  </xs:element>{0}" +
243 #endif
244                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
245                 }
246
247                 [Test]
248                 [Category ("NotWorking")] // bug #77117
249                 public void ExportXsdPrimitive ()
250                 {
251                         ArrayList types = new ArrayList ();
252                         types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte"));
253                         types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte"));
254                         types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean"));
255                         types.Add (new TypeDescription (typeof (short), true, "short", "Short"));
256                         types.Add (new TypeDescription (typeof (int), true, "int", "Int"));
257                         types.Add (new TypeDescription (typeof (long), true, "long", "Long"));
258                         types.Add (new TypeDescription (typeof (float), true, "float", "Float"));
259                         types.Add (new TypeDescription (typeof (double), true, "double", "Double"));
260                         types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal"));
261                         types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort"));
262                         types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt"));
263                         types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong"));
264                         types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime"));
265 #if NET_2_0
266                         types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true));
267 #else
268                         types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName"));
269 #endif
270                         types.Add (new TypeDescription (typeof (string), true, "string", "String", true));
271
272                         foreach (TypeDescription typeDesc in types) {
273                                 XmlReflectionImporter ri = new XmlReflectionImporter (typeDesc.Type.Name);
274                                 XmlSchemas schemas = new XmlSchemas ();
275                                 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
276                                 XmlTypeMapping tm = ri.ImportTypeMapping (typeDesc.Type);
277                                 sx.ExportTypeMapping (tm);
278
279                                 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
280
281                                 StringWriter sw = new StringWriter ();
282                                 schemas[0].Write (sw);
283
284                                 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
285                                         "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
286                                         "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
287                                         "  <xs:element name=\"{2}\" {3}type=\"xs:{2}\" />{0}" +
288                                         "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.XmlType, typeDesc.IsNillable ? "nillable=\"true\" " : ""),
289                                         sw.ToString (), typeDesc.Type.FullName + "#2");
290                         }
291                 }
292
293                 [Test]
294                 [Category ("NotWorking")] // bug #77117
295                 public void ExportXsdPrimitive_ByteArray ()
296                 {
297                         XmlReflectionImporter ri = new XmlReflectionImporter ("ByteArray");
298                         XmlSchemas schemas = new XmlSchemas ();
299                         XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
300                         XmlTypeMapping tm = ri.ImportTypeMapping (typeof (byte[]));
301                         sx.ExportTypeMapping (tm);
302
303                         Assert.AreEqual (1, schemas.Count, "#1");
304
305                         StringWriter sw = new StringWriter ();
306                         schemas[0].Write (sw);
307
308                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
309                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
310                                 "<xs:schema xmlns:tns=\"ByteArray\" elementFormDefault=\"qualified\" targetNamespace=\"ByteArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
311                                 "  <xs:element name=\"base64Binary\" nillable=\"true\" type=\"xs:base64Binary\" />{0}" +
312                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
313                 }
314
315                 [Test]
316                 [Category ("NotWorking")] // bug #77117
317                 public void ExportXsdPrimitive_Arrays ()
318                 {
319                         ArrayList types = new ArrayList ();
320                         types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte"));
321                         types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean"));
322                         types.Add (new TypeDescription (typeof (short[]), true, "short", "Short"));
323                         types.Add (new TypeDescription (typeof (int[]), true, "int", "Int"));
324                         types.Add (new TypeDescription (typeof (long[]), true, "long", "Long"));
325                         types.Add (new TypeDescription (typeof (float[]), true, "float", "Float"));
326                         types.Add (new TypeDescription (typeof (double[]), true, "double", "Double"));
327                         types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal"));
328                         types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort"));
329                         types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt"));
330                         types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong"));
331                         types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime"));
332 #if NET_2_0
333                         types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true));
334 #else
335                         types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName"));
336 #endif
337                         types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true));
338
339                         foreach (TypeDescription typeDesc in types) {
340                                 XmlReflectionImporter ri = new XmlReflectionImporter (typeDesc.Type.Name);
341                                 XmlSchemas schemas = new XmlSchemas ();
342                                 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
343                                 XmlTypeMapping tm = ri.ImportTypeMapping (typeDesc.Type);
344                                 sx.ExportTypeMapping (tm);
345
346                                 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
347
348                                 StringWriter sw = new StringWriter ();
349                                 schemas[0].Write (sw);
350
351                                 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
352                                         "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
353                                         "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
354                                         "  <xs:element name=\"ArrayOf{2}\" nillable=\"true\" type=\"tns:ArrayOf{2}\" />{0}" +
355                                         "  <xs:complexType name=\"ArrayOf{2}\">{0}" +
356                                         "    <xs:sequence>{0}" +
357                                         "      <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{3}\" {5}type=\"{4}:{3}\" />{0}" +
358                                         "    </xs:sequence>{0}" +
359                                         "  </xs:complexType>{0}" +
360                                         "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType, 
361                                         typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
362                                         sw.ToString (), typeDesc.Type.FullName + "#2");
363                         }
364                 }
365
366                 [Test]
367                 [Category ("NotWorking")] // bug #77117
368                 public void ExportNonXsdPrimitive_Guid ()
369                 {
370                         XmlReflectionImporter ri = new XmlReflectionImporter ("NSPrimGuid");
371                         XmlSchemas schemas = new XmlSchemas ();
372                         XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
373                         XmlTypeMapping tm = ri.ImportTypeMapping (typeof (Guid));
374                         sx.ExportTypeMapping (tm);
375
376                         Assert.AreEqual (2, schemas.Count, "#1");
377
378                         StringWriter sw = new StringWriter ();
379                         schemas[0].Write (sw);
380
381                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
382                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
383                                 "<xs:schema xmlns:tns=\"NSPrimGuid\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimGuid\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
384                                 "  <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
385                                 "  <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
386                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
387
388                         sw = new StringWriter ();
389                         schemas[1].Write (sw);
390
391                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
392                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
393                                 "<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}" +
394                                 "  <xs:simpleType name=\"guid\">{0}" +
395                                 "    <xs:restriction base=\"xs:string\">{0}" +
396                                 "      <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}" +
397                                 "    </xs:restriction>{0}" +
398                                 "  </xs:simpleType>{0}" +
399                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
400                 }
401
402                 [Test]
403                 [Category ("NotWorking")] // bug #77117
404                 public void ExportNonXsdPrimitive_Char ()
405                 {
406                         XmlReflectionImporter ri = new XmlReflectionImporter ("NSPrimChar");
407                         XmlSchemas schemas = new XmlSchemas ();
408                         XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
409                         XmlTypeMapping tm = ri.ImportTypeMapping (typeof (Char));
410                         sx.ExportTypeMapping (tm);
411
412                         Assert.AreEqual (2, schemas.Count, "#1");
413
414                         StringWriter sw = new StringWriter ();
415                         schemas[0].Write (sw);
416
417                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
418                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
419                                 "<xs:schema xmlns:tns=\"NSPrimChar\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimChar\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
420                                 "  <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
421                                 "  <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
422                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
423
424                         sw = new StringWriter ();
425                         schemas[1].Write (sw);
426
427                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
428                                 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
429                                 "<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}" +
430                                 "  <xs:simpleType name=\"char\">{0}" +
431                                 "    <xs:restriction base=\"xs:unsignedShort\" />{0}" +
432                                 "  </xs:simpleType>{0}" +
433                                 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
434                 }
435
436                 public class Employee : IXmlSerializable
437                 {
438                         private string _firstName;
439                         private string _lastName;
440                         private string _address;
441
442                         public XmlSchema GetSchema ()
443                         {
444                                 return null;
445                         }
446
447                         public void WriteXml (XmlWriter writer)
448                         {
449                                 writer.WriteStartElement ("employee", "urn:devx-com");
450                                 writer.WriteAttributeString ("firstName", _firstName);
451                                 writer.WriteAttributeString ("lastName", _lastName);
452                                 writer.WriteAttributeString ("address", _address);
453                                 writer.WriteEndElement ();
454                         }
455
456                         public void ReadXml (XmlReader reader)
457                         {
458                                 XmlNodeType type = reader.MoveToContent ();
459                                 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
460                                         _firstName = reader["firstName"];
461                                         _lastName = reader["lastName"];
462                                         _address = reader["address"];
463                                 }
464                         }
465                 }
466
467 #if NET_2_0
468                 [XmlSchemaProvider ("CreateEmployeeSchema")]
469 #endif
470                 public class EmployeeSchema : Employee
471                 {
472 #if NET_2_0
473                         public static XmlQualifiedName CreateEmployeeSchema (XmlSchemaSet schemaSet)
474                         {
475                                 XmlSchema schema = new XmlSchema();
476                                 schema.Id = "EmployeeSchema";
477                                 schema.TargetNamespace = "urn:types-devx-com";
478                         
479                                 XmlSchemaComplexType type = new XmlSchemaComplexType();
480                                 type.Name = "employeeRoot";
481                                 XmlSchemaAttribute firstNameAttr = new XmlSchemaAttribute();
482                                 firstNameAttr.Name = "firstName";
483                                 type.Attributes.Add(firstNameAttr);
484
485                                 XmlSchemaAttribute lastNameAttr = new XmlSchemaAttribute();
486                                 lastNameAttr.Name = "lastName";
487                                 type.Attributes.Add(lastNameAttr);
488
489                                 XmlSchemaAttribute addressAttr = new XmlSchemaAttribute();
490                                 addressAttr.Name = "address";
491                                 type.Attributes.Add(addressAttr);
492
493                                 XmlSchemaElement employeeElement = new XmlSchemaElement();
494                                 employeeElement.Name = "employee";
495                                 XmlQualifiedName name = new XmlQualifiedName("employeeRoot", "urn:types-devx-com");
496                                 employeeElement.SchemaTypeName = name;
497
498                                 schema.Items.Add(type);
499                                 schema.Items.Add(employeeElement);
500                                 schemaSet.Add(schema);
501                                 return name;
502                         }
503 #endif
504                 }
505
506                 private class TypeDescription
507                 {
508                         public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType) : this (type, xsdType, xmlType, arrayType, false)
509                         {
510                         }
511
512                         public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable)
513                         {
514                                 _type = type;
515                                 _xsdType = xsdType;
516                                 _xmlType = xmlType;
517                                 _arrayType = arrayType;
518                                 _isNillable = isNillable;
519                         }
520
521                         public Type Type {
522                                 get { return _type; }
523                         }
524
525                         public string XmlType {
526                                 get { return _xmlType; }
527                         }
528
529                         public string ArrayType {
530                                 get { return _arrayType; }
531                         }
532
533                         public bool XsdType {
534                                 get { return _xsdType; }
535                         }
536
537                         public bool IsNillable {
538                                 get { return _isNillable; }
539                         }
540
541                         private Type _type;
542                         private bool _xsdType;
543                         private string _xmlType;
544                         private string _arrayType;
545                         private bool _isNillable;
546                 }
547         }
548 }