2 // ConfigurationBaseTest.cs: ConfigurationBase Unit Tests
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
11 using System.Configuration;
14 using WSEC = Microsoft.Web.Services.Configuration;
16 using NUnit.Framework;
18 namespace MonoTests.MS.Web.Services.Configuration {
21 public class ConfigurationBaseTest : WSEC.ConfigurationBase {
24 public void CheckForChildNodes_NoChildNode ()
26 string xml = "<node attrib=\"value\"/>";
27 XmlDocument doc = new XmlDocument ();
29 CheckForChildNodes (doc.DocumentElement);
33 [ExpectedException (typeof (ArgumentNullException))]
34 public void CheckForChildNodes_Null ()
36 CheckForChildNodes (null);
40 [ExpectedException (typeof (ConfigurationException))]
41 public void CheckForChildNodes_OneNode ()
43 string xml = "<test><childnode/></test>";
44 XmlDocument doc = new XmlDocument ();
46 CheckForChildNodes (doc.DocumentElement);
50 public void CheckForDuplicateChildNodes_NoDupes ()
52 string xml = "<test><childnode/></test>";
53 XmlDocument doc = new XmlDocument ();
55 CheckForDuplicateChildNodes (doc.DocumentElement);
59 [ExpectedException (typeof (ArgumentNullException))]
60 public void CheckForDuplicateChildNodes_Null ()
62 CheckForDuplicateChildNodes (null);
66 [ExpectedException (typeof (ConfigurationException))]
67 public void CheckForDuplicateChildNodes_Dupes ()
69 string xml = "<test><childnode/><childnode/></test>";
70 XmlDocument doc = new XmlDocument ();
72 CheckForDuplicateChildNodes (doc.DocumentElement);
76 public void CheckForUnrecognizedAttributes_NoAttribute ()
78 string xml = "<node/>";
79 XmlDocument doc = new XmlDocument ();
81 CheckForUnrecognizedAttributes (doc.DocumentElement);
85 [ExpectedException (typeof (ArgumentNullException))]
86 public void CheckForUnrecognizedAttributes_Null ()
88 CheckForUnrecognizedAttributes (null);
92 [ExpectedException (typeof (ConfigurationException))]
93 public void CheckForUnrecognizedAttributes_OneAttribute ()
95 string xml = "<test attrib=\"value\"/>";
96 XmlDocument doc = new XmlDocument ();
98 CheckForUnrecognizedAttributes (doc.DocumentElement);
102 public void GetAndRemoveAttribute_AttribPresentNotRequired ()
104 string xml = "<test attrib=\"value\"/>";
105 XmlDocument doc = new XmlDocument ();
107 XmlNode xn = GetAndRemoveAttribute (doc.DocumentElement, "attrib", false);
108 Assertion.AssertEquals ("GetAndRemoveAttribute_AttribPresentNotRequired", "attrib=\"value\"", xn.OuterXml);
112 public void GetAndRemoveAttribute_AttribPresentAndRequired ()
114 string xml = "<test attrib=\"value\"/>";
115 XmlDocument doc = new XmlDocument ();
117 XmlNode xn = GetAndRemoveAttribute (doc.DocumentElement, "attrib", true);
118 Assertion.AssertEquals ("GetAndRemoveAttribute_AttribPresentAndRequired", "attrib=\"value\"", xn.OuterXml);
122 public void GetAndRemoveAttribute_AttribNotPresentNotRequired ()
124 string xml = "<test/>";
125 XmlDocument doc = new XmlDocument ();
127 XmlNode xn = GetAndRemoveAttribute (doc.DocumentElement, "attrib", false);
128 Assertion.AssertNull ("GetAndRemoveAttribute_AttribNotPresentNotRequired", xn);
132 [ExpectedException (typeof (ConfigurationException))]
133 public void GetAndRemoveAttribute_AttribNotPresentAndRequired ()
135 string xml = "<test/>";
136 XmlDocument doc = new XmlDocument ();
138 XmlNode xn = GetAndRemoveAttribute (doc.DocumentElement, "attrib", true);
142 [ExpectedException (typeof (ArgumentNullException))]
143 public void GetAndRemoveAttribute_NullNode ()
145 GetAndRemoveAttribute (null, "attrib", true);
149 public void GetAndRemoveAttribute_NullAttrib ()
151 string xml = "<test/>";
152 XmlDocument doc = new XmlDocument ();
154 XmlNode xn = GetAndRemoveAttribute (doc.DocumentElement, null, false);
155 Assertion.AssertNull ("GetAndRemoveAttribute_NullAttrib", xn);
159 public void GetAndRemoveBoolAttribute_AttribPresentNotRequired ()
161 string xml = "<test attrib=\"true\"/>";
162 XmlDocument doc = new XmlDocument ();
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);
171 public void GetAndRemoveBoolAttribute_AttribPresentAndRequired ()
173 string xml = "<test attrib=\"true\"/>";
174 XmlDocument doc = new XmlDocument ();
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);
183 public void GetAndRemoveBoolAttribute_AttribNotPresentNotRequired ()
185 string xml = "<test/>";
186 XmlDocument doc = new XmlDocument ();
189 XmlNode xn = GetAndRemoveBoolAttribute (doc.DocumentElement, "attrib", false, ref result);
190 Assertion.AssertNull ("GetAndRemoveBoolAttribute_AttribNotPresentNotRequired", xn);
191 Assertion.Assert ("GetAndRemoveBoolAttribute_AttribNotPresentNotRequired", !result);
195 [ExpectedException (typeof (ConfigurationException))]
196 public void GetAndRemoveBoolAttribute_AttribNotPresentAndRequired ()
198 string xml = "<test/>";
199 XmlDocument doc = new XmlDocument ();
202 XmlNode xn = GetAndRemoveBoolAttribute (doc.DocumentElement, "attrib", true, ref result);
206 [ExpectedException (typeof (ArgumentNullException))]
207 public void GetAndRemoveBoolAttribute_NullNode ()
210 GetAndRemoveBoolAttribute (null, "attrib", true, ref result);
214 public void GetAndRemoveBoolAttribute_NullAttrib ()
216 string xml = "<test/>";
217 XmlDocument doc = new XmlDocument ();
220 XmlNode xn = GetAndRemoveBoolAttribute (doc.DocumentElement, null, false, ref result);
221 Assertion.AssertNull ("GetAndRemoveBoolAttribute_NullAttrib", xn);
222 Assertion.Assert ("GetAndRemoveBoolAttribute_NullAttrib", !result);
226 public void GetAndRemoveStringAttribute_AttribPresentNotRequired ()
228 string xml = "<test attrib=\"true\"/>";
229 XmlDocument doc = new XmlDocument ();
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);
238 public void GetAndRemoveStringAttribute_AttribPresentAndRequired ()
240 string xml = "<test attrib=\"true\"/>";
241 XmlDocument doc = new XmlDocument ();
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);
250 public void GetAndRemoveStringAttribute_AttribNotPresentNotRequired ()
252 string xml = "<test/>";
253 XmlDocument doc = new XmlDocument ();
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);
262 [ExpectedException (typeof (ConfigurationException))]
263 public void GetAndRemoveStringAttribute_AttribNotPresentAndRequired ()
265 string xml = "<test/>";
266 XmlDocument doc = new XmlDocument ();
268 string result = null;
269 XmlNode xn = GetAndRemoveStringAttribute (doc.DocumentElement, "attrib", true, ref result);
273 [ExpectedException (typeof (ArgumentNullException))]
274 public void GetAndRemoveStringAttribute_NullNode ()
276 string result = null;
277 GetAndRemoveStringAttribute (null, "attrib", true, ref result);
281 public void GetAndRemoveStringAttribute_NullAttrib ()
283 string xml = "<test/>";
284 XmlDocument doc = new XmlDocument ();
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);
293 public void ThrowIfElement_NoElement ()
295 string xml = "<element><!-- comment --></element>";
296 XmlDocument doc = new XmlDocument ();
298 ThrowIfElement (doc.DocumentElement.ChildNodes [0]);
302 [ExpectedException (typeof (ArgumentNullException))]
303 public void ThrowIfElement_Null ()
305 ThrowIfElement (null);
309 [ExpectedException (typeof (ConfigurationException))]
310 public void ThrowIfElement_Element ()
312 string xml = "<element/>";
313 XmlDocument doc = new XmlDocument ();
315 ThrowIfElement (doc.DocumentElement);
319 public void ThrowIfNotComment_NoComment ()
321 string xml = "<element><!-- comment --></element>";
322 XmlDocument doc = new XmlDocument ();
324 ThrowIfNotComment (doc.DocumentElement.ChildNodes [0]);
328 [ExpectedException (typeof (ArgumentNullException))]
329 public void ThrowIfNotComment_Null ()
331 ThrowIfNotComment (null);
335 [ExpectedException (typeof (ConfigurationException))]
336 public void ThrowIfNotComment_Element ()
338 string xml = "<element/>";
339 XmlDocument doc = new XmlDocument ();
341 ThrowIfNotComment (doc.DocumentElement);