Merge pull request #1870 from saper/langinfo_h
[mono.git] / mcs / class / System / Test / System.Configuration / SettingsPropertyCollectionTest.cs
1 //
2 // System.Configuration.SettingsPropertyCollectionTest.cs - Unit tests
3 // for System.Configuration.SettingsPropertyCollection.
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
31 using System;
32 using System.Text;
33 using System.Configuration;
34 using System.Collections.Specialized;
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Configuration {
38
39         [TestFixture]
40         public class SettingsPropertyCollectionTest {
41
42                 [Test]
43                 public void Add ()
44                 {
45                         SettingsPropertyCollection col = new SettingsPropertyCollection ();
46                         SettingsProperty test_prop = new SettingsProperty ("test_prop");
47
48                         Assert.AreEqual (0, col.Count, "A1");
49
50                         col.Add (test_prop);
51
52                         Assert.AreEqual (1, col.Count, "A2");
53                 }
54
55                 [Test]
56                 [ExpectedException (typeof (ArgumentException))]
57                 public void AddDuplicate ()
58                 {
59                         SettingsPropertyCollection col = new SettingsPropertyCollection ();
60                         SettingsProperty test_prop = new SettingsProperty ("test_prop");
61
62                         col.Add (test_prop);
63
64                         Assert.AreEqual (1, col.Count, "A1");
65
66                         test_prop = new SettingsProperty ("test_prop");
67
68                         col.Add (test_prop);
69
70                         Assert.AreEqual (1, col.Count, "A2");
71                 }
72
73                 [Test]
74                 public void Remove ()
75                 {
76                         SettingsPropertyCollection col = new SettingsPropertyCollection ();
77                         SettingsProperty test_prop = new SettingsProperty ("test_prop");
78
79                         col.Add (test_prop);
80
81                         Assert.AreEqual (1, col.Count, "A1");
82
83                         col.Remove ("test_prop");
84
85                         Assert.AreEqual (0, col.Count, "A2");
86                 }
87
88                 [Test]
89                 public void Remove_NonExistant ()
90                 {
91                         SettingsPropertyCollection col = new SettingsPropertyCollection ();
92                         SettingsProperty test_prop = new SettingsProperty ("test_prop");
93
94                         col.Add (test_prop);
95
96                         Assert.AreEqual (1, col.Count, "A1");
97
98                         col.Remove ("test_prop2");
99
100                         Assert.AreEqual (1, col.Count, "A2");
101                 }
102
103                 [Test]
104                 public void Clear ()
105                 {
106                         SettingsPropertyCollection col = new SettingsPropertyCollection ();
107                         SettingsProperty test_prop = new SettingsProperty ("test_prop");
108
109                         col.Add (test_prop);
110
111                         Assert.AreEqual (1, col.Count, "A1");
112
113                         col.Clear ();
114
115                         Assert.AreEqual (0, col.Count, "A2");
116                 }
117
118                 [Test]
119                 [ExpectedException (typeof (NotSupportedException))]
120                 public void ReadOnly_Add ()
121                 {
122                         SettingsPropertyCollection col = new SettingsPropertyCollection ();
123
124                         col.SetReadOnly ();
125
126                         SettingsProperty test_prop = new SettingsProperty ("test_prop");
127                         col.Add (test_prop);
128                 }
129
130                 [Test]
131                 [ExpectedException (typeof (NotSupportedException))]
132                 public void ReadOnly_Remove ()
133                 {
134                         SettingsPropertyCollection col = new SettingsPropertyCollection ();
135
136                         SettingsProperty test_prop = new SettingsProperty ("test_prop");
137                         col.Add (test_prop);
138
139                         col.SetReadOnly ();
140
141                         col.Remove ("test_prop");
142                 }
143
144                 [Test]
145                 [ExpectedException (typeof (NotSupportedException))]
146                 public void ReadOnly_Clear ()
147                 {
148                         SettingsPropertyCollection col = new SettingsPropertyCollection ();
149
150                         SettingsProperty test_prop = new SettingsProperty ("test_prop");
151                         col.Add (test_prop);
152
153                         col.SetReadOnly ();
154
155                         col.Clear ();
156                 }
157         }
158
159 }
160