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