Welcome to mirror list, hosted at ThFree Co, Russian Federation.

XsdParticleValidationTests.cs « System.Xml « Test « System.XML « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 92d72231134d1f2514394434b2b92f5ffbac6835 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//
// MonoTests.System.Xml.XsdParticleValidationTests.cs
//
// Author:
//	Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
//
// (C)2003 Atsushi Enomoto
//
using System;
using System.Xml;
using System.Xml.Schema;
using NUnit.Framework;

#if NET_2_0
using ValidationException = System.Xml.Schema.XmlSchemaValidationException;
#else
using ValidationException = System.Xml.Schema.XmlSchemaException;
#endif

namespace MonoTests.System.Xml
{
//	using XmlValidatingReader = XmlTextReader;

	[TestFixture]
	public class XsdParticleValidationTests
	{
		XmlSchema schema;
		XmlReader xr;
		XmlValidatingReader xvr;

		private void PrepareReader1 (string xsdUrl, string xml)
		{
			schema = XmlSchema.Read (new XmlTextReader ("Test/XmlFiles/XsdValidation/" + xsdUrl), null);
			xr = new XmlTextReader (xml, XmlNodeType.Document, null);
			xvr = new XmlValidatingReader (xr);
			xvr.Schemas.Add (schema);
//			xvr = xr as XmlValidatingReader;
		}

		[Test]
		public void ValidateRootElementOnlyValid ()
		{
			PrepareReader1 ("1.xsd", "<root xmlns='urn:foo' />");
			xvr.Read ();
			PrepareReader1 ("1.xsd", "<root xmlns='urn:foo'></root>");
			xvr.Read ();
			xvr.Read ();
		}

		[Test]
#if NET_2_0
		[Category ("NotDotNet")]
		// MS.NET throws XmlSchemaException, not -ValidationException.
#endif
		[ExpectedException (typeof (ValidationException))]
		public void ValidateRootElementOnlyInvalid ()
		{
			PrepareReader1 ("1.xsd", "<invalid xmlns='urn:foo' />");
			xvr.Read ();
		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateRootElementOnlyInvalid2 ()
		{
			PrepareReader1 ("1.xsd", "<root xmlns='urn:foo'><invalid_child/></root>");
			xvr.Read ();
			xvr.Read ();
		}

		[Test]
		public void ValidateElementContainsElementValid1 ()
		{
			PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'><child/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		public void ValidateElementContainsElementValid2 ()
		{
			PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'><child/><child/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateElementContainsElementInvalid1 ()
		{
			PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateElementContainsElementInvalid2 ()
		{
			PrepareReader1 ("2.xsd", "<root xmlns='urn:foo'><child/><child/><child/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		public void ValidateSequenceValid ()
		{
			PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/></root>");
			while (!xvr.EOF)
				xvr.Read ();

			PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/><child2/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateSequenceInvalid1 ()
		{
			PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateSequenceInvalid2 ()
		{
			PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateSequenceInvalid3 ()
		{
			PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateSequenceInvalid4 ()
		{
			PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/><child2/><child1/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateSequenceInvalid5 ()
		{
			PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child1/><child2/><child1/><child2/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		public void ValidateChoiceValid ()
		{
			PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child1/></root>");
			while (!xvr.EOF)
				xvr.Read ();

			PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/></root>");
			while (!xvr.EOF)
				xvr.Read ();

			PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child1/><child2/></root>");
			while (!xvr.EOF)
				xvr.Read ();

			PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/><child2/></root>");
			while (!xvr.EOF)
				xvr.Read ();

			PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/><child2/><child2/><child2/></root>");
			while (!xvr.EOF)
				xvr.Read ();

			PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child2/><child2/><child1/></root>");
			while (!xvr.EOF)
				xvr.Read ();

			PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'></root>");
			while (!xvr.EOF)
				xvr.Read ();

		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateChoiceInvalid1 ()
		{
			PrepareReader1 ("4.xsd", "<root xmlns='urn:foo'><child1/><child1/><child1/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateChoiceInvalid2 ()
		{
			PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child2/><child2/><child2/><child2/><child2/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateChoiceInvalid3 ()
		{
			PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child2/><child2/><child2/><child1/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

		[Test]
		[ExpectedException (typeof (ValidationException))]
		public void ValidateChoiceInvalid4 ()
		{
			PrepareReader1 ("3.xsd", "<root xmlns='urn:foo'><child1/><child2/><child2/><child2/></root>");
			while (!xvr.EOF)
				xvr.Read ();
		}

	}
}