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 const string ANamespace = "some:urn";
28 const string AnotherNamespace = "another:urn";
30 string Infoset (string source)
32 return XmlSerializerTests.Infoset (source);
35 private XmlSchemas Export (Type type)
37 return Export (type, string.Empty);
40 private XmlSchemas Export (Type type, string defaultNamespace)
42 XmlReflectionImporter ri = new XmlReflectionImporter (defaultNamespace);
43 XmlSchemas schemas = new XmlSchemas ();
44 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
45 XmlTypeMapping tm = ri.ImportTypeMapping (type);
46 sx.ExportTypeMapping (tm);
50 private XmlSchemas Export (Type type, XmlAttributeOverrides overrides)
52 return Export (type, overrides, string.Empty);
55 private XmlSchemas Export (Type type, XmlAttributeOverrides overrides, string defaultNamespace)
57 XmlReflectionImporter ri = new XmlReflectionImporter (overrides, defaultNamespace);
58 XmlSchemas schemas = new XmlSchemas ();
59 XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
60 XmlTypeMapping tm = ri.ImportTypeMapping (type);
61 sx.ExportTypeMapping (tm);
66 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
67 public void ExportStruct ()
69 XmlSchemas schemas = Export (typeof (TimeSpan), "NSTimeSpan");
70 Assert.AreEqual (1, schemas.Count, "#1");
72 StringWriter sw = new StringWriter ();
73 schemas[0].Write (sw);
75 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
76 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
77 "<xs:schema xmlns:tns=\"NSTimeSpan\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpan\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
78 " <xs:element name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
79 " <xs:complexType name=\"TimeSpan\" />{0}" +
80 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
82 schemas = Export (typeof (TimeSpan));
83 Assert.AreEqual (1, schemas.Count, "#3");
85 sw.GetStringBuilder ().Length = 0;
86 schemas[0].Write (sw);
88 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
89 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
90 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
91 " <xs:element name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
92 " <xs:complexType name=\"TimeSpan\" />{0}" +
93 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
97 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
98 public void ExportStruct_Array ()
100 XmlSchemas schemas = Export (typeof (TimeSpan[]), "NSTimeSpanArray");
101 Assert.AreEqual (1, schemas.Count, "#1");
103 StringWriter sw = new StringWriter ();
104 schemas[0].Write (sw);
106 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
107 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
108 "<xs:schema xmlns:tns=\"NSTimeSpanArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpanArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
109 " <xs:element name=\"ArrayOfTimeSpan\" nillable=\"true\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
110 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
111 " <xs:sequence>{0}" +
112 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
113 " </xs:sequence>{0}" +
114 " </xs:complexType>{0}" +
115 " <xs:complexType name=\"TimeSpan\" />{0}" +
116 "</xs:schema>", Environment.NewLine)), Infoset (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 (Infoset (string.Format (CultureInfo.InvariantCulture,
125 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
126 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
127 " <xs:element name=\"ArrayOfTimeSpan\" nillable=\"true\" type=\"ArrayOfTimeSpan\" />{0}" +
128 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
129 " <xs:sequence>{0}" +
130 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
131 " </xs:sequence>{0}" +
132 " </xs:complexType>{0}" +
133 " <xs:complexType name=\"TimeSpan\" />{0}" +
134 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
138 public void ExportClass_SimpleClass ()
140 XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
141 XmlAttributes attr = new XmlAttributes ();
142 XmlElementAttribute element = new XmlElementAttribute ();
143 element.ElementName = "saying";
144 element.IsNullable = true;
145 attr.XmlElements.Add (element);
146 overrides.Add (typeof (SimpleClass), "something", attr);
148 XmlSchemas schemas = Export (typeof (SimpleClass), overrides, "NSSimpleClass");
149 Assert.AreEqual (1, schemas.Count, "#1");
151 StringWriter sw = new StringWriter ();
152 schemas[0].Write (sw);
154 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
155 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
156 "<xs:schema xmlns:tns=\"NSSimpleClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
157 " <xs:element name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
158 " <xs:complexType name=\"SimpleClass\">{0}" +
159 " <xs:sequence>{0}" +
160 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
161 " </xs:sequence>{0}" +
162 " </xs:complexType>{0}" +
163 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
165 schemas = Export (typeof (SimpleClass), overrides);
166 Assert.AreEqual (1, schemas.Count, "#3");
168 sw.GetStringBuilder ().Length = 0;
169 schemas[0].Write (sw);
171 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
172 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
173 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
174 " <xs:element name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
175 " <xs:complexType name=\"SimpleClass\">{0}" +
176 " <xs:sequence>{0}" +
177 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
178 " </xs:sequence>{0}" +
179 " </xs:complexType>{0}" +
180 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
184 public void ExportClass_StringCollection ()
186 XmlSchemas schemas = Export (typeof (StringCollection), "NSStringCollection");
187 Assert.AreEqual (1, schemas.Count, "#1");
189 StringWriter sw = new StringWriter ();
190 schemas[0].Write (sw);
192 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
193 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
194 "<xs:schema xmlns:tns=\"NSStringCollection\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollection\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
195 " <xs:element name=\"ArrayOfString\" nillable=\"true\" type=\"tns:ArrayOfString\" />{0}" +
196 " <xs:complexType name=\"ArrayOfString\">{0}" +
197 " <xs:sequence>{0}" +
198 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
199 " </xs:sequence>{0}" +
200 " </xs:complexType>{0}" +
201 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
203 schemas = Export (typeof (StringCollection));
204 Assert.AreEqual (1, schemas.Count, "#3");
206 sw.GetStringBuilder ().Length = 0;
207 schemas[0].Write (sw);
209 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
210 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
211 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
212 " <xs:element name=\"ArrayOfString\" nillable=\"true\" type=\"ArrayOfString\" />{0}" +
213 " <xs:complexType name=\"ArrayOfString\">{0}" +
214 " <xs:sequence>{0}" +
215 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
216 " </xs:sequence>{0}" +
217 " </xs:complexType>{0}" +
218 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
222 public void ExportClass_StringCollectionContainer ()
224 XmlSchemas schemas = Export (typeof (StringCollectionContainer), "NSStringCollectionContainer");
225 Assert.AreEqual (1, schemas.Count, "#1");
227 StringWriter sw = new StringWriter ();
228 schemas[0].Write (sw);
230 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
231 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
232 "<xs:schema xmlns:tns=\"NSStringCollectionContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollectionContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
233 " <xs:element name=\"StringCollectionContainer\" nillable=\"true\" type=\"tns:StringCollectionContainer\" />{0}" +
234 " <xs:complexType name=\"StringCollectionContainer\">{0}" +
235 " <xs:sequence>{0}" +
236 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"tns:ArrayOfString\" />{0}" +
237 " </xs:sequence>{0}" +
238 " </xs:complexType>{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)), Infoset (sw.ToString ()), "#2");
246 schemas = Export (typeof (StringCollectionContainer));
247 Assert.AreEqual (1, schemas.Count, "#3");
249 sw.GetStringBuilder ().Length = 0;
250 schemas[0].Write (sw);
252 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
253 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
254 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
255 " <xs:element name=\"StringCollectionContainer\" nillable=\"true\" type=\"StringCollectionContainer\" />{0}" +
256 " <xs:complexType name=\"StringCollectionContainer\">{0}" +
257 " <xs:sequence>{0}" +
258 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"ArrayOfString\" />{0}" +
259 " </xs:sequence>{0}" +
260 " </xs:complexType>{0}" +
261 " <xs:complexType name=\"ArrayOfString\">{0}" +
262 " <xs:sequence>{0}" +
263 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
264 " </xs:sequence>{0}" +
265 " </xs:complexType>{0}" +
266 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
270 public void ExportClass_ArrayContainer ()
272 XmlSchemas schemas = Export (typeof (ArrayContainer), "NSArrayContainer");
273 Assert.AreEqual (1, schemas.Count, "#1");
275 StringWriter sw = new StringWriter ();
276 schemas[0].Write (sw);
278 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
279 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
280 "<xs:schema xmlns:tns=\"NSArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
281 " <xs:element name=\"ArrayContainer\" nillable=\"true\" type=\"tns:ArrayContainer\" />{0}" +
282 " <xs:complexType name=\"ArrayContainer\">{0}" +
283 " <xs:sequence>{0}" +
284 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfAnyType\" />{0}" +
285 " </xs:sequence>{0}" +
286 " </xs:complexType>{0}" +
287 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
288 " <xs:sequence>{0}" +
289 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
290 " </xs:sequence>{0}" +
291 " </xs:complexType>{0}" +
292 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
294 schemas = Export (typeof (ArrayContainer));
295 Assert.AreEqual (1, schemas.Count, "#3");
297 sw.GetStringBuilder ().Length = 0;
298 schemas[0].Write (sw);
300 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
301 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
302 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
303 " <xs:element name=\"ArrayContainer\" nillable=\"true\" type=\"ArrayContainer\" />{0}" +
304 " <xs:complexType name=\"ArrayContainer\">{0}" +
305 " <xs:sequence>{0}" +
306 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfAnyType\" />{0}" +
307 " </xs:sequence>{0}" +
308 " </xs:complexType>{0}" +
309 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
310 " <xs:sequence>{0}" +
311 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
312 " </xs:sequence>{0}" +
313 " </xs:complexType>{0}" +
314 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
318 public void ExportClass_ClassArrayContainer ()
320 XmlSchemas schemas = Export (typeof (ClassArrayContainer), "NSClassArrayContainer");
321 Assert.AreEqual (1, schemas.Count, "#1");
323 StringWriter sw = new StringWriter ();
324 schemas[0].Write (sw);
326 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
327 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
328 "<xs:schema xmlns:tns=\"NSClassArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSClassArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
329 " <xs:element name=\"ClassArrayContainer\" nillable=\"true\" type=\"tns:ClassArrayContainer\" />{0}" +
330 " <xs:complexType name=\"ClassArrayContainer\">{0}" +
331 " <xs:sequence>{0}" +
332 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
333 " </xs:sequence>{0}" +
334 " </xs:complexType>{0}" +
335 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
336 " <xs:sequence>{0}" +
337 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
338 " </xs:sequence>{0}" +
339 " </xs:complexType>{0}" +
340 " <xs:complexType name=\"SimpleClass\">{0}" +
341 " <xs:sequence>{0}" +
342 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
343 " </xs:sequence>{0}" +
344 " </xs:complexType>{0}" +
345 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
347 schemas = Export (typeof (ClassArrayContainer));
348 Assert.AreEqual (1, schemas.Count, "#3");
350 sw.GetStringBuilder ().Length = 0;
351 schemas[0].Write (sw);
353 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
354 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
355 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
356 " <xs:element name=\"ClassArrayContainer\" nillable=\"true\" type=\"ClassArrayContainer\" />{0}" +
357 " <xs:complexType name=\"ClassArrayContainer\">{0}" +
358 " <xs:sequence>{0}" +
359 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfSimpleClass\" />{0}" +
360 " </xs:sequence>{0}" +
361 " </xs:complexType>{0}" +
362 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
363 " <xs:sequence>{0}" +
364 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
365 " </xs:sequence>{0}" +
366 " </xs:complexType>{0}" +
367 " <xs:complexType name=\"SimpleClass\">{0}" +
368 " <xs:sequence>{0}" +
369 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
370 " </xs:sequence>{0}" +
371 " </xs:complexType>{0}" +
372 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
376 public void ExportClass_SimpleClassWithXmlAttributes ()
378 XmlSchemas schemas = Export (typeof (SimpleClassWithXmlAttributes), "NSSimpleClassWithXmlAttributes");
379 Assert.AreEqual (1, schemas.Count, "#1");
381 StringWriter sw = new StringWriter ();
382 schemas[0].Write (sw);
384 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
385 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
386 "<xs:schema xmlns:tns=\"NSSimpleClassWithXmlAttributes\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassWithXmlAttributes\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
387 " <xs:element name=\"simple\" nillable=\"true\" type=\"tns:SimpleClassWithXmlAttributes\" />{0}" +
388 " <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
389 " <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
390 " </xs:complexType>{0}" +
391 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
393 schemas = Export (typeof (SimpleClassWithXmlAttributes));
394 Assert.AreEqual (1, schemas.Count, "#3");
396 sw.GetStringBuilder ().Length = 0;
397 schemas[0].Write (sw);
399 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
400 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
401 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
402 " <xs:element name=\"simple\" nillable=\"true\" type=\"SimpleClassWithXmlAttributes\" />{0}" +
403 " <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
404 " <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
405 " </xs:complexType>{0}" +
406 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
410 public void ExportClass_Field ()
412 XmlSchemas schemas = Export (typeof (Field), "NSField");
413 Assert.AreEqual (1, schemas.Count, "#1");
415 StringWriter sw = new StringWriter ();
416 schemas[0].Write (sw);
418 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
419 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
420 "<xs:schema xmlns:tns=\"NSField\" elementFormDefault=\"qualified\" targetNamespace=\"NSField\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
421 " <xs:element name=\"field\" nillable=\"true\" type=\"tns:Field\" />{0}" +
422 " <xs:complexType name=\"Field\">{0}" +
423 " <xs:attribute default=\"one\" name=\"flag1\" type=\"tns:FlagEnum\" />{0}" +
424 " <xs:attribute default=\"one\" name=\"flag2\" type=\"tns:FlagEnum\" />{0}" +
425 " <xs:attribute default=\"one two\" form=\"qualified\" name=\"flag3\" type=\"tns:FlagEnum\" />{0}" +
426 " <xs:attribute name=\"flag4\" type=\"tns:FlagEnum\" use=\"required\" />{0}" +
427 " <xs:attribute name=\"modifiers\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
428 " <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
429 " <xs:attribute default=\"public\" name=\"modifiers3\" type=\"tns:MapModifiers\" />{0}" +
430 " <xs:attribute default=\"protected\" form=\"unqualified\" name=\"modifiers4\" type=\"tns:MapModifiers\" />{0}" +
431 " <xs:attribute default=\"public\" form=\"qualified\" name=\"modifiers5\" type=\"tns:MapModifiers\" />{0}" +
432 " <xs:attribute name=\"names\">{0}" +
433 " <xs:simpleType>{0}" +
434 " <xs:list itemType=\"xs:string\" />{0}" +
435 " </xs:simpleType>{0}" +
436 " </xs:attribute>{0}" +
437 " <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
438 " </xs:complexType>{0}" +
439 " <xs:simpleType name=\"FlagEnum\">{0}" +
441 " <xs:simpleType>{0}" +
442 " <xs:restriction base=\"xs:string\">{0}" +
443 " <xs:enumeration value=\"one\" />{0}" +
444 " <xs:enumeration value=\"two\" />{0}" +
445 " <xs:enumeration value=\"four\" />{0}" +
446 " </xs:restriction>{0}" +
447 " </xs:simpleType>{0}" +
449 " </xs:simpleType>{0}" +
450 " <xs:simpleType name=\"MapModifiers\">{0}" +
452 " <xs:simpleType>{0}" +
453 " <xs:restriction base=\"xs:string\">{0}" +
454 " <xs:enumeration value=\"public\" />{0}" +
455 " <xs:enumeration value=\"protected\" />{0}" +
456 " </xs:restriction>{0}" +
457 " </xs:simpleType>{0}" +
459 " </xs:simpleType>{0}" +
460 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
462 schemas = Export (typeof (Field));
463 Assert.AreEqual (1, schemas.Count, "#3");
465 sw.GetStringBuilder ().Length = 0;
466 schemas[0].Write (sw);
468 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
469 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
470 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
471 " <xs:element name=\"field\" nillable=\"true\" type=\"Field\" />{0}" +
472 " <xs:complexType name=\"Field\">{0}" +
473 " <xs:attribute default=\"one\" name=\"flag1\" type=\"FlagEnum\" />{0}" +
474 " <xs:attribute default=\"one\" name=\"flag2\" type=\"FlagEnum\" />{0}" +
475 " <xs:attribute default=\"one two\" form=\"qualified\" name=\"flag3\" type=\"FlagEnum\" />{0}" +
476 " <xs:attribute name=\"flag4\" type=\"FlagEnum\" use=\"required\" />{0}" +
477 " <xs:attribute name=\"modifiers\" type=\"MapModifiers\" use=\"required\" />{0}" +
478 " <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"MapModifiers\" use=\"required\" />{0}" +
479 " <xs:attribute default=\"public\" name=\"modifiers3\" type=\"MapModifiers\" />{0}" +
480 " <xs:attribute default=\"protected\" form=\"unqualified\" name=\"modifiers4\" type=\"MapModifiers\" />{0}" +
481 " <xs:attribute default=\"public\" form=\"qualified\" name=\"modifiers5\" type=\"MapModifiers\" />{0}" +
482 " <xs:attribute name=\"names\">{0}" +
483 " <xs:simpleType>{0}" +
484 " <xs:list itemType=\"xs:string\" />{0}" +
485 " </xs:simpleType>{0}" +
486 " </xs:attribute>{0}" +
487 " <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
488 " </xs:complexType>{0}" +
489 " <xs:simpleType name=\"FlagEnum\">{0}" +
491 " <xs:simpleType>{0}" +
492 " <xs:restriction base=\"xs:string\">{0}" +
493 " <xs:enumeration value=\"one\" />{0}" +
494 " <xs:enumeration value=\"two\" />{0}" +
495 " <xs:enumeration value=\"four\" />{0}" +
496 " </xs:restriction>{0}" +
497 " </xs:simpleType>{0}" +
499 " </xs:simpleType>{0}" +
500 " <xs:simpleType name=\"MapModifiers\">{0}" +
502 " <xs:simpleType>{0}" +
503 " <xs:restriction base=\"xs:string\">{0}" +
504 " <xs:enumeration value=\"public\" />{0}" +
505 " <xs:enumeration value=\"protected\" />{0}" +
506 " </xs:restriction>{0}" +
507 " </xs:simpleType>{0}" +
509 " </xs:simpleType>{0}" +
510 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
514 public void ExportClass_MyList ()
516 XmlSchemas schemas = Export (typeof (MyList), "NSMyList");
517 Assert.AreEqual (1, schemas.Count, "#1");
519 StringWriter sw = new StringWriter ();
520 schemas[0].Write (sw);
522 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
523 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
524 "<xs:schema xmlns:tns=\"NSMyList\" elementFormDefault=\"qualified\" targetNamespace=\"NSMyList\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
525 " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"tns:ArrayOfAnyType\" />{0}" +
526 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
527 " <xs:sequence>{0}" +
528 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
529 " </xs:sequence>{0}" +
530 " </xs:complexType>{0}" +
531 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
533 schemas = Export (typeof (MyList));
534 Assert.AreEqual (1, schemas.Count, "#3");
536 sw.GetStringBuilder ().Length = 0;
537 schemas[0].Write (sw);
539 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
540 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
541 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
542 " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"ArrayOfAnyType\" />{0}" +
543 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
544 " <xs:sequence>{0}" +
545 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
546 " </xs:sequence>{0}" +
547 " </xs:complexType>{0}" +
548 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
552 public void ExportClass_Container ()
554 XmlSchemas schemas = Export (typeof (Container), "NSContainer");
555 Assert.AreEqual (1, schemas.Count, "#1");
557 StringWriter sw = new StringWriter ();
558 schemas[0].Write (sw);
560 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
561 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
562 "<xs:schema xmlns:tns=\"NSContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
563 " <xs:element name=\"Container\" nillable=\"true\" type=\"tns:Container\" />{0}" +
564 " <xs:complexType name=\"Container\">{0}" +
565 " <xs:sequence>{0}" +
566 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
567 " </xs:sequence>{0}" +
568 " </xs:complexType>{0}" +
569 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
570 " <xs:sequence>{0}" +
571 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
572 " </xs:sequence>{0}" +
573 " </xs:complexType>{0}" +
574 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
576 schemas = Export (typeof (Container));
577 Assert.AreEqual (1, schemas.Count, "#3");
579 sw.GetStringBuilder ().Length = 0;
580 schemas[0].Write (sw);
582 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
583 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
584 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
585 " <xs:element name=\"Container\" nillable=\"true\" type=\"Container\" />{0}" +
586 " <xs:complexType name=\"Container\">{0}" +
587 " <xs:sequence>{0}" +
588 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
589 " </xs:sequence>{0}" +
590 " </xs:complexType>{0}" +
591 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
592 " <xs:sequence>{0}" +
593 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
594 " </xs:sequence>{0}" +
595 " </xs:complexType>{0}" +
596 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
600 public void ExportClass_Container2 ()
602 XmlSchemas schemas = Export (typeof (Container2), "NSContainer2");
603 Assert.AreEqual (1, schemas.Count, "#1");
605 StringWriter sw = new StringWriter ();
606 schemas[0].Write (sw);
608 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
609 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
610 "<xs:schema xmlns:tns=\"NSContainer2\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
611 " <xs:element name=\"Container2\" nillable=\"true\" type=\"tns:Container2\" />{0}" +
612 " <xs:complexType name=\"Container2\">{0}" +
613 " <xs:sequence>{0}" +
614 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
615 " </xs:sequence>{0}" +
616 " </xs:complexType>{0}" +
617 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
618 " <xs:sequence>{0}" +
619 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
620 " </xs:sequence>{0}" +
621 " </xs:complexType>{0}" +
622 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
624 schemas = Export (typeof (Container2));
625 Assert.AreEqual (1, schemas.Count, "#3");
627 sw.GetStringBuilder ().Length = 0;
628 schemas[0].Write (sw);
630 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
631 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
632 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
633 " <xs:element name=\"Container2\" nillable=\"true\" type=\"Container2\" />{0}" +
634 " <xs:complexType name=\"Container2\">{0}" +
635 " <xs:sequence>{0}" +
636 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
637 " </xs:sequence>{0}" +
638 " </xs:complexType>{0}" +
639 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
640 " <xs:sequence>{0}" +
641 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
642 " </xs:sequence>{0}" +
643 " </xs:complexType>{0}" +
644 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
648 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
649 [ExpectedException (typeof (InvalidOperationException))] // Cannot use wildcards at the top level of a schema.
650 public void ExportClass_MyElem ()
652 Export (typeof (MyElem), "NSMyElem");
656 public void ExportClass_CDataContainer ()
658 XmlSchemas schemas = Export (typeof (CDataContainer), "NSCDataContainer");
659 Assert.AreEqual (1, schemas.Count, "#1");
661 StringWriter sw = new StringWriter ();
662 schemas[0].Write (sw);
664 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
665 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
666 "<xs:schema xmlns:tns=\"NSCDataContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSCDataContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
667 " <xs:element name=\"CDataContainer\" nillable=\"true\" type=\"tns:CDataContainer\" />{0}" +
668 " <xs:complexType name=\"CDataContainer\">{0}" +
669 " <xs:sequence>{0}" +
670 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
671 " <xs:complexType mixed=\"true\">{0}" +
672 " <xs:sequence>{0}" +
674 " </xs:sequence>{0}" +
675 " </xs:complexType>{0}" +
676 " </xs:element>{0}" +
677 " </xs:sequence>{0}" +
678 " </xs:complexType>{0}" +
679 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
681 schemas = Export (typeof (CDataContainer));
682 Assert.AreEqual (1, schemas.Count, "#3");
684 sw.GetStringBuilder ().Length = 0;
685 schemas[0].Write (sw);
687 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
688 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
689 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
690 " <xs:element name=\"CDataContainer\" nillable=\"true\" type=\"CDataContainer\" />{0}" +
691 " <xs:complexType name=\"CDataContainer\">{0}" +
692 " <xs:sequence>{0}" +
693 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
694 " <xs:complexType mixed=\"true\">{0}" +
695 " <xs:sequence>{0}" +
697 " </xs:sequence>{0}" +
698 " </xs:complexType>{0}" +
699 " </xs:element>{0}" +
700 " </xs:sequence>{0}" +
701 " </xs:complexType>{0}" +
702 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
706 public void ExportClass_NodeContainer ()
708 XmlSchemas schemas = Export (typeof (NodeContainer), "NSNodeContainer");
709 Assert.AreEqual (1, schemas.Count, "#1");
711 StringWriter sw = new StringWriter ();
712 schemas[0].Write (sw);
714 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
715 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
716 "<xs:schema xmlns:tns=\"NSNodeContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSNodeContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
717 " <xs:element name=\"NodeContainer\" nillable=\"true\" type=\"tns:NodeContainer\" />{0}" +
718 " <xs:complexType name=\"NodeContainer\">{0}" +
719 " <xs:sequence>{0}" +
720 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
721 " <xs:complexType mixed=\"true\">{0}" +
722 " <xs:sequence>{0}" +
724 " </xs:sequence>{0}" +
725 " </xs:complexType>{0}" +
726 " </xs:element>{0}" +
727 " </xs:sequence>{0}" +
728 " </xs:complexType>{0}" +
729 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
731 schemas = Export (typeof (NodeContainer));
732 Assert.AreEqual (1, schemas.Count, "#3");
734 sw.GetStringBuilder ().Length = 0;
735 schemas[0].Write (sw);
737 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
738 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
739 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
740 " <xs:element name=\"NodeContainer\" nillable=\"true\" type=\"NodeContainer\" />{0}" +
741 " <xs:complexType name=\"NodeContainer\">{0}" +
742 " <xs:sequence>{0}" +
743 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
744 " <xs:complexType mixed=\"true\">{0}" +
745 " <xs:sequence>{0}" +
747 " </xs:sequence>{0}" +
748 " </xs:complexType>{0}" +
749 " </xs:element>{0}" +
750 " </xs:sequence>{0}" +
751 " </xs:complexType>{0}" +
752 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
756 [Category ("NotWorking")] // Mono does not generate the <xs:choice> node
757 [Category ("NotDotNet")] // MS.NET randomly modifies the order of the elements! -> Of course. There is nothing strange. The test is rather strange.
758 public void ExportClass_Choices ()
760 XmlSchemas schemas = Export (typeof (Choices), "NSChoices");
761 Assert.AreEqual (1, schemas.Count, "#1");
763 StringWriter sw = new StringWriter ();
764 schemas[0].Write (sw);
766 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
767 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
768 "<xs:schema xmlns:tns=\"NSChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
769 " <xs:element name=\"Choices\" type=\"tns:Choices\" />{0}" +
770 " <xs:complexType name=\"Choices\">{0}" +
771 " <xs:sequence>{0}" +
772 " <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
773 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
774 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
775 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
777 " </xs:sequence>{0}" +
778 " </xs:complexType>{0}" +
779 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
781 schemas = Export (typeof (Choices));
782 Assert.AreEqual (1, schemas.Count, "#3");
784 sw.GetStringBuilder ().Length = 0;
785 schemas[0].Write (sw);
787 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
788 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
789 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
790 " <xs:element name=\"Choices\" type=\"Choices\" />{0}" +
791 " <xs:complexType name=\"Choices\">{0}" +
792 " <xs:sequence>{0}" +
793 " <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
794 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
795 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
796 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
798 " </xs:sequence>{0}" +
799 " </xs:complexType>{0}" +
800 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
805 [Category ("NotDotNet")] // MS.NET 1.x does not escape spaces in a type name, bug is fixed in .NET 2.0
807 public void ExportClass_TestSpace ()
809 XmlSchemas schemas = Export (typeof (TestSpace), "NSTestSpace");
810 Assert.AreEqual (1, schemas.Count, "#1");
812 StringWriter sw = new StringWriter ();
813 schemas[0].Write (sw);
815 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
816 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
817 "<xs:schema xmlns:tns=\"NSTestSpace\" elementFormDefault=\"qualified\" targetNamespace=\"NSTestSpace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
818 " <xs:element name=\"Type_x0020_with_x0020_space\" nillable=\"true\" type=\"tns:Type_x0020_with_x0020_space\" />{0}" +
819 " <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
820 " <xs:sequence>{0}" +
821 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
822 " </xs:sequence>{0}" +
823 " <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
824 " </xs:complexType>{0}" +
825 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
827 schemas = Export (typeof (TestSpace));
828 Assert.AreEqual (1, schemas.Count, "#3");
830 sw.GetStringBuilder ().Length = 0;
831 schemas[0].Write (sw);
833 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
834 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
835 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
836 " <xs:element name=\"Type_x0020_with_x0020_space\" nillable=\"true\" type=\"Type_x0020_with_x0020_space\" />{0}" +
837 " <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
838 " <xs:sequence>{0}" +
839 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
840 " </xs:sequence>{0}" +
841 " <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
842 " </xs:complexType>{0}" +
843 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
847 public void ExportClass_OptionalValueTypeContainer ()
849 XmlAttributeOverrides overrides;
852 XmlSchemas schemas = Export (typeof (OptionalValueTypeContainer));
853 Assert.AreEqual (2, schemas.Count, "#1");
855 StringWriter sw = new StringWriter ();
856 schemas[0].Write (sw);
858 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
859 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
860 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
861 " <xs:import namespace=\"{2}\" />{0}" +
862 " <xs:element name=\"optionalValue\" xmlns:q1=\"{2}\" type=\"q1:optionalValueType\" />{0}" +
863 "</xs:schema>", Environment.NewLine, AnotherNamespace, ANamespace),
864 sw.ToString (), "#2");
866 sw.GetStringBuilder ().Length = 0;
867 schemas[1].Write (sw);
869 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
870 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
871 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
872 " <xs:complexType name=\"optionalValueType\">{0}" +
873 " <xs:sequence>{0}" +
874 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"one four\" name=\"Attributes\" type=\"tns:FlagEnum\" />{0}" +
875 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"one\" name=\"Flags\" type=\"tns:FlagEnum\" />{0}" +
876 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"false\" name=\"IsEmpty\" type=\"xs:boolean\" />{0}" +
877 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"false\" name=\"IsNull\" type=\"xs:boolean\" />{0}" +
878 " </xs:sequence>{0}" +
879 " </xs:complexType>{0}" +
880 " <xs:simpleType name=\"FlagEnum\">{0}" +
882 " <xs:simpleType>{0}" +
883 " <xs:restriction base=\"xs:string\">{0}" +
884 " <xs:enumeration value=\"one\" />{0}" +
885 " <xs:enumeration value=\"two\" />{0}" +
886 " <xs:enumeration value=\"four\" />{0}" +
887 " </xs:restriction>{0}" +
888 " </xs:simpleType>{0}" +
890 " </xs:simpleType>{0}" +
891 "</xs:schema>", Environment.NewLine, ANamespace), sw.ToString (), "#3");
893 overrides = new XmlAttributeOverrides ();
894 attr = new XmlAttributes ();
896 // remove the DefaultValue attribute on the Flags member
897 overrides.Add (typeof (OptionalValueTypeContainer), "Flags", attr);
898 // remove the DefaultValue attribute on the Attributes member
899 overrides.Add (typeof (OptionalValueTypeContainer), "Attributes", attr);
900 // remove the DefaultValue attribute on the IsEmpty member
901 overrides.Add (typeof (OptionalValueTypeContainer), "IsEmpty", attr);
902 // remove the DefaultValue attribute on the IsNull member
903 overrides.Add (typeof (OptionalValueTypeContainer), "IsNull", attr);
905 schemas = Export (typeof (OptionalValueTypeContainer), overrides, "urn:myNS");
906 Assert.AreEqual (2, schemas.Count, "#4");
908 sw.GetStringBuilder ().Length = 0;
909 schemas[0].Write (sw);
911 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
912 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
913 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
914 " <xs:import namespace=\"{2}\" />{0}" +
915 " <xs:element name=\"optionalValue\" xmlns:q1=\"{2}\" type=\"q1:optionalValueType\" />{0}" +
916 "</xs:schema>", Environment.NewLine, AnotherNamespace, ANamespace),
917 sw.ToString (), "#5");
919 sw.GetStringBuilder ().Length = 0;
920 schemas[1].Write (sw);
922 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
923 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
924 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
925 " <xs:complexType name=\"optionalValueType\">{0}" +
926 " <xs:sequence>{0}" +
927 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Attributes\" type=\"tns:FlagEnum\" />{0}" +
928 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Flags\" type=\"tns:FlagEnum\" />{0}" +
929 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"IsEmpty\" type=\"xs:boolean\" />{0}" +
930 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"IsNull\" type=\"xs:boolean\" />{0}" +
931 " </xs:sequence>{0}" +
932 " </xs:complexType>{0}" +
933 " <xs:simpleType name=\"FlagEnum\">{0}" +
935 " <xs:simpleType>{0}" +
936 " <xs:restriction base=\"xs:string\">{0}" +
937 " <xs:enumeration value=\"one\" />{0}" +
938 " <xs:enumeration value=\"two\" />{0}" +
939 " <xs:enumeration value=\"four\" />{0}" +
940 " </xs:restriction>{0}" +
941 " </xs:simpleType>{0}" +
943 " </xs:simpleType>{0}" +
944 "</xs:schema>", Environment.NewLine, ANamespace), sw.ToString (), "#6");
948 public void ExportClass_ReadOnlyProperties ()
950 XmlSchemas schemas = Export (typeof (ReadOnlyProperties), "NSReadOnlyProperties");
951 Assert.AreEqual (1, schemas.Count, "#1");
953 StringWriter sw = new StringWriter ();
954 schemas[0].Write (sw);
956 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
957 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
958 "<xs:schema xmlns:tns=\"NSReadOnlyProperties\" elementFormDefault=\"qualified\" targetNamespace=\"NSReadOnlyProperties\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
959 " <xs:element name=\"ReadOnlyProperties\" nillable=\"true\" type=\"tns:ReadOnlyProperties\" />{0}" +
960 " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
961 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
963 schemas = Export (typeof (ReadOnlyProperties));
964 Assert.AreEqual (1, schemas.Count, "#3");
966 sw.GetStringBuilder ().Length = 0;
967 schemas[0].Write (sw);
969 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
970 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
971 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
972 " <xs:element name=\"ReadOnlyProperties\" nillable=\"true\" type=\"ReadOnlyProperties\" />{0}" +
973 " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
974 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
978 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
979 public void ExportClass_ListDefaults ()
981 XmlSchemas schemas = Export (typeof (ListDefaults), "NSListDefaults");
982 Assert.AreEqual (1, schemas.Count, "#1");
984 StringWriter sw = new StringWriter ();
985 schemas[0].Write (sw);
987 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
988 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
989 "<xs:schema xmlns:tns=\"NSListDefaults\" elementFormDefault=\"qualified\" targetNamespace=\"NSListDefaults\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
990 " <xs:element name=\"root\" nillable=\"true\" type=\"tns:ListDefaults\" />{0}" +
991 " <xs:complexType name=\"ListDefaults\">{0}" +
992 " <xs:sequence>{0}" +
993 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"tns:ArrayOfAnyType\" />{0}" +
994 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"tns:ArrayOfAnyType\" />{0}" +
995 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"tns:ArrayOfString\" />{0}" +
996 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"tns:SimpleClass\" />{0}" +
997 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"tns:SimpleClass\" />{0}" +
998 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
999 " </xs:sequence>{0}" +
1000 " </xs:complexType>{0}" +
1001 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1002 " <xs:sequence>{0}" +
1003 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1004 " </xs:sequence>{0}" +
1005 " </xs:complexType>{0}" +
1006 " <xs:complexType name=\"ArrayOfString\">{0}" +
1007 " <xs:sequence>{0}" +
1008 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
1009 " </xs:sequence>{0}" +
1010 " </xs:complexType>{0}" +
1011 " <xs:complexType name=\"SimpleClass\">{0}" +
1012 " <xs:sequence>{0}" +
1013 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
1014 " </xs:sequence>{0}" +
1015 " </xs:complexType>{0}" +
1016 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1018 schemas = Export (typeof (ListDefaults));
1019 Assert.AreEqual (1, schemas.Count, "#3");
1021 sw.GetStringBuilder ().Length = 0;
1022 schemas[0].Write (sw);
1024 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1025 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1026 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1027 " <xs:element name=\"root\" nillable=\"true\" type=\"ListDefaults\" />{0}" +
1028 " <xs:complexType name=\"ListDefaults\">{0}" +
1029 " <xs:sequence>{0}" +
1030 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"ArrayOfAnyType\" />{0}" +
1031 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"ArrayOfAnyType\" />{0}" +
1032 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"ArrayOfString\" />{0}" +
1033 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"SimpleClass\" />{0}" +
1034 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"SimpleClass\" />{0}" +
1035 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
1036 " </xs:sequence>{0}" +
1037 " </xs:complexType>{0}" +
1038 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1039 " <xs:sequence>{0}" +
1040 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1041 " </xs:sequence>{0}" +
1042 " </xs:complexType>{0}" +
1043 " <xs:complexType name=\"ArrayOfString\">{0}" +
1044 " <xs:sequence>{0}" +
1045 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
1046 " </xs:sequence>{0}" +
1047 " </xs:complexType>{0}" +
1048 " <xs:complexType name=\"SimpleClass\">{0}" +
1049 " <xs:sequence>{0}" +
1050 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
1051 " </xs:sequence>{0}" +
1052 " </xs:complexType>{0}" +
1053 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1057 public void ExportClass_ClsPerson ()
1059 XmlSchemas schemas = Export (typeof (clsPerson), "NSClsPerson");
1060 Assert.AreEqual (1, schemas.Count, "#1");
1062 StringWriter sw = new StringWriter ();
1063 schemas[0].Write (sw);
1065 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1066 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1067 "<xs:schema xmlns:tns=\"NSClsPerson\" elementFormDefault=\"qualified\" targetNamespace=\"NSClsPerson\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1068 " <xs:element name=\"clsPerson\" nillable=\"true\" type=\"tns:clsPerson\" />{0}" +
1069 " <xs:complexType name=\"clsPerson\">{0}" +
1070 " <xs:sequence>{0}" +
1071 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"tns:ArrayOfAnyType\" />{0}" +
1072 " </xs:sequence>{0}" +
1073 " </xs:complexType>{0}" +
1074 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1075 " <xs:sequence>{0}" +
1076 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1077 " </xs:sequence>{0}" +
1078 " </xs:complexType>{0}" +
1079 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1081 schemas = Export (typeof (clsPerson));
1082 Assert.AreEqual (1, schemas.Count, "#3");
1084 sw.GetStringBuilder ().Length = 0;
1085 schemas[0].Write (sw);
1087 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1088 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1089 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1090 " <xs:element name=\"clsPerson\" nillable=\"true\" type=\"clsPerson\" />{0}" +
1091 " <xs:complexType name=\"clsPerson\">{0}" +
1092 " <xs:sequence>{0}" +
1093 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"ArrayOfAnyType\" />{0}" +
1094 " </xs:sequence>{0}" +
1095 " </xs:complexType>{0}" +
1096 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
1097 " <xs:sequence>{0}" +
1098 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
1099 " </xs:sequence>{0}" +
1100 " </xs:complexType>{0}" +
1101 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1105 public void ExportClass_ArrayClass ()
1107 XmlSchemas schemas = Export (typeof (ArrayClass), "NSArrayClass");
1108 Assert.AreEqual (1, schemas.Count, "#1");
1110 StringWriter sw = new StringWriter ();
1111 schemas[0].Write (sw);
1113 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1114 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1115 "<xs:schema xmlns:tns=\"NSArrayClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1116 " <xs:element name=\"ArrayClass\" nillable=\"true\" type=\"tns:ArrayClass\" />{0}" +
1117 " <xs:complexType name=\"ArrayClass\">{0}" +
1118 " <xs:sequence>{0}" +
1119 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"names\" />{0}" +
1120 " </xs:sequence>{0}" +
1121 " </xs:complexType>{0}" +
1122 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1124 schemas = Export (typeof (ArrayClass));
1125 Assert.AreEqual (1, schemas.Count, "#3");
1127 sw.GetStringBuilder ().Length = 0;
1128 schemas[0].Write (sw);
1130 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1131 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1132 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1133 " <xs:element name=\"ArrayClass\" nillable=\"true\" type=\"ArrayClass\" />{0}" +
1134 " <xs:complexType name=\"ArrayClass\">{0}" +
1135 " <xs:sequence>{0}" +
1136 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"names\" />{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_StructContainer ()
1146 XmlSchemas schemas = Export (typeof (StructContainer), "NSStructContainer");
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=\"NSStructContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStructContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1155 " <xs:element name=\"StructContainer\" nillable=\"true\" type=\"tns:StructContainer\" />{0}" +
1156 " <xs:complexType name=\"StructContainer\">{0}" +
1157 " <xs:sequence>{0}" +
1158 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"tns:EnumDefaultValue\" />{0}" +
1159 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Times\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
1160 " </xs:sequence>{0}" +
1161 " </xs:complexType>{0}" +
1162 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1164 " <xs:simpleType>{0}" +
1165 " <xs:restriction base=\"xs:string\">{0}" +
1166 " <xs:enumeration value=\"e1\" />{0}" +
1167 " <xs:enumeration value=\"e2\" />{0}" +
1168 " <xs:enumeration value=\"e3\" />{0}" +
1169 " </xs:restriction>{0}" +
1170 " </xs:simpleType>{0}" +
1172 " </xs:simpleType>{0}" +
1173 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
1174 " <xs:sequence>{0}" +
1175 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
1176 " </xs:sequence>{0}" +
1177 " </xs:complexType>{0}" +
1178 " <xs:complexType name=\"TimeSpan\" />{0}" +
1179 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1181 schemas = Export (typeof (StructContainer));
1182 Assert.AreEqual (1, schemas.Count, "#3");
1184 sw.GetStringBuilder ().Length = 0;
1185 schemas[0].Write (sw);
1187 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1188 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1189 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1190 " <xs:element name=\"StructContainer\" nillable=\"true\" type=\"StructContainer\" />{0}" +
1191 " <xs:complexType name=\"StructContainer\">{0}" +
1192 " <xs:sequence>{0}" +
1193 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"EnumDefaultValue\" />{0}" +
1194 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Times\" type=\"ArrayOfTimeSpan\" />{0}" +
1195 " </xs:sequence>{0}" +
1196 " </xs:complexType>{0}" +
1197 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1199 " <xs:simpleType>{0}" +
1200 " <xs:restriction base=\"xs:string\">{0}" +
1201 " <xs:enumeration value=\"e1\" />{0}" +
1202 " <xs:enumeration value=\"e2\" />{0}" +
1203 " <xs:enumeration value=\"e3\" />{0}" +
1204 " </xs:restriction>{0}" +
1205 " </xs:simpleType>{0}" +
1207 " </xs:simpleType>{0}" +
1208 " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
1209 " <xs:sequence>{0}" +
1210 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
1211 " </xs:sequence>{0}" +
1212 " </xs:complexType>{0}" +
1213 " <xs:complexType name=\"TimeSpan\" />{0}" +
1214 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1218 public void ExportClass_TestDefault ()
1220 XmlSchemas schemas = Export (typeof (TestDefault));
1221 Assert.AreEqual (1, schemas.Count, "#1");
1223 StringWriter sw = new StringWriter ();
1224 schemas [0].Write (sw);
1226 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1227 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1228 "<xs:schema xmlns:tns=\"urn:myNS\" elementFormDefault=\"qualified\" targetNamespace=\"urn:myNS\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1229 " <xs:element name=\"testDefault\" type=\"tns:TestDefault\" />{0}" +
1230 " <xs:complexType name=\"TestDefault\">{0}" +
1231 " <xs:sequence>{0}" +
1232 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
1233 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"Default Value\" name=\"strDefault\" type=\"xs:string\" />{0}" +
1234 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"true\" name=\"boolT\" type=\"xs:boolean\" />{0}" +
1235 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"false\" name=\"boolF\" type=\"xs:boolean\" />{0}" +
1236 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"10\" name=\"decimalval\" type=\"xs:decimal\" />{0}" +
1237 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"one four\" name=\"flag\" type=\"tns:FlagEnum\" />{0}" +
1238 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"e1 e4\" name=\"flagencoded\" type=\"tns:FlagEnum_Encoded\" />{0}" +
1239 " </xs:sequence>{0}" +
1240 " </xs:complexType>{0}" +
1241 " <xs:simpleType name=\"FlagEnum\">{0}" +
1243 " <xs:simpleType>{0}" +
1244 " <xs:restriction base=\"xs:string\">{0}" +
1245 " <xs:enumeration value=\"one\" />{0}" +
1246 " <xs:enumeration value=\"two\" />{0}" +
1247 " <xs:enumeration value=\"four\" />{0}" +
1248 " </xs:restriction>{0}" +
1249 " </xs:simpleType>{0}" +
1251 " </xs:simpleType>{0}" +
1252 " <xs:simpleType name=\"FlagEnum_Encoded\">{0}" +
1254 " <xs:simpleType>{0}" +
1255 " <xs:restriction base=\"xs:string\">{0}" +
1256 " <xs:enumeration value=\"e1\" />{0}" +
1257 " <xs:enumeration value=\"e2\" />{0}" +
1258 " <xs:enumeration value=\"e4\" />{0}" +
1259 " </xs:restriction>{0}" +
1260 " </xs:simpleType>{0}" +
1262 " </xs:simpleType>{0}" +
1263 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1265 schemas = Export (typeof (TestDefault), "NSTestDefault");
1266 Assert.AreEqual (1, schemas.Count, "#3");
1268 sw.GetStringBuilder ().Length = 0;
1269 schemas [0].Write (sw);
1271 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1272 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1273 "<xs:schema xmlns:tns=\"urn:myNS\" elementFormDefault=\"qualified\" targetNamespace=\"urn:myNS\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1274 " <xs:element name=\"testDefault\" type=\"tns:TestDefault\" />{0}" +
1275 " <xs:complexType name=\"TestDefault\">{0}" +
1276 " <xs:sequence>{0}" +
1277 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
1278 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"Default Value\" name=\"strDefault\" type=\"xs:string\" />{0}" +
1279 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"true\" name=\"boolT\" type=\"xs:boolean\" />{0}" +
1280 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"false\" name=\"boolF\" type=\"xs:boolean\" />{0}" +
1281 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"10\" name=\"decimalval\" type=\"xs:decimal\" />{0}" +
1282 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"one four\" name=\"flag\" type=\"tns:FlagEnum\" />{0}" +
1283 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"e1 e4\" name=\"flagencoded\" type=\"tns:FlagEnum_Encoded\" />{0}" +
1284 " </xs:sequence>{0}" +
1285 " </xs:complexType>{0}" +
1286 " <xs:simpleType name=\"FlagEnum\">{0}" +
1288 " <xs:simpleType>{0}" +
1289 " <xs:restriction base=\"xs:string\">{0}" +
1290 " <xs:enumeration value=\"one\" />{0}" +
1291 " <xs:enumeration value=\"two\" />{0}" +
1292 " <xs:enumeration value=\"four\" />{0}" +
1293 " </xs:restriction>{0}" +
1294 " </xs:simpleType>{0}" +
1296 " </xs:simpleType>{0}" +
1297 " <xs:simpleType name=\"FlagEnum_Encoded\">{0}" +
1299 " <xs:simpleType>{0}" +
1300 " <xs:restriction base=\"xs:string\">{0}" +
1301 " <xs:enumeration value=\"e1\" />{0}" +
1302 " <xs:enumeration value=\"e2\" />{0}" +
1303 " <xs:enumeration value=\"e4\" />{0}" +
1304 " </xs:restriction>{0}" +
1305 " </xs:simpleType>{0}" +
1307 " </xs:simpleType>{0}" +
1308 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1312 public void ExportClass_TestDefault_Overrides ()
1314 XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
1315 XmlAttributes attr = new XmlAttributes ();
1316 XmlTypeAttribute xmlType = new XmlTypeAttribute ("flagenum");
1317 xmlType.Namespace = "yetanother:urn";
1318 attr.XmlType = xmlType;
1319 overrides.Add (typeof (FlagEnum_Encoded), attr);
1321 XmlSchemas schemas = Export (typeof (TestDefault), overrides, "NSTestDefault");
1322 Assert.AreEqual (2, schemas.Count, "#1");
1324 StringWriter sw = new StringWriter ();
1325 schemas [0].Write (sw);
1327 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1328 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1329 "<xs:schema xmlns:tns=\"urn:myNS\" elementFormDefault=\"qualified\" targetNamespace=\"urn:myNS\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1330 " <xs:import namespace=\"yetanother:urn\" />{0}" +
1331 " <xs:element name=\"testDefault\" type=\"tns:TestDefault\" />{0}" +
1332 " <xs:complexType name=\"TestDefault\">{0}" +
1333 " <xs:sequence>{0}" +
1334 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
1335 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"Default Value\" name=\"strDefault\" type=\"xs:string\" />{0}" +
1336 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"true\" name=\"boolT\" type=\"xs:boolean\" />{0}" +
1337 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"false\" name=\"boolF\" type=\"xs:boolean\" />{0}" +
1338 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"10\" name=\"decimalval\" type=\"xs:decimal\" />{0}" +
1339 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"one four\" name=\"flag\" type=\"tns:FlagEnum\" />{0}" +
1340 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"e1 e4\" name=\"flagencoded\" xmlns:q1=\"yetanother:urn\" type=\"q1:flagenum\" />{0}" +
1341 " </xs:sequence>{0}" +
1342 " </xs:complexType>{0}" +
1343 " <xs:simpleType name=\"FlagEnum\">{0}" +
1345 " <xs:simpleType>{0}" +
1346 " <xs:restriction base=\"xs:string\">{0}" +
1347 " <xs:enumeration value=\"one\" />{0}" +
1348 " <xs:enumeration value=\"two\" />{0}" +
1349 " <xs:enumeration value=\"four\" />{0}" +
1350 " </xs:restriction>{0}" +
1351 " </xs:simpleType>{0}" +
1353 " </xs:simpleType>{0}" +
1354 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1356 sw.GetStringBuilder ().Length = 0;
1357 schemas [1].Write (sw);
1359 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1360 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1361 "<xs:schema xmlns:tns=\"yetanother:urn\" elementFormDefault=\"qualified\" targetNamespace=\"yetanother:urn\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1362 " <xs:simpleType name=\"flagenum\">{0}" +
1364 " <xs:simpleType>{0}" +
1365 " <xs:restriction base=\"xs:string\">{0}" +
1366 " <xs:enumeration value=\"e1\" />{0}" +
1367 " <xs:enumeration value=\"e2\" />{0}" +
1368 " <xs:enumeration value=\"e4\" />{0}" +
1369 " </xs:restriction>{0}" +
1370 " </xs:simpleType>{0}" +
1372 " </xs:simpleType>{0}" +
1373 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
1377 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1378 [ExpectedException (typeof (InvalidOperationException))] // Cannot use wildcards at the top level of a schema.
1379 public void ExportClass_XmlElement ()
1381 XmlSchemas schemas = Export (typeof (XmlElement), "NS1");
1385 public void ExportClass_Array ()
1387 XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
1388 XmlAttributes attr = new XmlAttributes ();
1389 XmlElementAttribute element = new XmlElementAttribute ();
1390 element.ElementName = "saying";
1391 element.IsNullable = true;
1392 attr.XmlElements.Add (element);
1393 overrides.Add (typeof (SimpleClass), "something", attr);
1395 XmlSchemas schemas = Export (typeof (SimpleClass[]), overrides, "NSSimpleClassArray");
1396 Assert.AreEqual (1, schemas.Count, "#1");
1398 StringWriter sw = new StringWriter ();
1399 schemas[0].Write (sw);
1401 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1402 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1403 "<xs:schema xmlns:tns=\"NSSimpleClassArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1404 " <xs:element name=\"ArrayOfSimpleClass\" nillable=\"true\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
1405 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
1406 " <xs:sequence>{0}" +
1407 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
1408 " </xs:sequence>{0}" +
1409 " </xs:complexType>{0}" +
1410 " <xs:complexType name=\"SimpleClass\">{0}" +
1411 " <xs:sequence>{0}" +
1412 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
1413 " </xs:sequence>{0}" +
1414 " </xs:complexType>{0}" +
1415 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1417 schemas = Export (typeof (SimpleClass[]), overrides);
1418 Assert.AreEqual (1, schemas.Count, "#3");
1420 sw.GetStringBuilder ().Length = 0;
1421 schemas[0].Write (sw);
1423 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1424 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1425 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1426 " <xs:element name=\"ArrayOfSimpleClass\" nillable=\"true\" type=\"ArrayOfSimpleClass\" />{0}" +
1427 " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
1428 " <xs:sequence>{0}" +
1429 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
1430 " </xs:sequence>{0}" +
1431 " </xs:complexType>{0}" +
1432 " <xs:complexType name=\"SimpleClass\">{0}" +
1433 " <xs:sequence>{0}" +
1434 " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
1435 " </xs:sequence>{0}" +
1436 " </xs:complexType>{0}" +
1437 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1441 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1442 public void ExportEnum ()
1444 XmlSchemas schemas = Export (typeof (EnumDefaultValue), "NSEnumDefaultValue");
1445 Assert.AreEqual (1, schemas.Count, "#1");
1447 StringWriter sw = new StringWriter ();
1448 schemas[0].Write (sw);
1450 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1451 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1452 "<xs:schema xmlns:tns=\"NSEnumDefaultValue\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValue\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1453 " <xs:element name=\"EnumDefaultValue\" type=\"tns:EnumDefaultValue\" />{0}" +
1454 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1456 " <xs:simpleType>{0}" +
1457 " <xs:restriction base=\"xs:string\">{0}" +
1458 " <xs:enumeration value=\"e1\" />{0}" +
1459 " <xs:enumeration value=\"e2\" />{0}" +
1460 " <xs:enumeration value=\"e3\" />{0}" +
1461 " </xs:restriction>{0}" +
1462 " </xs:simpleType>{0}" +
1464 " </xs:simpleType>{0}" +
1465 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1467 schemas = Export (typeof (EnumDefaultValueNF), "NSEnumDefaultValueNF");
1468 Assert.AreEqual (1, schemas.Count, "#3");
1470 sw.GetStringBuilder ().Length = 0;
1471 schemas[0].Write (sw);
1473 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1474 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1475 "<xs:schema xmlns:tns=\"NSEnumDefaultValueNF\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValueNF\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1476 " <xs:element name=\"EnumDefaultValueNF\" type=\"tns:EnumDefaultValueNF\" />{0}" +
1477 " <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
1478 " <xs:restriction base=\"xs:string\">{0}" +
1479 " <xs:enumeration value=\"e1\" />{0}" +
1480 " <xs:enumeration value=\"e2\" />{0}" +
1481 " <xs:enumeration value=\"e3\" />{0}" +
1482 " </xs:restriction>{0}" +
1483 " </xs:simpleType>{0}" +
1484 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1486 schemas = Export (typeof (EnumDefaultValue));
1487 Assert.AreEqual (1, schemas.Count, "#5");
1489 sw.GetStringBuilder ().Length = 0;
1490 schemas[0].Write (sw);
1492 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1493 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1494 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1495 " <xs:element name=\"EnumDefaultValue\" type=\"EnumDefaultValue\" />{0}" +
1496 " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
1498 " <xs:simpleType>{0}" +
1499 " <xs:restriction base=\"xs:string\">{0}" +
1500 " <xs:enumeration value=\"e1\" />{0}" +
1501 " <xs:enumeration value=\"e2\" />{0}" +
1502 " <xs:enumeration value=\"e3\" />{0}" +
1503 " </xs:restriction>{0}" +
1504 " </xs:simpleType>{0}" +
1506 " </xs:simpleType>{0}" +
1507 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
1509 schemas = Export (typeof (EnumDefaultValueNF));
1510 Assert.AreEqual (1, schemas.Count, "#7");
1512 sw.GetStringBuilder ().Length = 0;
1513 schemas[0].Write (sw);
1515 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1516 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1517 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1518 " <xs:element name=\"EnumDefaultValueNF\" type=\"EnumDefaultValueNF\" />{0}" +
1519 " <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
1520 " <xs:restriction base=\"xs:string\">{0}" +
1521 " <xs:enumeration value=\"e1\" />{0}" +
1522 " <xs:enumeration value=\"e2\" />{0}" +
1523 " <xs:enumeration value=\"e3\" />{0}" +
1524 " </xs:restriction>{0}" +
1525 " </xs:simpleType>{0}" +
1526 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1530 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1531 public void ExportXmlSerializable ()
1533 XmlSchemas schemas = Export (typeof (Employee), "NSEmployee");
1534 Assert.AreEqual (1, schemas.Count, "#1");
1536 StringWriter sw = new StringWriter ();
1537 schemas[0].Write (sw);
1539 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1540 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1541 "<xs:schema xmlns:tns=\"NSEmployee\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployee\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1542 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1543 " <xs:element name=\"Employee\" nillable=\"true\">{0}" +
1544 " <xs:complexType>{0}" +
1545 " <xs:sequence>{0}" +
1546 " <xs:element ref=\"xs:schema\" />{0}" +
1548 " </xs:sequence>{0}" +
1549 " </xs:complexType>{0}" +
1550 " </xs:element>{0}" +
1551 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1553 schemas = Export (typeof (Employee));
1554 Assert.AreEqual (1, schemas.Count, "#3");
1556 sw.GetStringBuilder ().Length = 0;
1557 schemas[0].Write (sw);
1559 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1560 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1561 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1562 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1563 " <xs:element name=\"Employee\" nillable=\"true\">{0}" +
1564 " <xs:complexType>{0}" +
1565 " <xs:sequence>{0}" +
1566 " <xs:element ref=\"xs:schema\" />{0}" +
1568 " </xs:sequence>{0}" +
1569 " </xs:complexType>{0}" +
1570 " </xs:element>{0}" +
1571 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
1575 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1576 public void ExportXmlSerializable_Schema ()
1578 XmlSchemas schemas = Export (typeof (EmployeeSchema), "NSEmployeeSchema");
1579 Assert.AreEqual (2, schemas.Count, "#1");
1581 StringWriter sw = new StringWriter ();
1582 schemas[0].Write (sw);
1584 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1585 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1586 "<xs:schema xmlns:tns=\"NSEmployeeSchema\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1588 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1590 " <xs:element name=\"EmployeeSchema\" nillable=\"true\">{0}" +
1591 " <xs:complexType>{0}" +
1592 " <xs:sequence>{0}" +
1593 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1594 " </xs:sequence>{0}" +
1595 " </xs:complexType>{0}" +
1596 " </xs:element>{0}" +
1597 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
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 xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1605 " <xs:complexType name=\"employeeRoot\">{0}" +
1606 " <xs:attribute name=\"firstName\" />{0}" +
1607 " <xs:attribute name=\"lastName\" />{0}" +
1608 " <xs:attribute name=\"address\" />{0}" +
1609 " </xs:complexType>{0}" +
1610 " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1611 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
1613 schemas = Export (typeof (EmployeeSchema));
1614 Assert.AreEqual (2, schemas.Count, "#4");
1616 sw.GetStringBuilder ().Length = 0;
1617 schemas[0].Write (sw);
1619 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1620 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1621 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1623 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1625 " <xs:element name=\"EmployeeSchema\" nillable=\"true\">{0}" +
1626 " <xs:complexType>{0}" +
1627 " <xs:sequence>{0}" +
1628 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1629 " </xs:sequence>{0}" +
1630 " </xs:complexType>{0}" +
1631 " </xs:element>{0}" +
1632 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
1634 sw.GetStringBuilder ().Length = 0;
1635 schemas[1].Write (sw);
1637 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1638 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1639 "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1640 " <xs:complexType name=\"employeeRoot\">{0}" +
1641 " <xs:attribute name=\"firstName\" />{0}" +
1642 " <xs:attribute name=\"lastName\" />{0}" +
1643 " <xs:attribute name=\"address\" />{0}" +
1644 " </xs:complexType>{0}" +
1645 " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1646 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
1648 schemas = Export (typeof (PrimitiveSchema), "NSPrimitiveSchema");
1649 Assert.AreEqual (2, schemas.Count, "#7");
1651 sw.GetStringBuilder ().Length = 0;
1652 schemas[0].Write (sw);
1654 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1655 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1656 "<xs:schema xmlns:tns=\"NSPrimitiveSchema\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimitiveSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1657 " <xs:element name=\"PrimitiveSchema\" nillable=\"true\">{0}" +
1658 " <xs:complexType>{0}" +
1659 " <xs:sequence>{0}" +
1660 " <xs:any namespace=\"\" />{0}" +
1661 " </xs:sequence>{0}" +
1662 " </xs:complexType>{0}" +
1663 " </xs:element>{0}" +
1664 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1666 sw.GetStringBuilder ().Length = 0;
1667 schemas[1].Write (sw);
1669 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1670 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1671 "<xs:schema id=\"LuckyNumberSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1672 " <xs:element name=\"LuckyNumber\" type=\"xs:int\" />{0}" +
1673 "</xs:schema>", Environment.NewLine), sw.ToString (), "#9");
1677 [ExpectedException (typeof (InvalidOperationException))] // Schema Id is missing
1678 public void ExportXmlSerializable_MissingID ()
1680 Export (typeof (MissingIDSchema));
1683 [ExpectedException (typeof (InvalidOperationException))]
1684 public void ExportXmlSerializable_DuplicateNamespace ()
1687 Export (typeof (PrimitiveSchema));
1689 } catch (InvalidOperationException) {
1690 // The namespace, , is a duplicate.
1694 Export (typeof (XmlSerializableContainer));
1696 } catch (InvalidOperationException) {
1697 // The namespace, , is a duplicate.
1703 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1705 public void ExportXmlSerializable_SchemaProvider ()
1707 XmlSchemas schemas = Export (typeof (EmployeeSchemaProvider), "NSEmployeeSchemaProvider");
1708 //Assert.AreEqual (1, schemas.Count, "#1"); //# of returned schemas is checked in ExportXmlSerializable_SchemaProvider1
1710 StringWriter sw = new StringWriter ();
1711 schemas[0].Write (sw);
1713 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
1714 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1715 "<xs:schema xmlns:tns=\"NSEmployeeSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployeeSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1717 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1718 " <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1720 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1721 " <xs:element name=\"EmployeeSchemaProvider\" nillable=\"true\">{0}" +
1722 " <xs:complexType>{0}" +
1723 " <xs:sequence>{0}" +
1724 " <xs:element ref=\"xs:schema\" />{0}" +
1726 " </xs:sequence>{0}" +
1727 " </xs:complexType>{0}" +
1728 " </xs:element>{0}" +
1730 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
1732 schemas = Export (typeof (EmployeeSchemaProvider));
1733 //Assert.AreEqual (1, schemas.Count, "#3");
1735 sw.GetStringBuilder ().Length = 0;
1736 schemas[0].Write (sw);
1738 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
1739 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1740 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1742 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1743 " <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1745 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1746 " <xs:element name=\"EmployeeSchemaProvider\" nillable=\"true\">{0}" +
1747 " <xs:complexType>{0}" +
1748 " <xs:sequence>{0}" +
1749 " <xs:element ref=\"xs:schema\" />{0}" +
1751 " </xs:sequence>{0}" +
1752 " </xs:complexType>{0}" +
1753 " </xs:element>{0}" +
1755 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
1757 schemas = Export (typeof (PrimitiveSchemaProvider), "NSPrimitiveSchemaProvider");
1758 //Assert.AreEqual (1, schemas.Count, "#5");
1760 sw.GetStringBuilder ().Length = 0;
1761 schemas[0].Write (sw);
1763 Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
1764 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1765 "<xs:schema xmlns:tns=\"NSPrimitiveSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimitiveSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1767 //" <xs:import />{0}" +
1768 " <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
1770 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1771 " <xs:element name=\"PrimitiveSchemaProvider\" nillable=\"true\">{0}" +
1772 " <xs:complexType>{0}" +
1773 " <xs:sequence>{0}" +
1774 " <xs:element ref=\"xs:schema\" />{0}" +
1776 " </xs:sequence>{0}" +
1777 " </xs:complexType>{0}" +
1778 " </xs:element>{0}" +
1780 "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ().Replace("<xs:import />" + Environment.NewLine, "")), "#6");
1785 [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
1787 public void ExportXmlSerializable_SchemaProvider1 () {
1788 XmlSchemas schemas = Export (typeof (PrimitiveSchemaProvider));
1789 Assert.AreEqual (1, schemas.Count, "#1");
1791 StringWriter sw = new StringWriter ();
1792 schemas[0].Write (sw);
1794 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1795 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1796 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1798 " <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
1800 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1801 " <xs:element name=\"PrimitiveSchemaProvider\" nillable=\"true\">{0}" +
1802 " <xs:complexType>{0}" +
1803 " <xs:sequence>{0}" +
1804 " <xs:element ref=\"xs:schema\" />{0}" +
1806 " </xs:sequence>{0}" +
1807 " </xs:complexType>{0}" +
1808 " </xs:element>{0}" +
1810 "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
1814 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
1816 [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
1818 public void ExportXmlSerializable_Container ()
1820 XmlSchemas schemas = Export (typeof (XmlSerializableContainer), "NSXmlSerializableContainer");
1821 Assert.AreEqual (3, schemas.Count, "#1");
1823 StringWriter sw = new StringWriter ();
1824 schemas[0].Write (sw);
1826 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1827 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1828 "<xs:schema xmlns:tns=\"NSXmlSerializableContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSXmlSerializableContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1829 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1830 " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
1832 " <xs:import />{0}" +
1834 " <xs:element name=\"XmlSerializableContainer\" nillable=\"true\" type=\"tns:XmlSerializableContainer\" />{0}" +
1835 " <xs:complexType name=\"XmlSerializableContainer\">{0}" +
1836 " <xs:sequence>{0}" +
1837 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Slave\">{0}" +
1838 " <xs:complexType>{0}" +
1839 " <xs:sequence>{0}" +
1840 " <xs:element ref=\"xs:schema\" />{0}" +
1842 " </xs:sequence>{0}" +
1843 " </xs:complexType>{0}" +
1844 " </xs:element>{0}" +
1845 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchema\">{0}" +
1846 " <xs:complexType>{0}" +
1847 " <xs:sequence>{0}" +
1848 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1849 " </xs:sequence>{0}" +
1850 " </xs:complexType>{0}" +
1851 " </xs:element>{0}" +
1853 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
1855 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\">{0}" +
1856 " <xs:complexType>{0}" +
1857 " <xs:sequence>{0}" +
1858 " <xs:element ref=\"xs:schema\" />{0}" +
1860 " </xs:sequence>{0}" +
1861 " </xs:complexType>{0}" +
1862 " </xs:element>{0}" +
1864 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchema\">{0}" +
1865 " <xs:complexType>{0}" +
1866 " <xs:sequence>{0}" +
1867 " <xs:any namespace=\"\" />{0}" +
1868 " </xs:sequence>{0}" +
1869 " </xs:complexType>{0}" +
1870 " </xs:element>{0}" +
1872 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\" type=\"xs:int\" />{0}" +
1873 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveNamespace\" />{0}" +
1874 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaNamespace\" />{0}" +
1875 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:SlaveSchemaProviderNamespace\" />{0}" +
1876 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaNamespace\" />{0}" +
1877 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:NativeSchemaProviderNamespace\" />{0}" +
1878 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveNSOnly\" />{0}" +
1879 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaNSOnly\" />{0}" +
1880 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:SlaveSchemaProviderNSOnly\" />{0}" +
1881 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaNSOnly\" />{0}" +
1882 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q11=\"urn:types-devx-com\" ref=\"q11:NativeSchemaProviderNSOnly\" />{0}" +
1884 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\">{0}" +
1885 " <xs:complexType>{0}" +
1886 " <xs:sequence>{0}" +
1887 " <xs:element ref=\"xs:schema\" />{0}" +
1889 " </xs:sequence>{0}" +
1890 " </xs:complexType>{0}" +
1891 " </xs:element>{0}" +
1892 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q1=\"urn:types-devx-com\" ref=\"q1:SlaveNamespace\" />{0}" +
1893 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveSchemaNamespace\" />{0}" +
1894 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaProviderNamespace\" />{0}" +
1895 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:NativeSchemaNamespace\" />{0}" +
1896 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaProviderNamespace\" />{0}" +
1897 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:SlaveNSOnly\" />{0}" +
1898 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveSchemaNSOnly\" />{0}" +
1899 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaProviderNSOnly\" />{0}" +
1900 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:NativeSchemaNSOnly\" />{0}" +
1901 " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaProviderNSOnly\" />{0}" +
1903 " </xs:sequence>{0}" +
1904 " </xs:complexType>{0}" +
1905 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
1907 sw.GetStringBuilder ().Length = 0;
1908 schemas[1].Write (sw);
1910 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
1911 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
1912 "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
1913 " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
1915 " <xs:import />{0}" +
1917 " <xs:complexType name=\"employeeRoot\">{0}" +
1918 " <xs:attribute name=\"firstName\" />{0}" +
1919 " <xs:attribute name=\"lastName\" />{0}" +
1920 " <xs:attribute name=\"address\" />{0}" +
1921 " </xs:complexType>{0}" +
1922 " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
1923 " <xs:element name=\"SlaveNamespace\">{0}" +
1924 " <xs:complexType>{0}" +
1925 " <xs:sequence>{0}" +
1926 " <xs:element ref=\"xs:schema\" />{0}" +
1928 " </xs:sequence>{0}" +
1929 " </xs:complexType>{0}" +
1930 " </xs:element>{0}" +
1931 " <xs:element name=\"SlaveSchemaNamespace\">{0}" +
1932 " <xs:complexType>{0}" +
1933 " <xs:sequence>{0}" +
1934 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1935 " </xs:sequence>{0}" +
1936 " </xs:complexType>{0}" +
1937 " </xs:element>{0}" +
1939 " <xs:element name=\"SlaveSchemaProviderNamespace\" type=\"tns:employeeRoot\" />{0}" +
1941 " <xs:element name=\"SlaveSchemaProviderNamespace\">{0}" +
1942 " <xs:complexType>{0}" +
1943 " <xs:sequence>{0}" +
1944 " <xs:element ref=\"xs:schema\" />{0}" +
1946 " </xs:sequence>{0}" +
1947 " </xs:complexType>{0}" +
1948 " </xs:element>{0}" +
1950 " <xs:element name=\"NativeSchemaNamespace\">{0}" +
1951 " <xs:complexType>{0}" +
1952 " <xs:sequence>{0}" +
1953 " <xs:any namespace=\"\" />{0}" +
1954 " </xs:sequence>{0}" +
1955 " </xs:complexType>{0}" +
1956 " </xs:element>{0}" +
1958 " <xs:element name=\"NativeSchemaProviderNamespace\" type=\"xs:int\" />{0}" +
1960 " <xs:element name=\"NativeSchemaProviderNamespace\">{0}" +
1961 " <xs:complexType>{0}" +
1962 " <xs:sequence>{0}" +
1963 " <xs:element ref=\"xs:schema\" />{0}" +
1965 " </xs:sequence>{0}" +
1966 " </xs:complexType>{0}" +
1967 " </xs:element>{0}" +
1969 " <xs:element name=\"SlaveNSOnly\">{0}" +
1970 " <xs:complexType>{0}" +
1971 " <xs:sequence>{0}" +
1972 " <xs:element ref=\"xs:schema\" />{0}" +
1974 " </xs:sequence>{0}" +
1975 " </xs:complexType>{0}" +
1976 " </xs:element>{0}" +
1977 " <xs:element name=\"SlaveSchemaNSOnly\">{0}" +
1978 " <xs:complexType>{0}" +
1979 " <xs:sequence>{0}" +
1980 " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
1981 " </xs:sequence>{0}" +
1982 " </xs:complexType>{0}" +
1983 " </xs:element>{0}" +
1985 " <xs:element name=\"SlaveSchemaProviderNSOnly\" type=\"tns:employeeRoot\" />{0}" +
1987 " <xs:element name=\"SlaveSchemaProviderNSOnly\">{0}" +
1988 " <xs:complexType>{0}" +
1989 " <xs:sequence>{0}" +
1990 " <xs:element ref=\"xs:schema\" />{0}" +
1992 " </xs:sequence>{0}" +
1993 " </xs:complexType>{0}" +
1994 " </xs:element>{0}" +
1996 " <xs:element name=\"NativeSchemaNSOnly\">{0}" +
1997 " <xs:complexType>{0}" +
1998 " <xs:sequence>{0}" +
1999 " <xs:any namespace=\"\" />{0}" +
2000 " </xs:sequence>{0}" +
2001 " </xs:complexType>{0}" +
2002 " </xs:element>{0}" +
2004 " <xs:element name=\"NativeSchemaProviderNSOnly\" type=\"xs:int\" />{0}" +
2006 " <xs:element name=\"NativeSchemaProviderNSOnly\">{0}" +
2007 " <xs:complexType>{0}" +
2008 " <xs:sequence>{0}" +
2009 " <xs:element ref=\"xs:schema\" />{0}" +
2011 " </xs:sequence>{0}" +
2012 " </xs:complexType>{0}" +
2013 " </xs:element>{0}" +
2015 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
2017 sw.GetStringBuilder ().Length = 0;
2018 schemas[2].Write (sw);
2020 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2021 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2022 "<xs:schema id=\"LuckyNumberSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2023 " <xs:element name=\"LuckyNumber\" type=\"xs:int\" />{0}" +
2024 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
2028 public void ExportXsdPrimitive ()
2030 ArrayList types = new ArrayList ();
2031 types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte"));
2032 types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte"));
2033 types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean"));
2034 types.Add (new TypeDescription (typeof (short), true, "short", "Short"));
2035 types.Add (new TypeDescription (typeof (int), true, "int", "Int"));
2036 types.Add (new TypeDescription (typeof (long), true, "long", "Long"));
2037 types.Add (new TypeDescription (typeof (float), true, "float", "Float"));
2038 types.Add (new TypeDescription (typeof (double), true, "double", "Double"));
2039 types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal"));
2040 types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort"));
2041 types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt"));
2042 types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong"));
2043 types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime"));
2045 types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true));
2047 types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName"));
2049 types.Add (new TypeDescription (typeof (string), true, "string", "String", true));
2051 foreach (TypeDescription typeDesc in types) {
2052 XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
2053 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
2055 StringWriter sw = new StringWriter ();
2056 schemas[0].Write (sw);
2058 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2059 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2060 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2061 " <xs:element name=\"{2}\" {3}type=\"xs:{2}\" />{0}" +
2062 "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.XmlType,
2063 typeDesc.IsNillable ? "nillable=\"true\" " : ""),
2064 sw.ToString (), typeDesc.Type.FullName + "#2");
2066 schemas = Export (typeDesc.Type);
2067 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
2069 sw.GetStringBuilder ().Length = 0;
2070 schemas[0].Write (sw);
2072 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2073 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2074 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2075 " <xs:element name=\"{1}\" {2}type=\"xs:{1}\" />{0}" +
2076 "</xs:schema>", Environment.NewLine, typeDesc.XmlType,
2077 typeDesc.IsNillable ? "nillable=\"true\" " : ""),
2078 sw.ToString (), typeDesc.Type.FullName + "#4");
2083 [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
2084 public void ExportXsdPrimitive_Object ()
2086 XmlSchemas schemas = Export (typeof (object), "NSAnyType");
2087 Assert.AreEqual (1, schemas.Count, "#1");
2089 StringWriter sw = new StringWriter ();
2090 schemas[0].Write (sw);
2092 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2093 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2094 "<xs:schema xmlns:tns=\"NSAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2095 " <xs:element name=\"anyType\" nillable=\"true\" />{0}" +
2096 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2098 schemas = Export (typeof (object));
2099 Assert.AreEqual (1, schemas.Count, "#3");
2101 sw.GetStringBuilder ().Length = 0;
2102 schemas[0].Write (sw);
2104 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2105 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2106 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2107 " <xs:element name=\"anyType\" nillable=\"true\" />{0}" +
2108 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
2112 public void ExportXsdPrimitive_ByteArray ()
2114 XmlSchemas schemas = Export (typeof (byte[]), "NSByteArray");
2115 Assert.AreEqual (1, schemas.Count, "#1");
2117 StringWriter sw = new StringWriter ();
2118 schemas[0].Write (sw);
2120 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2121 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2122 "<xs:schema xmlns:tns=\"NSByteArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSByteArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2123 " <xs:element name=\"base64Binary\" nillable=\"true\" type=\"xs:base64Binary\" />{0}" +
2124 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2126 schemas = Export (typeof (byte[]));
2127 Assert.AreEqual (1, schemas.Count, "#3");
2129 sw.GetStringBuilder ().Length = 0;
2130 schemas[0].Write (sw);
2132 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2133 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2134 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2135 " <xs:element name=\"base64Binary\" nillable=\"true\" type=\"xs:base64Binary\" />{0}" +
2136 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
2140 public void ExportXsdPrimitive_Arrays ()
2142 ArrayList types = new ArrayList ();
2143 types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte", true));
2144 types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean", true));
2145 types.Add (new TypeDescription (typeof (short[]), true, "short", "Short", true));
2146 types.Add (new TypeDescription (typeof (int[]), true, "int", "Int", true));
2147 types.Add (new TypeDescription (typeof (long[]), true, "long", "Long", true));
2148 types.Add (new TypeDescription (typeof (float[]), true, "float", "Float", true));
2149 types.Add (new TypeDescription (typeof (double[]), true, "double", "Double", true));
2150 types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal", true));
2151 types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort", true));
2152 types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt", true));
2153 types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong", true));
2154 types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime", true));
2156 types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true, true));
2158 types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true));
2160 types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true, true));
2162 foreach (TypeDescription typeDesc in types) {
2163 XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
2164 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
2166 StringWriter sw = new StringWriter ();
2167 schemas[0].Write (sw);
2169 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2170 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2171 "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2172 " <xs:element name=\"ArrayOf{2}\" {5}type=\"tns:ArrayOf{2}\" />{0}" +
2173 " <xs:complexType name=\"ArrayOf{2}\">{0}" +
2174 " <xs:sequence>{0}" +
2175 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{3}\" {6}type=\"{4}:{3}\" />{0}" +
2176 " </xs:sequence>{0}" +
2177 " </xs:complexType>{0}" +
2178 "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType,
2179 typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : "",
2180 typeDesc.IsElementNillable ? "nillable=\"true\" " : ""),
2181 sw.ToString (), typeDesc.Type.FullName + "#2" + "|" + typeDesc.IsNillable);
2183 schemas = Export (typeDesc.Type);
2184 Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
2186 sw.GetStringBuilder ().Length = 0;
2187 schemas[0].Write (sw);
2189 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2190 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2191 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2192 " <xs:element name=\"ArrayOf{1}\" {4}type=\"ArrayOf{1}\" />{0}" +
2193 " <xs:complexType name=\"ArrayOf{1}\">{0}" +
2194 " <xs:sequence>{0}" +
2195 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{2}\" {5}type=\"{3}:{2}\" />{0}" +
2196 " </xs:sequence>{0}" +
2197 " </xs:complexType>{0}" +
2198 "</xs:schema>", Environment.NewLine, typeDesc.ArrayType, typeDesc.XmlType,
2199 typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : "",
2200 typeDesc.IsElementNillable ? "nillable=\"true\" " : ""),
2201 sw.ToString (), typeDesc.Type.FullName + "#4");
2206 public void ExportXsdPrimitive_Object_Arrays ()
2208 XmlSchemas schemas = Export (typeof (object[]), "NSArrayOfAnyType");
2209 Assert.AreEqual (1, schemas.Count, "#1");
2211 StringWriter sw = new StringWriter ();
2212 schemas[0].Write (sw);
2214 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2215 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2216 "<xs:schema xmlns:tns=\"NSArrayOfAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayOfAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2217 " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"tns:ArrayOfAnyType\" />{0}" +
2218 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
2219 " <xs:sequence>{0}" +
2220 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
2221 " </xs:sequence>{0}" +
2222 " </xs:complexType>{0}" +
2223 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2225 schemas = Export (typeof (object[]));
2226 Assert.AreEqual (1, schemas.Count, "#3");
2228 sw.GetStringBuilder ().Length = 0;
2229 schemas[0].Write (sw);
2231 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2232 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2233 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2234 " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"ArrayOfAnyType\" />{0}" +
2235 " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
2236 " <xs:sequence>{0}" +
2237 " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
2238 " </xs:sequence>{0}" +
2239 " </xs:complexType>{0}" +
2240 "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
2244 public void ExportNonXsdPrimitive_Guid ()
2246 XmlSchemas schemas = Export (typeof (Guid), "NSPrimGuid");
2247 Assert.AreEqual (2, schemas.Count, "#1");
2249 StringWriter sw = new StringWriter ();
2250 schemas[0].Write (sw);
2252 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2253 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2254 "<xs:schema xmlns:tns=\"NSPrimGuid\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimGuid\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2255 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2256 " <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
2257 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2259 sw.GetStringBuilder ().Length = 0;
2260 schemas[1].Write (sw);
2262 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2263 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2264 "<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}" +
2265 " <xs:simpleType name=\"guid\">{0}" +
2266 " <xs:restriction base=\"xs:string\">{0}" +
2267 " <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}" +
2268 " </xs:restriction>{0}" +
2269 " </xs:simpleType>{0}" +
2270 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
2272 schemas = Export (typeof (Guid));
2273 Assert.AreEqual (2, schemas.Count, "#4");
2275 sw.GetStringBuilder ().Length = 0;
2276 schemas[0].Write (sw);
2278 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2279 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2280 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2281 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2282 " <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
2283 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
2285 sw.GetStringBuilder ().Length = 0;
2286 schemas[1].Write (sw);
2288 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2289 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2290 "<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}" +
2291 " <xs:simpleType name=\"guid\">{0}" +
2292 " <xs:restriction base=\"xs:string\">{0}" +
2293 " <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}" +
2294 " </xs:restriction>{0}" +
2295 " </xs:simpleType>{0}" +
2296 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
2300 public void ExportNonXsdPrimitive_Char ()
2302 XmlSchemas schemas = Export (typeof (char), "NSPrimChar");
2303 Assert.AreEqual (2, schemas.Count, "#1");
2305 StringWriter sw = new StringWriter ();
2306 schemas[0].Write (sw);
2308 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2309 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2310 "<xs:schema xmlns:tns=\"NSPrimChar\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimChar\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2311 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2312 " <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
2313 "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
2315 sw.GetStringBuilder ().Length = 0;
2316 schemas[1].Write (sw);
2318 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2319 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2320 "<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}" +
2321 " <xs:simpleType name=\"char\">{0}" +
2322 " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
2323 " </xs:simpleType>{0}" +
2324 "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
2326 schemas = Export (typeof (char));
2327 Assert.AreEqual (2, schemas.Count, "#4");
2329 sw.GetStringBuilder ().Length = 0;
2330 schemas[0].Write (sw);
2332 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2333 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2334 "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
2335 " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
2336 " <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
2337 "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
2339 sw.GetStringBuilder ().Length = 0;
2340 schemas[1].Write (sw);
2342 Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
2343 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
2344 "<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}" +
2345 " <xs:simpleType name=\"char\">{0}" +
2346 " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
2347 " </xs:simpleType>{0}" +
2348 "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
2351 public class Employee : IXmlSerializable
2353 private string _firstName;
2354 private string _lastName;
2355 private string _address;
2357 public virtual XmlSchema GetSchema ()
2362 public void WriteXml (XmlWriter writer)
2364 writer.WriteStartElement ("employee", "urn:devx-com");
2365 writer.WriteAttributeString ("firstName", _firstName);
2366 writer.WriteAttributeString ("lastName", _lastName);
2367 writer.WriteAttributeString ("address", _address);
2368 writer.WriteEndElement ();
2371 public void ReadXml (XmlReader reader)
2373 XmlNodeType type = reader.MoveToContent ();
2374 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2375 _firstName = reader["firstName"];
2376 _lastName = reader["lastName"];
2377 _address = reader["address"];
2382 public class EmployeeSchema : IXmlSerializable
2384 private string _firstName;
2385 private string _lastName;
2386 private string _address;
2388 public virtual XmlSchema GetSchema ()
2390 return CreateSchema ();
2393 public void WriteXml (XmlWriter writer)
2395 writer.WriteStartElement ("employee", "urn:devx-com");
2396 writer.WriteAttributeString ("firstName", _firstName);
2397 writer.WriteAttributeString ("lastName", _lastName);
2398 writer.WriteAttributeString ("address", _address);
2399 writer.WriteEndElement ();
2402 public void ReadXml (XmlReader reader)
2404 XmlNodeType type = reader.MoveToContent ();
2405 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2406 _firstName = reader["firstName"];
2407 _lastName = reader["lastName"];
2408 _address = reader["address"];
2412 protected static XmlSchema CreateSchema ()
2414 XmlSchema schema = new XmlSchema ();
2415 schema.Id = "EmployeeSchema";
2416 schema.TargetNamespace = "urn:types-devx-com";
2418 XmlSchemaComplexType type = new XmlSchemaComplexType ();
2419 type.Name = "employeeRoot";
2420 XmlSchemaAttribute firstNameAttr = new XmlSchemaAttribute ();
2421 firstNameAttr.Name = "firstName";
2422 type.Attributes.Add (firstNameAttr);
2424 XmlSchemaAttribute lastNameAttr = new XmlSchemaAttribute ();
2425 lastNameAttr.Name = "lastName";
2426 type.Attributes.Add (lastNameAttr);
2428 XmlSchemaAttribute addressAttr = new XmlSchemaAttribute ();
2429 addressAttr.Name = "address";
2430 type.Attributes.Add (addressAttr);
2432 XmlSchemaElement employeeElement = new XmlSchemaElement ();
2433 employeeElement.Name = "employee";
2434 XmlQualifiedName name = new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
2435 employeeElement.SchemaTypeName = name;
2437 schema.Items.Add (type);
2438 schema.Items.Add (employeeElement);
2443 public class PrimitiveSchema : IXmlSerializable
2445 private string _firstName;
2446 private string _lastName;
2447 private string _address;
2449 public virtual XmlSchema GetSchema ()
2451 XmlSchema schema = new XmlSchema ();
2452 schema.Id = "LuckyNumberSchema";
2453 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2454 luckyNumberElement.Name = "LuckyNumber";
2455 luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
2456 schema.Items.Add (luckyNumberElement);
2460 public void WriteXml (XmlWriter writer)
2462 writer.WriteStartElement ("employee", "urn:devx-com");
2463 writer.WriteAttributeString ("firstName", _firstName);
2464 writer.WriteAttributeString ("lastName", _lastName);
2465 writer.WriteAttributeString ("address", _address);
2466 writer.WriteEndElement ();
2469 public void ReadXml (XmlReader reader)
2471 XmlNodeType type = reader.MoveToContent ();
2472 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2473 _firstName = reader["firstName"];
2474 _lastName = reader["lastName"];
2475 _address = reader["address"];
2480 public class MissingIDSchema : IXmlSerializable
2482 private string _firstName;
2483 private string _lastName;
2484 private string _address;
2486 public virtual XmlSchema GetSchema ()
2488 XmlSchema schema = new XmlSchema ();
2489 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2490 luckyNumberElement.Name = "LuckyNumber";
2491 luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
2495 public void WriteXml (XmlWriter writer)
2497 writer.WriteStartElement ("employee", "urn:devx-com");
2498 writer.WriteAttributeString ("firstName", _firstName);
2499 writer.WriteAttributeString ("lastName", _lastName);
2500 writer.WriteAttributeString ("address", _address);
2501 writer.WriteEndElement ();
2504 public void ReadXml (XmlReader reader)
2506 XmlNodeType type = reader.MoveToContent ();
2507 if (type == XmlNodeType.Element && reader.LocalName == "employee") {
2508 _firstName = reader["firstName"];
2509 _lastName = reader["lastName"];
2510 _address = reader["address"];
2516 [XmlSchemaProvider ("CreateEmployeeSchema")]
2518 public class EmployeeSchemaProvider : EmployeeSchema
2521 public static XmlQualifiedName CreateEmployeeSchema (XmlSchemaSet schemaSet)
2523 schemaSet.Add (CreateSchema ());
2524 return new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
2527 public override XmlSchema GetSchema ()
2535 [XmlSchemaProvider ("CreateLuckyNumberSchema")]
2537 public class PrimitiveSchemaProvider : IXmlSerializable
2540 public static XmlQualifiedName CreateLuckyNumberSchema (XmlSchemaSet schemaSet)
2542 XmlSchema schema = new XmlSchema ();
2544 XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
2545 luckyNumberElement.Name = "LuckyNumber";
2547 XmlQualifiedName typeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");
2548 luckyNumberElement.SchemaTypeName = typeName;
2549 schema.Items.Add (luckyNumberElement);
2551 schemaSet.Add (schema);
2556 public XmlSchema GetSchema ()
2561 public void WriteXml (XmlWriter writer)
2563 writer.WriteElementString ("LuckyNumber", "7");
2566 public void ReadXml (XmlReader reader)
2568 XmlNodeType type = reader.MoveToContent ();
2569 if (type == XmlNodeType.Element && reader.LocalName == "LuckyNumber") {
2574 private class TypeDescription
2576 public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType) : this (type, xsdType, xmlType, arrayType, false)
2580 public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable) :
2581 this (type, xsdType, xmlType, arrayType, isNillable, false)
2585 public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable, bool isElementNillable)
2590 _arrayType = arrayType;
2591 _isNillable = isNillable;
2592 _isElementNillable = isElementNillable;
2596 get { return _type; }
2599 public string XmlType {
2600 get { return _xmlType; }
2603 public string ArrayType {
2604 get { return _arrayType; }
2607 public bool XsdType {
2608 get { return _xsdType; }
2611 public bool IsNillable {
2612 get { return _isNillable; }
2615 public bool IsElementNillable {
2616 get { return _isElementNillable; }
2620 private bool _xsdType;
2621 private string _xmlType;
2622 private string _arrayType;
2623 private bool _isNillable;
2624 private bool _isElementNillable;
2627 public class StructContainer
2629 public EnumDefaultValue Value;
2630 public TimeSpan[] Times;
2633 public class XmlSerializableContainer
2635 public Employee Slave;
2636 public EmployeeSchema SlaveSchema;
2637 public EmployeeSchemaProvider SlaveSchemaProvider;
2638 public PrimitiveSchema NativeSchema;
2639 public PrimitiveSchemaProvider NativeSchemaProvider;
2641 [XmlElement ("SlaveNamespace", Namespace = "urn:types-devx-com")]
2642 public Employee SlaveNS;
2643 [XmlElement ("SlaveSchemaNamespace", Namespace = "urn:types-devx-com")]
2644 public EmployeeSchema SlaveSchemaNS;
2645 [XmlElement ("SlaveSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
2646 public EmployeeSchemaProvider SlaveSchemaProviderNS;
2647 [XmlElement ("NativeSchemaNamespace", Namespace = "urn:types-devx-com")]
2648 public PrimitiveSchema NativeSchemaNS;
2649 [XmlElement ("NativeSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
2650 public PrimitiveSchemaProvider NativeSchemaProviderNS;
2653 [XmlElement (Namespace = "urn:types-devx-com")]
2654 public Employee SlaveNSOnly;
2655 [XmlElement (Namespace = "urn:types-devx-com")]
2656 public EmployeeSchema SlaveSchemaNSOnly;
2657 [XmlElement (Namespace = "urn:types-devx-com")]
2658 public EmployeeSchemaProvider SlaveSchemaProviderNSOnly;
2659 [XmlElement (Namespace = "urn:types-devx-com")]
2660 public PrimitiveSchema NativeSchemaNSOnly;
2661 [XmlElement (Namespace = "urn:types-devx-com")]
2662 public PrimitiveSchemaProvider NativeSchemaProviderNSOnly;