**** Merged from MCS ****
[mono-project.git] / mcs / class / Microsoft.Web.Services / Test / Microsoft.Web.Services.Configuration / ConfigurationBaseTest.cs
blobd02a7b4549ec566888d8ff3d8a9dfdd6a071e6a5
1 //
2 // ConfigurationBaseTest.cs: ConfigurationBase Unit Tests
3 //
4 // Author:
5 // Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
10 using System;
11 using System.Configuration;
12 using System.Xml;
14 using WSEC = Microsoft.Web.Services.Configuration;
16 using NUnit.Framework;
18 namespace MonoTests.MS.Web.Services.Configuration {
20 [TestFixture]
21 public class ConfigurationBaseTest : WSEC.ConfigurationBase {
23 [Test]
24 public void CheckForChildNodes_NoChildNode ()
26 string xml = "<node attrib=\"value\"/>";
27 XmlDocument doc = new XmlDocument ();
28 doc.LoadXml (xml);
29 CheckForChildNodes (doc.DocumentElement);
32 [Test]
33 [ExpectedException (typeof (ArgumentNullException))]
34 public void CheckForChildNodes_Null ()
36 CheckForChildNodes (null);
39 [Test]
40 [ExpectedException (typeof (ConfigurationException))]
41 public void CheckForChildNodes_OneNode ()
43 string xml = "<test><childnode/></test>";
44 XmlDocument doc = new XmlDocument ();
45 doc.LoadXml (xml);
46 CheckForChildNodes (doc.DocumentElement);
49 [Test]
50 public void CheckForDuplicateChildNodes_NoDupes ()
52 string xml = "<test><childnode/></test>";
53 XmlDocument doc = new XmlDocument ();
54 doc.LoadXml (xml);
55 CheckForDuplicateChildNodes (doc.DocumentElement);
58 [Test]
59 [ExpectedException (typeof (ArgumentNullException))]
60 public void CheckForDuplicateChildNodes_Null ()
62 CheckForDuplicateChildNodes (null);
65 [Test]
66 [ExpectedException (typeof (ConfigurationException))]
67 public void CheckForDuplicateChildNodes_Dupes ()
69 string xml = "<test><childnode/><childnode/></test>";
70 XmlDocument doc = new XmlDocument ();
71 doc.LoadXml (xml);
72 CheckForDuplicateChildNodes (doc.DocumentElement);
75 [Test]
76 public void CheckForUnrecognizedAttributes_NoAttribute ()
78 string xml = "<node/>";
79 XmlDocument doc = new XmlDocument ();
80 doc.LoadXml (xml);
81 CheckForUnrecognizedAttributes (doc.DocumentElement);
84 [Test]
85 [ExpectedException (typeof (ArgumentNullException))]
86 public void CheckForUnrecognizedAttributes_Null ()
88 CheckForUnrecognizedAttributes (null);
91 [Test]
92 [ExpectedException (typeof (ConfigurationException))]
93 public void CheckForUnrecognizedAttributes_OneAttribute ()
95 string xml = "<test attrib=\"value\"/>";
96 XmlDocument doc = new XmlDocument ();
97 doc.LoadXml (xml);
98 CheckForUnrecognizedAttributes (doc.DocumentElement);
101 [Test]
102 public void GetAndRemoveAttribute_AttribPresentNotRequired ()
104 string xml = "<test attrib=\"value\"/>";
105 XmlDocument doc = new XmlDocument ();
106 doc.LoadXml (xml);
107 XmlNode xn = GetAndRemoveAttribute (doc.DocumentElement, "attrib", false);
108 Assertion.AssertEquals ("GetAndRemoveAttribute_AttribPresentNotRequired", "attrib=\"value\"", xn.OuterXml);
111 [Test]
112 public void GetAndRemoveAttribute_AttribPresentAndRequired ()
114 string xml = "<test attrib=\"value\"/>";
115 XmlDocument doc = new XmlDocument ();
116 doc.LoadXml (xml);
117 XmlNode xn = GetAndRemoveAttribute (doc.DocumentElement, "attrib", true);
118 Assertion.AssertEquals ("GetAndRemoveAttribute_AttribPresentAndRequired", "attrib=\"value\"", xn.OuterXml);
121 [Test]
122 public void GetAndRemoveAttribute_AttribNotPresentNotRequired ()
124 string xml = "<test/>";
125 XmlDocument doc = new XmlDocument ();
126 doc.LoadXml (xml);
127 XmlNode xn = GetAndRemoveAttribute (doc.DocumentElement, "attrib", false);
128 Assertion.AssertNull ("GetAndRemoveAttribute_AttribNotPresentNotRequired", xn);
131 [Test]
132 [ExpectedException (typeof (ConfigurationException))]
133 public void GetAndRemoveAttribute_AttribNotPresentAndRequired ()
135 string xml = "<test/>";
136 XmlDocument doc = new XmlDocument ();
137 doc.LoadXml (xml);
138 XmlNode xn = GetAndRemoveAttribute (doc.DocumentElement, "attrib", true);
141 [Test]
142 [ExpectedException (typeof (ArgumentNullException))]
143 public void GetAndRemoveAttribute_NullNode ()
145 GetAndRemoveAttribute (null, "attrib", true);
148 [Test]
149 public void GetAndRemoveAttribute_NullAttrib ()
151 string xml = "<test/>";
152 XmlDocument doc = new XmlDocument ();
153 doc.LoadXml (xml);
154 XmlNode xn = GetAndRemoveAttribute (doc.DocumentElement, null, false);
155 Assertion.AssertNull ("GetAndRemoveAttribute_NullAttrib", xn);
158 [Test]
159 public void GetAndRemoveBoolAttribute_AttribPresentNotRequired ()
161 string xml = "<test attrib=\"true\"/>";
162 XmlDocument doc = new XmlDocument ();
163 doc.LoadXml (xml);
164 bool result = false;
165 XmlNode xn = GetAndRemoveBoolAttribute (doc.DocumentElement, "attrib", false, ref result);
166 Assertion.AssertEquals ("GetAndRemoveBoolAttribute_AttribPresentNotRequired", "attrib=\"true\"", xn.OuterXml);
167 Assertion.Assert ("GetAndRemoveBoolAttribute_AttribPresentNotRequired", result);
170 [Test]
171 public void GetAndRemoveBoolAttribute_AttribPresentAndRequired ()
173 string xml = "<test attrib=\"true\"/>";
174 XmlDocument doc = new XmlDocument ();
175 doc.LoadXml (xml);
176 bool result = false;
177 XmlNode xn = GetAndRemoveBoolAttribute (doc.DocumentElement, "attrib", true, ref result);
178 Assertion.AssertEquals ("GetAndRemoveBoolAttribute_AttribPresentAndRequired", "attrib=\"true\"", xn.OuterXml);
179 Assertion.Assert ("GetAndRemoveBoolAttribute_AttribPresentAndRequired", result);
182 [Test]
183 public void GetAndRemoveBoolAttribute_AttribNotPresentNotRequired ()
185 string xml = "<test/>";
186 XmlDocument doc = new XmlDocument ();
187 doc.LoadXml (xml);
188 bool result = false;
189 XmlNode xn = GetAndRemoveBoolAttribute (doc.DocumentElement, "attrib", false, ref result);
190 Assertion.AssertNull ("GetAndRemoveBoolAttribute_AttribNotPresentNotRequired", xn);
191 Assertion.Assert ("GetAndRemoveBoolAttribute_AttribNotPresentNotRequired", !result);
194 [Test]
195 [ExpectedException (typeof (ConfigurationException))]
196 public void GetAndRemoveBoolAttribute_AttribNotPresentAndRequired ()
198 string xml = "<test/>";
199 XmlDocument doc = new XmlDocument ();
200 doc.LoadXml (xml);
201 bool result = false;
202 XmlNode xn = GetAndRemoveBoolAttribute (doc.DocumentElement, "attrib", true, ref result);
205 [Test]
206 [ExpectedException (typeof (ArgumentNullException))]
207 public void GetAndRemoveBoolAttribute_NullNode ()
209 bool result = false;
210 GetAndRemoveBoolAttribute (null, "attrib", true, ref result);
213 [Test]
214 public void GetAndRemoveBoolAttribute_NullAttrib ()
216 string xml = "<test/>";
217 XmlDocument doc = new XmlDocument ();
218 doc.LoadXml (xml);
219 bool result = false;
220 XmlNode xn = GetAndRemoveBoolAttribute (doc.DocumentElement, null, false, ref result);
221 Assertion.AssertNull ("GetAndRemoveBoolAttribute_NullAttrib", xn);
222 Assertion.Assert ("GetAndRemoveBoolAttribute_NullAttrib", !result);
225 [Test]
226 public void GetAndRemoveStringAttribute_AttribPresentNotRequired ()
228 string xml = "<test attrib=\"true\"/>";
229 XmlDocument doc = new XmlDocument ();
230 doc.LoadXml (xml);
231 string result = null;
232 XmlNode xn = GetAndRemoveStringAttribute (doc.DocumentElement, "attrib", false, ref result);
233 Assertion.AssertEquals ("GetAndRemoveStringAttribute_AttribPresentNotRequired", "attrib=\"true\"", xn.OuterXml);
234 Assertion.AssertEquals ("GetAndRemoveStringAttribute_AttribPresentNotRequired", "true", result);
237 [Test]
238 public void GetAndRemoveStringAttribute_AttribPresentAndRequired ()
240 string xml = "<test attrib=\"true\"/>";
241 XmlDocument doc = new XmlDocument ();
242 doc.LoadXml (xml);
243 string result = null;
244 XmlNode xn = GetAndRemoveStringAttribute (doc.DocumentElement, "attrib", true, ref result);
245 Assertion.AssertEquals ("GetAndRemoveStringAttribute_AttribPresentAndRequired", "attrib=\"true\"", xn.OuterXml);
246 Assertion.AssertEquals ("GetAndRemoveStringAttribute_AttribPresentAndRequired", "true", result);
249 [Test]
250 public void GetAndRemoveStringAttribute_AttribNotPresentNotRequired ()
252 string xml = "<test/>";
253 XmlDocument doc = new XmlDocument ();
254 doc.LoadXml (xml);
255 string result = null;
256 XmlNode xn = GetAndRemoveStringAttribute (doc.DocumentElement, "attrib", false, ref result);
257 Assertion.AssertNull ("GetAndRemoveBoolAttribute_AttribNotPresentNotRequired", xn);
258 Assertion.AssertNull ("GetAndRemoveBoolAttribute_AttribNotPresentNotRequired", result);
261 [Test]
262 [ExpectedException (typeof (ConfigurationException))]
263 public void GetAndRemoveStringAttribute_AttribNotPresentAndRequired ()
265 string xml = "<test/>";
266 XmlDocument doc = new XmlDocument ();
267 doc.LoadXml (xml);
268 string result = null;
269 XmlNode xn = GetAndRemoveStringAttribute (doc.DocumentElement, "attrib", true, ref result);
272 [Test]
273 [ExpectedException (typeof (ArgumentNullException))]
274 public void GetAndRemoveStringAttribute_NullNode ()
276 string result = null;
277 GetAndRemoveStringAttribute (null, "attrib", true, ref result);
280 [Test]
281 public void GetAndRemoveStringAttribute_NullAttrib ()
283 string xml = "<test/>";
284 XmlDocument doc = new XmlDocument ();
285 doc.LoadXml (xml);
286 string result = null;
287 XmlNode xn = GetAndRemoveStringAttribute (doc.DocumentElement, null, false, ref result);
288 Assertion.AssertNull ("GetAndRemoveStringAttribute_NullAttrib", xn);
289 Assertion.AssertNull ("GetAndRemoveStringAttribute_NullAttrib", result);
292 [Test]
293 public void ThrowIfElement_NoElement ()
295 string xml = "<element><!-- comment --></element>";
296 XmlDocument doc = new XmlDocument ();
297 doc.LoadXml (xml);
298 ThrowIfElement (doc.DocumentElement.ChildNodes [0]);
301 [Test]
302 [ExpectedException (typeof (ArgumentNullException))]
303 public void ThrowIfElement_Null ()
305 ThrowIfElement (null);
308 [Test]
309 [ExpectedException (typeof (ConfigurationException))]
310 public void ThrowIfElement_Element ()
312 string xml = "<element/>";
313 XmlDocument doc = new XmlDocument ();
314 doc.LoadXml (xml);
315 ThrowIfElement (doc.DocumentElement);
318 [Test]
319 public void ThrowIfNotComment_NoComment ()
321 string xml = "<element><!-- comment --></element>";
322 XmlDocument doc = new XmlDocument ();
323 doc.LoadXml (xml);
324 ThrowIfNotComment (doc.DocumentElement.ChildNodes [0]);
327 [Test]
328 [ExpectedException (typeof (ArgumentNullException))]
329 public void ThrowIfNotComment_Null ()
331 ThrowIfNotComment (null);
334 [Test]
335 [ExpectedException (typeof (ConfigurationException))]
336 public void ThrowIfNotComment_Element ()
338 string xml = "<element/>";
339 XmlDocument doc = new XmlDocument ();
340 doc.LoadXml (xml);
341 ThrowIfNotComment (doc.DocumentElement);