/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSchemaExporterTests.cs
https://github.com/iainlane/mono · C# · 1060 lines · 915 code · 133 blank · 12 comment · 0 complexity · 3b674d9f8408e61034189542568f3123 MD5 · raw file
- //
- // System.Xml.Serialization.XmlSchemaExporterTests
- //
- // Author:
- // Gert Driesen (drieseng@users.sourceforge.net)
- //
- // (C) 2005 Novell
- //
- using System;
- using System.Collections;
- using System.Globalization;
- using System.IO;
- using System.Xml;
- using System.Xml.Schema;
- using System.Xml.Serialization;
- using NUnit.Framework;
- using MonoTests.System.Xml.TestClasses;
- namespace MonoTests.System.XmlSerialization
- {
- [TestFixture]
- public class XmlSchemaExporterTests
- {
- const string ANamespace = "some:urn";
- const string AnotherNamespace = "another:urn";
- string Infoset (string source)
- {
- return XmlSerializerTests.Infoset (source);
- }
- private XmlSchemas Export (Type type)
- {
- return Export (type, string.Empty);
- }
- private XmlSchemas Export (Type type, string defaultNamespace)
- {
- XmlReflectionImporter ri = new XmlReflectionImporter (defaultNamespace);
- XmlSchemas schemas = new XmlSchemas ();
- XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
- XmlTypeMapping tm = ri.ImportTypeMapping (type);
- sx.ExportTypeMapping (tm);
- return schemas;
- }
- private XmlSchemas Export (Type type, XmlAttributeOverrides overrides)
- {
- return Export (type, overrides, string.Empty);
- }
- private XmlSchemas Export (Type type, XmlAttributeOverrides overrides, string defaultNamespace)
- {
- XmlReflectionImporter ri = new XmlReflectionImporter (overrides, defaultNamespace);
- XmlSchemas schemas = new XmlSchemas ();
- XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
- XmlTypeMapping tm = ri.ImportTypeMapping (type);
- sx.ExportTypeMapping (tm);
- return schemas;
- }
- [Test]
- [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
- public void ExportStruct ()
- {
- XmlSchemas schemas = Export (typeof (TimeSpan), "NSTimeSpan");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSTimeSpan\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpan\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
- " <xs:complexType name=\"TimeSpan\" />{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (TimeSpan));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
- " <xs:complexType name=\"TimeSpan\" />{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
- public void ExportStruct_Array ()
- {
- XmlSchemas schemas = Export (typeof (TimeSpan[]), "NSTimeSpanArray");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSTimeSpanArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpanArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ArrayOfTimeSpan\" nillable=\"true\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
- " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"TimeSpan\" />{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (TimeSpan[]));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ArrayOfTimeSpan\" nillable=\"true\" type=\"ArrayOfTimeSpan\" />{0}" +
- " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"TimeSpan\" />{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- public void ExportClass_SimpleClass ()
- {
- XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
- XmlAttributes attr = new XmlAttributes ();
- XmlElementAttribute element = new XmlElementAttribute ();
- element.ElementName = "saying";
- element.IsNullable = true;
- attr.XmlElements.Add (element);
- overrides.Add (typeof (SimpleClass), "something", attr);
- XmlSchemas schemas = Export (typeof (SimpleClass), overrides, "NSSimpleClass");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSSimpleClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
- " <xs:complexType name=\"SimpleClass\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (SimpleClass), overrides);
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
- " <xs:complexType name=\"SimpleClass\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- public void ExportClass_StringCollection ()
- {
- XmlSchemas schemas = Export (typeof (StringCollection), "NSStringCollection");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSStringCollection\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollection\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ArrayOfString\" nillable=\"true\" type=\"tns:ArrayOfString\" />{0}" +
- " <xs:complexType name=\"ArrayOfString\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (StringCollection));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ArrayOfString\" nillable=\"true\" type=\"ArrayOfString\" />{0}" +
- " <xs:complexType name=\"ArrayOfString\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- public void ExportClass_StringCollectionContainer ()
- {
- XmlSchemas schemas = Export (typeof (StringCollectionContainer), "NSStringCollectionContainer");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSStringCollectionContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollectionContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"StringCollectionContainer\" nillable=\"true\" type=\"tns:StringCollectionContainer\" />{0}" +
- " <xs:complexType name=\"StringCollectionContainer\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"tns:ArrayOfString\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfString\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (StringCollectionContainer));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"StringCollectionContainer\" nillable=\"true\" type=\"StringCollectionContainer\" />{0}" +
- " <xs:complexType name=\"StringCollectionContainer\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"ArrayOfString\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfString\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- public void ExportClass_ArrayContainer ()
- {
- XmlSchemas schemas = Export (typeof (ArrayContainer), "NSArrayContainer");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ArrayContainer\" nillable=\"true\" type=\"tns:ArrayContainer\" />{0}" +
- " <xs:complexType name=\"ArrayContainer\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfAnyType\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (ArrayContainer));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ArrayContainer\" nillable=\"true\" type=\"ArrayContainer\" />{0}" +
- " <xs:complexType name=\"ArrayContainer\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfAnyType\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- public void ExportClass_ClassArrayContainer ()
- {
- XmlSchemas schemas = Export (typeof (ClassArrayContainer), "NSClassArrayContainer");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSClassArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSClassArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ClassArrayContainer\" nillable=\"true\" type=\"tns:ClassArrayContainer\" />{0}" +
- " <xs:complexType name=\"ClassArrayContainer\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"SimpleClass\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (ClassArrayContainer));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ClassArrayContainer\" nillable=\"true\" type=\"ClassArrayContainer\" />{0}" +
- " <xs:complexType name=\"ClassArrayContainer\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfSimpleClass\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"SimpleClass\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- public void ExportClass_SimpleClassWithXmlAttributes ()
- {
- XmlSchemas schemas = Export (typeof (SimpleClassWithXmlAttributes), "NSSimpleClassWithXmlAttributes");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSSimpleClassWithXmlAttributes\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassWithXmlAttributes\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"simple\" nillable=\"true\" type=\"tns:SimpleClassWithXmlAttributes\" />{0}" +
- " <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
- " <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (SimpleClassWithXmlAttributes));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"simple\" nillable=\"true\" type=\"SimpleClassWithXmlAttributes\" />{0}" +
- " <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
- " <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- public void ExportClass_Field ()
- {
- XmlSchemas schemas = Export (typeof (Field), "NSField");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSField\" elementFormDefault=\"qualified\" targetNamespace=\"NSField\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"field\" nillable=\"true\" type=\"tns:Field\" />{0}" +
- " <xs:complexType name=\"Field\">{0}" +
- " <xs:attribute default=\"one\" name=\"flag1\" type=\"tns:FlagEnum\" />{0}" +
- " <xs:attribute default=\"one\" name=\"flag2\" type=\"tns:FlagEnum\" />{0}" +
- " <xs:attribute default=\"one two\" form=\"qualified\" name=\"flag3\" type=\"tns:FlagEnum\" />{0}" +
- " <xs:attribute name=\"flag4\" type=\"tns:FlagEnum\" use=\"required\" />{0}" +
- " <xs:attribute name=\"modifiers\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
- " <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
- " <xs:attribute default=\"public\" name=\"modifiers3\" type=\"tns:MapModifiers\" />{0}" +
- " <xs:attribute default=\"protected\" form=\"unqualified\" name=\"modifiers4\" type=\"tns:MapModifiers\" />{0}" +
- " <xs:attribute default=\"public\" form=\"qualified\" name=\"modifiers5\" type=\"tns:MapModifiers\" />{0}" +
- " <xs:attribute name=\"names\">{0}" +
- " <xs:simpleType>{0}" +
- " <xs:list itemType=\"xs:string\" />{0}" +
- " </xs:simpleType>{0}" +
- " </xs:attribute>{0}" +
- " <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
- " </xs:complexType>{0}" +
- " <xs:simpleType name=\"FlagEnum\">{0}" +
- " <xs:list>{0}" +
- " <xs:simpleType>{0}" +
- " <xs:restriction base=\"xs:string\">{0}" +
- " <xs:enumeration value=\"one\" />{0}" +
- " <xs:enumeration value=\"two\" />{0}" +
- " <xs:enumeration value=\"four\" />{0}" +
- " </xs:restriction>{0}" +
- " </xs:simpleType>{0}" +
- " </xs:list>{0}" +
- " </xs:simpleType>{0}" +
- " <xs:simpleType name=\"MapModifiers\">{0}" +
- " <xs:list>{0}" +
- " <xs:simpleType>{0}" +
- " <xs:restriction base=\"xs:string\">{0}" +
- " <xs:enumeration value=\"public\" />{0}" +
- " <xs:enumeration value=\"protected\" />{0}" +
- " </xs:restriction>{0}" +
- " </xs:simpleType>{0}" +
- " </xs:list>{0}" +
- " </xs:simpleType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (Field));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"field\" nillable=\"true\" type=\"Field\" />{0}" +
- " <xs:complexType name=\"Field\">{0}" +
- " <xs:attribute default=\"one\" name=\"flag1\" type=\"FlagEnum\" />{0}" +
- " <xs:attribute default=\"one\" name=\"flag2\" type=\"FlagEnum\" />{0}" +
- " <xs:attribute default=\"one two\" form=\"qualified\" name=\"flag3\" type=\"FlagEnum\" />{0}" +
- " <xs:attribute name=\"flag4\" type=\"FlagEnum\" use=\"required\" />{0}" +
- " <xs:attribute name=\"modifiers\" type=\"MapModifiers\" use=\"required\" />{0}" +
- " <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"MapModifiers\" use=\"required\" />{0}" +
- " <xs:attribute default=\"public\" name=\"modifiers3\" type=\"MapModifiers\" />{0}" +
- " <xs:attribute default=\"protected\" form=\"unqualified\" name=\"modifiers4\" type=\"MapModifiers\" />{0}" +
- " <xs:attribute default=\"public\" form=\"qualified\" name=\"modifiers5\" type=\"MapModifiers\" />{0}" +
- " <xs:attribute name=\"names\">{0}" +
- " <xs:simpleType>{0}" +
- " <xs:list itemType=\"xs:string\" />{0}" +
- " </xs:simpleType>{0}" +
- " </xs:attribute>{0}" +
- " <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
- " </xs:complexType>{0}" +
- " <xs:simpleType name=\"FlagEnum\">{0}" +
- " <xs:list>{0}" +
- " <xs:simpleType>{0}" +
- " <xs:restriction base=\"xs:string\">{0}" +
- " <xs:enumeration value=\"one\" />{0}" +
- " <xs:enumeration value=\"two\" />{0}" +
- " <xs:enumeration value=\"four\" />{0}" +
- " </xs:restriction>{0}" +
- " </xs:simpleType>{0}" +
- " </xs:list>{0}" +
- " </xs:simpleType>{0}" +
- " <xs:simpleType name=\"MapModifiers\">{0}" +
- " <xs:list>{0}" +
- " <xs:simpleType>{0}" +
- " <xs:restriction base=\"xs:string\">{0}" +
- " <xs:enumeration value=\"public\" />{0}" +
- " <xs:enumeration value=\"protected\" />{0}" +
- " </xs:restriction>{0}" +
- " </xs:simpleType>{0}" +
- " </xs:list>{0}" +
- " </xs:simpleType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- public void ExportClass_MyList ()
- {
- XmlSchemas schemas = Export (typeof (MyList), "NSMyList");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSMyList\" elementFormDefault=\"qualified\" targetNamespace=\"NSMyList\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"tns:ArrayOfAnyType\" />{0}" +
- " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (MyList));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"ArrayOfAnyType\" />{0}" +
- " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- }
- [Test]
- public void ExportClass_Container ()
- {
- XmlSchemas schemas = Export (typeof (Container), "NSContainer");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"Container\" nillable=\"true\" type=\"tns:Container\" />{0}" +
- " <xs:complexType name=\"Container\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (Container));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"Container\" nillable=\"true\" type=\"Container\" />{0}" +
- " <xs:complexType name=\"Container\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- public void ExportClass_Container2 ()
- {
- XmlSchemas schemas = Export (typeof (Container2), "NSContainer2");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSContainer2\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"Container2\" nillable=\"true\" type=\"tns:Container2\" />{0}" +
- " <xs:complexType name=\"Container2\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (Container2));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"Container2\" nillable=\"true\" type=\"Container2\" />{0}" +
- " <xs:complexType name=\"Container2\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
- [ExpectedException (typeof (InvalidOperationException))] // Cannot use wildcards at the top level of a schema.
- public void ExportClass_MyElem ()
- {
- Export (typeof (MyElem), "NSMyElem");
- }
- [Test]
- public void ExportClass_CDataContainer ()
- {
- XmlSchemas schemas = Export (typeof (CDataContainer), "NSCDataContainer");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSCDataContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSCDataContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"CDataContainer\" nillable=\"true\" type=\"tns:CDataContainer\" />{0}" +
- " <xs:complexType name=\"CDataContainer\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
- " <xs:complexType mixed=\"true\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:any />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " </xs:element>{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#2");
- schemas = Export (typeof (CDataContainer));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"CDataContainer\" nillable=\"true\" type=\"CDataContainer\" />{0}" +
- " <xs:complexType name=\"CDataContainer\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
- " <xs:complexType mixed=\"true\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:any />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " </xs:element>{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine)), Infoset (sw.ToString ()), "#4");
- }
- [Test]
- public void ExportClass_NodeContainer ()
- {
- XmlSchemas schemas = Export (typeof (NodeContainer), "NSNodeContainer");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSNodeContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSNodeContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"NodeContainer\" nillable=\"true\" type=\"tns:NodeContainer\" />{0}" +
- " <xs:complexType name=\"NodeContainer\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
- " <xs:complexType mixed=\"true\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:any />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " </xs:element>{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
- schemas = Export (typeof (NodeContainer));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"NodeContainer\" nillable=\"true\" type=\"NodeContainer\" />{0}" +
- " <xs:complexType name=\"NodeContainer\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
- " <xs:complexType mixed=\"true\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:any />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " </xs:element>{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
- }
- [Test]
- [Category ("NotWorking")] // Mono does not generate the <xs:choice> node
- [Category ("NotDotNet")] // MS.NET randomly modifies the order of the elements! -> Of course. There is nothing strange. The test is rather strange.
- public void ExportClass_Choices ()
- {
- XmlSchemas schemas = Export (typeof (Choices), "NSChoices");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"Choices\" type=\"tns:Choices\" />{0}" +
- " <xs:complexType name=\"Choices\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
- " </xs:choice>{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
- schemas = Export (typeof (Choices));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"Choices\" type=\"Choices\" />{0}" +
- " <xs:complexType name=\"Choices\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
- " </xs:choice>{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
- }
- [Test]
- #if ONLY_1_1
- [Category ("NotDotNet")] // MS.NET 1.x does not escape spaces in a type name, bug is fixed in .NET 2.0
- #endif
- public void ExportClass_TestSpace ()
- {
- XmlSchemas schemas = Export (typeof (TestSpace), "NSTestSpace");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSTestSpace\" elementFormDefault=\"qualified\" targetNamespace=\"NSTestSpace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"Type_x0020_with_x0020_space\" nillable=\"true\" type=\"tns:Type_x0020_with_x0020_space\" />{0}" +
- " <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
- " </xs:sequence>{0}" +
- " <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
- schemas = Export (typeof (TestSpace));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"Type_x0020_with_x0020_space\" nillable=\"true\" type=\"Type_x0020_with_x0020_space\" />{0}" +
- " <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
- " </xs:sequence>{0}" +
- " <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
- }
- [Test]
- public void ExportClass_OptionalValueTypeContainer ()
- {
- XmlAttributeOverrides overrides;
- XmlAttributes attr;
- XmlSchemas schemas = Export (typeof (OptionalValueTypeContainer));
- Assert.AreEqual (2, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:import namespace=\"{2}\" />{0}" +
- " <xs:element name=\"optionalValue\" xmlns:q1=\"{2}\" type=\"q1:optionalValueType\" />{0}" +
- "</xs:schema>", Environment.NewLine, AnotherNamespace, ANamespace),
- sw.ToString (), "#2");
- sw.GetStringBuilder ().Length = 0;
- schemas[1].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:complexType name=\"optionalValueType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"one four\" name=\"Attributes\" type=\"tns:FlagEnum\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"one\" name=\"Flags\" type=\"tns:FlagEnum\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"false\" name=\"IsEmpty\" type=\"xs:boolean\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" default=\"false\" name=\"IsNull\" type=\"xs:boolean\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:simpleType name=\"FlagEnum\">{0}" +
- " <xs:list>{0}" +
- " <xs:simpleType>{0}" +
- " <xs:restriction base=\"xs:string\">{0}" +
- " <xs:enumeration value=\"one\" />{0}" +
- " <xs:enumeration value=\"two\" />{0}" +
- " <xs:enumeration value=\"four\" />{0}" +
- " </xs:restriction>{0}" +
- " </xs:simpleType>{0}" +
- " </xs:list>{0}" +
- " </xs:simpleType>{0}" +
- "</xs:schema>", Environment.NewLine, ANamespace), sw.ToString (), "#3");
- overrides = new XmlAttributeOverrides ();
- attr = new XmlAttributes ();
- // remove the DefaultValue attribute on the Flags member
- overrides.Add (typeof (OptionalValueTypeContainer), "Flags", attr);
- // remove the DefaultValue attribute on the Attributes member
- overrides.Add (typeof (OptionalValueTypeContainer), "Attributes", attr);
- // remove the DefaultValue attribute on the IsEmpty member
- overrides.Add (typeof (OptionalValueTypeContainer), "IsEmpty", attr);
- // remove the DefaultValue attribute on the IsNull member
- overrides.Add (typeof (OptionalValueTypeContainer), "IsNull", attr);
- schemas = Export (typeof (OptionalValueTypeContainer), overrides, "urn:myNS");
- Assert.AreEqual (2, schemas.Count, "#4");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:import namespace=\"{2}\" />{0}" +
- " <xs:element name=\"optionalValue\" xmlns:q1=\"{2}\" type=\"q1:optionalValueType\" />{0}" +
- "</xs:schema>", Environment.NewLine, AnotherNamespace, ANamespace),
- sw.ToString (), "#5");
- sw.GetStringBuilder ().Length = 0;
- schemas[1].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:complexType name=\"optionalValueType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Attributes\" type=\"tns:FlagEnum\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Flags\" type=\"tns:FlagEnum\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"IsEmpty\" type=\"xs:boolean\" />{0}" +
- " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"IsNull\" type=\"xs:boolean\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:simpleType name=\"FlagEnum\">{0}" +
- " <xs:list>{0}" +
- " <xs:simpleType>{0}" +
- " <xs:restriction base=\"xs:string\">{0}" +
- " <xs:enumeration value=\"one\" />{0}" +
- " <xs:enumeration value=\"two\" />{0}" +
- " <xs:enumeration value=\"four\" />{0}" +
- " </xs:restriction>{0}" +
- " </xs:simpleType>{0}" +
- " </xs:list>{0}" +
- " </xs:simpleType>{0}" +
- "</xs:schema>", Environment.NewLine, ANamespace), sw.ToString (), "#6");
- }
- [Test]
- public void ExportClass_ReadOnlyProperties ()
- {
- XmlSchemas schemas = Export (typeof (ReadOnlyProperties), "NSReadOnlyProperties");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSReadOnlyProperties\" elementFormDefault=\"qualified\" targetNamespace=\"NSReadOnlyProperties\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ReadOnlyProperties\" nillable=\"true\" type=\"tns:ReadOnlyProperties\" />{0}" +
- " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
- "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
- schemas = Export (typeof (ReadOnlyProperties));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"ReadOnlyProperties\" nillable=\"true\" type=\"ReadOnlyProperties\" />{0}" +
- " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
- "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
- }
- [Test]
- [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
- public void ExportClass_ListDefaults ()
- {
- XmlSchemas schemas = Export (typeof (ListDefaults), "NSListDefaults");
- Assert.AreEqual (1, schemas.Count, "#1");
- StringWriter sw = new StringWriter ();
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema xmlns:tns=\"NSListDefaults\" elementFormDefault=\"qualified\" targetNamespace=\"NSListDefaults\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"root\" nillable=\"true\" type=\"tns:ListDefaults\" />{0}" +
- " <xs:complexType name=\"ListDefaults\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"tns:ArrayOfAnyType\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"tns:ArrayOfAnyType\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"tns:ArrayOfString\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"tns:SimpleClass\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"tns:SimpleClass\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfString\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"SimpleClass\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
- schemas = Export (typeof (ListDefaults));
- Assert.AreEqual (1, schemas.Count, "#3");
- sw.GetStringBuilder ().Length = 0;
- schemas[0].Write (sw);
- Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
- "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
- "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
- " <xs:element name=\"root\" nillable=\"true\" type=\"ListDefaults\" />{0}" +
- " <xs:complexType name=\"ListDefaults\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"ArrayOfAnyType\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"ArrayOfAnyType\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"ArrayOfString\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"SimpleClass\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"SimpleClass\" />{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"ArrayOfString\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- " <xs:complexType name=\"SimpleClass\">{0}" +
- " <xs:sequence>{0}" +
- " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
- " </xs:sequence>{0}" +
- " </xs:complexType>{0}" +
- "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
- }
- [Test]
- public void ExportClass_ClsPerson ()
- {
- XmlSchemas schemas = Export (typeof (clsPerson), "NSClsPerson");
- Assert.AreEqual (1, schemas.Co