[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Configuration / Test / System.Configuration.Provider / ProviderCollectionTest.cs
1 //
2 // System.Configuration.ProviderCollectionTest.cs - Unit tests for
3 // System.Configuration.ProviderCollection.
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.Configuration.Provider;
35 using System.Collections.Specialized;
36 using NUnit.Framework;
37
38 namespace MonoTests.System.Configuration {
39
40         class TestProvider : SettingsProvider {
41                 public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context,
42                                                                                    SettingsPropertyCollection collection)
43                 {
44                         throw new NotImplementedException ();
45                 }
46
47                 public override void SetPropertyValues (SettingsContext context,
48                                                         SettingsPropertyValueCollection collection)
49                 {
50                         throw new NotImplementedException ();
51                 }
52
53                 public override string ApplicationName {
54                         get {
55                                 throw new NotImplementedException ();
56                         }
57                         set {
58                                 throw new NotImplementedException ();
59                         }
60                 }
61         }
62
63         class TestProviderBase : ProviderBase {
64         }
65
66         [TestFixture]
67         public class ProviderCollectionTest {
68
69                 [Test]
70                 [ExpectedException (typeof (ArgumentException))]
71                 public void Add_duplicate ()
72                 {
73                         ProviderCollection col = new ProviderCollection();
74                         TestProvider provider;
75
76                         provider = new TestProvider();
77                         provider.Initialize ("test", null);
78
79
80                         col.Add (provider);
81                         col.Add (provider);
82                 }
83
84                 [Test]
85                 public void Add_providerbase ()
86                 {
87                         ProviderCollection col = new ProviderCollection();
88                         TestProviderBase provider;
89
90                         provider = new TestProviderBase();
91                         provider.Initialize ("test", null);
92
93                         col.Add (provider);
94
95                         Assert.AreEqual (provider, col["test"], "A1");
96                 }
97
98                 [Test]
99                 public void Get_nonexistant ()
100                 {
101                         ProviderCollection col = new ProviderCollection();
102                         TestProvider provider;
103
104                         provider = new TestProvider();
105                         provider.Initialize ("test", null);
106
107
108                         col.Add (provider);
109
110                         Assert.AreEqual (provider, col["test"], "A1");
111                         Assert.IsNull (col["test2"], "A2");
112                 }
113
114                 [Test]
115                 public void Ctor_2 ()
116                 {
117                         SettingsProperty q = new SettingsProperty ("property",
118                                                                    typeof (int),
119                                                                    null,
120                                                                    true,
121                                                                    10,
122                                                                    SettingsSerializeAs.Binary,
123                                                                    new SettingsAttributeDictionary(),
124                                                                    true,
125                                                                    false);
126
127                         SettingsProperty p = new SettingsProperty (q);
128
129                         Assert.AreEqual ("property", p.Name, "A1");
130                         Assert.AreEqual (typeof (int), p.PropertyType, "A2");
131                         Assert.AreEqual (null, p.Provider, "A3");
132                         Assert.AreEqual (10, (int)p.DefaultValue, "A4");
133                         Assert.AreEqual (SettingsSerializeAs.Binary, p.SerializeAs, "A5");
134                         Assert.IsNotNull (p.Attributes, "A6");
135                         Assert.IsTrue (p.ThrowOnErrorDeserializing, "A7");
136                         Assert.IsFalse (p.ThrowOnErrorSerializing, "A8");
137                         Assert.IsTrue (p.IsReadOnly, "A9");
138                 }
139
140                 [Test]
141                 [ExpectedException (typeof (ArgumentNullException))]
142                 public void Ctor_2_ArgNull ()
143                 {
144                         /* same as above, but a null
145                          * SettingsAttributeDictionary, which causes a
146                          * ANE in the ctor. */
147                         SettingsProperty q = new SettingsProperty ("property",
148                                                                    typeof (int),
149                                                                    null,
150                                                                    true,
151                                                                    10,
152                                                                    SettingsSerializeAs.Binary,
153                                                                    null,
154                                                                    true,
155                                                                    false);
156
157                         SettingsProperty p = new SettingsProperty (q);
158                 }
159
160                 [Test]
161                 public void Ctor_3 ()
162                 {
163                         SettingsProperty p = new SettingsProperty ("property");
164
165                         Assert.AreEqual ("property", p.Name, "A1");
166                         Assert.AreEqual (null, p.PropertyType, "A2");
167                         Assert.AreEqual (null, p.Provider, "A3");
168                         Assert.AreEqual (null, p.DefaultValue, "A4");
169                         Assert.AreEqual (SettingsSerializeAs.String, p.SerializeAs, "A5");
170                         Assert.IsNotNull (p.Attributes, "A6");
171                         Assert.IsFalse (p.ThrowOnErrorDeserializing, "A7");
172                         Assert.IsFalse (p.ThrowOnErrorSerializing, "A8");
173                         Assert.IsFalse (p.IsReadOnly, "A9");
174                 }
175
176         }
177
178 }
179