merge -r 53370:58178
[mono.git] / mcs / class / System.Configuration / Test / System.Configuration / ConfigurationLockCollectionTest.cs
1 //
2 // System.Configuration.ConfigurationLockCollectionTest.cs - Unit
3 // tests for System.Configuration.ConfigurationLockCollection.
4 //
5 // Author:
6 //      Chris Toshok  <toshok@ximian.com>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 #if NET_2_0
31
32 using System;
33 using System.Configuration;
34 using System.Collections;
35 using NUnit.Framework;
36 using SysConfig = System.Configuration.Configuration;
37
38 namespace MonoTests.System.Configuration {
39         [TestFixture]
40         public class ConfigurationLockCollectionTest
41         {
42
43                 [Test]
44                 public void InitialState ()
45                 {
46                         SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
47                         ConfigurationLockCollection col;
48
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");
56
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");
63
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");
70
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");
77                 }
78
79                 [Test]
80                 [ExpectedException (typeof (ConfigurationErrorsException))]
81                 public void NonExistantItem ()
82                 {
83                         SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
84                         ConfigurationLockCollection col;
85
86                         col = cfg.AppSettings.LockAttributes;
87
88                         Assert.IsFalse (col.IsReadOnly ("file"), "A3");
89                 }
90
91                 [Test]
92                 public void Populate ()
93                 {
94                         SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
95                         ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
96
97                         col.Add ("file");
98
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");
103                 }
104
105                 [Test]
106                 [ExpectedException (typeof (ConfigurationErrorsException))]
107                 public void Populate_Error ()
108                 {
109                         SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
110                         ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
111
112                         col.Add ("boo");
113                 }
114
115                 [Test]
116                 public void Enumerator ()
117                 {
118                         SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
119                         ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
120
121                         col.Add ("file");
122
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");
127                 }
128
129                 [Test]
130                 public void SetFromList ()
131                 {
132                         SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
133                         ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
134
135                         col.SetFromList ("file");
136                         Assert.AreEqual (1, col.Count, "A1");
137                         Assert.IsTrue (col.Contains ("file"), "A2");
138
139                         col.Clear ();
140                         Assert.AreEqual (0, col.Count, "A5");
141
142                         col.SetFromList (" file ");
143                         Assert.AreEqual (1, col.Count, "A1");
144                         Assert.IsTrue (col.Contains ("file"), "A2");
145
146                 }
147         }
148 }
149
150 #endif