2 // System.Xml.XmlSchemaCollectionTests.cs
5 // Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
7 // (C) 2002 Atsushi Enomoto
11 using System.Globalization;
14 using System.Xml.Schema;
15 using NUnit.Framework;
17 namespace MonoTests.System.Xml
20 public class XmlSchemaCollectionTests : Assertion
22 private XmlSchema GetSchema (string path)
24 return XmlSchema.Read (new XmlTextReader (path), null);
27 private XmlQualifiedName QName (string name, string ns)
29 return new XmlQualifiedName (name, ns);
33 public void TestAdd ()
35 XmlSchemaCollection col = new XmlSchemaCollection ();
36 XmlSchema schema = new XmlSchema ();
37 XmlSchemaElement elem = new XmlSchemaElement ();
39 schema.Items.Add (elem);
40 schema.TargetNamespace = "urn:foo";
42 col.Add (schema); // No problem !?
44 XmlSchema schema2 = new XmlSchema ();
45 schema2.Items.Add (elem);
46 schema2.TargetNamespace = "urn:foo";
47 col.Add (schema2); // No problem !!
49 schema.Compile (null);
51 col.Add (schema); // Still no problem !!!
53 schema2.Compile (null);
56 schema = GetSchema ("Test/XmlFiles/xsd/3.xsd");
57 schema.Compile (null);
60 schema2 = GetSchema ("Test/XmlFiles/xsd/3.xsd");
61 schema2.Compile (null);
66 public void TestAddDoesCompilation ()
68 XmlSchema schema = new XmlSchema ();
69 Assert (!schema.IsCompiled);
70 XmlSchemaCollection col = new XmlSchemaCollection ();
72 Assert (schema.IsCompiled);
76 public void TestGetEnumerator ()
78 new XmlSchemaCollection().GetEnumerator();
82 [Category ("NotWorking")]
83 public void TestCompile ()
85 string schemaFragment1 = string.Format (CultureInfo.InvariantCulture,
86 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
87 "<xs:schema xmlns:tns=\"NSDate\" elementFormDefault=\"qualified\" targetNamespace=\"NSDate\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
88 " <xs:import namespace=\"NSStatus\" />{0}" +
89 " <xs:element name=\"trans\" type=\"tns:TranslationStatus\" />{0}" +
90 " <xs:complexType name=\"TranslationStatus\">{0}" +
91 " <xs:simpleContent>{0}" +
92 " <xs:extension xmlns:q1=\"NSStatus\" base=\"q1:StatusType\">{0}" +
93 " <xs:attribute name=\"Language\" type=\"xs:int\" use=\"required\" />{0}" +
94 " </xs:extension>{0}" +
95 " </xs:simpleContent>{0}" +
96 " </xs:complexType>{0}" +
97 "</xs:schema>", Environment.NewLine);
99 string schemaFragment2 = string.Format (CultureInfo.InvariantCulture,
100 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
101 "<xs:schema xmlns:tns=\"NSStatus\" elementFormDefault=\"qualified\" targetNamespace=\"NSStatus\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
102 " <xs:simpleType name=\"StatusType\">{0}" +
103 " <xs:restriction base=\"xs:string\">{0}" +
104 " <xs:enumeration value=\"Untouched\" />{0}" +
105 " <xs:enumeration value=\"Touched\" />{0}" +
106 " <xs:enumeration value=\"Complete\" />{0}" +
107 " <xs:enumeration value=\"None\" />{0}" +
108 " </xs:restriction>{0}" +
109 " </xs:simpleType>{0}" +
110 "</xs:schema>", Environment.NewLine);
112 XmlSchema schema1 = XmlSchema.Read (new StringReader (schemaFragment1), null);
113 XmlSchema schema2 = XmlSchema.Read (new StringReader (schemaFragment2), null);
115 XmlSchemaCollection schemas = new XmlSchemaCollection ();
116 schemas.Add (schema2);
117 schemas.Add (schema1);
119 Assert ("#1", schema1.IsCompiled);
120 Assert ("#2", schema2.IsCompiled);