2 // System.Xml.Serialization.XmlSchemaExporterTests
5 // Gert Driesen (drieseng@users.sourceforge.net)
11 using System.Collections;
12 using System.Globalization;
15 using System.Xml.Schema;
16 using System.Xml.Serialization;
18 using NUnit.Framework;
20 using MonoTests.System.Xml.TestClasses;
22 namespace MonoTests.System.XmlSerialization
25 public class XmlSchemaExporterTests
27 private XmlSchemas Export (Type type)
29 return Export (type, string.Empty);
32 private XmlSchemas Export (Type type, string defaultNamespace)
34 XmlReflectionImporter ri = new XmlReflectionImporter (defaultNamespace);
35 XmlSchemas schemas = new XmlSchemas ();
36 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
37 XmlTypeMapping tm = ri.ImportTypeMapping (type);
38 sx.ExportTypeMapping (tm);
42 private XmlSchemas Export (Type type, XmlAttributeOverrides overrides)
44 return Export (type, overrides, string.Empty);
47 private XmlSchemas Export (Type type, XmlAttributeOverrides overrides, string defaultNamespace)
49 XmlReflectionImporter ri = new XmlReflectionImporter (overrides, defaultNamespace);
50 XmlSchemas schemas = new XmlSchemas ();
51 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
52 XmlTypeMapping tm = ri.ImportTypeMapping (type);
53 sx.ExportTypeMapping (tm);
58 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
59 public void ExportStruct ()
61 XmlSchemas schemas = Export (typeof (TimeSpan), "NSTimeSpan");
62 Assert.AreEqual (1, schemas.Count, "#1");
64 StringWriter sw = new StringWriter ();
65 schemas[0].Write (sw);
67 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
68 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
69 "<xs:schema xmlns:tns=\"NSTimeSpan\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpan\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
70 " <xs:element name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
71 " <xs:complexType name=\"TimeSpan\" />{0}" +
72 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
74 schemas = Export (typeof (TimeSpan));
75 Assert.AreEqual (1, schemas.Count, "#3");
77 sw.GetStringBuilder ().Length = 0;
78 schemas[0].Write (sw);
80 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
81 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
82 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
83 " <xs:element name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
84 " <xs:complexType name=\"TimeSpan\" />{0}" +
85 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
89 [Category ("NotDotNet")] // Mono bug ##77117
90 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
91 public void ExportStruct_Array ()
93 XmlSchemas schemas = Export (typeof (TimeSpan[]), "NSTimeSpanArray");
94 Assert.AreEqual (1, schemas.Count, "#1");
96 StringWriter sw = new StringWriter ();
97 schemas[0].Write (sw);
99 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
100 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
101 "<xs:schema xmlns:tns=\"NSTimeSpanArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpanArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
102 " <xs:element name=\"ArrayOfTimeSpan\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
103 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
104 " <xs:sequence>{0}" +
105 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"tns:TimeSpan\" />{0}" +
106 " </xs:sequence>{0}" +
107 " </xs:complexType>{0}" +
108 " <xs:complexType name=\"TimeSpan\" />{0}" +
109 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
111 schemas = Export (typeof (TimeSpan[]));
112 Assert.AreEqual (1, schemas.Count, "#3");
114 sw.GetStringBuilder ().Length = 0;
115 schemas[0].Write (sw);
117 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
118 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
119 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
120 " <xs:element name=\"ArrayOfTimeSpan\" type=\"ArrayOfTimeSpan\" />{0}" +
121 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
122 " <xs:sequence>{0}" +
123 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"TimeSpan\" />{0}" +
124 " </xs:sequence>{0}" +
125 " </xs:complexType>{0}" +
126 " <xs:complexType name=\"TimeSpan\" />{0}" +
127 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
131 [Category ("NotDotNet")] // Mono bug ##77117
132 public void ExportClass_SimpleClass ()
134 XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
135 XmlAttributes attr = new XmlAttributes ();
136 XmlElementAttribute element = new XmlElementAttribute ();
137 element.ElementName = "saying";
138 element.IsNullable = true;
139 attr.XmlElements.Add (element);
140 overrides.Add (typeof (SimpleClass), "something", attr);
142 XmlSchemas schemas = Export (typeof (SimpleClass), overrides, "NSSimpleClass");
143 Assert.AreEqual (1, schemas.Count, "#1");
145 StringWriter sw = new StringWriter ();
146 schemas[0].Write (sw);
148 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
149 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
150 "<xs:schema xmlns:tns=\"NSSimpleClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
151 " <xs:element name=\"SimpleClass\" type=\"tns:SimpleClass\" />{0}" +
152 " <xs:complexType name=\"SimpleClass\">{0}" +
153 " <xs:sequence>{0}" +
154 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
155 " </xs:sequence>{0}" +
156 " </xs:complexType>{0}" +
157 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
159 schemas = Export (typeof (SimpleClass), overrides);
160 Assert.AreEqual (1, schemas.Count, "#3");
162 sw.GetStringBuilder ().Length = 0;
163 schemas[0].Write (sw);
165 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
166 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
167 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
168 " <xs:element name=\"SimpleClass\" type=\"SimpleClass\" />{0}" +
169 " <xs:complexType name=\"SimpleClass\">{0}" +
170 " <xs:sequence>{0}" +
171 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
172 " </xs:sequence>{0}" +
173 " </xs:complexType>{0}" +
174 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
178 [Category ("NotDotNet")] // Mono bug ##77117
179 public void ExportClass_StringCollection ()
181 XmlSchemas schemas = Export (typeof (StringCollection), "NSStringCollection");
182 Assert.AreEqual (1, schemas.Count, "#1");
184 StringWriter sw = new StringWriter ();
185 schemas[0].Write (sw);
187 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
188 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
189 "<xs:schema xmlns:tns=\"NSStringCollection\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollection\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
190 " <xs:element name=\"ArrayOfString\" type=\"tns:ArrayOfString\" />{0}" +
191 " <xs:complexType name=\"ArrayOfString\">{0}" +
192 " <xs:sequence>{0}" +
193 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
194 " </xs:sequence>{0}" +
195 " </xs:complexType>{0}" +
196 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
198 schemas = Export (typeof (StringCollection));
199 Assert.AreEqual (1, schemas.Count, "#3");
201 sw.GetStringBuilder ().Length = 0;
202 schemas[0].Write (sw);
204 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
205 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
206 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
207 " <xs:element name=\"ArrayOfString\" type=\"ArrayOfString\" />{0}" +
208 " <xs:complexType name=\"ArrayOfString\">{0}" +
209 " <xs:sequence>{0}" +
210 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
211 " </xs:sequence>{0}" +
212 " </xs:complexType>{0}" +
213 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
217 [Category ("NotDotNet")] // Mono bug ##77117
218 public void ExportClass_StringCollectionContainer ()
220 XmlSchemas schemas = Export (typeof (StringCollectionContainer), "NSStringCollectionContainer");
221 Assert.AreEqual (1, schemas.Count, "#1");
223 StringWriter sw = new StringWriter ();
224 schemas[0].Write (sw);
226 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
227 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
228 "<xs:schema xmlns:tns=\"NSStringCollectionContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollectionContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
229 " <xs:element name=\"StringCollectionContainer\" type=\"tns:StringCollectionContainer\" />{0}" +
230 " <xs:complexType name=\"StringCollectionContainer\">{0}" +
231 " <xs:sequence>{0}" +
232 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"tns:ArrayOfString\" />{0}" +
233 " </xs:sequence>{0}" +
234 " </xs:complexType>{0}" +
235 " <xs:complexType name=\"ArrayOfString\">{0}" +
236 " <xs:sequence>{0}" +
237 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
238 " </xs:sequence>{0}" +
239 " </xs:complexType>{0}" +
240 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
242 schemas = Export (typeof (StringCollectionContainer));
243 Assert.AreEqual (1, schemas.Count, "#3");
245 sw.GetStringBuilder ().Length = 0;
246 schemas[0].Write (sw);
248 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
249 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
250 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
251 " <xs:element name=\"StringCollectionContainer\" type=\"StringCollectionContainer\" />{0}" +
252 " <xs:complexType name=\"StringCollectionContainer\">{0}" +
253 " <xs:sequence>{0}" +
254 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"ArrayOfString\" />{0}" +
255 " </xs:sequence>{0}" +
256 " </xs:complexType>{0}" +
257 " <xs:complexType name=\"ArrayOfString\">{0}" +
258 " <xs:sequence>{0}" +
259 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
260 " </xs:sequence>{0}" +
261 " </xs:complexType>{0}" +
262 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
266 [Category ("NotDotNet")] // Mono bug ##77117
267 public void ExportClass_ArrayContainer ()
269 XmlSchemas schemas = Export (typeof (ArrayContainer), "NSArrayContainer");
270 Assert.AreEqual (1, schemas.Count, "#1");
272 StringWriter sw = new StringWriter ();
273 schemas[0].Write (sw);
275 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
276 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
277 "<xs:schema xmlns:tns=\"NSArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
278 " <xs:element name=\"ArrayContainer\" type=\"tns:ArrayContainer\" />{0}" +
279 " <xs:complexType name=\"ArrayContainer\">{0}" +
280 " <xs:sequence>{0}" +
281 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfAnyType\" />{0}" +
282 " </xs:sequence>{0}" +
283 " </xs:complexType>{0}" +
284 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
285 " <xs:sequence>{0}" +
286 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
287 " </xs:sequence>{0}" +
288 " </xs:complexType>{0}" +
289 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
291 schemas = Export (typeof (ArrayContainer));
292 Assert.AreEqual (1, schemas.Count, "#3");
294 sw.GetStringBuilder ().Length = 0;
295 schemas[0].Write (sw);
297 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
298 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
299 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
300 " <xs:element name=\"ArrayContainer\" type=\"ArrayContainer\" />{0}" +
301 " <xs:complexType name=\"ArrayContainer\">{0}" +
302 " <xs:sequence>{0}" +
303 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfAnyType\" />{0}" +
304 " </xs:sequence>{0}" +
305 " </xs:complexType>{0}" +
306 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
307 " <xs:sequence>{0}" +
308 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
309 " </xs:sequence>{0}" +
310 " </xs:complexType>{0}" +
311 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
315 [Category ("NotDotNet")] // Mono bug ##77117
316 public void ExportClass_ClassArrayContainer ()
318 XmlSchemas schemas = Export (typeof (ClassArrayContainer), "NSClassArrayContainer");
319 Assert.AreEqual (1, schemas.Count, "#1");
321 StringWriter sw = new StringWriter ();
322 schemas[0].Write (sw);
324 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
325 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
326 "<xs:schema xmlns:tns=\"NSClassArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSClassArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
327 " <xs:element name=\"ClassArrayContainer\" type=\"tns:ClassArrayContainer\" />{0}" +
328 " <xs:complexType name=\"ClassArrayContainer\">{0}" +
329 " <xs:sequence>{0}" +
330 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
331 " </xs:sequence>{0}" +
332 " </xs:complexType>{0}" +
333 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
334 " <xs:sequence>{0}" +
335 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
336 " </xs:sequence>{0}" +
337 " </xs:complexType>{0}" +
338 " <xs:complexType name=\"SimpleClass\">{0}" +
339 " <xs:sequence>{0}" +
340 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
341 " </xs:sequence>{0}" +
342 " </xs:complexType>{0}" +
343 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
345 schemas = Export (typeof (ClassArrayContainer));
346 Assert.AreEqual (1, schemas.Count, "#3");
348 sw.GetStringBuilder ().Length = 0;
349 schemas[0].Write (sw);
351 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
352 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
353 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
354 " <xs:element name=\"ClassArrayContainer\" type=\"ClassArrayContainer\" />{0}" +
355 " <xs:complexType name=\"ClassArrayContainer\">{0}" +
356 " <xs:sequence>{0}" +
357 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfSimpleClass\" />{0}" +
358 " </xs:sequence>{0}" +
359 " </xs:complexType>{0}" +
360 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
361 " <xs:sequence>{0}" +
362 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
363 " </xs:sequence>{0}" +
364 " </xs:complexType>{0}" +
365 " <xs:complexType name=\"SimpleClass\">{0}" +
366 " <xs:sequence>{0}" +
367 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
368 " </xs:sequence>{0}" +
369 " </xs:complexType>{0}" +
370 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
374 [Category ("NotDotNet")] // Mono bug ##77117
375 public void ExportClass_SimpleClassWithXmlAttributes ()
377 XmlSchemas schemas = Export (typeof (SimpleClassWithXmlAttributes), "NSSimpleClassWithXmlAttributes");
378 Assert.AreEqual (1, schemas.Count, "#1");
380 StringWriter sw = new StringWriter ();
381 schemas[0].Write (sw);
383 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
384 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
385 "<xs:schema xmlns:tns=\"NSSimpleClassWithXmlAttributes\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassWithXmlAttributes\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
386 " <xs:element name=\"simple\" type=\"tns:SimpleClassWithXmlAttributes\" />{0}" +
387 " <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
388 " <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
389 " </xs:complexType>{0}" +
390 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
392 schemas = Export (typeof (SimpleClassWithXmlAttributes));
393 Assert.AreEqual (1, schemas.Count, "#3");
395 sw.GetStringBuilder ().Length = 0;
396 schemas[0].Write (sw);
398 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
399 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
400 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
401 " <xs:element name=\"simple\" type=\"SimpleClassWithXmlAttributes\" />{0}" +
402 " <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
403 " <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
404 " </xs:complexType>{0}" +
405 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
409 [Category ("NotDotNet")] // Mono does not translate default values to corresponding enum fields
410 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
411 public void ExportClass_Field ()
413 XmlSchemas schemas = Export (typeof (Field), "NSField");
414 Assert.AreEqual (1, schemas.Count, "#1");
416 StringWriter sw = new StringWriter ();
417 schemas[0].Write (sw);
419 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
420 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
421 "<xs:schema xmlns:tns=\"NSField\" elementFormDefault=\"qualified\" targetNamespace=\"NSField\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
422 " <xs:element name=\"field\" type=\"tns:Field\" />{0}" +
423 " <xs:complexType name=\"Field\">{0}" +
424 " <xs:attribute name=\"modifiers\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
425 " <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
426 " <xs:attribute default=\"0\" name=\"modifiers3\" type=\"tns:MapModifiers\" />{0}" +
427 " <xs:attribute default=\"0\" form=\"unqualified\" name=\"modifiers4\" type=\"tns:MapModifiers\" />{0}" +
428 " <xs:attribute name=\"names\">{0}" +
429 " <xs:simpleType>{0}" +
430 " <xs:list itemType=\"xs:string\" />{0}" +
431 " </xs:simpleType>{0}" +
432 " </xs:attribute>{0}" +
433 " <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
434 " </xs:complexType>{0}" +
435 " <xs:simpleType name=\"MapModifiers\">{0}" +
437 " <xs:simpleType>{0}" +
438 " <xs:restriction base=\"xs:string\">{0}" +
439 " <xs:enumeration value=\"public\" />{0}" +
440 " <xs:enumeration value=\"protected\" />{0}" +
441 " </xs:restriction>{0}" +
442 " </xs:simpleType>{0}" +
444 " </xs:simpleType>{0}" +
445 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
447 schemas = Export (typeof (Field));
448 Assert.AreEqual (1, schemas.Count, "#3");
450 sw.GetStringBuilder ().Length = 0;
451 schemas[0].Write (sw);
453 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
454 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
455 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
456 " <xs:element name=\"field\" type=\"Field\" />{0}" +
457 " <xs:complexType name=\"Field\">{0}" +
458 " <xs:attribute name=\"modifiers\" type=\"MapModifiers\" use=\"required\" />{0}" +
459 " <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"MapModifiers\" use=\"required\" />{0}" +
460 " <xs:attribute default=\"0\" name=\"modifiers3\" type=\"MapModifiers\" />{0}" +
461 " <xs:attribute default=\"0\" form=\"unqualified\" name=\"modifiers4\" type=\"MapModifiers\" />{0}" +
462 " <xs:attribute name=\"names\">{0}" +
463 " <xs:simpleType>{0}" +
464 " <xs:list itemType=\"xs:string\" />{0}" +
465 " </xs:simpleType>{0}" +
466 " </xs:attribute>{0}" +
467 " <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
468 " </xs:complexType>{0}" +
469 " <xs:simpleType name=\"MapModifiers\">{0}" +
471 " <xs:simpleType>{0}" +
472 " <xs:restriction base=\"xs:string\">{0}" +
473 " <xs:enumeration value=\"public\" />{0}" +
474 " <xs:enumeration value=\"protected\" />{0}" +
475 " </xs:restriction>{0}" +
476 " </xs:simpleType>{0}" +
478 " </xs:simpleType>{0}" +
479 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
483 [Category ("NotDotNet")] // Mono bug ##77117
484 public void ExportClass_MyList ()
486 XmlSchemas schemas = Export (typeof (MyList), "NSMyList");
487 Assert.AreEqual (1, schemas.Count, "#1");
489 StringWriter sw = new StringWriter ();
490 schemas[0].Write (sw);
492 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
493 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
494 "<xs:schema xmlns:tns=\"NSMyList\" elementFormDefault=\"qualified\" targetNamespace=\"NSMyList\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
495 " <xs:element name=\"ArrayOfAnyType\" type=\"tns:ArrayOfAnyType\" />{0}" +
496 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
497 " <xs:sequence>{0}" +
498 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
499 " </xs:sequence>{0}" +
500 " </xs:complexType>{0}" +
501 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
503 schemas = Export (typeof (MyList));
504 Assert.AreEqual (1, schemas.Count, "#3");
506 sw.GetStringBuilder ().Length = 0;
507 schemas[0].Write (sw);
509 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
510 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
511 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
512 " <xs:element name=\"ArrayOfAnyType\" type=\"ArrayOfAnyType\" />{0}" +
513 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
514 " <xs:sequence>{0}" +
515 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
516 " </xs:sequence>{0}" +
517 " </xs:complexType>{0}" +
518 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
522 [Category ("NotDotNet")] // Mono bug ##77117
523 public void ExportClass_Container ()
525 XmlSchemas schemas = Export (typeof (Container), "NSContainer");
526 Assert.AreEqual (1, schemas.Count, "#1");
528 StringWriter sw = new StringWriter ();
529 schemas[0].Write (sw);
531 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
532 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
533 "<xs:schema xmlns:tns=\"NSContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
534 " <xs:element name=\"Container\" type=\"tns:Container\" />{0}" +
535 " <xs:complexType name=\"Container\">{0}" +
536 " <xs:sequence>{0}" +
537 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
538 " </xs:sequence>{0}" +
539 " </xs:complexType>{0}" +
540 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
541 " <xs:sequence>{0}" +
542 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
543 " </xs:sequence>{0}" +
544 " </xs:complexType>{0}" +
545 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
547 schemas = Export (typeof (Container));
548 Assert.AreEqual (1, schemas.Count, "#3");
550 sw.GetStringBuilder ().Length = 0;
551 schemas[0].Write (sw);
553 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
554 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
555 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
556 " <xs:element name=\"Container\" type=\"Container\" />{0}" +
557 " <xs:complexType name=\"Container\">{0}" +
558 " <xs:sequence>{0}" +
559 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
560 " </xs:sequence>{0}" +
561 " </xs:complexType>{0}" +
562 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
563 " <xs:sequence>{0}" +
564 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
565 " </xs:sequence>{0}" +
566 " </xs:complexType>{0}" +
567 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
571 [Category ("NotDotNet")] // Mono bug ##77117
572 public void ExportClass_Container2 ()
574 XmlSchemas schemas = Export (typeof (Container2), "NSContainer2");
575 Assert.AreEqual (1, schemas.Count, "#1");
577 StringWriter sw = new StringWriter ();
578 schemas[0].Write (sw);
580 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
581 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
582 "<xs:schema xmlns:tns=\"NSContainer2\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
583 " <xs:element name=\"Container2\" type=\"tns:Container2\" />{0}" +
584 " <xs:complexType name=\"Container2\">{0}" +
585 " <xs:sequence>{0}" +
586 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
587 " </xs:sequence>{0}" +
588 " </xs:complexType>{0}" +
589 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
590 " <xs:sequence>{0}" +
591 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
592 " </xs:sequence>{0}" +
593 " </xs:complexType>{0}" +
594 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
596 schemas = Export (typeof (Container2));
597 Assert.AreEqual (1, schemas.Count, "#3");
599 sw.GetStringBuilder ().Length = 0;
600 schemas[0].Write (sw);
602 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
603 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
604 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
605 " <xs:element name=\"Container2\" type=\"Container2\" />{0}" +
606 " <xs:complexType name=\"Container2\">{0}" +
607 " <xs:sequence>{0}" +
608 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
609 " </xs:sequence>{0}" +
610 " </xs:complexType>{0}" +
611 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
612 " <xs:sequence>{0}" +
613 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
614 " </xs:sequence>{0}" +
615 " </xs:complexType>{0}" +
616 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
620 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
621 [ExpectedException (typeof (InvalidOperationException))] // Cannot use wildcards at the top level of a schema.
622 public void ExportClass_MyElem ()
624 Export (typeof (MyElem), "NSMyElem");
628 [Category ("NotDotNet")] // Mono bug ##77117
629 public void ExportClass_CDataContainer ()
631 XmlSchemas schemas = Export (typeof (CDataContainer), "NSCDataContainer");
632 Assert.AreEqual (1, schemas.Count, "#1");
634 StringWriter sw = new StringWriter ();
635 schemas[0].Write (sw);
637 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
638 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
639 "<xs:schema xmlns:tns=\"NSCDataContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSCDataContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
640 " <xs:element name=\"CDataContainer\" type=\"tns:CDataContainer\" />{0}" +
641 " <xs:complexType name=\"CDataContainer\">{0}" +
642 " <xs:sequence>{0}" +
643 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
644 " <xs:complexType mixed=\"true\">{0}" +
645 " <xs:sequence>{0}" +
647 " </xs:sequence>{0}" +
648 " </xs:complexType>{0}" +
649 " </xs:element>{0}" +
650 " </xs:sequence>{0}" +
651 " </xs:complexType>{0}" +
652 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
654 schemas = Export (typeof (CDataContainer));
655 Assert.AreEqual (1, schemas.Count, "#3");
657 sw.GetStringBuilder ().Length = 0;
658 schemas[0].Write (sw);
660 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
661 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
662 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
663 " <xs:element name=\"CDataContainer\" type=\"CDataContainer\" />{0}" +
664 " <xs:complexType name=\"CDataContainer\">{0}" +
665 " <xs:sequence>{0}" +
666 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
667 " <xs:complexType mixed=\"true\">{0}" +
668 " <xs:sequence>{0}" +
670 " </xs:sequence>{0}" +
671 " </xs:complexType>{0}" +
672 " </xs:element>{0}" +
673 " </xs:sequence>{0}" +
674 " </xs:complexType>{0}" +
675 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
679 [Category ("NotDotNet")] // Mono bug ##77117
680 public void ExportClass_NodeContainer ()
682 XmlSchemas schemas = Export (typeof (NodeContainer), "NSNodeContainer");
683 Assert.AreEqual (1, schemas.Count, "#1");
685 StringWriter sw = new StringWriter ();
686 schemas[0].Write (sw);
688 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
689 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
690 "<xs:schema xmlns:tns=\"NSNodeContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSNodeContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
691 " <xs:element name=\"NodeContainer\" type=\"tns:NodeContainer\" />{0}" +
692 " <xs:complexType name=\"NodeContainer\">{0}" +
693 " <xs:sequence>{0}" +
694 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
695 " <xs:complexType mixed=\"true\">{0}" +
696 " <xs:sequence>{0}" +
698 " </xs:sequence>{0}" +
699 " </xs:complexType>{0}" +
700 " </xs:element>{0}" +
701 " </xs:sequence>{0}" +
702 " </xs:complexType>{0}" +
703 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
705 schemas = Export (typeof (NodeContainer));
706 Assert.AreEqual (1, schemas.Count, "#3");
708 sw.GetStringBuilder ().Length = 0;
709 schemas[0].Write (sw);
711 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
712 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
713 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
714 " <xs:element name=\"NodeContainer\" type=\"NodeContainer\" />{0}" +
715 " <xs:complexType name=\"NodeContainer\">{0}" +
716 " <xs:sequence>{0}" +
717 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
718 " <xs:complexType mixed=\"true\">{0}" +
719 " <xs:sequence>{0}" +
721 " </xs:sequence>{0}" +
722 " </xs:complexType>{0}" +
723 " </xs:element>{0}" +
724 " </xs:sequence>{0}" +
725 " </xs:complexType>{0}" +
726 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
730 [Category ("NotWorking")] // Mono does not generate the <xs:choice> node
731 [Category ("NotDotNet")] // Mono bug ##77117 and MS.NET randomly modifies the order of the elements!
732 public void ExportClass_Choices ()
734 XmlSchemas schemas = Export (typeof (Choices), "NSChoices");
735 Assert.AreEqual (1, schemas.Count, "#1");
737 StringWriter sw = new StringWriter ();
738 schemas[0].Write (sw);
740 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
741 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
742 "<xs:schema xmlns:tns=\"NSChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
743 " <xs:element name=\"Choices\" type=\"tns:Choices\" />{0}" +
744 " <xs:complexType name=\"Choices\">{0}" +
745 " <xs:sequence>{0}" +
746 " <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
747 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
748 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
749 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
751 " </xs:sequence>{0}" +
752 " </xs:complexType>{0}" +
753 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
755 schemas = Export (typeof (Choices));
756 Assert.AreEqual (1, schemas.Count, "#3");
758 sw.GetStringBuilder ().Length = 0;
759 schemas[0].Write (sw);
761 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
762 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
763 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
764 " <xs:element name=\"Choices\" type=\"Choices\" />{0}" +
765 " <xs:complexType name=\"Choices\">{0}" +
766 " <xs:sequence>{0}" +
767 " <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
768 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
769 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
770 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
772 " </xs:sequence>{0}" +
773 " </xs:complexType>{0}" +
774 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
778 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
780 [Category ("NotDotNet")] // MS.NET 1.x does not escape spaces in a type name, bug is fixed in .NET 2.0
782 [Category ("NotDotNet")] // Mono bug ##77117
784 public void ExportClass_TestSpace ()
786 XmlSchemas schemas = Export (typeof (TestSpace), "NSTestSpace");
787 Assert.AreEqual (1, schemas.Count, "#1");
789 StringWriter sw = new StringWriter ();
790 schemas[0].Write (sw);
792 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
793 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
794 "<xs:schema xmlns:tns=\"NSTestSpace\" elementFormDefault=\"qualified\" targetNamespace=\"NSTestSpace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
795 " <xs:element name=\"Type_x0020_with_x0020_space\" type=\"tns:Type_x0020_with_x0020_space\" />{0}" +
796 " <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
797 " <xs:sequence>{0}" +
798 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
799 " </xs:sequence>{0}" +
800 " <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
801 " </xs:complexType>{0}" +
802 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
804 schemas = Export (typeof (TestSpace));
805 Assert.AreEqual (1, schemas.Count, "#3");
807 sw.GetStringBuilder ().Length = 0;
808 schemas[0].Write (sw);
810 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
811 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
812 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
813 " <xs:element name=\"Type_x0020_with_x0020_space\" type=\"Type_x0020_with_x0020_space\" />{0}" +
814 " <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
815 " <xs:sequence>{0}" +
816 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
817 " </xs:sequence>{0}" +
818 " <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
819 " </xs:complexType>{0}" +
820 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
824 [Category ("NotDotNet")] // Mono bug ##77117
825 public void ExportClass_ReadOnlyProperties ()
827 XmlSchemas schemas = Export (typeof (ReadOnlyProperties), "NSReadOnlyProperties");
828 Assert.AreEqual (1, schemas.Count, "#1");
830 StringWriter sw = new StringWriter ();
831 schemas[0].Write (sw);
833 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
834 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
835 "<xs:schema xmlns:tns=\"NSReadOnlyProperties\" elementFormDefault=\"qualified\" targetNamespace=\"NSReadOnlyProperties\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
836 " <xs:element name=\"ReadOnlyProperties\" type=\"tns:ReadOnlyProperties\" />{0}" +
837 " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
838 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
840 schemas = Export (typeof (ReadOnlyProperties));
841 Assert.AreEqual (1, schemas.Count, "#3");
843 sw.GetStringBuilder ().Length = 0;
844 schemas[0].Write (sw);
846 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
847 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
848 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
849 " <xs:element name=\"ReadOnlyProperties\" type=\"ReadOnlyProperties\" />{0}" +
850 " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
851 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
855 [Category ("NotDotNet")] // Mono bug ##77117
856 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
857 public void ExportClass_ListDefaults ()
859 XmlSchemas schemas = Export (typeof (ListDefaults), "NSListDefaults");
860 Assert.AreEqual (1, schemas.Count, "#1");
862 StringWriter sw = new StringWriter ();
863 schemas[0].Write (sw);
865 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
866 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
867 "<xs:schema xmlns:tns=\"NSListDefaults\" elementFormDefault=\"qualified\" targetNamespace=\"NSListDefaults\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
868 " <xs:element name=\"root\" type=\"tns:ListDefaults\" />{0}" +
869 " <xs:complexType name=\"ListDefaults\">{0}" +
870 " <xs:sequence>{0}" +
871 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"tns:ArrayOfAnyType\" />{0}" +
872 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"tns:ArrayOfAnyType\" />{0}" +
873 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"tns:ArrayOfString\" />{0}" +
874 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"tns:SimpleClass\" />{0}" +
875 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"tns:SimpleClass\" />{0}" +
876 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
877 " </xs:sequence>{0}" +
878 " </xs:complexType>{0}" +
879 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
880 " <xs:sequence>{0}" +
881 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
882 " </xs:sequence>{0}" +
883 " </xs:complexType>{0}" +
884 " <xs:complexType name=\"ArrayOfString\">{0}" +
885 " <xs:sequence>{0}" +
886 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
887 " </xs:sequence>{0}" +
888 " </xs:complexType>{0}" +
889 " <xs:complexType name=\"SimpleClass\">{0}" +
890 " <xs:sequence>{0}" +
891 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
892 " </xs:sequence>{0}" +
893 " </xs:complexType>{0}" +
894 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
896 schemas = Export (typeof (ListDefaults));
897 Assert.AreEqual (1, schemas.Count, "#3");
899 sw.GetStringBuilder ().Length = 0;
900 schemas[0].Write (sw);
902 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
903 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
904 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
905 " <xs:element name=\"root\" type=\"ListDefaults\" />{0}" +
906 " <xs:complexType name=\"ListDefaults\">{0}" +
907 " <xs:sequence>{0}" +
908 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"ArrayOfAnyType\" />{0}" +
909 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"ArrayOfAnyType\" />{0}" +
910 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"ArrayOfString\" />{0}" +
911 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"SimpleClass\" />{0}" +
912 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"SimpleClass\" />{0}" +
913 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
914 " </xs:sequence>{0}" +
915 " </xs:complexType>{0}" +
916 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
917 " <xs:sequence>{0}" +
918 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
919 " </xs:sequence>{0}" +
920 " </xs:complexType>{0}" +
921 " <xs:complexType name=\"ArrayOfString\">{0}" +
922 " <xs:sequence>{0}" +
923 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
924 " </xs:sequence>{0}" +
925 " </xs:complexType>{0}" +
926 " <xs:complexType name=\"SimpleClass\">{0}" +
927 " <xs:sequence>{0}" +
928 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
929 " </xs:sequence>{0}" +
930 " </xs:complexType>{0}" +
931 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
935 [Category ("NotDotNet")] // Mono bug ##77117
936 public void ExportClass_ClsPerson ()
938 XmlSchemas schemas = Export (typeof (clsPerson), "NSClsPerson");
939 Assert.AreEqual (1, schemas.Count, "#1");
941 StringWriter sw = new StringWriter ();
942 schemas[0].Write (sw);
944 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
945 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
946 "<xs:schema xmlns:tns=\"NSClsPerson\" elementFormDefault=\"qualified\" targetNamespace=\"NSClsPerson\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
947 " <xs:element name=\"clsPerson\" type=\"tns:clsPerson\" />{0}" +
948 " <xs:complexType name=\"clsPerson\">{0}" +
949 " <xs:sequence>{0}" +
950 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"tns:ArrayOfAnyType\" />{0}" +
951 " </xs:sequence>{0}" +
952 " </xs:complexType>{0}" +
953 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
954 " <xs:sequence>{0}" +
955 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
956 " </xs:sequence>{0}" +
957 " </xs:complexType>{0}" +
958 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
960 schemas = Export (typeof (clsPerson));
961 Assert.AreEqual (1, schemas.Count, "#3");
963 sw.GetStringBuilder ().Length = 0;
964 schemas[0].Write (sw);
966 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
967 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
968 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
969 " <xs:element name=\"clsPerson\" type=\"clsPerson\" />{0}" +
970 " <xs:complexType name=\"clsPerson\">{0}" +
971 " <xs:sequence>{0}" +
972 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"ArrayOfAnyType\" />{0}" +
973 " </xs:sequence>{0}" +
974 " </xs:complexType>{0}" +
975 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
976 " <xs:sequence>{0}" +
977 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
978 " </xs:sequence>{0}" +
979 " </xs:complexType>{0}" +
980 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
984 [Category ("NotDotNet")] // Mono bug ##77117
985 public void ExportClass_ArrayClass ()
987 XmlSchemas schemas = Export (typeof (ArrayClass), "NSArrayClass");
988 Assert.AreEqual (1, schemas.Count, "#1");
990 StringWriter sw = new StringWriter ();
991 schemas[0].Write (sw);
993 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
994 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
995 "<xs:schema xmlns:tns=\"NSArrayClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
996 " <xs:element name=\"ArrayClass\" type=\"tns:ArrayClass\" />{0}" +
997 " <xs:complexType name=\"ArrayClass\">{0}" +
998 " <xs:sequence>{0}" +
999 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"names\" />{0}" +
1000 " </xs:sequence>{0}" +
1001 " </xs:complexType>{0}" +
1002 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1004 schemas = Export (typeof (ArrayClass));
1005 Assert.AreEqual (1, schemas.Count, "#3");
1007 sw.GetStringBuilder ().Length = 0;
1008 schemas[0].Write (sw);
1010 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1011 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1012 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1013 " <xs:element name=\"ArrayClass\" type=\"ArrayClass\" />{0}" +
1014 " <xs:complexType name=\"ArrayClass\">{0}" +
1015 " <xs:sequence>{0}" +
1016 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"names\" />{0}" +
1017 " </xs:sequence>{0}" +
1018 " </xs:complexType>{0}" +
1019 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1023 [Category ("NotDotNet")] // Mono bug ##77117
1024 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1025 public void ExportClass_StructContainer ()
1027 XmlSchemas schemas = Export (typeof (StructContainer), "NSStructContainer");
1028 Assert.AreEqual (1, schemas.Count, "#1");
1030 StringWriter sw = new StringWriter ();
1031 schemas[0].Write (sw);
1033 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1034 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1035 "<xs:schema xmlns:tns=\"NSStructContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStructContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1036 " <xs:element name=\"StructContainer\" type=\"tns:StructContainer\" />{0}" +
1037 " <xs:complexType name=\"StructContainer\">{0}" +
1038 " <xs:sequence>{0}" +
1039 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"tns:EnumDefaultValue\" />{0}" +
1040 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Times\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
1041 " </xs:sequence>{0}" +
1042 " </xs:complexType>{0}" +
1043 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1045 " <xs:simpleType>{0}" +
1046 " <xs:restriction base=\"xs:string\">{0}" +
1047 " <xs:enumeration value=\"e1\" />{0}" +
1048 " <xs:enumeration value=\"e2\" />{0}" +
1049 " <xs:enumeration value=\"e3\" />{0}" +
1050 " </xs:restriction>{0}" +
1051 " </xs:simpleType>{0}" +
1053 " </xs:simpleType>{0}" +
1054 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
1055 " <xs:sequence>{0}" +
1056 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"tns:TimeSpan\" />{0}" +
1057 " </xs:sequence>{0}" +
1058 " </xs:complexType>{0}" +
1059 " <xs:complexType name=\"TimeSpan\" />{0}" +
1060 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1062 schemas = Export (typeof (StructContainer));
1063 Assert.AreEqual (1, schemas.Count, "#3");
1065 sw.GetStringBuilder ().Length = 0;
1066 schemas[0].Write (sw);
1068 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1069 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1070 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1071 " <xs:element name=\"StructContainer\" type=\"StructContainer\" />{0}" +
1072 " <xs:complexType name=\"StructContainer\">{0}" +
1073 " <xs:sequence>{0}" +
1074 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"EnumDefaultValue\" />{0}" +
1075 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Times\" type=\"ArrayOfTimeSpan\" />{0}" +
1076 " </xs:sequence>{0}" +
1077 " </xs:complexType>{0}" +
1078 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1080 " <xs:simpleType>{0}" +
1081 " <xs:restriction base=\"xs:string\">{0}" +
1082 " <xs:enumeration value=\"e1\" />{0}" +
1083 " <xs:enumeration value=\"e2\" />{0}" +
1084 " <xs:enumeration value=\"e3\" />{0}" +
1085 " </xs:restriction>{0}" +
1086 " </xs:simpleType>{0}" +
1088 " </xs:simpleType>{0}" +
1089 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
1090 " <xs:sequence>{0}" +
1091 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"TimeSpan\" />{0}" +
1092 " </xs:sequence>{0}" +
1093 " </xs:complexType>{0}" +
1094 " <xs:complexType name=\"TimeSpan\" />{0}" +
1095 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1099 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1100 [ExpectedException (typeof (InvalidOperationException))] // Cannot use wildcards at the top level of a schema.
1101 public void ExportClass_XmlElement ()
1103 XmlSchemas schemas = Export (typeof (XmlElement), "NS1");
1107 [Category ("NotDotNet")] // Mono bug ##77117
1108 public void ExportClass_Array ()
1110 XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
1111 XmlAttributes attr = new XmlAttributes ();
1112 XmlElementAttribute element = new XmlElementAttribute ();
1113 element.ElementName = "saying";
1114 element.IsNullable = true;
1115 attr.XmlElements.Add (element);
1116 overrides.Add (typeof (SimpleClass), "something", attr);
1118 XmlSchemas schemas = Export (typeof (SimpleClass[]), overrides, "NSSimpleClassArray");
1119 Assert.AreEqual (1, schemas.Count, "#1");
1121 StringWriter sw = new StringWriter ();
1122 schemas[0].Write (sw);
1124 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1125 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1126 "<xs:schema xmlns:tns=\"NSSimpleClassArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1127 " <xs:element name=\"ArrayOfSimpleClass\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
1128 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
1129 " <xs:sequence>{0}" +
1130 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
1131 " </xs:sequence>{0}" +
1132 " </xs:complexType>{0}" +
1133 " <xs:complexType name=\"SimpleClass\">{0}" +
1134 " <xs:sequence>{0}" +
1135 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
1136 " </xs:sequence>{0}" +
1137 " </xs:complexType>{0}" +
1138 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1140 schemas = Export (typeof (SimpleClass[]), overrides);
1141 Assert.AreEqual (1, schemas.Count, "#3");
1143 sw.GetStringBuilder ().Length = 0;
1144 schemas[0].Write (sw);
1146 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1147 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1148 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1149 " <xs:element name=\"ArrayOfSimpleClass\" type=\"ArrayOfSimpleClass\" />{0}" +
1150 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
1151 " <xs:sequence>{0}" +
1152 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
1153 " </xs:sequence>{0}" +
1154 " </xs:complexType>{0}" +
1155 " <xs:complexType name=\"SimpleClass\">{0}" +
1156 " <xs:sequence>{0}" +
1157 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
1158 " </xs:sequence>{0}" +
1159 " </xs:complexType>{0}" +
1160 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1164 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1165 public void ExportEnum ()
1167 XmlSchemas schemas = Export (typeof (EnumDefaultValue), "NSEnumDefaultValue");
1168 Assert.AreEqual (1, schemas.Count, "#1");
1170 StringWriter sw = new StringWriter ();
1171 schemas[0].Write (sw);
1173 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1174 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1175 "<xs:schema xmlns:tns=\"NSEnumDefaultValue\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValue\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1176 " <xs:element name=\"EnumDefaultValue\" type=\"tns:EnumDefaultValue\" />{0}" +
1177 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1179 " <xs:simpleType>{0}" +
1180 " <xs:restriction base=\"xs:string\">{0}" +
1181 " <xs:enumeration value=\"e1\" />{0}" +
1182 " <xs:enumeration value=\"e2\" />{0}" +
1183 " <xs:enumeration value=\"e3\" />{0}" +
1184 " </xs:restriction>{0}" +
1185 " </xs:simpleType>{0}" +
1187 " </xs:simpleType>{0}" +
1188 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1190 schemas = Export (typeof (EnumDefaultValueNF), "NSEnumDefaultValueNF");
1191 Assert.AreEqual (1, schemas.Count, "#3");
1193 sw.GetStringBuilder ().Length = 0;
1194 schemas[0].Write (sw);
1196 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1197 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1198 "<xs:schema xmlns:tns=\"NSEnumDefaultValueNF\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValueNF\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1199 " <xs:element name=\"EnumDefaultValueNF\" type=\"tns:EnumDefaultValueNF\" />{0}" +
1200 " <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
1201 " <xs:restriction base=\"xs:string\">{0}" +
1202 " <xs:enumeration value=\"e1\" />{0}" +
1203 " <xs:enumeration value=\"e2\" />{0}" +
1204 " <xs:enumeration value=\"e3\" />{0}" +
1205 " </xs:restriction>{0}" +
1206 " </xs:simpleType>{0}" +
1207 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1209 schemas = Export (typeof (EnumDefaultValue));
1210 Assert.AreEqual (1, schemas.Count, "#5");
1212 sw.GetStringBuilder ().Length = 0;
1213 schemas[0].Write (sw);
1215 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1216 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1217 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1218 " <xs:element name=\"EnumDefaultValue\" type=\"EnumDefaultValue\" />{0}" +
1219 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1221 " <xs:simpleType>{0}" +
1222 " <xs:restriction base=\"xs:string\">{0}" +
1223 " <xs:enumeration value=\"e1\" />{0}" +
1224 " <xs:enumeration value=\"e2\" />{0}" +
1225 " <xs:enumeration value=\"e3\" />{0}" +
1226 " </xs:restriction>{0}" +
1227 " </xs:simpleType>{0}" +
1229 " </xs:simpleType>{0}" +
1230 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
1232 schemas = Export (typeof (EnumDefaultValueNF));
1233 Assert.AreEqual (1, schemas.Count, "#7");
1235 sw.GetStringBuilder ().Length = 0;
1236 schemas[0].Write (sw);
1238 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1239 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1240 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1241 " <xs:element name=\"EnumDefaultValueNF\" type=\"EnumDefaultValueNF\" />{0}" +
1242 " <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
1243 " <xs:restriction base=\"xs:string\">{0}" +
1244 " <xs:enumeration value=\"e1\" />{0}" +
1245 " <xs:enumeration value=\"e2\" />{0}" +
1246 " <xs:enumeration value=\"e3\" />{0}" +
1247 " </xs:restriction>{0}" +
1248 " </xs:simpleType>{0}" +
1249 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1253 [Category ("NotDotNet")] // Mono bug ##77117
1254 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1255 public void ExportXmlSerializable ()
1257 XmlSchemas schemas = Export (typeof (Employee), "NSEmployee");
1258 Assert.AreEqual (1, schemas.Count, "#1");
1260 StringWriter sw = new StringWriter ();
1261 schemas[0].Write (sw);
1263 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1264 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1265 "<xs:schema xmlns:tns=\"NSEmployee\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployee\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1266 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1267 " <xs:element name=\"Employee\">{0}" +
1268 " <xs:complexType>{0}" +
1269 " <xs:sequence>{0}" +
1270 " <xs:element ref=\"xs:schema\" />{0}" +
1272 " </xs:sequence>{0}" +
1273 " </xs:complexType>{0}" +
1274 " </xs:element>{0}" +
1275 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1277 schemas = Export (typeof (Employee));
1278 Assert.AreEqual (1, schemas.Count, "#3");
1280 sw.GetStringBuilder ().Length = 0;
1281 schemas[0].Write (sw);
1283 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1284 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1285 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1286 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1287 " <xs:element name=\"Employee\">{0}" +
1288 " <xs:complexType>{0}" +
1289 " <xs:sequence>{0}" +
1290 " <xs:element ref=\"xs:schema\" />{0}" +
1292 " </xs:sequence>{0}" +
1293 " </xs:complexType>{0}" +
1294 " </xs:element>{0}" +
1295 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1299 [Category ("NotDotNet")] // Mono bug ##77117
1300 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1301 public void ExportXmlSerializable_Schema ()
1303 XmlSchemas schemas = Export (typeof (EmployeeSchema), "NSEmployeeSchema");
1304 Assert.AreEqual (2, schemas.Count, "#1");
1306 StringWriter sw = new StringWriter ();
1307 schemas[0].Write (sw);
1309 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1310 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1311 "<xs:schema xmlns:tns=\"NSEmployeeSchema\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1313 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1315 " <xs:element name=\"EmployeeSchema\">{0}" +
1316 " <xs:complexType>{0}" +
1317 " <xs:sequence>{0}" +
1318 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1319 " </xs:sequence>{0}" +
1320 " </xs:complexType>{0}" +
1321 " </xs:element>{0}" +
1322 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1324 sw.GetStringBuilder ().Length = 0;
1325 schemas[1].Write (sw);
1327 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1328 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1329 "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1330 " <xs:complexType name=\"employeeRoot\">{0}" +
1331 " <xs:attribute name=\"firstName\" />{0}" +
1332 " <xs:attribute name=\"lastName\" />{0}" +
1333 " <xs:attribute name=\"address\" />{0}" +
1334 " </xs:complexType>{0}" +
1335 " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1336 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
1338 schemas = Export (typeof (EmployeeSchema));
1339 Assert.AreEqual (2, schemas.Count, "#4");
1341 sw.GetStringBuilder ().Length = 0;
1342 schemas[0].Write (sw);
1344 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1345 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1346 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1348 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1350 " <xs:element name=\"EmployeeSchema\">{0}" +
1351 " <xs:complexType>{0}" +
1352 " <xs:sequence>{0}" +
1353 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1354 " </xs:sequence>{0}" +
1355 " </xs:complexType>{0}" +
1356 " </xs:element>{0}" +
1357 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
1359 sw.GetStringBuilder ().Length = 0;
1360 schemas[1].Write (sw);
1362 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1363 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1364 "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1365 " <xs:complexType name=\"employeeRoot\">{0}" +
1366 " <xs:attribute name=\"firstName\" />{0}" +
1367 " <xs:attribute name=\"lastName\" />{0}" +
1368 " <xs:attribute name=\"address\" />{0}" +
1369 " </xs:complexType>{0}" +
1370 " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1371 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
1373 schemas = Export (typeof (PrimitiveSchema), "NSPrimitiveSchema");
1374 Assert.AreEqual (2, schemas.Count, "#7");
1376 sw.GetStringBuilder ().Length = 0;
1377 schemas[0].Write (sw);
1379 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1380 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1381 "<xs:schema xmlns:tns=\"NSPrimitiveSchema\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimitiveSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1382 " <xs:element name=\"PrimitiveSchema\">{0}" +
1383 " <xs:complexType>{0}" +
1384 " <xs:sequence>{0}" +
1385 " <xs:any namespace=\"\" />{0}" +
1386 " </xs:sequence>{0}" +
1387 " </xs:complexType>{0}" +
1388 " </xs:element>{0}" +
1389 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1391 sw.GetStringBuilder ().Length = 0;
1392 schemas[1].Write (sw);
1394 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1395 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1396 "<xs:schema id=\"LuckyNumberSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1397 " <xs:element name=\"LuckyNumber\" type=\"xs:int\" />{0}" +
1398 "</xs:schema>", Environment.NewLine), sw.ToString (), "#9");
1402 [ExpectedException (typeof (InvalidOperationException))] // Schema Id is missing
1403 public void ExportXmlSerializable_MissingID ()
1405 Export (typeof (MissingIDSchema));
1408 [ExpectedException (typeof (InvalidOperationException))]
1409 public void ExportXmlSerializable_DuplicateNamespace ()
1412 Export (typeof (PrimitiveSchema));
1414 } catch (InvalidOperationException) {
1415 // The namespace, , is a duplicate.
1419 Export (typeof (XmlSerializableContainer));
1421 } catch (InvalidOperationException) {
1422 // The namespace, , is a duplicate.
1427 [Category ("NotDotNet")] // Mono bug ##77117
1428 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1430 [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
1432 public void ExportXmlSerializable_SchemaProvider ()
1434 XmlSchemas schemas = Export (typeof (EmployeeSchemaProvider), "NSEmployeeSchemaProvider");
1435 Assert.AreEqual (1, schemas.Count, "#1");
1437 StringWriter sw = new StringWriter ();
1438 schemas[0].Write (sw);
1440 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1441 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1442 "<xs:schema xmlns:tns=\"NSEmployeeSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployeeSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1444 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1445 " <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1447 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1448 " <xs:element name=\"EmployeeSchemaProvider\">{0}" +
1449 " <xs:complexType>{0}" +
1450 " <xs:sequence>{0}" +
1451 " <xs:element ref=\"xs:schema\" />{0}" +
1453 " </xs:sequence>{0}" +
1454 " </xs:complexType>{0}" +
1455 " </xs:element>{0}" +
1457 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1459 schemas = Export (typeof (EmployeeSchemaProvider));
1460 Assert.AreEqual (1, schemas.Count, "#3");
1462 sw.GetStringBuilder ().Length = 0;
1463 schemas[0].Write (sw);
1465 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1466 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1467 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1469 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1470 " <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1472 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1473 " <xs:element name=\"EmployeeSchemaProvider\">{0}" +
1474 " <xs:complexType>{0}" +
1475 " <xs:sequence>{0}" +
1476 " <xs:element ref=\"xs:schema\" />{0}" +
1478 " </xs:sequence>{0}" +
1479 " </xs:complexType>{0}" +
1480 " </xs:element>{0}" +
1482 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1484 schemas = Export (typeof (PrimitiveSchemaProvider), "NSPrimitiveSchemaProvider");
1485 Assert.AreEqual (1, schemas.Count, "#5");
1487 sw.GetStringBuilder ().Length = 0;
1488 schemas[0].Write (sw);
1490 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1491 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1492 "<xs:schema xmlns:tns=\"NSPrimitiveSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimitiveSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1494 " <xs:import />{0}" +
1495 " <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
1497 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1498 " <xs:element name=\"PrimitiveSchemaProvider\">{0}" +
1499 " <xs:complexType>{0}" +
1500 " <xs:sequence>{0}" +
1501 " <xs:element ref=\"xs:schema\" />{0}" +
1503 " </xs:sequence>{0}" +
1504 " </xs:complexType>{0}" +
1505 " </xs:element>{0}" +
1507 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
1509 schemas = Export (typeof (PrimitiveSchemaProvider));
1510 Assert.AreEqual (1, schemas.Count, "#7");
1512 sw.GetStringBuilder ().Length = 0;
1513 schemas[0].Write (sw);
1515 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1516 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1517 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1519 " <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
1521 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1522 " <xs:element name=\"PrimitiveSchemaProvider\">{0}" +
1523 " <xs:complexType>{0}" +
1524 " <xs:sequence>{0}" +
1525 " <xs:element ref=\"xs:schema\" />{0}" +
1527 " </xs:sequence>{0}" +
1528 " </xs:complexType>{0}" +
1529 " </xs:element>{0}" +
1531 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1535 [Category ("NotDotNet")] // Mono bug ##77117
1536 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1538 [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
1540 public void ExportXmlSerializable_Container ()
1542 XmlSchemas schemas = Export (typeof (XmlSerializableContainer), "NSXmlSerializableContainer");
1543 Assert.AreEqual (3, schemas.Count, "#1");
1545 StringWriter sw = new StringWriter ();
1546 schemas[0].Write (sw);
1548 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1549 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1550 "<xs:schema xmlns:tns=\"NSXmlSerializableContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSXmlSerializableContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1551 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1552 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1554 " <xs:import />{0}" +
1556 " <xs:element name=\"XmlSerializableContainer\" type=\"tns:XmlSerializableContainer\" />{0}" +
1557 " <xs:complexType name=\"XmlSerializableContainer\">{0}" +
1558 " <xs:sequence>{0}" +
1559 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Slave\">{0}" +
1560 " <xs:complexType>{0}" +
1561 " <xs:sequence>{0}" +
1562 " <xs:element ref=\"xs:schema\" />{0}" +
1564 " </xs:sequence>{0}" +
1565 " </xs:complexType>{0}" +
1566 " </xs:element>{0}" +
1567 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchema\">{0}" +
1568 " <xs:complexType>{0}" +
1569 " <xs:sequence>{0}" +
1570 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1571 " </xs:sequence>{0}" +
1572 " </xs:complexType>{0}" +
1573 " </xs:element>{0}" +
1575 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1577 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\">{0}" +
1578 " <xs:complexType>{0}" +
1579 " <xs:sequence>{0}" +
1580 " <xs:element ref=\"xs:schema\" />{0}" +
1582 " </xs:sequence>{0}" +
1583 " </xs:complexType>{0}" +
1584 " </xs:element>{0}" +
1586 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchema\">{0}" +
1587 " <xs:complexType>{0}" +
1588 " <xs:sequence>{0}" +
1589 " <xs:any namespace=\"\" />{0}" +
1590 " </xs:sequence>{0}" +
1591 " </xs:complexType>{0}" +
1592 " </xs:element>{0}" +
1594 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\" type=\"xs:int\" />{0}" +
1595 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveNamespace\" />{0}" +
1596 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaNamespace\" />{0}" +
1597 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:SlaveSchemaProviderNamespace\" />{0}" +
1598 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaNamespace\" />{0}" +
1599 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:NativeSchemaProviderNamespace\" />{0}" +
1600 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveNSOnly\" />{0}" +
1601 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaNSOnly\" />{0}" +
1602 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:SlaveSchemaProviderNSOnly\" />{0}" +
1603 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaNSOnly\" />{0}" +
1604 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q11=\"urn:types-devx-com\" ref=\"q11:NativeSchemaProviderNSOnly\" />{0}" +
1606 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\">{0}" +
1607 " <xs:complexType>{0}" +
1608 " <xs:sequence>{0}" +
1609 " <xs:element ref=\"xs:schema\" />{0}" +
1611 " </xs:sequence>{0}" +
1612 " </xs:complexType>{0}" +
1613 " </xs:element>{0}" +
1614 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q1=\"urn:types-devx-com\" ref=\"q1:SlaveNamespace\" />{0}" +
1615 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveSchemaNamespace\" />{0}" +
1616 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaProviderNamespace\" />{0}" +
1617 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:NativeSchemaNamespace\" />{0}" +
1618 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaProviderNamespace\" />{0}" +
1619 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:SlaveNSOnly\" />{0}" +
1620 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveSchemaNSOnly\" />{0}" +
1621 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaProviderNSOnly\" />{0}" +
1622 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:NativeSchemaNSOnly\" />{0}" +
1623 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaProviderNSOnly\" />{0}" +
1625 " </xs:sequence>{0}" +
1626 " </xs:complexType>{0}" +
1627 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1629 sw.GetStringBuilder ().Length = 0;
1630 schemas[1].Write (sw);
1632 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1633 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1634 "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1635 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1637 " <xs:import />{0}" +
1639 " <xs:complexType name=\"employeeRoot\">{0}" +
1640 " <xs:attribute name=\"firstName\" />{0}" +
1641 " <xs:attribute name=\"lastName\" />{0}" +
1642 " <xs:attribute name=\"address\" />{0}" +
1643 " </xs:complexType>{0}" +
1644 " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1645 " <xs:element name=\"SlaveNamespace\">{0}" +
1646 " <xs:complexType>{0}" +
1647 " <xs:sequence>{0}" +
1648 " <xs:element ref=\"xs:schema\" />{0}" +
1650 " </xs:sequence>{0}" +
1651 " </xs:complexType>{0}" +
1652 " </xs:element>{0}" +
1653 " <xs:element name=\"SlaveSchemaNamespace\">{0}" +
1654 " <xs:complexType>{0}" +
1655 " <xs:sequence>{0}" +
1656 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1657 " </xs:sequence>{0}" +
1658 " </xs:complexType>{0}" +
1659 " </xs:element>{0}" +
1661 " <xs:element name=\"SlaveSchemaProviderNamespace\" type=\"tns:employeeRoot\" />{0}" +
1663 " <xs:element name=\"SlaveSchemaProviderNamespace\">{0}" +
1664 " <xs:complexType>{0}" +
1665 " <xs:sequence>{0}" +
1666 " <xs:element ref=\"xs:schema\" />{0}" +
1668 " </xs:sequence>{0}" +
1669 " </xs:complexType>{0}" +
1670 " </xs:element>{0}" +
1672 " <xs:element name=\"NativeSchemaNamespace\">{0}" +
1673 " <xs:complexType>{0}" +
1674 " <xs:sequence>{0}" +
1675 " <xs:any namespace=\"\" />{0}" +
1676 " </xs:sequence>{0}" +
1677 " </xs:complexType>{0}" +
1678 " </xs:element>{0}" +
1680 " <xs:element name=\"NativeSchemaProviderNamespace\" type=\"xs:int\" />{0}" +
1682 " <xs:element name=\"NativeSchemaProviderNamespace\">{0}" +
1683 " <xs:complexType>{0}" +
1684 " <xs:sequence>{0}" +
1685 " <xs:element ref=\"xs:schema\" />{0}" +
1687 " </xs:sequence>{0}" +
1688 " </xs:complexType>{0}" +
1689 " </xs:element>{0}" +
1691 " <xs:element name=\"SlaveNSOnly\">{0}" +
1692 " <xs:complexType>{0}" +
1693 " <xs:sequence>{0}" +
1694 " <xs:element ref=\"xs:schema\" />{0}" +
1696 " </xs:sequence>{0}" +
1697 " </xs:complexType>{0}" +
1698 " </xs:element>{0}" +
1699 " <xs:element name=\"SlaveSchemaNSOnly\">{0}" +
1700 " <xs:complexType>{0}" +
1701 " <xs:sequence>{0}" +
1702 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1703 " </xs:sequence>{0}" +
1704 " </xs:complexType>{0}" +
1705 " </xs:element>{0}" +
1707 " <xs:element name=\"SlaveSchemaProviderNSOnly\" type=\"tns:employeeRoot\" />{0}" +
1709 " <xs:element name=\"SlaveSchemaProviderNSOnly\">{0}" +
1710 " <xs:complexType>{0}" +
1711 " <xs:sequence>{0}" +
1712 " <xs:element ref=\"xs:schema\" />{0}" +
1714 " </xs:sequence>{0}" +
1715 " </xs:complexType>{0}" +
1716 " </xs:element>{0}" +
1718 " <xs:element name=\"NativeSchemaNSOnly\">{0}" +
1719 " <xs:complexType>{0}" +
1720 " <xs:sequence>{0}" +
1721 " <xs:any namespace=\"\" />{0}" +
1722 " </xs:sequence>{0}" +
1723 " </xs:complexType>{0}" +
1724 " </xs:element>{0}" +
1726 " <xs:element name=\"NativeSchemaProviderNSOnly\" type=\"xs:int\" />{0}" +
1728 " <xs:element name=\"NativeSchemaProviderNSOnly\">{0}" +
1729 " <xs:complexType>{0}" +
1730 " <xs:sequence>{0}" +
1731 " <xs:element ref=\"xs:schema\" />{0}" +
1733 " </xs:sequence>{0}" +
1734 " </xs:complexType>{0}" +
1735 " </xs:element>{0}" +
1737 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
1739 sw.GetStringBuilder ().Length = 0;
1740 schemas[2].Write (sw);
1742 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1743 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1744 "<xs:schema id=\"LuckyNumberSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1745 " <xs:element name=\"LuckyNumber\" type=\"xs:int\" />{0}" +
1746 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1750 [Category ("NotDotNet")] // Mono bug ##77117
1751 public void ExportXsdPrimitive ()
1753 ArrayList types = new ArrayList ();
1754 types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte"));
1755 types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte"));
1756 types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean"));
1757 types.Add (new TypeDescription (typeof (short), true, "short", "Short"));
1758 types.Add (new TypeDescription (typeof (int), true, "int", "Int"));
1759 types.Add (new TypeDescription (typeof (long), true, "long", "Long"));
1760 types.Add (new TypeDescription (typeof (float), true, "float", "Float"));
1761 types.Add (new TypeDescription (typeof (double), true, "double", "Double"));
1762 types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal"));
1763 types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort"));
1764 types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt"));
1765 types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong"));
1766 types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime"));
1768 types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true));
1770 types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName"));
1772 types.Add (new TypeDescription (typeof (string), true, "string", "String", true));
1774 foreach (TypeDescription typeDesc in types) {
1775 XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
1776 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
1778 StringWriter sw = new StringWriter ();
1779 schemas[0].Write (sw);
1781 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1782 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1783 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1784 " <xs:element name=\"{2}\" {3}type=\"xs:{2}\" />{0}" +
1785 "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.XmlType, ""),
1786 sw.ToString (), typeDesc.Type.FullName + "#2");
1788 schemas = Export (typeDesc.Type);
1789 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
1791 sw.GetStringBuilder ().Length = 0;
1792 schemas[0].Write (sw);
1794 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1795 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1796 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1797 " <xs:element name=\"{1}\" {2}type=\"xs:{1}\" />{0}" +
1798 "</xs:schema>", Environment.NewLine, typeDesc.XmlType, ""),
1799 sw.ToString (), typeDesc.Type.FullName + "#4");
1804 [Category ("NotDotNet")] // Mono bug ##77117
1805 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1806 public void ExportXsdPrimitive_Object ()
1808 XmlSchemas schemas = Export (typeof (object), "NSAnyType");
1809 Assert.AreEqual (1, schemas.Count, "#1");
1811 StringWriter sw = new StringWriter ();
1812 schemas[0].Write (sw);
1814 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1815 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1816 "<xs:schema xmlns:tns=\"NSAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1817 " <xs:element name=\"anyType\" />{0}" +
1818 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1820 schemas = Export (typeof (object));
1821 Assert.AreEqual (1, schemas.Count, "#3");
1823 sw.GetStringBuilder ().Length = 0;
1824 schemas[0].Write (sw);
1826 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1827 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1828 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1829 " <xs:element name=\"anyType\" />{0}" +
1830 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1834 [Category ("NotDotNet")] // Mono bug ##77117
1835 public void ExportXsdPrimitive_ByteArray ()
1837 XmlSchemas schemas = Export (typeof (byte[]), "NSByteArray");
1838 Assert.AreEqual (1, schemas.Count, "#1");
1840 StringWriter sw = new StringWriter ();
1841 schemas[0].Write (sw);
1843 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1844 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1845 "<xs:schema xmlns:tns=\"NSByteArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSByteArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1846 " <xs:element name=\"base64Binary\" type=\"xs:base64Binary\" />{0}" +
1847 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1849 schemas = Export (typeof (byte[]));
1850 Assert.AreEqual (1, schemas.Count, "#3");
1852 sw.GetStringBuilder ().Length = 0;
1853 schemas[0].Write (sw);
1855 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1856 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1857 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1858 " <xs:element name=\"base64Binary\" type=\"xs:base64Binary\" />{0}" +
1859 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1864 [Category ("NotWorking")] // in 2.0 profile, QName must be nillable
1866 [Category ("NotDotNet")] // Mono bug ##77117
1867 public void ExportXsdPrimitive_Arrays ()
1869 ArrayList types = new ArrayList ();
1870 types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte"));
1871 types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean"));
1872 types.Add (new TypeDescription (typeof (short[]), true, "short", "Short"));
1873 types.Add (new TypeDescription (typeof (int[]), true, "int", "Int"));
1874 types.Add (new TypeDescription (typeof (long[]), true, "long", "Long"));
1875 types.Add (new TypeDescription (typeof (float[]), true, "float", "Float"));
1876 types.Add (new TypeDescription (typeof (double[]), true, "double", "Double"));
1877 types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal"));
1878 types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort"));
1879 types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt"));
1880 types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong"));
1881 types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime"));
1883 types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true));
1885 types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName"));
1887 types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true));
1889 foreach (TypeDescription typeDesc in types) {
1890 XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
1891 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
1893 StringWriter sw = new StringWriter ();
1894 schemas[0].Write (sw);
1896 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1897 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1898 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1899 " <xs:element name=\"ArrayOf{2}\" type=\"tns:ArrayOf{2}\" />{0}" +
1900 " <xs:complexType name=\"ArrayOf{2}\">{0}" +
1901 " <xs:sequence>{0}" +
1902 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{3}\" {5}type=\"{4}:{3}\" />{0}" +
1903 " </xs:sequence>{0}" +
1904 " </xs:complexType>{0}" +
1905 "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType,
1906 typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
1907 sw.ToString (), typeDesc.Type.FullName + "#2");
1909 schemas = Export (typeDesc.Type);
1910 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
1912 sw.GetStringBuilder ().Length = 0;
1913 schemas[0].Write (sw);
1915 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1916 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1917 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1918 " <xs:element name=\"ArrayOf{1}\" type=\"ArrayOf{1}\" />{0}" +
1919 " <xs:complexType name=\"ArrayOf{1}\">{0}" +
1920 " <xs:sequence>{0}" +
1921 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{2}\" {4}type=\"{3}:{2}\" />{0}" +
1922 " </xs:sequence>{0}" +
1923 " </xs:complexType>{0}" +
1924 "</xs:schema>", Environment.NewLine, typeDesc.ArrayType, typeDesc.XmlType,
1925 typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
1926 sw.ToString (), typeDesc.Type.FullName + "#4");
1931 [Category ("NotDotNet")] // Mono bug ##77117
1932 public void ExportXsdPrimitive_Object_Arrays ()
1934 XmlSchemas schemas = Export (typeof (object[]), "NSArrayOfAnyType");
1935 Assert.AreEqual (1, schemas.Count, "#1");
1937 StringWriter sw = new StringWriter ();
1938 schemas[0].Write (sw);
1940 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1941 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1942 "<xs:schema xmlns:tns=\"NSArrayOfAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayOfAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1943 " <xs:element name=\"ArrayOfAnyType\" type=\"tns:ArrayOfAnyType\" />{0}" +
1944 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1945 " <xs:sequence>{0}" +
1946 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1947 " </xs:sequence>{0}" +
1948 " </xs:complexType>{0}" +
1949 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1951 schemas = Export (typeof (object[]));
1952 Assert.AreEqual (1, schemas.Count, "#3");
1954 sw.GetStringBuilder ().Length = 0;
1955 schemas[0].Write (sw);
1957 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1958 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1959 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1960 " <xs:element name=\"ArrayOfAnyType\" type=\"ArrayOfAnyType\" />{0}" +
1961 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1962 " <xs:sequence>{0}" +
1963 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1964 " </xs:sequence>{0}" +
1965 " </xs:complexType>{0}" +
1966 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1970 public void ExportNonXsdPrimitive_Guid ()
1972 XmlSchemas schemas = Export (typeof (Guid), "NSPrimGuid");
1973 Assert.AreEqual (2, schemas.Count, "#1");
1975 StringWriter sw = new StringWriter ();
1976 schemas[0].Write (sw);
1978 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1979 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1980 "<xs:schema xmlns:tns=\"NSPrimGuid\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimGuid\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1981 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
1982 " <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
1983 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1985 sw.GetStringBuilder ().Length = 0;
1986 schemas[1].Write (sw);
1988 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1989 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1990 "<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}" +
1991 " <xs:simpleType name=\"guid\">{0}" +
1992 " <xs:restriction base=\"xs:string\">{0}" +
1993 " <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}" +
1994 " </xs:restriction>{0}" +
1995 " </xs:simpleType>{0}" +
1996 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
1998 schemas = Export (typeof (Guid));
1999 Assert.AreEqual (2, schemas.Count, "#4");
2001 sw.GetStringBuilder ().Length = 0;
2002 schemas[0].Write (sw);
2004 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2005 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2006 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2007 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2008 " <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
2009 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
2011 sw.GetStringBuilder ().Length = 0;
2012 schemas[1].Write (sw);
2014 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2015 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2016 "<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}" +
2017 " <xs:simpleType name=\"guid\">{0}" +
2018 " <xs:restriction base=\"xs:string\">{0}" +
2019 " <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}" +
2020 " </xs:restriction>{0}" +
2021 " </xs:simpleType>{0}" +
2022 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
2026 public void ExportNonXsdPrimitive_Char ()
2028 XmlSchemas schemas = Export (typeof (char), "NSPrimChar");
2029 Assert.AreEqual (2, schemas.Count, "#1");
2031 StringWriter sw = new StringWriter ();
2032 schemas[0].Write (sw);
2034 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2035 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2036 "<xs:schema xmlns:tns=\"NSPrimChar\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimChar\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2037 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2038 " <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
2039 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2041 sw.GetStringBuilder ().Length = 0;
2042 schemas[1].Write (sw);
2044 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2045 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2046 "<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}" +
2047 " <xs:simpleType name=\"char\">{0}" +
2048 " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
2049 " </xs:simpleType>{0}" +
2050 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
2052 schemas = Export (typeof (char));
2053 Assert.AreEqual (2, schemas.Count, "#4");
2055 sw.GetStringBuilder ().Length = 0;
2056 schemas[0].Write (sw);
2058 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2059 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2060 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2061 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2062 " <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
2063 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
2065 sw.GetStringBuilder ().Length = 0;
2066 schemas[1].Write (sw);
2068 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2069 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2070 "<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}" +
2071 " <xs:simpleType name=\"char\">{0}" +
2072 " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
2073 " </xs:simpleType>{0}" +
2074 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
2077 public class Employee : IXmlSerializable
2079 private string _firstName;
2080 private string _lastName;
2081 private string _address;
2083 public virtual XmlSchema GetSchema ()
2088 public void WriteXml (XmlWriter writer)
2090 writer.WriteStartElement ("employee", "urn:devx-com");
2091 writer.WriteAttributeString ("firstName", _firstName);
2092 writer.WriteAttributeString ("lastName", _lastName);
2093 writer.WriteAttributeString ("address", _address);
2094 writer.WriteEndElement ();
2097 public void ReadXml (XmlReader reader)
2099 XmlNodeType type = reader.MoveToContent ();
2100 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2101 _firstName = reader["firstName"];
2102 _lastName = reader["lastName"];
2103 _address = reader["address"];
2108 public class EmployeeSchema : IXmlSerializable
2110 private string _firstName;
2111 private string _lastName;
2112 private string _address;
2114 public virtual XmlSchema GetSchema ()
2116 return CreateSchema ();
2119 public void WriteXml (XmlWriter writer)
2121 writer.WriteStartElement ("employee", "urn:devx-com");
2122 writer.WriteAttributeString ("firstName", _firstName);
2123 writer.WriteAttributeString ("lastName", _lastName);
2124 writer.WriteAttributeString ("address", _address);
2125 writer.WriteEndElement ();
2128 public void ReadXml (XmlReader reader)
2130 XmlNodeType type = reader.MoveToContent ();
2131 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2132 _firstName = reader["firstName"];
2133 _lastName = reader["lastName"];
2134 _address = reader["address"];
2138 protected static XmlSchema CreateSchema ()
2140 XmlSchema schema = new XmlSchema ();
2141 schema.Id = "EmployeeSchema";
2142 schema.TargetNamespace = "urn:types-devx-com";
2144 XmlSchemaComplexType type = new XmlSchemaComplexType ();
2145 type.Name = "employeeRoot";
2146 XmlSchemaAttribute firstNameAttr = new XmlSchemaAttribute ();
2147 firstNameAttr.Name = "firstName";
2148 type.Attributes.Add (firstNameAttr);
2150 XmlSchemaAttribute lastNameAttr = new XmlSchemaAttribute ();
2151 lastNameAttr.Name = "lastName";
2152 type.Attributes.Add (lastNameAttr);
2154 XmlSchemaAttribute addressAttr = new XmlSchemaAttribute ();
2155 addressAttr.Name = "address";
2156 type.Attributes.Add (addressAttr);
2158 XmlSchemaElement employeeElement = new XmlSchemaElement ();
2159 employeeElement.Name = "employee";
2160 XmlQualifiedName name = new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
2161 employeeElement.SchemaTypeName = name;
2163 schema.Items.Add (type);
2164 schema.Items.Add (employeeElement);
2169 public class PrimitiveSchema : IXmlSerializable
2171 private string _firstName;
2172 private string _lastName;
2173 private string _address;
2175 public virtual XmlSchema GetSchema ()
2177 XmlSchema schema = new XmlSchema ();
2178 schema.Id = "LuckyNumberSchema";
2179 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2180 luckyNumberElement.Name = "LuckyNumber";
2181 luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
2182 schema.Items.Add (luckyNumberElement);
2186 public void WriteXml (XmlWriter writer)
2188 writer.WriteStartElement ("employee", "urn:devx-com");
2189 writer.WriteAttributeString ("firstName", _firstName);
2190 writer.WriteAttributeString ("lastName", _lastName);
2191 writer.WriteAttributeString ("address", _address);
2192 writer.WriteEndElement ();
2195 public void ReadXml (XmlReader reader)
2197 XmlNodeType type = reader.MoveToContent ();
2198 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2199 _firstName = reader["firstName"];
2200 _lastName = reader["lastName"];
2201 _address = reader["address"];
2206 public class MissingIDSchema : IXmlSerializable
2208 private string _firstName;
2209 private string _lastName;
2210 private string _address;
2212 public virtual XmlSchema GetSchema ()
2214 XmlSchema schema = new XmlSchema ();
2215 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2216 luckyNumberElement.Name = "LuckyNumber";
2217 luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
2221 public void WriteXml (XmlWriter writer)
2223 writer.WriteStartElement ("employee", "urn:devx-com");
2224 writer.WriteAttributeString ("firstName", _firstName);
2225 writer.WriteAttributeString ("lastName", _lastName);
2226 writer.WriteAttributeString ("address", _address);
2227 writer.WriteEndElement ();
2230 public void ReadXml (XmlReader reader)
2232 XmlNodeType type = reader.MoveToContent ();
2233 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2234 _firstName = reader["firstName"];
2235 _lastName = reader["lastName"];
2236 _address = reader["address"];
2242 [XmlSchemaProvider ("CreateEmployeeSchema")]
2244 public class EmployeeSchemaProvider : EmployeeSchema
2247 public static XmlQualifiedName CreateEmployeeSchema (XmlSchemaSet schemaSet)
2249 schemaSet.Add (CreateSchema ());
2250 return new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
2253 public override XmlSchema GetSchema ()
2261 [XmlSchemaProvider ("CreateLuckyNumberSchema")]
2263 public class PrimitiveSchemaProvider : IXmlSerializable
2266 public static XmlQualifiedName CreateLuckyNumberSchema (XmlSchemaSet schemaSet)
2268 XmlSchema schema = new XmlSchema ();
2270 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2271 luckyNumberElement.Name = "LuckyNumber";
2273 XmlQualifiedName typeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");
2274 luckyNumberElement.SchemaTypeName = typeName;
2275 schema.Items.Add (luckyNumberElement);
2277 schemaSet.Add (schema);
2282 public XmlSchema GetSchema ()
2287 public void WriteXml (XmlWriter writer)
2289 writer.WriteElementString ("LuckyNumber", "7");
2292 public void ReadXml (XmlReader reader)
2294 XmlNodeType type = reader.MoveToContent ();
2295 if (type == XmlNodeType.Element && reader.LocalName == "LuckyNumber") {
2300 private class TypeDescription
2302 public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType) : this (type, xsdType, xmlType, arrayType, false)
2306 public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable)
2311 _arrayType = arrayType;
2312 _isNillable = isNillable;
2316 get { return _type; }
2319 public string XmlType {
2320 get { return _xmlType; }
2323 public string ArrayType {
2324 get { return _arrayType; }
2327 public bool XsdType {
2328 get { return _xsdType; }
2331 public bool IsNillable {
2332 get { return _isNillable; }
2336 private bool _xsdType;
2337 private string _xmlType;
2338 private string _arrayType;
2339 private bool _isNillable;
2342 public class StructContainer
2344 public EnumDefaultValue Value;
2345 public TimeSpan[] Times;
2348 public class XmlSerializableContainer
2350 public Employee Slave;
2351 public EmployeeSchema SlaveSchema;
2352 public EmployeeSchemaProvider SlaveSchemaProvider;
2353 public PrimitiveSchema NativeSchema;
2354 public PrimitiveSchemaProvider NativeSchemaProvider;
2356 [XmlElement ("SlaveNamespace", Namespace = "urn:types-devx-com")]
2357 public Employee SlaveNS;
2358 [XmlElement ("SlaveSchemaNamespace", Namespace = "urn:types-devx-com")]
2359 public EmployeeSchema SlaveSchemaNS;
2360 [XmlElement ("SlaveSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
2361 public EmployeeSchemaProvider SlaveSchemaProviderNS;
2362 [XmlElement ("NativeSchemaNamespace", Namespace = "urn:types-devx-com")]
2363 public PrimitiveSchema NativeSchemaNS;
2364 [XmlElement ("NativeSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
2365 public PrimitiveSchemaProvider NativeSchemaProviderNS;
2368 [XmlElement (Namespace = "urn:types-devx-com")]
2369 public Employee SlaveNSOnly;
2370 [XmlElement (Namespace = "urn:types-devx-com")]
2371 public EmployeeSchema SlaveSchemaNSOnly;
2372 [XmlElement (Namespace = "urn:types-devx-com")]
2373 public EmployeeSchemaProvider SlaveSchemaProviderNSOnly;
2374 [XmlElement (Namespace = "urn:types-devx-com")]
2375 public PrimitiveSchema NativeSchemaNSOnly;
2376 [XmlElement (Namespace = "urn:types-devx-com")]
2377 public PrimitiveSchemaProvider NativeSchemaProviderNSOnly;