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 ("NotWorking")] // mark it NotWorking until fixes have landed in svn
90 public void ExportStruct_Array ()
92 XmlSchemas schemas = Export (typeof (TimeSpan[]), "NSTimeSpanArray");
93 Assert.AreEqual (1, schemas.Count, "#1");
95 StringWriter sw = new StringWriter ();
96 schemas[0].Write (sw);
98 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
99 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
100 "<xs:schema xmlns:tns=\"NSTimeSpanArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpanArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
102 " <xs:element name=\"ArrayOfTimeSpan\" nillable=\"true\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
104 " <xs:element name=\"ArrayOfTimeSpan\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
106 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
107 " <xs:sequence>{0}" +
109 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
111 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"tns:TimeSpan\" />{0}" +
113 " </xs:sequence>{0}" +
114 " </xs:complexType>{0}" +
115 " <xs:complexType name=\"TimeSpan\" />{0}" +
116 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
118 schemas = Export (typeof (TimeSpan[]));
119 Assert.AreEqual (1, schemas.Count, "#3");
121 sw.GetStringBuilder ().Length = 0;
122 schemas[0].Write (sw);
124 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
125 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
126 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
128 " <xs:element name=\"ArrayOfTimeSpan\" nillable=\"true\" type=\"ArrayOfTimeSpan\" />{0}" +
130 " <xs:element name=\"ArrayOfTimeSpan\" type=\"ArrayOfTimeSpan\" />{0}" +
132 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
133 " <xs:sequence>{0}" +
135 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
137 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"TimeSpan\" />{0}" +
139 " </xs:sequence>{0}" +
140 " </xs:complexType>{0}" +
141 " <xs:complexType name=\"TimeSpan\" />{0}" +
142 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
146 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
147 public void ExportClass_SimpleClass ()
149 XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
150 XmlAttributes attr = new XmlAttributes ();
151 XmlElementAttribute element = new XmlElementAttribute ();
152 element.ElementName = "saying";
153 element.IsNullable = true;
154 attr.XmlElements.Add (element);
155 overrides.Add (typeof (SimpleClass), "something", attr);
157 XmlSchemas schemas = Export (typeof (SimpleClass), overrides, "NSSimpleClass");
158 Assert.AreEqual (1, schemas.Count, "#1");
160 StringWriter sw = new StringWriter ();
161 schemas[0].Write (sw);
163 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
164 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
165 "<xs:schema xmlns:tns=\"NSSimpleClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
167 " <xs:element name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
169 " <xs:element name=\"SimpleClass\" type=\"tns:SimpleClass\" />{0}" +
171 " <xs:complexType name=\"SimpleClass\">{0}" +
172 " <xs:sequence>{0}" +
173 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
174 " </xs:sequence>{0}" +
175 " </xs:complexType>{0}" +
176 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
178 schemas = Export (typeof (SimpleClass), overrides);
179 Assert.AreEqual (1, schemas.Count, "#3");
181 sw.GetStringBuilder ().Length = 0;
182 schemas[0].Write (sw);
184 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
185 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
186 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
188 " <xs:element name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
190 " <xs:element name=\"SimpleClass\" type=\"SimpleClass\" />{0}" +
192 " <xs:complexType name=\"SimpleClass\">{0}" +
193 " <xs:sequence>{0}" +
194 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
195 " </xs:sequence>{0}" +
196 " </xs:complexType>{0}" +
197 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
201 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
202 public void ExportClass_StringCollection ()
204 XmlSchemas schemas = Export (typeof (StringCollection), "NSStringCollection");
205 Assert.AreEqual (1, schemas.Count, "#1");
207 StringWriter sw = new StringWriter ();
208 schemas[0].Write (sw);
210 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
211 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
212 "<xs:schema xmlns:tns=\"NSStringCollection\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollection\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
214 " <xs:element name=\"ArrayOfString\" nillable=\"true\" type=\"tns:ArrayOfString\" />{0}" +
216 " <xs:element name=\"ArrayOfString\" type=\"tns:ArrayOfString\" />{0}" +
218 " <xs:complexType name=\"ArrayOfString\">{0}" +
219 " <xs:sequence>{0}" +
220 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
221 " </xs:sequence>{0}" +
222 " </xs:complexType>{0}" +
223 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
225 schemas = Export (typeof (StringCollection));
226 Assert.AreEqual (1, schemas.Count, "#3");
228 sw.GetStringBuilder ().Length = 0;
229 schemas[0].Write (sw);
231 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
232 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
233 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
235 " <xs:element name=\"ArrayOfString\" nillable=\"true\" type=\"ArrayOfString\" />{0}" +
237 " <xs:element name=\"ArrayOfString\" type=\"ArrayOfString\" />{0}" +
239 " <xs:complexType name=\"ArrayOfString\">{0}" +
240 " <xs:sequence>{0}" +
241 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
242 " </xs:sequence>{0}" +
243 " </xs:complexType>{0}" +
244 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
248 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
249 public void ExportClass_StringCollectionContainer ()
251 XmlSchemas schemas = Export (typeof (StringCollectionContainer), "NSStringCollectionContainer");
252 Assert.AreEqual (1, schemas.Count, "#1");
254 StringWriter sw = new StringWriter ();
255 schemas[0].Write (sw);
257 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
258 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
259 "<xs:schema xmlns:tns=\"NSStringCollectionContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollectionContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
261 " <xs:element name=\"StringCollectionContainer\" nillable=\"true\" type=\"tns:StringCollectionContainer\" />{0}" +
263 " <xs:element name=\"StringCollectionContainer\" type=\"tns:StringCollectionContainer\" />{0}" +
265 " <xs:complexType name=\"StringCollectionContainer\">{0}" +
266 " <xs:sequence>{0}" +
267 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"tns:ArrayOfString\" />{0}" +
268 " </xs:sequence>{0}" +
269 " </xs:complexType>{0}" +
270 " <xs:complexType name=\"ArrayOfString\">{0}" +
271 " <xs:sequence>{0}" +
272 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
273 " </xs:sequence>{0}" +
274 " </xs:complexType>{0}" +
275 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
277 schemas = Export (typeof (StringCollectionContainer));
278 Assert.AreEqual (1, schemas.Count, "#3");
280 sw.GetStringBuilder ().Length = 0;
281 schemas[0].Write (sw);
283 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
284 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
285 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
287 " <xs:element name=\"StringCollectionContainer\" nillable=\"true\" type=\"StringCollectionContainer\" />{0}" +
289 " <xs:element name=\"StringCollectionContainer\" type=\"StringCollectionContainer\" />{0}" +
291 " <xs:complexType name=\"StringCollectionContainer\">{0}" +
292 " <xs:sequence>{0}" +
293 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"ArrayOfString\" />{0}" +
294 " </xs:sequence>{0}" +
295 " </xs:complexType>{0}" +
296 " <xs:complexType name=\"ArrayOfString\">{0}" +
297 " <xs:sequence>{0}" +
298 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
299 " </xs:sequence>{0}" +
300 " </xs:complexType>{0}" +
301 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
305 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
306 public void ExportClass_ArrayContainer ()
308 XmlSchemas schemas = Export (typeof (ArrayContainer), "NSArrayContainer");
309 Assert.AreEqual (1, schemas.Count, "#1");
311 StringWriter sw = new StringWriter ();
312 schemas[0].Write (sw);
314 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
315 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
316 "<xs:schema xmlns:tns=\"NSArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
318 " <xs:element name=\"ArrayContainer\" nillable=\"true\" type=\"tns:ArrayContainer\" />{0}" +
320 " <xs:element name=\"ArrayContainer\" type=\"tns:ArrayContainer\" />{0}" +
322 " <xs:complexType name=\"ArrayContainer\">{0}" +
323 " <xs:sequence>{0}" +
324 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfAnyType\" />{0}" +
325 " </xs:sequence>{0}" +
326 " </xs:complexType>{0}" +
327 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
328 " <xs:sequence>{0}" +
329 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
330 " </xs:sequence>{0}" +
331 " </xs:complexType>{0}" +
332 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
334 schemas = Export (typeof (ArrayContainer));
335 Assert.AreEqual (1, schemas.Count, "#3");
337 sw.GetStringBuilder ().Length = 0;
338 schemas[0].Write (sw);
340 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
341 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
342 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
344 " <xs:element name=\"ArrayContainer\" nillable=\"true\" type=\"ArrayContainer\" />{0}" +
346 " <xs:element name=\"ArrayContainer\" type=\"ArrayContainer\" />{0}" +
348 " <xs:complexType name=\"ArrayContainer\">{0}" +
349 " <xs:sequence>{0}" +
350 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfAnyType\" />{0}" +
351 " </xs:sequence>{0}" +
352 " </xs:complexType>{0}" +
353 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
354 " <xs:sequence>{0}" +
355 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
356 " </xs:sequence>{0}" +
357 " </xs:complexType>{0}" +
358 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
362 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
363 public void ExportClass_ClassArrayContainer ()
365 XmlSchemas schemas = Export (typeof (ClassArrayContainer), "NSClassArrayContainer");
366 Assert.AreEqual (1, schemas.Count, "#1");
368 StringWriter sw = new StringWriter ();
369 schemas[0].Write (sw);
371 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
372 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
373 "<xs:schema xmlns:tns=\"NSClassArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSClassArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
375 " <xs:element name=\"ClassArrayContainer\" nillable=\"true\" type=\"tns:ClassArrayContainer\" />{0}" +
377 " <xs:element name=\"ClassArrayContainer\" type=\"tns:ClassArrayContainer\" />{0}" +
379 " <xs:complexType name=\"ClassArrayContainer\">{0}" +
380 " <xs:sequence>{0}" +
381 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
382 " </xs:sequence>{0}" +
383 " </xs:complexType>{0}" +
384 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
385 " <xs:sequence>{0}" +
386 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
387 " </xs:sequence>{0}" +
388 " </xs:complexType>{0}" +
389 " <xs:complexType name=\"SimpleClass\">{0}" +
390 " <xs:sequence>{0}" +
391 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
392 " </xs:sequence>{0}" +
393 " </xs:complexType>{0}" +
394 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
396 schemas = Export (typeof (ClassArrayContainer));
397 Assert.AreEqual (1, schemas.Count, "#3");
399 sw.GetStringBuilder ().Length = 0;
400 schemas[0].Write (sw);
402 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
403 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
404 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
406 " <xs:element name=\"ClassArrayContainer\" nillable=\"true\" type=\"ClassArrayContainer\" />{0}" +
408 " <xs:element name=\"ClassArrayContainer\" type=\"ClassArrayContainer\" />{0}" +
410 " <xs:complexType name=\"ClassArrayContainer\">{0}" +
411 " <xs:sequence>{0}" +
412 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfSimpleClass\" />{0}" +
413 " </xs:sequence>{0}" +
414 " </xs:complexType>{0}" +
415 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
416 " <xs:sequence>{0}" +
417 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
418 " </xs:sequence>{0}" +
419 " </xs:complexType>{0}" +
420 " <xs:complexType name=\"SimpleClass\">{0}" +
421 " <xs:sequence>{0}" +
422 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
423 " </xs:sequence>{0}" +
424 " </xs:complexType>{0}" +
425 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
429 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
430 public void ExportClass_SimpleClassWithXmlAttributes ()
432 XmlSchemas schemas = Export (typeof (SimpleClassWithXmlAttributes), "NSSimpleClassWithXmlAttributes");
433 Assert.AreEqual (1, schemas.Count, "#1");
435 StringWriter sw = new StringWriter ();
436 schemas[0].Write (sw);
438 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
439 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
440 "<xs:schema xmlns:tns=\"NSSimpleClassWithXmlAttributes\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassWithXmlAttributes\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
442 " <xs:element name=\"simple\" nillable=\"true\" type=\"tns:SimpleClassWithXmlAttributes\" />{0}" +
444 " <xs:element name=\"simple\" type=\"tns:SimpleClassWithXmlAttributes\" />{0}" +
446 " <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
447 " <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
448 " </xs:complexType>{0}" +
449 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
451 schemas = Export (typeof (SimpleClassWithXmlAttributes));
452 Assert.AreEqual (1, schemas.Count, "#3");
454 sw.GetStringBuilder ().Length = 0;
455 schemas[0].Write (sw);
457 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
458 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
459 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
461 " <xs:element name=\"simple\" nillable=\"true\" type=\"SimpleClassWithXmlAttributes\" />{0}" +
463 " <xs:element name=\"simple\" type=\"SimpleClassWithXmlAttributes\" />{0}" +
465 " <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
466 " <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
467 " </xs:complexType>{0}" +
468 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
472 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
473 public void ExportClass_Field ()
475 XmlSchemas schemas = Export (typeof (Field), "NSField");
476 Assert.AreEqual (1, schemas.Count, "#1");
478 StringWriter sw = new StringWriter ();
479 schemas[0].Write (sw);
481 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
482 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
483 "<xs:schema xmlns:tns=\"NSField\" elementFormDefault=\"qualified\" targetNamespace=\"NSField\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
485 " <xs:element name=\"field\" nillable=\"true\" type=\"tns:Field\" />{0}" +
487 " <xs:element name=\"field\" type=\"tns:Field\" />{0}" +
489 " <xs:complexType name=\"Field\">{0}" +
490 " <xs:attribute name=\"modifiers\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
491 " <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
492 #if MS // Mono does not yet translate default values to corresponding enum fields
493 " <xs:attribute default=\"public\" name=\"modifiers3\" type=\"tns:MapModifiers\" />{0}" +
494 " <xs:attribute default=\"public\" form=\"unqualified\" name=\"modifiers4\" type=\"tns:MapModifiers\" />{0}" +
496 " <xs:attribute default=\"0\" name=\"modifiers3\" type=\"tns:MapModifiers\" />{0}" +
497 " <xs:attribute default=\"0\" form=\"unqualified\" name=\"modifiers4\" type=\"tns:MapModifiers\" />{0}" +
499 " <xs:attribute name=\"names\">{0}" +
500 " <xs:simpleType>{0}" +
501 " <xs:list itemType=\"xs:string\" />{0}" +
502 " </xs:simpleType>{0}" +
503 " </xs:attribute>{0}" +
504 " <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
505 " </xs:complexType>{0}" +
506 " <xs:simpleType name=\"MapModifiers\">{0}" +
508 " <xs:simpleType>{0}" +
509 " <xs:restriction base=\"xs:string\">{0}" +
510 " <xs:enumeration value=\"public\" />{0}" +
511 " <xs:enumeration value=\"protected\" />{0}" +
512 " </xs:restriction>{0}" +
513 " </xs:simpleType>{0}" +
515 " </xs:simpleType>{0}" +
516 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
518 schemas = Export (typeof (Field));
519 Assert.AreEqual (1, schemas.Count, "#3");
521 sw.GetStringBuilder ().Length = 0;
522 schemas[0].Write (sw);
524 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
525 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
526 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
528 " <xs:element name=\"field\" nillable=\"true\" type=\"Field\" />{0}" +
530 " <xs:element name=\"field\" type=\"Field\" />{0}" +
532 " <xs:complexType name=\"Field\">{0}" +
533 " <xs:attribute name=\"modifiers\" type=\"MapModifiers\" use=\"required\" />{0}" +
534 " <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"MapModifiers\" use=\"required\" />{0}" +
535 #if MS // Mono does not yet translate default values to corresponding enum fields
536 " <xs:attribute default=\"public\" name=\"modifiers3\" type=\"MapModifiers\" />{0}" +
537 " <xs:attribute default=\"public\" form=\"unqualified\" name=\"modifiers4\" type=\"MapModifiers\" />{0}" +
539 " <xs:attribute default=\"0\" name=\"modifiers3\" type=\"MapModifiers\" />{0}" +
540 " <xs:attribute default=\"0\" form=\"unqualified\" name=\"modifiers4\" type=\"MapModifiers\" />{0}" +
542 " <xs:attribute name=\"names\">{0}" +
543 " <xs:simpleType>{0}" +
544 " <xs:list itemType=\"xs:string\" />{0}" +
545 " </xs:simpleType>{0}" +
546 " </xs:attribute>{0}" +
547 " <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
548 " </xs:complexType>{0}" +
549 " <xs:simpleType name=\"MapModifiers\">{0}" +
551 " <xs:simpleType>{0}" +
552 " <xs:restriction base=\"xs:string\">{0}" +
553 " <xs:enumeration value=\"public\" />{0}" +
554 " <xs:enumeration value=\"protected\" />{0}" +
555 " </xs:restriction>{0}" +
556 " </xs:simpleType>{0}" +
558 " </xs:simpleType>{0}" +
559 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
563 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
564 public void ExportClass_MyList ()
566 XmlSchemas schemas = Export (typeof (MyList), "NSMyList");
567 Assert.AreEqual (1, schemas.Count, "#1");
569 StringWriter sw = new StringWriter ();
570 schemas[0].Write (sw);
572 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
573 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
574 "<xs:schema xmlns:tns=\"NSMyList\" elementFormDefault=\"qualified\" targetNamespace=\"NSMyList\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
576 " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"tns:ArrayOfAnyType\" />{0}" +
578 " <xs:element name=\"ArrayOfAnyType\" type=\"tns:ArrayOfAnyType\" />{0}" +
580 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
581 " <xs:sequence>{0}" +
582 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
583 " </xs:sequence>{0}" +
584 " </xs:complexType>{0}" +
585 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
587 schemas = Export (typeof (MyList));
588 Assert.AreEqual (1, schemas.Count, "#3");
590 sw.GetStringBuilder ().Length = 0;
591 schemas[0].Write (sw);
593 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
594 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
595 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
597 " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"ArrayOfAnyType\" />{0}" +
599 " <xs:element name=\"ArrayOfAnyType\" type=\"ArrayOfAnyType\" />{0}" +
601 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
602 " <xs:sequence>{0}" +
603 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
604 " </xs:sequence>{0}" +
605 " </xs:complexType>{0}" +
606 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
610 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
611 public void ExportClass_Container ()
613 XmlSchemas schemas = Export (typeof (Container), "NSContainer");
614 Assert.AreEqual (1, schemas.Count, "#1");
616 StringWriter sw = new StringWriter ();
617 schemas[0].Write (sw);
619 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
620 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
621 "<xs:schema xmlns:tns=\"NSContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
623 " <xs:element name=\"Container\" nillable=\"true\" type=\"tns:Container\" />{0}" +
625 " <xs:element name=\"Container\" type=\"tns:Container\" />{0}" +
627 " <xs:complexType name=\"Container\">{0}" +
628 " <xs:sequence>{0}" +
629 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
630 " </xs:sequence>{0}" +
631 " </xs:complexType>{0}" +
632 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
633 " <xs:sequence>{0}" +
634 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
635 " </xs:sequence>{0}" +
636 " </xs:complexType>{0}" +
637 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
639 schemas = Export (typeof (Container));
640 Assert.AreEqual (1, schemas.Count, "#3");
642 sw.GetStringBuilder ().Length = 0;
643 schemas[0].Write (sw);
645 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
646 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
647 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
649 " <xs:element name=\"Container\" nillable=\"true\" type=\"Container\" />{0}" +
651 " <xs:element name=\"Container\" type=\"Container\" />{0}" +
653 " <xs:complexType name=\"Container\">{0}" +
654 " <xs:sequence>{0}" +
655 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
656 " </xs:sequence>{0}" +
657 " </xs:complexType>{0}" +
658 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
659 " <xs:sequence>{0}" +
660 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
661 " </xs:sequence>{0}" +
662 " </xs:complexType>{0}" +
663 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
667 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
668 public void ExportClass_Container2 ()
670 XmlSchemas schemas = Export (typeof (Container2), "NSContainer2");
671 Assert.AreEqual (1, schemas.Count, "#1");
673 StringWriter sw = new StringWriter ();
674 schemas[0].Write (sw);
676 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
677 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
678 "<xs:schema xmlns:tns=\"NSContainer2\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
680 " <xs:element name=\"Container2\" nillable=\"true\" type=\"tns:Container2\" />{0}" +
682 " <xs:element name=\"Container2\" type=\"tns:Container2\" />{0}" +
684 " <xs:complexType name=\"Container2\">{0}" +
685 " <xs:sequence>{0}" +
686 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
687 " </xs:sequence>{0}" +
688 " </xs:complexType>{0}" +
689 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
690 " <xs:sequence>{0}" +
691 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
692 " </xs:sequence>{0}" +
693 " </xs:complexType>{0}" +
694 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
696 schemas = Export (typeof (Container2));
697 Assert.AreEqual (1, schemas.Count, "#3");
699 sw.GetStringBuilder ().Length = 0;
700 schemas[0].Write (sw);
702 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
703 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
704 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
706 " <xs:element name=\"Container2\" nillable=\"true\" type=\"Container2\" />{0}" +
708 " <xs:element name=\"Container2\" type=\"Container2\" />{0}" +
710 " <xs:complexType name=\"Container2\">{0}" +
711 " <xs:sequence>{0}" +
712 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
713 " </xs:sequence>{0}" +
714 " </xs:complexType>{0}" +
715 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
716 " <xs:sequence>{0}" +
717 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
718 " </xs:sequence>{0}" +
719 " </xs:complexType>{0}" +
720 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
724 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
725 [ExpectedException (typeof (InvalidOperationException))] // Cannot use wildcards at the top level of a schema.
726 public void ExportClass_MyElem ()
728 Export (typeof (MyElem), "NSMyElem");
732 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
733 public void ExportClass_CDataContainer ()
735 XmlSchemas schemas = Export (typeof (CDataContainer), "NSCDataContainer");
736 Assert.AreEqual (1, schemas.Count, "#1");
738 StringWriter sw = new StringWriter ();
739 schemas[0].Write (sw);
741 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
742 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
743 "<xs:schema xmlns:tns=\"NSCDataContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSCDataContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
745 " <xs:element name=\"CDataContainer\" nillable=\"true\" type=\"tns:CDataContainer\" />{0}" +
747 " <xs:element name=\"CDataContainer\" type=\"tns:CDataContainer\" />{0}" +
749 " <xs:complexType name=\"CDataContainer\">{0}" +
750 " <xs:sequence>{0}" +
751 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
752 " <xs:complexType mixed=\"true\">{0}" +
753 " <xs:sequence>{0}" +
755 " </xs:sequence>{0}" +
756 " </xs:complexType>{0}" +
757 " </xs:element>{0}" +
758 " </xs:sequence>{0}" +
759 " </xs:complexType>{0}" +
760 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
762 schemas = Export (typeof (CDataContainer));
763 Assert.AreEqual (1, schemas.Count, "#3");
765 sw.GetStringBuilder ().Length = 0;
766 schemas[0].Write (sw);
768 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
769 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
770 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
772 " <xs:element name=\"CDataContainer\" nillable=\"true\" type=\"CDataContainer\" />{0}" +
774 " <xs:element name=\"CDataContainer\" type=\"CDataContainer\" />{0}" +
776 " <xs:complexType name=\"CDataContainer\">{0}" +
777 " <xs:sequence>{0}" +
778 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
779 " <xs:complexType mixed=\"true\">{0}" +
780 " <xs:sequence>{0}" +
782 " </xs:sequence>{0}" +
783 " </xs:complexType>{0}" +
784 " </xs:element>{0}" +
785 " </xs:sequence>{0}" +
786 " </xs:complexType>{0}" +
787 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
791 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
792 public void ExportClass_NodeContainer ()
794 XmlSchemas schemas = Export (typeof (NodeContainer), "NSNodeContainer");
795 Assert.AreEqual (1, schemas.Count, "#1");
797 StringWriter sw = new StringWriter ();
798 schemas[0].Write (sw);
800 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
801 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
802 "<xs:schema xmlns:tns=\"NSNodeContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSNodeContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
804 " <xs:element name=\"NodeContainer\" nillable=\"true\" type=\"tns:NodeContainer\" />{0}" +
806 " <xs:element name=\"NodeContainer\" type=\"tns:NodeContainer\" />{0}" +
808 " <xs:complexType name=\"NodeContainer\">{0}" +
809 " <xs:sequence>{0}" +
810 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
811 " <xs:complexType mixed=\"true\">{0}" +
812 " <xs:sequence>{0}" +
814 " </xs:sequence>{0}" +
815 " </xs:complexType>{0}" +
816 " </xs:element>{0}" +
817 " </xs:sequence>{0}" +
818 " </xs:complexType>{0}" +
819 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
821 schemas = Export (typeof (NodeContainer));
822 Assert.AreEqual (1, schemas.Count, "#3");
824 sw.GetStringBuilder ().Length = 0;
825 schemas[0].Write (sw);
827 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
828 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
829 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
831 " <xs:element name=\"NodeContainer\" nillable=\"true\" type=\"NodeContainer\" />{0}" +
833 " <xs:element name=\"NodeContainer\" type=\"NodeContainer\" />{0}" +
835 " <xs:complexType name=\"NodeContainer\">{0}" +
836 " <xs:sequence>{0}" +
837 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
838 " <xs:complexType mixed=\"true\">{0}" +
839 " <xs:sequence>{0}" +
841 " </xs:sequence>{0}" +
842 " </xs:complexType>{0}" +
843 " </xs:element>{0}" +
844 " </xs:sequence>{0}" +
845 " </xs:complexType>{0}" +
846 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
850 [Category ("NotWorking")] // Mono does not generate the <xs:choice> node
852 [Category ("NotDotNet")] // MS.NET 2.0 randomly modifies the order of the elements!
854 public void ExportClass_Choices ()
856 XmlSchemas schemas = Export (typeof (Choices), "NSChoices");
857 Assert.AreEqual (1, schemas.Count, "#1");
859 StringWriter sw = new StringWriter ();
860 schemas[0].Write (sw);
862 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
863 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
864 "<xs:schema xmlns:tns=\"NSChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
866 " <xs:element name=\"Choices\" nillable=\"true\" type=\"tns:Choices\" />{0}" +
868 " <xs:element name=\"Choices\" type=\"tns:Choices\" />{0}" +
870 " <xs:complexType name=\"Choices\">{0}" +
871 " <xs:sequence>{0}" +
872 " <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
873 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
874 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
875 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
877 " </xs:sequence>{0}" +
878 " </xs:complexType>{0}" +
879 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
881 schemas = Export (typeof (Choices));
882 Assert.AreEqual (1, schemas.Count, "#3");
884 sw.GetStringBuilder ().Length = 0;
885 schemas[0].Write (sw);
887 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
888 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
889 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
891 " <xs:element name=\"Choices\" nillable=\"true\" type=\"Choices\" />{0}" +
893 " <xs:element name=\"Choices\" type=\"Choices\" />{0}" +
895 " <xs:complexType name=\"Choices\">{0}" +
896 " <xs:sequence>{0}" +
897 " <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
898 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
899 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
900 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
902 " </xs:sequence>{0}" +
903 " </xs:complexType>{0}" +
904 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
908 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
910 [Category ("NotDotNet")] // MS.NET 1.x does not escape spaces in a type name, bug is fixed in .NET 2.0
912 public void ExportClass_TestSpace ()
914 XmlSchemas schemas = Export (typeof (TestSpace), "NSTestSpace");
915 Assert.AreEqual (1, schemas.Count, "#1");
917 StringWriter sw = new StringWriter ();
918 schemas[0].Write (sw);
920 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
921 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
922 "<xs:schema xmlns:tns=\"NSTestSpace\" elementFormDefault=\"qualified\" targetNamespace=\"NSTestSpace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
924 " <xs:element name=\"Type_x0020_with_x0020_space\" nillable=\"true\" type=\"tns:Type_x0020_with_x0020_space\" />{0}" +
926 " <xs:element name=\"Type_x0020_with_x0020_space\" type=\"tns:Type_x0020_with_x0020_space\" />{0}" +
928 " <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
929 " <xs:sequence>{0}" +
930 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
931 " </xs:sequence>{0}" +
932 " <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
933 " </xs:complexType>{0}" +
934 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
936 schemas = Export (typeof (TestSpace));
937 Assert.AreEqual (1, schemas.Count, "#3");
939 sw.GetStringBuilder ().Length = 0;
940 schemas[0].Write (sw);
942 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
943 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
944 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
946 " <xs:element name=\"Type_x0020_with_x0020_space\" nillable=\"true\" type=\"Type_x0020_with_x0020_space\" />{0}" +
948 " <xs:element name=\"Type_x0020_with_x0020_space\" type=\"Type_x0020_with_x0020_space\" />{0}" +
950 " <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
951 " <xs:sequence>{0}" +
952 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
953 " </xs:sequence>{0}" +
954 " <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
955 " </xs:complexType>{0}" +
956 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
960 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
961 public void ExportClass_ReadOnlyProperties ()
963 XmlSchemas schemas = Export (typeof (ReadOnlyProperties), "NSReadOnlyProperties");
964 Assert.AreEqual (1, schemas.Count, "#1");
966 StringWriter sw = new StringWriter ();
967 schemas[0].Write (sw);
969 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
970 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
971 "<xs:schema xmlns:tns=\"NSReadOnlyProperties\" elementFormDefault=\"qualified\" targetNamespace=\"NSReadOnlyProperties\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
973 " <xs:element name=\"ReadOnlyProperties\" nillable=\"true\" type=\"tns:ReadOnlyProperties\" />{0}" +
975 " <xs:element name=\"ReadOnlyProperties\" type=\"tns:ReadOnlyProperties\" />{0}" +
977 " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
978 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
980 schemas = Export (typeof (ReadOnlyProperties));
981 Assert.AreEqual (1, schemas.Count, "#3");
983 sw.GetStringBuilder ().Length = 0;
984 schemas[0].Write (sw);
986 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
987 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
988 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
990 " <xs:element name=\"ReadOnlyProperties\" nillable=\"true\" type=\"ReadOnlyProperties\" />{0}" +
992 " <xs:element name=\"ReadOnlyProperties\" type=\"ReadOnlyProperties\" />{0}" +
994 " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
995 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
999 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1000 public void ExportClass_ListDefaults ()
1002 XmlSchemas schemas = Export (typeof (ListDefaults), "NSListDefaults");
1003 Assert.AreEqual (1, schemas.Count, "#1");
1005 StringWriter sw = new StringWriter ();
1006 schemas[0].Write (sw);
1008 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1009 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1010 "<xs:schema xmlns:tns=\"NSListDefaults\" elementFormDefault=\"qualified\" targetNamespace=\"NSListDefaults\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1011 #if MS // bug #77117
1012 " <xs:element name=\"root\" nillable=\"true\" type=\"tns:ListDefaults\" />{0}" +
1014 " <xs:element name=\"root\" type=\"tns:ListDefaults\" />{0}" +
1016 " <xs:complexType name=\"ListDefaults\">{0}" +
1017 " <xs:sequence>{0}" +
1018 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"tns:ArrayOfAnyType\" />{0}" +
1019 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"tns:ArrayOfAnyType\" />{0}" +
1020 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"tns:ArrayOfString\" />{0}" +
1021 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"tns:SimpleClass\" />{0}" +
1022 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"tns:SimpleClass\" />{0}" +
1023 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
1024 " </xs:sequence>{0}" +
1025 " </xs:complexType>{0}" +
1026 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1027 " <xs:sequence>{0}" +
1028 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1029 " </xs:sequence>{0}" +
1030 " </xs:complexType>{0}" +
1031 " <xs:complexType name=\"ArrayOfString\">{0}" +
1032 " <xs:sequence>{0}" +
1033 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
1034 " </xs:sequence>{0}" +
1035 " </xs:complexType>{0}" +
1036 " <xs:complexType name=\"SimpleClass\">{0}" +
1037 " <xs:sequence>{0}" +
1038 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
1039 " </xs:sequence>{0}" +
1040 " </xs:complexType>{0}" +
1041 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1043 schemas = Export (typeof (ListDefaults));
1044 Assert.AreEqual (1, schemas.Count, "#3");
1046 sw.GetStringBuilder ().Length = 0;
1047 schemas[0].Write (sw);
1049 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1050 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1051 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1052 #if MS // bug #77117
1053 " <xs:element name=\"root\" nillable=\"true\" type=\"ListDefaults\" />{0}" +
1055 " <xs:element name=\"root\" type=\"ListDefaults\" />{0}" +
1057 " <xs:complexType name=\"ListDefaults\">{0}" +
1058 " <xs:sequence>{0}" +
1059 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"ArrayOfAnyType\" />{0}" +
1060 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"ArrayOfAnyType\" />{0}" +
1061 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"ArrayOfString\" />{0}" +
1062 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"SimpleClass\" />{0}" +
1063 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"SimpleClass\" />{0}" +
1064 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
1065 " </xs:sequence>{0}" +
1066 " </xs:complexType>{0}" +
1067 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1068 " <xs:sequence>{0}" +
1069 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1070 " </xs:sequence>{0}" +
1071 " </xs:complexType>{0}" +
1072 " <xs:complexType name=\"ArrayOfString\">{0}" +
1073 " <xs:sequence>{0}" +
1074 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
1075 " </xs:sequence>{0}" +
1076 " </xs:complexType>{0}" +
1077 " <xs:complexType name=\"SimpleClass\">{0}" +
1078 " <xs:sequence>{0}" +
1079 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
1080 " </xs:sequence>{0}" +
1081 " </xs:complexType>{0}" +
1082 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1086 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1087 public void ExportClass_ClsPerson ()
1089 XmlSchemas schemas = Export (typeof (clsPerson), "NSClsPerson");
1090 Assert.AreEqual (1, schemas.Count, "#1");
1092 StringWriter sw = new StringWriter ();
1093 schemas[0].Write (sw);
1095 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1096 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1097 "<xs:schema xmlns:tns=\"NSClsPerson\" elementFormDefault=\"qualified\" targetNamespace=\"NSClsPerson\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1098 #if MS // bug #77117
1099 " <xs:element name=\"clsPerson\" nillable=\"true\" type=\"tns:clsPerson\" />{0}" +
1101 " <xs:element name=\"clsPerson\" type=\"tns:clsPerson\" />{0}" +
1103 " <xs:complexType name=\"clsPerson\">{0}" +
1104 " <xs:sequence>{0}" +
1105 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"tns:ArrayOfAnyType\" />{0}" +
1106 " </xs:sequence>{0}" +
1107 " </xs:complexType>{0}" +
1108 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1109 " <xs:sequence>{0}" +
1110 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1111 " </xs:sequence>{0}" +
1112 " </xs:complexType>{0}" +
1113 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1115 schemas = Export (typeof (clsPerson));
1116 Assert.AreEqual (1, schemas.Count, "#3");
1118 sw.GetStringBuilder ().Length = 0;
1119 schemas[0].Write (sw);
1121 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1122 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1123 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1124 #if MS // bug #77117
1125 " <xs:element name=\"clsPerson\" nillable=\"true\" type=\"clsPerson\" />{0}" +
1127 " <xs:element name=\"clsPerson\" type=\"clsPerson\" />{0}" +
1129 " <xs:complexType name=\"clsPerson\">{0}" +
1130 " <xs:sequence>{0}" +
1131 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"ArrayOfAnyType\" />{0}" +
1132 " </xs:sequence>{0}" +
1133 " </xs:complexType>{0}" +
1134 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1135 " <xs:sequence>{0}" +
1136 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1137 " </xs:sequence>{0}" +
1138 " </xs:complexType>{0}" +
1139 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1143 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1144 public void ExportClass_ArrayClass ()
1146 XmlSchemas schemas = Export (typeof (ArrayClass), "NSArrayClass");
1147 Assert.AreEqual (1, schemas.Count, "#1");
1149 StringWriter sw = new StringWriter ();
1150 schemas[0].Write (sw);
1152 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1153 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1154 "<xs:schema xmlns:tns=\"NSArrayClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1155 #if MS // bug #77117
1156 " <xs:element name=\"ArrayClass\" nillable=\"true\" type=\"tns:ArrayClass\" />{0}" +
1158 " <xs:element name=\"ArrayClass\" type=\"tns:ArrayClass\" />{0}" +
1160 " <xs:complexType name=\"ArrayClass\">{0}" +
1161 " <xs:sequence>{0}" +
1162 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"names\" />{0}" +
1163 " </xs:sequence>{0}" +
1164 " </xs:complexType>{0}" +
1165 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1167 schemas = Export (typeof (ArrayClass));
1168 Assert.AreEqual (1, schemas.Count, "#3");
1170 sw.GetStringBuilder ().Length = 0;
1171 schemas[0].Write (sw);
1173 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1174 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1175 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1176 #if MS // bug #77117
1177 " <xs:element name=\"ArrayClass\" nillable=\"true\" type=\"ArrayClass\" />{0}" +
1179 " <xs:element name=\"ArrayClass\" type=\"ArrayClass\" />{0}" +
1181 " <xs:complexType name=\"ArrayClass\">{0}" +
1182 " <xs:sequence>{0}" +
1183 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"names\" />{0}" +
1184 " </xs:sequence>{0}" +
1185 " </xs:complexType>{0}" +
1186 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1190 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1191 public void ExportClass_StructContainer ()
1193 XmlSchemas schemas = Export (typeof (StructContainer), "NSStructContainer");
1194 Assert.AreEqual (1, schemas.Count, "#1");
1196 StringWriter sw = new StringWriter ();
1197 schemas[0].Write (sw);
1199 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1200 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1201 "<xs:schema xmlns:tns=\"NSStructContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStructContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1202 #if MS // bug #77117
1203 " <xs:element name=\"StructContainer\" nillable=\"true\" type=\"tns:StructContainer\" />{0}" +
1205 " <xs:element name=\"StructContainer\" type=\"tns:StructContainer\" />{0}" +
1207 " <xs:complexType name=\"StructContainer\">{0}" +
1208 " <xs:sequence>{0}" +
1209 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"tns:EnumDefaultValue\" />{0}" +
1210 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Times\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
1211 " </xs:sequence>{0}" +
1212 " </xs:complexType>{0}" +
1213 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1215 " <xs:simpleType>{0}" +
1216 " <xs:restriction base=\"xs:string\">{0}" +
1217 " <xs:enumeration value=\"e1\" />{0}" +
1218 " <xs:enumeration value=\"e2\" />{0}" +
1219 " <xs:enumeration value=\"e3\" />{0}" +
1220 " </xs:restriction>{0}" +
1221 " </xs:simpleType>{0}" +
1223 " </xs:simpleType>{0}" +
1224 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
1225 " <xs:sequence>{0}" +
1226 #if MS // bug #77117
1227 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
1229 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"tns:TimeSpan\" />{0}" +
1231 " </xs:sequence>{0}" +
1232 " </xs:complexType>{0}" +
1233 " <xs:complexType name=\"TimeSpan\" />{0}" +
1234 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1236 schemas = Export (typeof (StructContainer));
1237 Assert.AreEqual (1, schemas.Count, "#3");
1239 sw.GetStringBuilder ().Length = 0;
1240 schemas[0].Write (sw);
1242 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1243 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1244 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1245 #if MS // bug #77117
1246 " <xs:element name=\"StructContainer\" nillable=\"true\" type=\"StructContainer\" />{0}" +
1248 " <xs:element name=\"StructContainer\" type=\"StructContainer\" />{0}" +
1250 " <xs:complexType name=\"StructContainer\">{0}" +
1251 " <xs:sequence>{0}" +
1252 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"EnumDefaultValue\" />{0}" +
1253 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Times\" type=\"ArrayOfTimeSpan\" />{0}" +
1254 " </xs:sequence>{0}" +
1255 " </xs:complexType>{0}" +
1256 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1258 " <xs:simpleType>{0}" +
1259 " <xs:restriction base=\"xs:string\">{0}" +
1260 " <xs:enumeration value=\"e1\" />{0}" +
1261 " <xs:enumeration value=\"e2\" />{0}" +
1262 " <xs:enumeration value=\"e3\" />{0}" +
1263 " </xs:restriction>{0}" +
1264 " </xs:simpleType>{0}" +
1266 " </xs:simpleType>{0}" +
1267 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
1268 " <xs:sequence>{0}" +
1269 #if MS // bug #77117
1270 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
1272 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"TimeSpan\" />{0}" +
1274 " </xs:sequence>{0}" +
1275 " </xs:complexType>{0}" +
1276 " <xs:complexType name=\"TimeSpan\" />{0}" +
1277 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1281 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1282 [ExpectedException (typeof (InvalidOperationException))] // Cannot use wildcards at the top level of a schema.
1283 public void ExportClass_XmlElement ()
1285 XmlSchemas schemas = Export (typeof (XmlElement), "NS1");
1289 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1290 public void ExportClass_Array ()
1292 XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
1293 XmlAttributes attr = new XmlAttributes ();
1294 XmlElementAttribute element = new XmlElementAttribute ();
1295 element.ElementName = "saying";
1296 element.IsNullable = true;
1297 attr.XmlElements.Add (element);
1298 overrides.Add (typeof (SimpleClass), "something", attr);
1300 XmlSchemas schemas = Export (typeof (SimpleClass[]), overrides, "NSSimpleClassArray");
1301 Assert.AreEqual (1, schemas.Count, "#1");
1303 StringWriter sw = new StringWriter ();
1304 schemas[0].Write (sw);
1306 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1307 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1308 "<xs:schema xmlns:tns=\"NSSimpleClassArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1309 #if MS // bug #77117
1310 " <xs:element name=\"ArrayOfSimpleClass\" nillable=\"true\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
1312 " <xs:element name=\"ArrayOfSimpleClass\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
1314 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
1315 " <xs:sequence>{0}" +
1316 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
1317 " </xs:sequence>{0}" +
1318 " </xs:complexType>{0}" +
1319 " <xs:complexType name=\"SimpleClass\">{0}" +
1320 " <xs:sequence>{0}" +
1321 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
1322 " </xs:sequence>{0}" +
1323 " </xs:complexType>{0}" +
1324 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1326 schemas = Export (typeof (SimpleClass[]), overrides);
1327 Assert.AreEqual (1, schemas.Count, "#3");
1329 sw.GetStringBuilder ().Length = 0;
1330 schemas[0].Write (sw);
1332 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1333 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1334 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1335 #if MS // bug #77117
1336 " <xs:element name=\"ArrayOfSimpleClass\" nillable=\"true\" type=\"ArrayOfSimpleClass\" />{0}" +
1338 " <xs:element name=\"ArrayOfSimpleClass\" type=\"ArrayOfSimpleClass\" />{0}" +
1340 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
1341 " <xs:sequence>{0}" +
1342 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
1343 " </xs:sequence>{0}" +
1344 " </xs:complexType>{0}" +
1345 " <xs:complexType name=\"SimpleClass\">{0}" +
1346 " <xs:sequence>{0}" +
1347 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
1348 " </xs:sequence>{0}" +
1349 " </xs:complexType>{0}" +
1350 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1354 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1355 public void ExportEnum ()
1357 XmlSchemas schemas = Export (typeof (EnumDefaultValue), "NSEnumDefaultValue");
1358 Assert.AreEqual (1, schemas.Count, "#1");
1360 StringWriter sw = new StringWriter ();
1361 schemas[0].Write (sw);
1363 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1364 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1365 "<xs:schema xmlns:tns=\"NSEnumDefaultValue\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValue\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1366 " <xs:element name=\"EnumDefaultValue\" type=\"tns:EnumDefaultValue\" />{0}" +
1367 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1369 " <xs:simpleType>{0}" +
1370 " <xs:restriction base=\"xs:string\">{0}" +
1371 " <xs:enumeration value=\"e1\" />{0}" +
1372 " <xs:enumeration value=\"e2\" />{0}" +
1373 " <xs:enumeration value=\"e3\" />{0}" +
1374 " </xs:restriction>{0}" +
1375 " </xs:simpleType>{0}" +
1377 " </xs:simpleType>{0}" +
1378 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1380 schemas = Export (typeof (EnumDefaultValueNF), "NSEnumDefaultValueNF");
1381 Assert.AreEqual (1, schemas.Count, "#3");
1383 sw.GetStringBuilder ().Length = 0;
1384 schemas[0].Write (sw);
1386 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1387 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1388 "<xs:schema xmlns:tns=\"NSEnumDefaultValueNF\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValueNF\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1389 " <xs:element name=\"EnumDefaultValueNF\" type=\"tns:EnumDefaultValueNF\" />{0}" +
1390 " <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
1391 " <xs:restriction base=\"xs:string\">{0}" +
1392 " <xs:enumeration value=\"e1\" />{0}" +
1393 " <xs:enumeration value=\"e2\" />{0}" +
1394 " <xs:enumeration value=\"e3\" />{0}" +
1395 " </xs:restriction>{0}" +
1396 " </xs:simpleType>{0}" +
1397 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1399 schemas = Export (typeof (EnumDefaultValue));
1400 Assert.AreEqual (1, schemas.Count, "#5");
1402 sw.GetStringBuilder ().Length = 0;
1403 schemas[0].Write (sw);
1405 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1406 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1407 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1408 " <xs:element name=\"EnumDefaultValue\" type=\"EnumDefaultValue\" />{0}" +
1409 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1411 " <xs:simpleType>{0}" +
1412 " <xs:restriction base=\"xs:string\">{0}" +
1413 " <xs:enumeration value=\"e1\" />{0}" +
1414 " <xs:enumeration value=\"e2\" />{0}" +
1415 " <xs:enumeration value=\"e3\" />{0}" +
1416 " </xs:restriction>{0}" +
1417 " </xs:simpleType>{0}" +
1419 " </xs:simpleType>{0}" +
1420 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
1422 schemas = Export (typeof (EnumDefaultValueNF));
1423 Assert.AreEqual (1, schemas.Count, "#7");
1425 sw.GetStringBuilder ().Length = 0;
1426 schemas[0].Write (sw);
1428 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1429 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1430 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1431 " <xs:element name=\"EnumDefaultValueNF\" type=\"EnumDefaultValueNF\" />{0}" +
1432 " <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
1433 " <xs:restriction base=\"xs:string\">{0}" +
1434 " <xs:enumeration value=\"e1\" />{0}" +
1435 " <xs:enumeration value=\"e2\" />{0}" +
1436 " <xs:enumeration value=\"e3\" />{0}" +
1437 " </xs:restriction>{0}" +
1438 " </xs:simpleType>{0}" +
1439 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1443 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1444 public void ExportXmlSerializable ()
1446 XmlSchemas schemas = Export (typeof (Employee), "NSEmployee");
1447 Assert.AreEqual (1, schemas.Count, "#1");
1449 StringWriter sw = new StringWriter ();
1450 schemas[0].Write (sw);
1452 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1453 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1454 "<xs:schema xmlns:tns=\"NSEmployee\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployee\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1455 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1456 #if MS // bug #77117
1457 " <xs:element name=\"Employee\" nillable=\"true\">{0}" +
1459 " <xs:element name=\"Employee\">{0}" +
1461 " <xs:complexType>{0}" +
1462 " <xs:sequence>{0}" +
1463 " <xs:element ref=\"xs:schema\" />{0}" +
1465 " </xs:sequence>{0}" +
1466 " </xs:complexType>{0}" +
1467 " </xs:element>{0}" +
1468 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1470 schemas = Export (typeof (Employee));
1471 Assert.AreEqual (1, schemas.Count, "#3");
1473 sw.GetStringBuilder ().Length = 0;
1474 schemas[0].Write (sw);
1476 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1477 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1478 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1479 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1480 #if MS // bug #77117
1481 " <xs:element name=\"Employee\" nillable=\"true\">{0}" +
1483 " <xs:element name=\"Employee\">{0}" +
1485 " <xs:complexType>{0}" +
1486 " <xs:sequence>{0}" +
1487 " <xs:element ref=\"xs:schema\" />{0}" +
1489 " </xs:sequence>{0}" +
1490 " </xs:complexType>{0}" +
1491 " </xs:element>{0}" +
1492 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1496 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1497 public void ExportXmlSerializable_Schema ()
1499 XmlSchemas schemas = Export (typeof (EmployeeSchema), "NSEmployeeSchema");
1500 Assert.AreEqual (2, schemas.Count, "#1");
1502 StringWriter sw = new StringWriter ();
1503 schemas[0].Write (sw);
1505 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1506 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1507 "<xs:schema xmlns:tns=\"NSEmployeeSchema\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1509 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1511 #if MS // bug #77117
1512 " <xs:element name=\"EmployeeSchema\" nillable=\"true\">{0}" +
1514 " <xs:element name=\"EmployeeSchema\">{0}" +
1516 " <xs:complexType>{0}" +
1517 " <xs:sequence>{0}" +
1518 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1519 " </xs:sequence>{0}" +
1520 " </xs:complexType>{0}" +
1521 " </xs:element>{0}" +
1522 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1524 sw.GetStringBuilder ().Length = 0;
1525 schemas[1].Write (sw);
1527 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1528 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1529 "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1530 " <xs:complexType name=\"employeeRoot\">{0}" +
1531 " <xs:attribute name=\"firstName\" />{0}" +
1532 " <xs:attribute name=\"lastName\" />{0}" +
1533 " <xs:attribute name=\"address\" />{0}" +
1534 " </xs:complexType>{0}" +
1535 " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1536 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
1538 schemas = Export (typeof (EmployeeSchema));
1539 Assert.AreEqual (2, schemas.Count, "#4");
1541 sw.GetStringBuilder ().Length = 0;
1542 schemas[0].Write (sw);
1544 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1545 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1546 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1548 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1550 #if MS // bug #77117
1551 " <xs:element name=\"EmployeeSchema\" nillable=\"true\">{0}" +
1553 " <xs:element name=\"EmployeeSchema\">{0}" +
1555 " <xs:complexType>{0}" +
1556 " <xs:sequence>{0}" +
1557 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1558 " </xs:sequence>{0}" +
1559 " </xs:complexType>{0}" +
1560 " </xs:element>{0}" +
1561 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
1563 sw.GetStringBuilder ().Length = 0;
1564 schemas[1].Write (sw);
1566 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1567 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1568 "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1569 " <xs:complexType name=\"employeeRoot\">{0}" +
1570 " <xs:attribute name=\"firstName\" />{0}" +
1571 " <xs:attribute name=\"lastName\" />{0}" +
1572 " <xs:attribute name=\"address\" />{0}" +
1573 " </xs:complexType>{0}" +
1574 " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1575 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
1577 schemas = Export (typeof (PrimitiveSchema), "NSPrimitiveSchema");
1578 Assert.AreEqual (2, schemas.Count, "#7");
1580 sw.GetStringBuilder ().Length = 0;
1581 schemas[0].Write (sw);
1583 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1584 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1585 "<xs:schema xmlns:tns=\"NSPrimitiveSchema\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimitiveSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1586 #if MS // bug #77117
1587 " <xs:element name=\"PrimitiveSchema\" nillable=\"true\">{0}" +
1589 " <xs:element name=\"PrimitiveSchema\">{0}" +
1591 " <xs:complexType>{0}" +
1592 " <xs:sequence>{0}" +
1593 " <xs:any namespace=\"\" />{0}" +
1594 " </xs:sequence>{0}" +
1595 " </xs:complexType>{0}" +
1596 " </xs:element>{0}" +
1597 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1599 sw.GetStringBuilder ().Length = 0;
1600 schemas[1].Write (sw);
1602 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1603 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1604 "<xs:schema id=\"LuckyNumberSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1605 " <xs:element name=\"LuckyNumber\" type=\"xs:int\" />{0}" +
1606 "</xs:schema>", Environment.NewLine), sw.ToString (), "#9");
1610 [ExpectedException (typeof (InvalidOperationException))] // Schema Id is missing
1611 public void ExportXmlSerializable_MissingID ()
1613 Export (typeof (MissingIDSchema));
1616 [ExpectedException (typeof (InvalidOperationException))]
1617 public void ExportXmlSerializable_DuplicateNamespace ()
1620 Export (typeof (PrimitiveSchema));
1622 } catch (InvalidOperationException) {
1623 // The namespace, , is a duplicate.
1627 Export (typeof (XmlSerializableContainer));
1629 } catch (InvalidOperationException) {
1630 // The namespace, , is a duplicate.
1635 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1637 [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
1639 public void ExportXmlSerializable_SchemaProvider ()
1641 XmlSchemas schemas = Export (typeof (EmployeeSchemaProvider), "NSEmployeeSchemaProvider");
1642 Assert.AreEqual (1, schemas.Count, "#1");
1644 StringWriter sw = new StringWriter ();
1645 schemas[0].Write (sw);
1647 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1648 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1649 "<xs:schema xmlns:tns=\"NSEmployeeSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployeeSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1651 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1652 " <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1654 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1655 #if MS // bug #77117
1656 " <xs:element name=\"EmployeeSchemaProvider\" nillable=\"true\">{0}" +
1658 " <xs:element name=\"EmployeeSchemaProvider\">{0}" +
1660 " <xs:complexType>{0}" +
1661 " <xs:sequence>{0}" +
1662 " <xs:element ref=\"xs:schema\" />{0}" +
1664 " </xs:sequence>{0}" +
1665 " </xs:complexType>{0}" +
1666 " </xs:element>{0}" +
1668 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1670 schemas = Export (typeof (EmployeeSchemaProvider));
1671 Assert.AreEqual (1, schemas.Count, "#3");
1673 sw.GetStringBuilder ().Length = 0;
1674 schemas[0].Write (sw);
1676 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1677 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1678 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1680 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1681 " <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1683 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1684 #if MS // bug #77117
1685 " <xs:element name=\"EmployeeSchemaProvider\" nillable=\"true\">{0}" +
1687 " <xs:element name=\"EmployeeSchemaProvider\">{0}" +
1689 " <xs:complexType>{0}" +
1690 " <xs:sequence>{0}" +
1691 " <xs:element ref=\"xs:schema\" />{0}" +
1693 " </xs:sequence>{0}" +
1694 " </xs:complexType>{0}" +
1695 " </xs:element>{0}" +
1697 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1699 schemas = Export (typeof (PrimitiveSchemaProvider), "NSPrimitiveSchemaProvider");
1700 Assert.AreEqual (1, schemas.Count, "#5");
1702 sw.GetStringBuilder ().Length = 0;
1703 schemas[0].Write (sw);
1705 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1706 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1707 "<xs:schema xmlns:tns=\"NSPrimitiveSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimitiveSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1709 " <xs:import />{0}" +
1710 " <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
1712 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1713 #if MS // bug #77117
1714 " <xs:element name=\"PrimitiveSchemaProvider\" nillable=\"true\">{0}" +
1716 " <xs:element name=\"PrimitiveSchemaProvider\">{0}" +
1718 " <xs:complexType>{0}" +
1719 " <xs:sequence>{0}" +
1720 " <xs:element ref=\"xs:schema\" />{0}" +
1722 " </xs:sequence>{0}" +
1723 " </xs:complexType>{0}" +
1724 " </xs:element>{0}" +
1726 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
1728 schemas = Export (typeof (PrimitiveSchemaProvider));
1729 Assert.AreEqual (1, schemas.Count, "#7");
1731 sw.GetStringBuilder ().Length = 0;
1732 schemas[0].Write (sw);
1734 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1735 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1736 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1738 " <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
1740 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1741 #if MS // bug #77117
1742 " <xs:element name=\"PrimitiveSchemaProvider\" nillable=\"true\">{0}" +
1744 " <xs:element name=\"PrimitiveSchemaProvider\">{0}" +
1746 " <xs:complexType>{0}" +
1747 " <xs:sequence>{0}" +
1748 " <xs:element ref=\"xs:schema\" />{0}" +
1750 " </xs:sequence>{0}" +
1751 " </xs:complexType>{0}" +
1752 " </xs:element>{0}" +
1754 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1758 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1760 [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
1762 public void ExportXmlSerializable_Container ()
1764 XmlSchemas schemas = Export (typeof (XmlSerializableContainer), "NSXmlSerializableContainer");
1765 Assert.AreEqual (3, schemas.Count, "#1");
1767 StringWriter sw = new StringWriter ();
1768 schemas[0].Write (sw);
1770 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1771 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1772 "<xs:schema xmlns:tns=\"NSXmlSerializableContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSXmlSerializableContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1773 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1774 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1776 " <xs:import />{0}" +
1778 #if MS // bug #77117
1779 " <xs:element name=\"XmlSerializableContainer\" nillable=\"true\" type=\"tns:XmlSerializableContainer\" />{0}" +
1781 " <xs:element name=\"XmlSerializableContainer\" type=\"tns:XmlSerializableContainer\" />{0}" +
1783 " <xs:complexType name=\"XmlSerializableContainer\">{0}" +
1784 " <xs:sequence>{0}" +
1785 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Slave\">{0}" +
1786 " <xs:complexType>{0}" +
1787 " <xs:sequence>{0}" +
1788 " <xs:element ref=\"xs:schema\" />{0}" +
1790 " </xs:sequence>{0}" +
1791 " </xs:complexType>{0}" +
1792 " </xs:element>{0}" +
1793 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchema\">{0}" +
1794 " <xs:complexType>{0}" +
1795 " <xs:sequence>{0}" +
1796 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1797 " </xs:sequence>{0}" +
1798 " </xs:complexType>{0}" +
1799 " </xs:element>{0}" +
1801 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1803 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\">{0}" +
1804 " <xs:complexType>{0}" +
1805 " <xs:sequence>{0}" +
1806 " <xs:element ref=\"xs:schema\" />{0}" +
1808 " </xs:sequence>{0}" +
1809 " </xs:complexType>{0}" +
1810 " </xs:element>{0}" +
1812 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchema\">{0}" +
1813 " <xs:complexType>{0}" +
1814 " <xs:sequence>{0}" +
1815 " <xs:any namespace=\"\" />{0}" +
1816 " </xs:sequence>{0}" +
1817 " </xs:complexType>{0}" +
1818 " </xs:element>{0}" +
1820 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\" type=\"xs:int\" />{0}" +
1821 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveNamespace\" />{0}" +
1822 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaNamespace\" />{0}" +
1823 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:SlaveSchemaProviderNamespace\" />{0}" +
1824 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaNamespace\" />{0}" +
1825 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:NativeSchemaProviderNamespace\" />{0}" +
1826 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveNSOnly\" />{0}" +
1827 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaNSOnly\" />{0}" +
1828 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:SlaveSchemaProviderNSOnly\" />{0}" +
1829 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaNSOnly\" />{0}" +
1830 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q11=\"urn:types-devx-com\" ref=\"q11:NativeSchemaProviderNSOnly\" />{0}" +
1832 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\">{0}" +
1833 " <xs:complexType>{0}" +
1834 " <xs:sequence>{0}" +
1835 " <xs:element ref=\"xs:schema\" />{0}" +
1837 " </xs:sequence>{0}" +
1838 " </xs:complexType>{0}" +
1839 " </xs:element>{0}" +
1840 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q1=\"urn:types-devx-com\" ref=\"q1:SlaveNamespace\" />{0}" +
1841 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveSchemaNamespace\" />{0}" +
1842 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaProviderNamespace\" />{0}" +
1843 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:NativeSchemaNamespace\" />{0}" +
1844 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaProviderNamespace\" />{0}" +
1845 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:SlaveNSOnly\" />{0}" +
1846 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveSchemaNSOnly\" />{0}" +
1847 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaProviderNSOnly\" />{0}" +
1848 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:NativeSchemaNSOnly\" />{0}" +
1849 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaProviderNSOnly\" />{0}" +
1851 " </xs:sequence>{0}" +
1852 " </xs:complexType>{0}" +
1853 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1855 sw.GetStringBuilder ().Length = 0;
1856 schemas[1].Write (sw);
1858 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1859 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1860 "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1861 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1863 " <xs:import />{0}" +
1865 " <xs:complexType name=\"employeeRoot\">{0}" +
1866 " <xs:attribute name=\"firstName\" />{0}" +
1867 " <xs:attribute name=\"lastName\" />{0}" +
1868 " <xs:attribute name=\"address\" />{0}" +
1869 " </xs:complexType>{0}" +
1870 " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1871 " <xs:element name=\"SlaveNamespace\">{0}" +
1872 " <xs:complexType>{0}" +
1873 " <xs:sequence>{0}" +
1874 " <xs:element ref=\"xs:schema\" />{0}" +
1876 " </xs:sequence>{0}" +
1877 " </xs:complexType>{0}" +
1878 " </xs:element>{0}" +
1879 " <xs:element name=\"SlaveSchemaNamespace\">{0}" +
1880 " <xs:complexType>{0}" +
1881 " <xs:sequence>{0}" +
1882 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1883 " </xs:sequence>{0}" +
1884 " </xs:complexType>{0}" +
1885 " </xs:element>{0}" +
1887 " <xs:element name=\"SlaveSchemaProviderNamespace\" type=\"tns:employeeRoot\" />{0}" +
1889 " <xs:element name=\"SlaveSchemaProviderNamespace\">{0}" +
1890 " <xs:complexType>{0}" +
1891 " <xs:sequence>{0}" +
1892 " <xs:element ref=\"xs:schema\" />{0}" +
1894 " </xs:sequence>{0}" +
1895 " </xs:complexType>{0}" +
1896 " </xs:element>{0}" +
1898 " <xs:element name=\"NativeSchemaNamespace\">{0}" +
1899 " <xs:complexType>{0}" +
1900 " <xs:sequence>{0}" +
1901 " <xs:any namespace=\"\" />{0}" +
1902 " </xs:sequence>{0}" +
1903 " </xs:complexType>{0}" +
1904 " </xs:element>{0}" +
1906 " <xs:element name=\"NativeSchemaProviderNamespace\" type=\"xs:int\" />{0}" +
1908 " <xs:element name=\"NativeSchemaProviderNamespace\">{0}" +
1909 " <xs:complexType>{0}" +
1910 " <xs:sequence>{0}" +
1911 " <xs:element ref=\"xs:schema\" />{0}" +
1913 " </xs:sequence>{0}" +
1914 " </xs:complexType>{0}" +
1915 " </xs:element>{0}" +
1917 " <xs:element name=\"SlaveNSOnly\">{0}" +
1918 " <xs:complexType>{0}" +
1919 " <xs:sequence>{0}" +
1920 " <xs:element ref=\"xs:schema\" />{0}" +
1922 " </xs:sequence>{0}" +
1923 " </xs:complexType>{0}" +
1924 " </xs:element>{0}" +
1925 " <xs:element name=\"SlaveSchemaNSOnly\">{0}" +
1926 " <xs:complexType>{0}" +
1927 " <xs:sequence>{0}" +
1928 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1929 " </xs:sequence>{0}" +
1930 " </xs:complexType>{0}" +
1931 " </xs:element>{0}" +
1933 " <xs:element name=\"SlaveSchemaProviderNSOnly\" type=\"tns:employeeRoot\" />{0}" +
1935 " <xs:element name=\"SlaveSchemaProviderNSOnly\">{0}" +
1936 " <xs:complexType>{0}" +
1937 " <xs:sequence>{0}" +
1938 " <xs:element ref=\"xs:schema\" />{0}" +
1940 " </xs:sequence>{0}" +
1941 " </xs:complexType>{0}" +
1942 " </xs:element>{0}" +
1944 " <xs:element name=\"NativeSchemaNSOnly\">{0}" +
1945 " <xs:complexType>{0}" +
1946 " <xs:sequence>{0}" +
1947 " <xs:any namespace=\"\" />{0}" +
1948 " </xs:sequence>{0}" +
1949 " </xs:complexType>{0}" +
1950 " </xs:element>{0}" +
1952 " <xs:element name=\"NativeSchemaProviderNSOnly\" type=\"xs:int\" />{0}" +
1954 " <xs:element name=\"NativeSchemaProviderNSOnly\">{0}" +
1955 " <xs:complexType>{0}" +
1956 " <xs:sequence>{0}" +
1957 " <xs:element ref=\"xs:schema\" />{0}" +
1959 " </xs:sequence>{0}" +
1960 " </xs:complexType>{0}" +
1961 " </xs:element>{0}" +
1963 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
1965 sw.GetStringBuilder ().Length = 0;
1966 schemas[2].Write (sw);
1968 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1969 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1970 "<xs:schema id=\"LuckyNumberSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1971 " <xs:element name=\"LuckyNumber\" type=\"xs:int\" />{0}" +
1972 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1976 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1977 public void ExportXsdPrimitive ()
1979 ArrayList types = new ArrayList ();
1980 types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte"));
1981 types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte"));
1982 types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean"));
1983 types.Add (new TypeDescription (typeof (short), true, "short", "Short"));
1984 types.Add (new TypeDescription (typeof (int), true, "int", "Int"));
1985 types.Add (new TypeDescription (typeof (long), true, "long", "Long"));
1986 types.Add (new TypeDescription (typeof (float), true, "float", "Float"));
1987 types.Add (new TypeDescription (typeof (double), true, "double", "Double"));
1988 types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal"));
1989 types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort"));
1990 types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt"));
1991 types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong"));
1992 types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime"));
1994 types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true));
1996 types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName"));
1998 types.Add (new TypeDescription (typeof (string), true, "string", "String", true));
2000 foreach (TypeDescription typeDesc in types) {
2001 XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
2002 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
2004 StringWriter sw = new StringWriter ();
2005 schemas[0].Write (sw);
2007 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2008 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2009 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2010 " <xs:element name=\"{2}\" {3}type=\"xs:{2}\" />{0}" +
2011 #if MS // bug #77117
2012 "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.XmlType, typeDesc.IsNillable ? "nillable=\"true\" " : ""),
2014 "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.XmlType, ""),
2016 sw.ToString (), typeDesc.Type.FullName + "#2");
2018 schemas = Export (typeDesc.Type);
2019 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
2021 sw.GetStringBuilder ().Length = 0;
2022 schemas[0].Write (sw);
2024 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2025 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2026 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2027 " <xs:element name=\"{1}\" {2}type=\"xs:{1}\" />{0}" +
2028 #if MS // bug #77117
2029 "</xs:schema>", Environment.NewLine, typeDesc.XmlType, typeDesc.IsNillable ? "nillable=\"true\" " : ""),
2031 "</xs:schema>", Environment.NewLine, typeDesc.XmlType, ""),
2033 sw.ToString (), typeDesc.Type.FullName + "#4");
2038 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2039 public void ExportXsdPrimitive_Object ()
2041 XmlSchemas schemas = Export (typeof (object), "NSAnyType");
2042 Assert.AreEqual (1, schemas.Count, "#1");
2044 StringWriter sw = new StringWriter ();
2045 schemas[0].Write (sw);
2047 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2048 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2049 "<xs:schema xmlns:tns=\"NSAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2050 #if MS // bug #77117
2051 " <xs:element name=\"anyType\" nillable=\"true\" />{0}" +
2053 " <xs:element name=\"anyType\" />{0}" +
2055 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2057 schemas = Export (typeof (object));
2058 Assert.AreEqual (1, schemas.Count, "#3");
2060 sw.GetStringBuilder ().Length = 0;
2061 schemas[0].Write (sw);
2063 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2064 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2065 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2066 #if MS // bug #77117
2067 " <xs:element name=\"anyType\" nillable=\"true\" />{0}" +
2069 " <xs:element name=\"anyType\" />{0}" +
2071 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
2075 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2076 public void ExportXsdPrimitive_ByteArray ()
2078 XmlSchemas schemas = Export (typeof (byte[]), "NSByteArray");
2079 Assert.AreEqual (1, schemas.Count, "#1");
2081 StringWriter sw = new StringWriter ();
2082 schemas[0].Write (sw);
2084 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2085 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2086 "<xs:schema xmlns:tns=\"NSByteArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSByteArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2087 #if MS // bug #77117
2088 " <xs:element name=\"base64Binary\" nillable=\"true\" type=\"xs:base64Binary\" />{0}" +
2090 " <xs:element name=\"base64Binary\" type=\"xs:base64Binary\" />{0}" +
2092 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2094 schemas = Export (typeof (byte[]));
2095 Assert.AreEqual (1, schemas.Count, "#3");
2097 sw.GetStringBuilder ().Length = 0;
2098 schemas[0].Write (sw);
2100 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2101 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2102 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2103 #if MS // bug #77117
2104 " <xs:element name=\"base64Binary\" nillable=\"true\" type=\"xs:base64Binary\" />{0}" +
2106 " <xs:element name=\"base64Binary\" type=\"xs:base64Binary\" />{0}" +
2108 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
2112 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2113 public void ExportXsdPrimitive_Arrays ()
2115 ArrayList types = new ArrayList ();
2116 types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte"));
2117 types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean"));
2118 types.Add (new TypeDescription (typeof (short[]), true, "short", "Short"));
2119 types.Add (new TypeDescription (typeof (int[]), true, "int", "Int"));
2120 types.Add (new TypeDescription (typeof (long[]), true, "long", "Long"));
2121 types.Add (new TypeDescription (typeof (float[]), true, "float", "Float"));
2122 types.Add (new TypeDescription (typeof (double[]), true, "double", "Double"));
2123 types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal"));
2124 types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort"));
2125 types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt"));
2126 types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong"));
2127 types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime"));
2129 types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true));
2131 types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName"));
2133 types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true));
2135 foreach (TypeDescription typeDesc in types) {
2136 XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
2137 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
2139 StringWriter sw = new StringWriter ();
2140 schemas[0].Write (sw);
2142 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2143 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2144 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2145 #if MS // bug #77117
2146 " <xs:element name=\"ArrayOf{2}\" nillable=\"true\" type=\"tns:ArrayOf{2}\" />{0}" +
2148 " <xs:element name=\"ArrayOf{2}\" type=\"tns:ArrayOf{2}\" />{0}" +
2150 " <xs:complexType name=\"ArrayOf{2}\">{0}" +
2151 " <xs:sequence>{0}" +
2152 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{3}\" {5}type=\"{4}:{3}\" />{0}" +
2153 " </xs:sequence>{0}" +
2154 " </xs:complexType>{0}" +
2155 "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType,
2156 typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
2157 sw.ToString (), typeDesc.Type.FullName + "#2");
2159 schemas = Export (typeDesc.Type);
2160 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
2162 sw.GetStringBuilder ().Length = 0;
2163 schemas[0].Write (sw);
2165 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2166 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2167 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2168 #if MS // bug #77117
2169 " <xs:element name=\"ArrayOf{1}\" nillable=\"true\" type=\"ArrayOf{1}\" />{0}" +
2171 " <xs:element name=\"ArrayOf{1}\" type=\"ArrayOf{1}\" />{0}" +
2173 " <xs:complexType name=\"ArrayOf{1}\">{0}" +
2174 " <xs:sequence>{0}" +
2175 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{2}\" {4}type=\"{3}:{2}\" />{0}" +
2176 " </xs:sequence>{0}" +
2177 " </xs:complexType>{0}" +
2178 "</xs:schema>", Environment.NewLine, typeDesc.ArrayType, typeDesc.XmlType,
2179 typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
2180 sw.ToString (), typeDesc.Type.FullName + "#4");
2185 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2186 public void ExportXsdPrimitive_Object_Arrays ()
2188 XmlSchemas schemas = Export (typeof (object[]), "NSArrayOfAnyType");
2189 Assert.AreEqual (1, schemas.Count, "#1");
2191 StringWriter sw = new StringWriter ();
2192 schemas[0].Write (sw);
2194 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2195 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2196 "<xs:schema xmlns:tns=\"NSArrayOfAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayOfAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2197 #if MS // bug #77117
2198 " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"tns:ArrayOfAnyType\" />{0}" +
2200 " <xs:element name=\"ArrayOfAnyType\" type=\"tns:ArrayOfAnyType\" />{0}" +
2202 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
2203 " <xs:sequence>{0}" +
2204 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
2205 " </xs:sequence>{0}" +
2206 " </xs:complexType>{0}" +
2207 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2209 schemas = Export (typeof (object[]));
2210 Assert.AreEqual (1, schemas.Count, "#3");
2212 sw.GetStringBuilder ().Length = 0;
2213 schemas[0].Write (sw);
2215 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2216 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2217 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2218 #if MS // bug #77117
2219 " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"ArrayOfAnyType\" />{0}" +
2221 " <xs:element name=\"ArrayOfAnyType\" type=\"ArrayOfAnyType\" />{0}" +
2223 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
2224 " <xs:sequence>{0}" +
2225 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
2226 " </xs:sequence>{0}" +
2227 " </xs:complexType>{0}" +
2228 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
2232 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2233 public void ExportNonXsdPrimitive_Guid ()
2235 XmlSchemas schemas = Export (typeof (Guid), "NSPrimGuid");
2236 Assert.AreEqual (2, schemas.Count, "#1");
2238 StringWriter sw = new StringWriter ();
2239 schemas[0].Write (sw);
2241 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2242 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2243 "<xs:schema xmlns:tns=\"NSPrimGuid\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimGuid\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2244 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2245 " <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
2246 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2248 sw.GetStringBuilder ().Length = 0;
2249 schemas[1].Write (sw);
2251 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2252 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2253 "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2254 " <xs:simpleType name=\"guid\">{0}" +
2255 " <xs:restriction base=\"xs:string\">{0}" +
2256 " <xs:pattern value=\"[0-9a-fA-F]{{8}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{12}}\" />{0}" +
2257 " </xs:restriction>{0}" +
2258 " </xs:simpleType>{0}" +
2259 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
2261 schemas = Export (typeof (Guid));
2262 Assert.AreEqual (2, schemas.Count, "#4");
2264 sw.GetStringBuilder ().Length = 0;
2265 schemas[0].Write (sw);
2267 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2268 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2269 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2270 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2271 " <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
2272 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
2274 sw.GetStringBuilder ().Length = 0;
2275 schemas[1].Write (sw);
2277 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2278 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2279 "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2280 " <xs:simpleType name=\"guid\">{0}" +
2281 " <xs:restriction base=\"xs:string\">{0}" +
2282 " <xs:pattern value=\"[0-9a-fA-F]{{8}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{12}}\" />{0}" +
2283 " </xs:restriction>{0}" +
2284 " </xs:simpleType>{0}" +
2285 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
2289 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2290 public void ExportNonXsdPrimitive_Char ()
2292 XmlSchemas schemas = Export (typeof (char), "NSPrimChar");
2293 Assert.AreEqual (2, schemas.Count, "#1");
2295 StringWriter sw = new StringWriter ();
2296 schemas[0].Write (sw);
2298 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2299 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2300 "<xs:schema xmlns:tns=\"NSPrimChar\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimChar\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2301 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2302 " <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
2303 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2305 sw.GetStringBuilder ().Length = 0;
2306 schemas[1].Write (sw);
2308 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2309 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2310 "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2311 " <xs:simpleType name=\"char\">{0}" +
2312 " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
2313 " </xs:simpleType>{0}" +
2314 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
2316 schemas = Export (typeof (char));
2317 Assert.AreEqual (2, schemas.Count, "#4");
2319 sw.GetStringBuilder ().Length = 0;
2320 schemas[0].Write (sw);
2322 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2323 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2324 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2325 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2326 " <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
2327 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
2329 sw.GetStringBuilder ().Length = 0;
2330 schemas[1].Write (sw);
2332 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2333 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2334 "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2335 " <xs:simpleType name=\"char\">{0}" +
2336 " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
2337 " </xs:simpleType>{0}" +
2338 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
2341 public class Employee : IXmlSerializable
2343 private string _firstName;
2344 private string _lastName;
2345 private string _address;
2347 public virtual XmlSchema GetSchema ()
2352 public void WriteXml (XmlWriter writer)
2354 writer.WriteStartElement ("employee", "urn:devx-com");
2355 writer.WriteAttributeString ("firstName", _firstName);
2356 writer.WriteAttributeString ("lastName", _lastName);
2357 writer.WriteAttributeString ("address", _address);
2358 writer.WriteEndElement ();
2361 public void ReadXml (XmlReader reader)
2363 XmlNodeType type = reader.MoveToContent ();
2364 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2365 _firstName = reader["firstName"];
2366 _lastName = reader["lastName"];
2367 _address = reader["address"];
2372 public class EmployeeSchema : IXmlSerializable
2374 private string _firstName;
2375 private string _lastName;
2376 private string _address;
2378 public virtual XmlSchema GetSchema ()
2380 return CreateSchema ();
2383 public void WriteXml (XmlWriter writer)
2385 writer.WriteStartElement ("employee", "urn:devx-com");
2386 writer.WriteAttributeString ("firstName", _firstName);
2387 writer.WriteAttributeString ("lastName", _lastName);
2388 writer.WriteAttributeString ("address", _address);
2389 writer.WriteEndElement ();
2392 public void ReadXml (XmlReader reader)
2394 XmlNodeType type = reader.MoveToContent ();
2395 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2396 _firstName = reader["firstName"];
2397 _lastName = reader["lastName"];
2398 _address = reader["address"];
2402 protected static XmlSchema CreateSchema ()
2404 XmlSchema schema = new XmlSchema ();
2405 schema.Id = "EmployeeSchema";
2406 schema.TargetNamespace = "urn:types-devx-com";
2408 XmlSchemaComplexType type = new XmlSchemaComplexType ();
2409 type.Name = "employeeRoot";
2410 XmlSchemaAttribute firstNameAttr = new XmlSchemaAttribute ();
2411 firstNameAttr.Name = "firstName";
2412 type.Attributes.Add (firstNameAttr);
2414 XmlSchemaAttribute lastNameAttr = new XmlSchemaAttribute ();
2415 lastNameAttr.Name = "lastName";
2416 type.Attributes.Add (lastNameAttr);
2418 XmlSchemaAttribute addressAttr = new XmlSchemaAttribute ();
2419 addressAttr.Name = "address";
2420 type.Attributes.Add (addressAttr);
2422 XmlSchemaElement employeeElement = new XmlSchemaElement ();
2423 employeeElement.Name = "employee";
2424 XmlQualifiedName name = new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
2425 employeeElement.SchemaTypeName = name;
2427 schema.Items.Add (type);
2428 schema.Items.Add (employeeElement);
2433 public class PrimitiveSchema : IXmlSerializable
2435 private string _firstName;
2436 private string _lastName;
2437 private string _address;
2439 public virtual XmlSchema GetSchema ()
2441 XmlSchema schema = new XmlSchema ();
2442 schema.Id = "LuckyNumberSchema";
2443 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2444 luckyNumberElement.Name = "LuckyNumber";
2445 luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
2446 schema.Items.Add (luckyNumberElement);
2450 public void WriteXml (XmlWriter writer)
2452 writer.WriteStartElement ("employee", "urn:devx-com");
2453 writer.WriteAttributeString ("firstName", _firstName);
2454 writer.WriteAttributeString ("lastName", _lastName);
2455 writer.WriteAttributeString ("address", _address);
2456 writer.WriteEndElement ();
2459 public void ReadXml (XmlReader reader)
2461 XmlNodeType type = reader.MoveToContent ();
2462 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2463 _firstName = reader["firstName"];
2464 _lastName = reader["lastName"];
2465 _address = reader["address"];
2470 public class MissingIDSchema : IXmlSerializable
2472 private string _firstName;
2473 private string _lastName;
2474 private string _address;
2476 public virtual XmlSchema GetSchema ()
2478 XmlSchema schema = new XmlSchema ();
2479 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2480 luckyNumberElement.Name = "LuckyNumber";
2481 luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
2485 public void WriteXml (XmlWriter writer)
2487 writer.WriteStartElement ("employee", "urn:devx-com");
2488 writer.WriteAttributeString ("firstName", _firstName);
2489 writer.WriteAttributeString ("lastName", _lastName);
2490 writer.WriteAttributeString ("address", _address);
2491 writer.WriteEndElement ();
2494 public void ReadXml (XmlReader reader)
2496 XmlNodeType type = reader.MoveToContent ();
2497 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2498 _firstName = reader["firstName"];
2499 _lastName = reader["lastName"];
2500 _address = reader["address"];
2506 [XmlSchemaProvider ("CreateEmployeeSchema")]
2508 public class EmployeeSchemaProvider : EmployeeSchema
2511 public static XmlQualifiedName CreateEmployeeSchema (XmlSchemaSet schemaSet)
2513 schemaSet.Add (CreateSchema ());
2514 return new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
2517 public override XmlSchema GetSchema ()
2525 [XmlSchemaProvider ("CreateLuckyNumberSchema")]
2527 public class PrimitiveSchemaProvider : IXmlSerializable
2530 public static XmlQualifiedName CreateLuckyNumberSchema (XmlSchemaSet schemaSet)
2532 XmlSchema schema = new XmlSchema ();
2534 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2535 luckyNumberElement.Name = "LuckyNumber";
2537 XmlQualifiedName typeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");
2538 luckyNumberElement.SchemaTypeName = typeName;
2539 schema.Items.Add (luckyNumberElement);
2541 schemaSet.Add (schema);
2546 public XmlSchema GetSchema ()
2551 public void WriteXml (XmlWriter writer)
2553 writer.WriteElementString ("LuckyNumber", "7");
2556 public void ReadXml (XmlReader reader)
2558 XmlNodeType type = reader.MoveToContent ();
2559 if (type == XmlNodeType.Element && reader.LocalName == "LuckyNumber") {
2564 private class TypeDescription
2566 public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType) : this (type, xsdType, xmlType, arrayType, false)
2570 public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable)
2575 _arrayType = arrayType;
2576 _isNillable = isNillable;
2580 get { return _type; }
2583 public string XmlType {
2584 get { return _xmlType; }
2587 public string ArrayType {
2588 get { return _arrayType; }
2591 public bool XsdType {
2592 get { return _xsdType; }
2595 public bool IsNillable {
2596 get { return _isNillable; }
2600 private bool _xsdType;
2601 private string _xmlType;
2602 private string _arrayType;
2603 private bool _isNillable;
2606 public class StructContainer
2608 public EnumDefaultValue Value;
2609 public TimeSpan[] Times;
2612 public class XmlSerializableContainer
2614 public Employee Slave;
2615 public EmployeeSchema SlaveSchema;
2616 public EmployeeSchemaProvider SlaveSchemaProvider;
2617 public PrimitiveSchema NativeSchema;
2618 public PrimitiveSchemaProvider NativeSchemaProvider;
2620 [XmlElement ("SlaveNamespace", Namespace = "urn:types-devx-com")]
2621 public Employee SlaveNS;
2622 [XmlElement ("SlaveSchemaNamespace", Namespace = "urn:types-devx-com")]
2623 public EmployeeSchema SlaveSchemaNS;
2624 [XmlElement ("SlaveSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
2625 public EmployeeSchemaProvider SlaveSchemaProviderNS;
2626 [XmlElement ("NativeSchemaNamespace", Namespace = "urn:types-devx-com")]
2627 public PrimitiveSchema NativeSchemaNS;
2628 [XmlElement ("NativeSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
2629 public PrimitiveSchemaProvider NativeSchemaProviderNS;
2632 [XmlElement (Namespace = "urn:types-devx-com")]
2633 public Employee SlaveNSOnly;
2634 [XmlElement (Namespace = "urn:types-devx-com")]
2635 public EmployeeSchema SlaveSchemaNSOnly;
2636 [XmlElement (Namespace = "urn:types-devx-com")]
2637 public EmployeeSchemaProvider SlaveSchemaProviderNSOnly;
2638 [XmlElement (Namespace = "urn:types-devx-com")]
2639 public PrimitiveSchema NativeSchemaNSOnly;
2640 [XmlElement (Namespace = "urn:types-devx-com")]
2641 public PrimitiveSchemaProvider NativeSchemaProviderNSOnly;