TARGET_J2EE/JVM fixes
[mono.git] / mcs / class / Microsoft.Web.Services / Test / Microsoft.Web.Services.Configuration / ConfigurationBaseTest.cs
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 //
9
10 using System;
11 using System.Configuration;
12 using System.Xml;
13
14 using WSEC = Microsoft.Web.Services.Configuration;
15
16 using NUnit.Framework;
17
18 namespace MonoTests.MS.Web.Services.Configuration {
19
20         [TestFixture]
21         public class ConfigurationBaseTest : WSEC.ConfigurationBase {
22
23                 [Test]
24                 public void CheckForChildNodes_NoChildNode () 
25                 {
26                         string xml = "<node attrib=\"value\"/>";
27                         XmlDocument doc = new XmlDocument ();
28                         doc.LoadXml (xml);
29                         CheckForChildNodes (doc.DocumentElement);
30                 }
31
32                 [Test]
33                 [ExpectedException (typeof (ArgumentNullException))]
34                 public void CheckForChildNodes_Null ()
35                 {
36                         CheckForChildNodes (null);
37                 }
38
39                 [Test]
40                 [ExpectedException (typeof (ConfigurationException))]
41                 public void CheckForChildNodes_OneNode () 
42                 {
43                         string xml = "<test><childnode/></test>";
44                         XmlDocument doc = new XmlDocument ();
45                         doc.LoadXml (xml);
46                         CheckForChildNodes (doc.DocumentElement);
47                 }
48
49                 [Test]
50                 public void CheckForDuplicateChildNodes_NoDupes () 
51                 {
52                         string xml = "<test><childnode/></test>";
53                         XmlDocument doc = new XmlDocument ();
54                         doc.LoadXml (xml);
55                         CheckForDuplicateChildNodes (doc.DocumentElement);
56                 }
57
58                 [Test]
59                 [ExpectedException (typeof (ArgumentNullException))]
60                 public void CheckForDuplicateChildNodes_Null () 
61                 {
62                         CheckForDuplicateChildNodes (null);
63                 }
64
65                 [Test]
66                 [ExpectedException (typeof (ConfigurationException))]
67                 public void CheckForDuplicateChildNodes_Dupes () 
68                 {
69                         string xml = "<test><childnode/><childnode/></test>";
70                         XmlDocument doc = new XmlDocument ();
71                         doc.LoadXml (xml);
72                         CheckForDuplicateChildNodes (doc.DocumentElement);
73                 }
74
75                 [Test]
76                 public void CheckForUnrecognizedAttributes_NoAttribute () 
77                 {
78                         string xml = "<node/>";
79                         XmlDocument doc = new XmlDocument ();
80                         doc.LoadXml (xml);
81                         CheckForUnrecognizedAttributes (doc.DocumentElement);
82                 }
83
84                 [Test]
85                 [ExpectedException (typeof (ArgumentNullException))]
86                 public void CheckForUnrecognizedAttributes_Null () 
87                 {
88                         CheckForUnrecognizedAttributes (null);
89                 }
90
91                 [Test]
92                 [ExpectedException (typeof (ConfigurationException))]
93                 public void CheckForUnrecognizedAttributes_OneAttribute () 
94                 {
95                         string xml = "<test attrib=\"value\"/>";
96                         XmlDocument doc = new XmlDocument ();
97                         doc.LoadXml (xml);
98                         CheckForUnrecognizedAttributes (doc.DocumentElement);
99                 }
100
101                 [Test]
102                 public void GetAndRemoveAttribute_AttribPresentNotRequired () 
103                 {
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);
109                 }
110
111                 [Test]
112                 public void GetAndRemoveAttribute_AttribPresentAndRequired () 
113                 {
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);
119                 }
120
121                 [Test]
122                 public void GetAndRemoveAttribute_AttribNotPresentNotRequired () 
123                 {
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);
129                 }
130
131                 [Test]
132                 [ExpectedException (typeof (ConfigurationException))]
133                 public void GetAndRemoveAttribute_AttribNotPresentAndRequired () 
134                 {
135                         string xml = "<test/>";
136                         XmlDocument doc = new XmlDocument ();
137                         doc.LoadXml (xml);
138                         XmlNode xn = GetAndRemoveAttribute (doc.DocumentElement, "attrib", true);
139                 }
140
141                 [Test]
142                 [ExpectedException (typeof (ArgumentNullException))]
143                 public void GetAndRemoveAttribute_NullNode () 
144                 {
145                         GetAndRemoveAttribute (null, "attrib", true);
146                 }
147
148                 [Test]
149                 public void GetAndRemoveAttribute_NullAttrib () 
150                 {
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);
156                 }
157
158                 [Test]
159                 public void GetAndRemoveBoolAttribute_AttribPresentNotRequired () 
160                 {
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);
168                 }
169
170                 [Test]
171                 public void GetAndRemoveBoolAttribute_AttribPresentAndRequired () 
172                 {
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);
180                 }
181
182                 [Test]
183                 public void GetAndRemoveBoolAttribute_AttribNotPresentNotRequired () 
184                 {
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);
192                 }
193
194                 [Test]
195                 [ExpectedException (typeof (ConfigurationException))]
196                 public void GetAndRemoveBoolAttribute_AttribNotPresentAndRequired () 
197                 {
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);
203                 }
204
205                 [Test]
206                 [ExpectedException (typeof (ArgumentNullException))]
207                 public void GetAndRemoveBoolAttribute_NullNode () 
208                 {
209                         bool result = false;
210                         GetAndRemoveBoolAttribute (null, "attrib", true, ref result);
211                 }
212
213                 [Test]
214                 public void GetAndRemoveBoolAttribute_NullAttrib () 
215                 {
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);
223                 }
224
225                 [Test]
226                 public void GetAndRemoveStringAttribute_AttribPresentNotRequired () 
227                 {
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);
235                 }
236
237                 [Test]
238                 public void GetAndRemoveStringAttribute_AttribPresentAndRequired () 
239                 {
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);
247                 }
248
249                 [Test]
250                 public void GetAndRemoveStringAttribute_AttribNotPresentNotRequired () 
251                 {
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);
259                 }
260
261                 [Test]
262                 [ExpectedException (typeof (ConfigurationException))]
263                 public void GetAndRemoveStringAttribute_AttribNotPresentAndRequired () 
264                 {
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);
270                 }
271
272                 [Test]
273                 [ExpectedException (typeof (ArgumentNullException))]
274                 public void GetAndRemoveStringAttribute_NullNode () 
275                 {
276                         string result = null;
277                         GetAndRemoveStringAttribute (null, "attrib", true, ref result);
278                 }
279
280                 [Test]
281                 public void GetAndRemoveStringAttribute_NullAttrib () 
282                 {
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);
290                 }
291
292                 [Test]
293                 public void ThrowIfElement_NoElement () 
294                 {
295                         string xml = "<element><!-- comment --></element>";
296                         XmlDocument doc = new XmlDocument ();
297                         doc.LoadXml (xml);
298                         ThrowIfElement (doc.DocumentElement.ChildNodes [0]);
299                 }
300
301                 [Test]
302                 [ExpectedException (typeof (ArgumentNullException))]
303                 public void ThrowIfElement_Null () 
304                 {
305                         ThrowIfElement (null);
306                 }
307
308                 [Test]
309                 [ExpectedException (typeof (ConfigurationException))]
310                 public void ThrowIfElement_Element () 
311                 {
312                         string xml = "<element/>";
313                         XmlDocument doc = new XmlDocument ();
314                         doc.LoadXml (xml);
315                         ThrowIfElement (doc.DocumentElement);
316                 }
317
318                 [Test]
319                 public void ThrowIfNotComment_NoComment () 
320                 {
321                         string xml = "<element><!-- comment --></element>";
322                         XmlDocument doc = new XmlDocument ();
323                         doc.LoadXml (xml);
324                         ThrowIfNotComment (doc.DocumentElement.ChildNodes [0]);
325                 }
326
327                 [Test]
328                 [ExpectedException (typeof (ArgumentNullException))]
329                 public void ThrowIfNotComment_Null () 
330                 {
331                         ThrowIfNotComment (null);
332                 }
333
334                 [Test]
335                 [ExpectedException (typeof (ConfigurationException))]
336                 public void ThrowIfNotComment_Element () 
337                 {
338                         string xml = "<element/>";
339                         XmlDocument doc = new XmlDocument ();
340                         doc.LoadXml (xml);
341                         ThrowIfNotComment (doc.DocumentElement);
342                 }
343         }
344 }