Added tests for Task.WhenAll w/ empty list
[mono.git] / mcs / class / System.Configuration / Test / System.Configuration / ConfigurationManagerTest.cs
1 //
2 // System.Configuration.ConfigurationManagerTest.cs - Unit tests
3 // for System.Configuration.ConfigurationManager.
4 //
5 // Author:
6 //      Chris Toshok  <toshok@ximian.com>
7 //      Atsushi Enomoto  <atsushi@ximian.com>
8 //
9 // Copyright (C) 2005-2006 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.Collections;
33 using System.Collections.Specialized;
34 using System.Configuration;
35 using System.Net.Configuration;
36 using System.IO;
37 using NUnit.Framework;
38 using SysConfig = System.Configuration.Configuration;
39 using System.Runtime.InteropServices;
40
41 namespace MonoTests.System.Configuration {
42         using Util;
43
44         [TestFixture]
45         public class ConfigurationManagerTest
46         {
47                 private string originalCurrentDir;
48                 private string tempFolder;
49
50                 [SetUp]
51                 public void SetUp ()
52                 {
53                         originalCurrentDir = Directory.GetCurrentDirectory ();
54                         tempFolder = Path.Combine (Path.GetTempPath (), this.GetType ().FullName);
55                         if (!Directory.Exists (tempFolder))
56                                 Directory.CreateDirectory (tempFolder);
57                 }
58
59                 [TearDown]
60                 public void TearDown ()
61                 {
62                         Directory.SetCurrentDirectory (originalCurrentDir);
63                         if (Directory.Exists (tempFolder))
64                                 Directory.Delete (tempFolder, true);
65                 }
66                 
67                 [Test] // OpenExeConfiguration (ConfigurationUserLevel)
68                 [Category ("NotWorking")] // bug #323622
69                 public void OpenExeConfiguration1_Remote ()
70                 {
71                         AppDomain domain = null;
72                         string config_file;
73                         string config_xml = @"
74                                 <configuration>
75                                         <appSettings>
76                                                 <add key='anyKey' value='42' />
77                                         </appSettings>
78                                 </configuration>";
79
80                         config_file = Path.Combine (tempFolder, "otherConfig.noconfigext");
81                         File.WriteAllText (config_file, config_xml);
82
83                         try {
84                                 AppDomainSetup setup = new AppDomainSetup();
85                                 setup.ConfigurationFile = config_file;
86                                 setup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
87                                 domain = AppDomain.CreateDomain("foo", null, setup);
88
89                                 RemoteConfig config = RemoteConfig.GetInstance (domain);
90
91                                 ConfigurationUserLevel userLevel = ConfigurationUserLevel.None;
92                                 Assert.AreEqual (config_file, config.GetFilePath (userLevel));
93                                 Assert.AreEqual ("42", config.GetSettingValue (userLevel, "anyKey"));
94                                 Assert.AreEqual ("42", config.GetSettingValue ("anyKey"));
95                         } finally {
96                                 if (domain != null)
97                                         AppDomain.Unload (domain);
98                                 File.Delete (config_file);
99                         }
100
101                         config_file = Path.Combine (tempFolder, "otherConfig.exe.config");
102                         File.WriteAllText (config_file, config_xml);
103
104                         try {
105                                 AppDomainSetup setup = new AppDomainSetup();
106                                 setup.ConfigurationFile = config_file;
107                                 setup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
108                                 domain = AppDomain.CreateDomain("foo", null, setup);
109
110                                 RemoteConfig config = RemoteConfig.GetInstance (domain);
111
112                                 ConfigurationUserLevel userLevel = ConfigurationUserLevel.None;
113                                 Assert.AreEqual (config_file, config.GetFilePath (userLevel));
114                                 Assert.AreEqual ("42", config.GetSettingValue (userLevel, "anyKey"));
115                                 Assert.AreEqual ("42", config.GetSettingValue ("anyKey"));
116                         } finally {
117                                 if (domain != null)
118                                         AppDomain.Unload (domain);
119                                 File.Delete (config_file);
120                         }
121
122                         try {
123                                 AppDomainSetup setup = new AppDomainSetup();
124                                 setup.ConfigurationFile = config_file;
125                                 setup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
126                                 domain = AppDomain.CreateDomain("foo", null, setup);
127
128                                 RemoteConfig config = RemoteConfig.GetInstance (domain);
129
130                                 ConfigurationUserLevel userLevel = ConfigurationUserLevel.None;
131                                 Assert.AreEqual (config_file, config.GetFilePath (userLevel));
132                                 Assert.IsNull (config.GetSettingValue (userLevel, "anyKey"));
133                                 Assert.IsNull (config.GetSettingValue ("anyKey"));
134                         } finally {
135                                 if (domain != null)
136                                         AppDomain.Unload (domain);
137                                 File.Delete (config_file);
138                         }
139                 }
140
141                 [Test] // OpenExeConfiguration (ConfigurationUserLevel)
142                 public void OpenExeConfiguration1_UserLevel_None ()
143                 {
144                         SysConfig config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
145
146                         Console.WriteLine("application config path: {0}", config.FilePath);
147                         FileInfo fi = new FileInfo (config.FilePath);
148                         Assert.AreEqual (TestUtil.ThisConfigFileName, fi.Name);
149                 }
150
151                 [Test]
152                 public void OpenExeConfiguration1_UserLevel_PerUserRoaming ()
153                 {
154                         SysConfig config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming);
155                         Console.WriteLine("roaming user config path: {0}", config.FilePath);
156
157                         FileInfo fi = new FileInfo (config.FilePath);
158                         Assert.AreEqual ("user.config", fi.Name);
159                 }
160
161                 [Test]
162                 public void OpenExeConfiguration1_UserLevel_PerUserRoamingAndLocal ()
163                 {
164                         SysConfig config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
165                         Console.WriteLine("local user config path: {0}", config.FilePath);
166
167                         FileInfo fi = new FileInfo (config.FilePath);
168                         Assert.AreEqual ("user.config", fi.Name);
169                 }
170
171                 [Test] // OpenExeConfiguration (String)
172                 public void OpenExeConfiguration2 ()
173                 {
174                         String exePath;
175                         SysConfig config;
176
177                         exePath = Path.Combine (tempFolder, "DoesNotExist.whatever");
178                         File.Create (exePath).Close ();
179
180                         config = ConfigurationManager.OpenExeConfiguration (exePath);
181                         Assert.AreEqual (exePath + ".config", config.FilePath, "#1");
182
183                         exePath = Path.Combine (tempFolder, "SomeExecutable.exe");
184                         File.Create (exePath).Close ();
185
186                         config = ConfigurationManager.OpenExeConfiguration (exePath);
187                         Assert.AreEqual (exePath + ".config", config.FilePath, "#2");
188
189                         exePath = Path.Combine (tempFolder, "Foo.exe.config");
190                         File.Create (exePath).Close ();
191
192                         config = ConfigurationManager.OpenExeConfiguration (exePath);
193                         Assert.AreEqual (exePath + ".config", config.FilePath, "#3");
194
195                         Directory.SetCurrentDirectory (tempFolder);
196
197                         exePath = "relative.exe";
198                         File.Create (Path.Combine (tempFolder, exePath)).Close ();
199
200                         //
201                         // The temp directory as computed by the runtime is slightly different, as
202                         // it will contain the full path after following links, while the test
203                         // below is not comprehensive enough to follow links if there are any
204                         // present in tempFolder
205                         //
206                         
207                         //config = ConfigurationManager.OpenExeConfiguration (exePath);
208                         //Assert.AreEqual (Path.Combine (tempFolder, exePath + ".config"), config.FilePath, "#4");
209                 }
210
211                 [Test] // OpenExeConfiguration (String)
212                 public void OpenExeConfiguration2_ExePath_Empty ()
213                 {
214                         AppDomain domain = AppDomain.CurrentDomain;
215
216                         SysConfig config = ConfigurationManager.OpenExeConfiguration (string.Empty);
217                         Assert.AreEqual (domain.SetupInformation.ConfigurationFile, config.FilePath);
218                 }
219
220                 [Test] // OpenExeConfiguration (String)
221                 public void OpenExeConfiguration2_ExePath_Null ()
222                 {
223                         AppDomain domain = AppDomain.CurrentDomain;
224
225                         SysConfig config = ConfigurationManager.OpenExeConfiguration (string.Empty);
226                         Assert.AreEqual (domain.SetupInformation.ConfigurationFile, config.FilePath);
227                 }
228
229                 [Test] // OpenExeConfiguration (String)
230                 public void OpenExeConfiguration2_ExePath_DoesNotExist ()
231                 {
232                         String exePath = Path.Combine (tempFolder, "DoesNotExist.exe");
233
234                         try {
235                                 ConfigurationManager.OpenExeConfiguration (exePath);
236                                 Assert.Fail ("#1");
237                         } catch (ConfigurationErrorsException ex) {
238                                 // An error occurred loading a configuration file:
239                                 // The parameter 'exePath' is invalid
240                                 Assert.AreEqual (typeof (ConfigurationErrorsException), ex.GetType (), "#2");
241                                 Assert.IsNull (ex.Filename, "#3");
242                                 Assert.IsNotNull (ex.InnerException, "#4");
243                                 Assert.AreEqual (0, ex.Line, "#5");
244                                 Assert.IsNotNull (ex.Message, "#6");
245
246                                 // The parameter 'exePath' is invalid
247                                 ArgumentException inner = ex.InnerException as ArgumentException;
248                                 Assert.IsNotNull (inner, "#7");
249                                 Assert.AreEqual (typeof (ArgumentException), inner.GetType (), "#8");
250                                 Assert.IsNull (inner.InnerException, "#9");
251                                 Assert.IsNotNull (inner.Message, "#10");
252                                 Assert.AreEqual ("exePath", inner.ParamName, "#11");
253                         }
254                 }
255
256                 [Test]
257                 public void exePath_UserLevelNone ()
258                 {
259                         string basedir = AppDomain.CurrentDomain.BaseDirectory;
260                         string name = TestUtil.ThisDllName;
261                         SysConfig config = ConfigurationManager.OpenExeConfiguration (name);
262                         Assert.AreEqual (Path.Combine (basedir, name + ".config"), config.FilePath);
263                 }
264
265                 [Test]
266                 public void exePath_UserLevelPerRoaming ()
267                 {
268                         SysConfig config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming);
269                         string filePath = config.FilePath;
270                         string applicationData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
271                         Assert.IsTrue (filePath.StartsWith (applicationData), "#1:" + filePath);
272                         Assert.AreEqual ("user.config", Path.GetFileName (filePath), "#2:" + filePath);
273                 }
274
275                 [Test]
276                 public void exePath_UserLevelPerRoamingAndLocal ()
277                 {
278                         SysConfig config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
279                         string filePath = config.FilePath;
280                         string applicationData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
281                         Assert.IsTrue (filePath.StartsWith (applicationData), "#1:" + filePath);
282                         Assert.AreEqual ("user.config", Path.GetFileName (filePath), "#2:" + filePath);
283                 }
284
285                 [Test]
286                 public void mapped_UserLevelNone ()
287                 {
288                         ExeConfigurationFileMap map = new ExeConfigurationFileMap ();
289                         map.ExeConfigFilename = "execonfig";
290
291                         SysConfig config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
292                         Console.WriteLine("mapped application config path: {0}", config.FilePath);      
293
294                         FileInfo fi = new FileInfo (config.FilePath);
295                         Assert.AreEqual ("execonfig", fi.Name);
296
297                 }
298
299                 [Test]
300                 public void mapped_UserLevelPerRoaming ()
301                 {
302                         ExeConfigurationFileMap map = new ExeConfigurationFileMap ();
303                         map.ExeConfigFilename = "execonfig";
304                         map.RoamingUserConfigFilename = "roaminguser";
305
306                         SysConfig config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.PerUserRoaming);
307                         Console.WriteLine("mapped roaming user config path: {0}", config.FilePath);     
308
309                         FileInfo fi = new FileInfo (config.FilePath);
310                         Assert.AreEqual ("roaminguser", fi.Name);
311                 }
312
313                 [Test]
314                 [ExpectedException (typeof (ArgumentException))]
315                 [Category ("NotWorking")]
316                 public void mapped_UserLevelPerRoaming_no_execonfig ()
317                 {
318                         ExeConfigurationFileMap map = new ExeConfigurationFileMap ();
319                         map.RoamingUserConfigFilename = "roaminguser";
320
321                         ConfigurationManager.OpenMappedExeConfiguration (map, ConfigurationUserLevel.PerUserRoaming);
322                 }
323
324                 [Test]
325                 public void mapped_UserLevelPerRoamingAndLocal ()
326                 {
327                         ExeConfigurationFileMap map = new ExeConfigurationFileMap ();
328                         map.ExeConfigFilename = "execonfig";
329                         map.RoamingUserConfigFilename = "roaminguser";
330                         map.LocalUserConfigFilename = "localuser";
331
332                         SysConfig config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.PerUserRoamingAndLocal);
333                         Console.WriteLine("mapped local user config path: {0}", config.FilePath);       
334
335                         FileInfo fi = new FileInfo (config.FilePath);
336                         Assert.AreEqual ("localuser", fi.Name);
337                 }
338
339                 [Test]
340                 [ExpectedException (typeof (ArgumentException))]
341                 [Category ("NotWorking")]
342                 public void mapped_UserLevelPerRoamingAndLocal_no_execonfig ()
343                 {
344                         ExeConfigurationFileMap map = new ExeConfigurationFileMap ();
345                         map.RoamingUserConfigFilename = "roaminguser";
346                         map.LocalUserConfigFilename = "localuser";
347
348                         ConfigurationManager.OpenMappedExeConfiguration (map, ConfigurationUserLevel.PerUserRoamingAndLocal);
349                 }
350
351                 [Test]
352                 [ExpectedException (typeof (ArgumentException))]
353                 [Category ("NotWorking")]
354                 public void mapped_UserLevelPerRoamingAndLocal_no_roaminguser ()
355                 {
356                         ExeConfigurationFileMap map = new ExeConfigurationFileMap ();
357                         map.ExeConfigFilename = "execonfig";
358                         map.LocalUserConfigFilename = "localuser";
359
360                         ConfigurationManager.OpenMappedExeConfiguration (map, ConfigurationUserLevel.PerUserRoamingAndLocal);
361                 }
362
363                 [Test]
364                 public void MachineConfig ()
365                 {
366                         SysConfig config = ConfigurationManager.OpenMachineConfiguration ();
367                         Console.WriteLine("machine config path: {0}", config.FilePath);
368
369                         FileInfo fi = new FileInfo (config.FilePath);
370                         Assert.AreEqual ("machine.config", fi.Name);
371                 }
372
373                 [Test]
374                 public void mapped_MachineConfig ()
375                 {
376                         ConfigurationFileMap map = new ConfigurationFileMap ();
377                         map.MachineConfigFilename = "machineconfig";
378
379                         SysConfig config = ConfigurationManager.OpenMappedMachineConfiguration (map);
380                         Console.WriteLine("mapped machine config path: {0}", config.FilePath);
381
382                         FileInfo fi = new FileInfo (config.FilePath);
383                         Assert.AreEqual ("machineconfig", fi.Name);
384                 }
385
386                 [Test]
387                 public void exePath_UserLevelNone_null ()
388                 {
389 #if false
390                         SysConfig config = ConfigurationManager.OpenExeConfiguration (null);
391                         Console.WriteLine("null exe application config path: {0}", config.FilePath);    
392
393                         FileInfo fi = new FileInfo (config.FilePath);
394                         Assert.AreEqual (TestUtil.ThisConfigFileName, fi.Name);
395 #endif
396                 }
397
398                 [Test]
399                 [Category ("NotWorking")]
400                 public void mapped_ExeConfiguration_null ()
401                 {
402                         SysConfig config = ConfigurationManager.OpenMappedExeConfiguration(null, ConfigurationUserLevel.None);
403                         Console.WriteLine("null mapped application config path: {0}", config.FilePath);
404
405                         FileInfo fi = new FileInfo (config.FilePath);
406                         Assert.AreEqual (TestUtil.ThisConfigFileName, fi.Name);
407                 }
408
409                 [Test]
410                 [Category ("NotWorking")]
411                 public void mapped_MachineConfig_null ()
412                 {
413                         SysConfig config = ConfigurationManager.OpenMappedMachineConfiguration (null);
414                         Console.WriteLine("null mapped machine config path: {0}", config.FilePath);
415
416                         FileInfo fi = new FileInfo (config.FilePath);
417                         Assert.AreEqual ("machine.config", fi.Name);
418                 }
419
420                 [Test]
421                 public void GetSectionReturnsNativeObject ()
422                 {
423                         Assert.IsTrue (ConfigurationManager.GetSection ("appSettings") is NameValueCollection);
424                 }
425
426                 [Test] // test for bug #78372.
427                 public void OpenMachineConfiguration ()
428                 {
429                         SysConfig cfg = ConfigurationManager.OpenMachineConfiguration ();
430                         Assert.IsTrue (cfg.Sections.Count > 0, "#1");
431 #if !TARGET_JVM
432                         ConfigurationSection s = cfg.SectionGroups ["system.net"].Sections ["connectionManagement"];
433                         Assert.IsNotNull (s, "#2");
434                         Assert.IsTrue (s is ConnectionManagementSection, "#3");
435 #endif
436                 }
437
438                 [Test]
439                 public void SectionCollectionEnumerator ()
440                 {
441                         SysConfig c = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
442                         ConfigurationSectionCollection col =
443                                 c.GetSectionGroup ("system.web").Sections;
444                         IEnumerator e = col.GetEnumerator ();
445                         e.MoveNext ();
446                         Assert.IsTrue (e.Current is ConfigurationSection);
447                 }
448
449                 [Test]  // Test for bug #3412
450                 [Category("NotWorking")]
451                 public void TestAddRemoveSection()
452                 {
453                         const string name = "testsection";
454                         var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
455
456                         // ensure not present
457                         if (config.Sections.Get(name) != null)
458                         {
459                                 config.Sections.Remove(name);
460                         }
461
462                         // add
463                         config.Sections.Add(name, new TestSection());
464
465                         // remove
466                         var section = config.Sections.Get(name);
467                         Assert.IsNotNull(section);
468                         Assert.IsNotNull(section as TestSection);
469                         config.Sections.Remove(name);
470
471                         // add
472                         config.Sections.Add(name, new TestSection());
473
474                         // remove
475                         section = config.Sections.Get(name);
476                         Assert.IsNotNull(section);
477                         Assert.IsNotNull(section as TestSection);
478                         config.Sections.Remove(name);
479                 }
480                 
481                 [Test]
482                 public void TestFileMap ()
483                 {
484                         var name = Path.GetRandomFileName () + ".config";
485                         Assert.IsFalse (File.Exists (name));
486
487                         try {
488                                 var map = new ExeConfigurationFileMap ();
489                                 map.ExeConfigFilename = name;
490                         
491                                 var config = ConfigurationManager.OpenMappedExeConfiguration (
492                                         map, ConfigurationUserLevel.None);
493                                 
494                                 config.Sections.Add ("testsection", new TestSection ());
495                         
496                                 config.Save ();
497                         
498                                 Assert.IsTrue (File.Exists (name), "#1");
499                                 Assert.IsTrue (File.Exists (Path.GetFullPath (name)), "#2");
500                         } finally {
501                                 File.Delete (name);
502                         }
503                 }
504                 
505                 [Test]
506                 public void TestContext ()
507                 {
508                         var config = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
509                         const string name = "testsection";
510
511                         // ensure not present
512                         if (config.GetSection (name) != null)
513                                 config.Sections.Remove (name);
514
515                         var section = new TestContextSection ();
516
517                         // Can't access EvaluationContext ....
518                         try {
519                                 section.TestContext (null);
520                                 Assert.Fail ("#1");
521                         } catch (ConfigurationException) {
522                                 ;
523                         }
524
525                         // ... until it's been added to a section.
526                         config.Sections.Add (name, section);
527                         section.TestContext ("#2");
528
529                         // Remove ...
530                         config.Sections.Remove (name);
531
532                         // ... and it doesn't lose its context
533                         section.TestContext (null);
534                 }
535
536                 [Test]
537                 public void TestContext2 ()
538                 {
539                         var name = Path.GetRandomFileName () + ".config";
540                         Assert.IsFalse (File.Exists (name));
541                         
542                         try {
543                                 var map = new ExeConfigurationFileMap ();
544                                 map.ExeConfigFilename = name;
545                                 
546                                 var config = ConfigurationManager.OpenMappedExeConfiguration (
547                                         map, ConfigurationUserLevel.None);
548                                 
549                                 config.Sections.Add ("testsection", new TestSection ());
550                                 config.Sections.Add ("testcontext", new TestContextSection ());
551                                 
552                                 config.Save ();
553                                 
554                                 Assert.IsTrue (File.Exists (name), "#1");
555                         } finally {
556                                 File.Delete (name);
557                         }
558                 }
559
560                         
561                 class TestSection : ConfigurationSection  {}
562
563                 class RemoteConfig : MarshalByRefObject
564                 {
565                         public static RemoteConfig GetInstance (AppDomain domain)
566                         {
567                                 RemoteConfig config = (RemoteConfig) domain.CreateInstanceAndUnwrap (
568                                         typeof (RemoteConfig).Assembly.FullName,
569                                         typeof (RemoteConfig).FullName, new object [0]);
570                                 return config;
571                         }
572
573                         public string GetFilePath (string exePath)
574                         {
575                                 global::System.Configuration.Configuration config =
576                                         ConfigurationManager.OpenExeConfiguration (exePath);
577                                 return config.FilePath;
578                         }
579
580                         public string GetFilePath (ConfigurationUserLevel userLevel)
581                         {
582                                 global::System.Configuration.Configuration config =
583                                         ConfigurationManager.OpenExeConfiguration (userLevel);
584                                 return config.FilePath;
585                         }
586
587                         public string GetSettingValue (string exePath, string key)
588                         {
589                                 global::System.Configuration.Configuration config =
590                                         ConfigurationManager.OpenExeConfiguration (exePath);
591                                 return config.AppSettings.Settings [key].Value;
592                         }
593
594                         public string GetSettingValue (ConfigurationUserLevel userLevel, string key)
595                         {
596                                 global::System.Configuration.Configuration config =
597                                         ConfigurationManager.OpenExeConfiguration (userLevel);
598                                 KeyValueConfigurationElement value = config.AppSettings.Settings [key];
599                                 return value != null ? value.Value : null;
600                         }
601
602                         public string GetSettingValue (string key)
603                         {
604                                 return ConfigurationManager.AppSettings [key];
605                         }
606                 }
607                 
608                 class TestContextSection : ConfigurationSection {
609                         public void TestContext (string label)
610                         {
611                                 Assert.That (EvaluationContext != null, label);
612                         }
613                 }
614         }
615 }