2 // System.Configuration.ConfigurationLockCollectionTest.cs - Unit
3 // tests for System.Configuration.ConfigurationLockCollection.
6 // Chris Toshok <toshok@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Configuration;
34 using System.Collections;
35 using NUnit.Framework;
36 using SysConfig = System.Configuration.Configuration;
38 namespace MonoTests.System.Configuration {
40 public class ConfigurationLockCollectionTest
44 public void InitialState ()
46 SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
47 ConfigurationLockCollection col;
49 col = cfg.AppSettings.LockAttributes;
50 Assert.AreEqual (0, col.Count, "A1");
51 Assert.IsFalse (col.Contains ("file"), "A2");
52 Assert.IsFalse (col.HasParentElements, "A4");
53 Assert.IsFalse (col.IsModified, "A5");
54 Assert.IsFalse (col.IsSynchronized, "A6");
55 Assert.AreEqual (col, col.SyncRoot, "A7");
57 col = cfg.AppSettings.LockElements;
58 Assert.AreEqual (0, col.Count, "A8");
59 Assert.IsFalse (col.HasParentElements, "A11");
60 Assert.IsFalse (col.IsModified, "A12");
61 Assert.IsFalse (col.IsSynchronized, "A13");
62 Assert.AreEqual (col, col.SyncRoot, "A14");
64 col = cfg.ConnectionStrings.LockAttributes;
65 Assert.AreEqual (0, col.Count, "A8");
66 Assert.IsFalse (col.HasParentElements, "A11");
67 Assert.IsFalse (col.IsModified, "A12");
68 Assert.IsFalse (col.IsSynchronized, "A13");
69 Assert.AreEqual (col, col.SyncRoot, "A14");
71 col = cfg.ConnectionStrings.LockElements;
72 Assert.AreEqual (0, col.Count, "A8");
73 Assert.IsFalse (col.HasParentElements, "A11");
74 Assert.IsFalse (col.IsModified, "A12");
75 Assert.IsFalse (col.IsSynchronized, "A13");
76 Assert.AreEqual (col, col.SyncRoot, "A14");
80 [ExpectedException (typeof (ConfigurationErrorsException))]
81 public void NonExistantItem ()
83 SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
84 ConfigurationLockCollection col;
86 col = cfg.AppSettings.LockAttributes;
88 Assert.IsFalse (col.IsReadOnly ("file"), "A3");
92 public void Populate ()
94 SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
95 ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
99 Assert.AreEqual (1, col.Count, "A1");
100 Assert.IsFalse (col.HasParentElements, "A2");
101 Assert.IsTrue (col.IsModified, "A3");
102 Assert.IsTrue (col.Contains ("file"), "A4");
106 [ExpectedException (typeof (ConfigurationErrorsException))]
107 public void Populate_Error ()
109 SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
110 ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
116 public void Enumerator ()
118 SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
119 ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
123 IEnumerator e = col.GetEnumerator ();
124 Assert.IsTrue (e.MoveNext (), "A1");
125 Assert.AreEqual ("file", (string)e.Current, "A2");
126 Assert.IsFalse (e.MoveNext (), "A3");
130 public void SetFromList ()
132 SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
133 ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
135 col.SetFromList ("file");
136 Assert.AreEqual (1, col.Count, "A1");
137 Assert.IsTrue (col.Contains ("file"), "A2");
140 Assert.AreEqual (0, col.Count, "A5");
142 col.SetFromList (" file ");
143 Assert.AreEqual (1, col.Count, "A1");
144 Assert.IsTrue (col.Contains ("file"), "A2");