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
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.IsFalse (schema.IsCompiled);
70 XmlSchemaCollection col = new XmlSchemaCollection ();
72 Assert.IsTrue (schema.IsCompiled);
76 public void TestGetEnumerator ()
78 new XmlSchemaCollection().GetEnumerator();
82 public void TestCompile ()
84 string schemaFragment1 = string.Format (CultureInfo.InvariantCulture,
85 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
86 "<xs:schema xmlns:tns=\"NSDate\" elementFormDefault=\"qualified\" targetNamespace=\"NSDate\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
87 " <xs:import namespace=\"NSStatus\" />{0}" +
88 " <xs:element name=\"trans\" type=\"tns:TranslationStatus\" />{0}" +
89 " <xs:complexType name=\"TranslationStatus\">{0}" +
90 " <xs:simpleContent>{0}" +
91 " <xs:extension xmlns:q1=\"NSStatus\" base=\"q1:StatusType\">{0}" +
92 " <xs:attribute name=\"Language\" type=\"xs:int\" use=\"required\" />{0}" +
93 " </xs:extension>{0}" +
94 " </xs:simpleContent>{0}" +
95 " </xs:complexType>{0}" +
96 "</xs:schema>", Environment.NewLine);
98 string schemaFragment2 = string.Format (CultureInfo.InvariantCulture,
99 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
100 "<xs:schema xmlns:tns=\"NSStatus\" elementFormDefault=\"qualified\" targetNamespace=\"NSStatus\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
101 " <xs:simpleType name=\"StatusType\">{0}" +
102 " <xs:restriction base=\"xs:string\">{0}" +
103 " <xs:enumeration value=\"Untouched\" />{0}" +
104 " <xs:enumeration value=\"Touched\" />{0}" +
105 " <xs:enumeration value=\"Complete\" />{0}" +
106 " <xs:enumeration value=\"None\" />{0}" +
107 " </xs:restriction>{0}" +
108 " </xs:simpleType>{0}" +
109 "</xs:schema>", Environment.NewLine);
111 XmlSchema schema1 = XmlSchema.Read (new StringReader (schemaFragment1), null);
112 XmlSchema schema2 = XmlSchema.Read (new StringReader (schemaFragment2), null);
114 XmlSchemaCollection schemas = new XmlSchemaCollection ();
115 schemas.Add (schema2);
116 schemas.Add (schema1);
118 Assert.IsTrue (schema1.IsCompiled, "#1");
119 Assert.IsTrue (schema2.IsCompiled, "#2");