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 using MonoTests
.Helpers
;
19 namespace MonoTests
.System
.Xml
22 public class XmlSchemaCollectionTests
24 private XmlSchema
GetSchema (string resourceName
)
26 return XmlSchema
.Read (new XmlTextReader (TestResourceHelper
.GetFullPathOfResource (resourceName
)), null);
29 private XmlQualifiedName
QName (string name
, string ns
)
31 return new XmlQualifiedName (name
, ns
);
35 public void TestAdd ()
37 XmlSchemaCollection col
= new XmlSchemaCollection ();
38 XmlSchema schema
= new XmlSchema ();
39 XmlSchemaElement elem
= new XmlSchemaElement ();
41 schema
.Items
.Add (elem
);
42 schema
.TargetNamespace
= "urn:foo";
44 col
.Add (schema
); // No problem !?
46 XmlSchema schema2
= new XmlSchema ();
47 schema2
.Items
.Add (elem
);
48 schema2
.TargetNamespace
= "urn:foo";
49 col
.Add (schema2
); // No problem !!
51 schema
.Compile (null);
53 col
.Add (schema
); // Still no problem !!!
55 schema2
.Compile (null);
58 schema
= GetSchema ("Test/XmlFiles/xsd/3.xsd");
59 schema
.Compile (null);
62 schema2
= GetSchema ("Test/XmlFiles/xsd/3.xsd");
63 schema2
.Compile (null);
68 public void TestAddDoesCompilation ()
70 XmlSchema schema
= new XmlSchema ();
71 Assert
.IsFalse (schema
.IsCompiled
);
72 XmlSchemaCollection col
= new XmlSchemaCollection ();
74 Assert
.IsTrue (schema
.IsCompiled
);
78 public void TestGetEnumerator ()
80 new XmlSchemaCollection().GetEnumerator();
84 public void TestCompile ()
86 string schemaFragment1
= string.Format (CultureInfo
.InvariantCulture
,
87 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
88 "<xs:schema xmlns:tns=\"NSDate\" elementFormDefault=\"qualified\" targetNamespace=\"NSDate\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
89 " <xs:import namespace=\"NSStatus\" />{0}" +
90 " <xs:element name=\"trans\" type=\"tns:TranslationStatus\" />{0}" +
91 " <xs:complexType name=\"TranslationStatus\">{0}" +
92 " <xs:simpleContent>{0}" +
93 " <xs:extension xmlns:q1=\"NSStatus\" base=\"q1:StatusType\">{0}" +
94 " <xs:attribute name=\"Language\" type=\"xs:int\" use=\"required\" />{0}" +
95 " </xs:extension>{0}" +
96 " </xs:simpleContent>{0}" +
97 " </xs:complexType>{0}" +
98 "</xs:schema>", Environment
.NewLine
);
100 string schemaFragment2
= string.Format (CultureInfo
.InvariantCulture
,
101 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
102 "<xs:schema xmlns:tns=\"NSStatus\" elementFormDefault=\"qualified\" targetNamespace=\"NSStatus\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
103 " <xs:simpleType name=\"StatusType\">{0}" +
104 " <xs:restriction base=\"xs:string\">{0}" +
105 " <xs:enumeration value=\"Untouched\" />{0}" +
106 " <xs:enumeration value=\"Touched\" />{0}" +
107 " <xs:enumeration value=\"Complete\" />{0}" +
108 " <xs:enumeration value=\"None\" />{0}" +
109 " </xs:restriction>{0}" +
110 " </xs:simpleType>{0}" +
111 "</xs:schema>", Environment
.NewLine
);
113 XmlSchema schema1
= XmlSchema
.Read (new StringReader (schemaFragment1
), null);
114 XmlSchema schema2
= XmlSchema
.Read (new StringReader (schemaFragment2
), null);
116 XmlSchemaCollection schemas
= new XmlSchemaCollection ();
117 schemas
.Add (schema2
);
118 schemas
.Add (schema1
);
120 Assert
.IsTrue (schema1
.IsCompiled
, "#1");
121 Assert
.IsTrue (schema2
.IsCompiled
, "#2");