2 // MonoTests.System.Xml.XsdParticleValidationTests.cs
\r
5 // Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
\r
7 // (C)2003 Atsushi Enomoto
\r
11 using System.Xml.Schema;
\r
12 using NUnit.Framework;
\r
15 using ValidationException = System.Xml.Schema.XmlSchemaValidationException;
\r
17 using ValidationException = System.Xml.Schema.XmlSchemaException;
\r
20 namespace MonoTests.System.Xml
\r
22 // using XmlValidatingReader = XmlTextReader;
\r
25 public class XsdParticleValidationTests : Assertion
\r
29 XmlValidatingReader xvr;
\r
31 private void PrepareReader1 (string xsdUrl, string xml)
\r
33 schema = XmlSchema.Read (new XmlTextReader ("Test/XmlFiles/XsdValidation/" + xsdUrl), null);
\r
34 xr = new XmlTextReader (xml, XmlNodeType.Document, null);
\r
35 xvr = new XmlValidatingReader (xr);
\r
36 xvr.Schemas.Add (schema);
\r
37 // xvr = xr as XmlValidatingReader;
\r
41 public void ValidateRootElementOnlyValid ()
\r
43 PrepareReader1 ("1.xsd", "<root xmlns='urn:foo' />");
\r
45 PrepareReader1 ("1.xsd", "<root xmlns='urn:foo'></root>");
\r
51 [ExpectedException (typeof (ValidationException))]
\r
52 public void ValidateRootElementOnlyInvalid ()
\r
54 PrepareReader1 ("1.xsd", "<invalid xmlns='urn:foo' />");
\r
59 [ExpectedException (typeof (ValidationException))]
\r
60 public void ValidateRootElementOnlyInvalid2 ()
\r
62 PrepareReader1 ("1.xsd", "<root xmlns='urn:foo'><invalid_child/></root>");
\r
68 public void ValidateElementContainsElementValid1 ()
\r
70 PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'><child/></root>");
\r
76 public void ValidateElementContainsElementValid2 ()
\r
78 PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'><child/><child/></root>");
\r
84 [ExpectedException (typeof (ValidationException))]
\r
85 public void ValidateElementContainsElementInvalid1 ()
\r
87 PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'></root>");
\r
93 [ExpectedException (typeof (ValidationException))]
\r
94 public void ValidateElementContainsElementInvalid2 ()
\r
96 PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'><child/><child/><child/></root>");
\r
102 public void ValidateSequenceValid ()
\r
104 PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/></root>");
\r
108 PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/><child2/></root>");
\r
114 [ExpectedException (typeof (ValidationException))]
\r
115 public void ValidateSequenceInvalid1 ()
\r
117 PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'></root>");
\r
123 [ExpectedException (typeof (ValidationException))]
\r
124 public void ValidateSequenceInvalid2 ()
\r
126 PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/></root>");
\r
132 [ExpectedException (typeof (ValidationException))]
\r
133 public void ValidateSequenceInvalid3 ()
\r
135 PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/></root>");
\r
141 [ExpectedException (typeof (ValidationException))]
\r
142 public void ValidateSequenceInvalid4 ()
\r
144 PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/><child2/><child1/></root>");
\r
150 [ExpectedException (typeof (ValidationException))]
\r
151 public void ValidateSequenceInvalid5 ()
\r
153 PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/><child2/><child1/><child2/></root>");
\r
159 public void ValidateChoiceValid ()
\r
161 PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child1/></root>");
\r
165 PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/></root>");
\r
169 PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child1/><child2/></root>");
\r
173 PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/><child2/></root>");
\r
177 PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/><child2/><child2/><child2/></root>");
\r
181 PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/><child2/><child1/></root>");
\r
185 PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'></root>");
\r
192 [ExpectedException (typeof (ValidationException))]
\r
193 public void ValidateChoiceInvalid1 ()
\r
195 PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child1/><child1/><child1/></root>");
\r
201 [ExpectedException (typeof (ValidationException))]
\r
202 public void ValidateChoiceInvalid2 ()
\r
204 PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child2/><child2/><child2/><child2/><child2/></root>");
\r
210 [ExpectedException (typeof (ValidationException))]
\r
211 public void ValidateChoiceInvalid3 ()
\r
213 PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child2/><child2/><child2/><child1/></root>");
\r
219 [ExpectedException (typeof (ValidationException))]
\r
220 public void ValidateChoiceInvalid4 ()
\r
222 PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child2/><child2/></root>");
\r