2 // System.Xml.XmlSchemaSetTests.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2004 Novell Inc.
12 using System.Collections;
15 using System.Xml.Schema;
16 using NUnit.Framework;
18 namespace MonoTests.System.Xml
21 public class XmlSchemaSetTests
26 XmlSchemaSet ss = new XmlSchemaSet ();
27 XmlDocument doc = new XmlDocument ();
28 doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' />");
29 ss.Add (null, new XmlNodeReader (doc)); // null targetNamespace
32 // same document, different targetNamespace
33 ss.Add ("ab", new XmlNodeReader (doc));
35 // Add(null, xmlReader) -> targetNamespace in the schema
36 doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:foo' />");
37 ss.Add (null, new XmlNodeReader (doc));
39 Assert.AreEqual (3, ss.Count);
41 bool chameleon = false;
45 foreach (XmlSchema schema in ss.Schemas ()) {
46 if (schema.TargetNamespace == null)
48 else if (schema.TargetNamespace == "ab")
50 else if (schema.TargetNamespace == "urn:foo")
53 Assert.IsTrue (chameleon, "chameleon schema missing");
54 Assert.IsTrue (ab, "target-remapped schema missing");
55 Assert.IsTrue (urnfoo, "target specified in the schema ignored");
59 public void AddSchemaThenReader ()
61 XmlSchemaSet ss = new XmlSchemaSet ();
62 XmlDocument doc = new XmlDocument ();
63 doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' />");
64 XmlSchema xs = new XmlSchema ();
65 xs.TargetNamespace = "ab";
67 ss.Add ("ab", new XmlNodeReader (doc));
71 [Category ("NotWorking")] // How can we differentiate this
72 // case and the testcase above?
73 [ExpectedException (typeof (ArgumentException))]
74 public void AddReaderTwice ()
76 XmlSchemaSet ss = new XmlSchemaSet ();
77 XmlDocument doc = new XmlDocument ();
78 doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' />");
79 ss.Add ("ab", new XmlNodeReader (doc));
80 ss.Add ("ab", new XmlNodeReader (doc));
84 public void AddSchemaTwice ()
86 XmlSchemaSet ss = new XmlSchemaSet ();
87 XmlDocument doc = new XmlDocument ();
88 doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:ab' />");
89 ss.Add (XmlSchema.Read (new XmlNodeReader (doc), null));
90 ss.Add (XmlSchema.Read (new XmlNodeReader (doc), null));
94 public void CompilationSettings ()
96 Assert.IsNotNull (new XmlSchemaSet ().CompilationSettings);
97 new XmlSchemaSet ().CompilationSettings = null;
101 public void DisableUpaCheck ()
103 string schema = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
104 <xs:complexType name='Foo'>
106 <xs:choice minOccurs='0'>
107 <xs:element name='el'/>
109 <xs:element name='el' />
113 XmlSchema xs = XmlSchema.Read (new XmlTextReader (
114 schema, XmlNodeType.Document, null), null);
115 XmlSchemaSet xss = new XmlSchemaSet ();
117 xss.CompilationSettings.EnableUpaCheck = false;
123 public void AddRollbackIsCompiled ()
125 XmlSchemaSet ss = new XmlSchemaSet ();
126 ss.Add (new XmlSchema ());
128 Assert.IsTrue (ss.IsCompiled, "#1");
129 XmlSchema sc = new XmlSchema (); // compiled one
132 Assert.IsFalse (ss.IsCompiled, "#2");
133 ss.Add (new XmlSchema ()); // not-compiled one
134 Assert.IsFalse (ss.IsCompiled, "#3");
137 s = new XmlSchema ();
138 s.TargetNamespace = "urn:foo";
140 el = new XmlSchemaElement ();
145 s = new XmlSchema ();
146 s.TargetNamespace = "urn:foo";
147 el = new XmlSchemaElement ();
152 Assert.IsTrue (ss.IsCompiled, "#4");
153 ss.RemoveRecursive (s);
154 Assert.IsTrue (ss.IsCompiled, "#5");