2 // System.Configuration.ProviderCollectionTest.cs - Unit tests for
3 // System.Configuration.ProviderCollection.
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.Configuration.Provider;
35 using System.Collections.Specialized;
36 using NUnit.Framework;
38 namespace MonoTests.System.Configuration {
40 class TestProvider : SettingsProvider {
41 public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context,
42 SettingsPropertyCollection collection)
44 throw new NotImplementedException ();
47 public override void SetPropertyValues (SettingsContext context,
48 SettingsPropertyValueCollection collection)
50 throw new NotImplementedException ();
53 public override string ApplicationName {
55 throw new NotImplementedException ();
58 throw new NotImplementedException ();
63 class TestProviderBase : ProviderBase {
67 public class ProviderCollectionTest {
70 [ExpectedException (typeof (ArgumentException))]
71 public void Add_duplicate ()
73 ProviderCollection col = new ProviderCollection();
74 TestProvider provider;
76 provider = new TestProvider();
77 provider.Initialize ("test", null);
85 public void Add_providerbase ()
87 ProviderCollection col = new ProviderCollection();
88 TestProviderBase provider;
90 provider = new TestProviderBase();
91 provider.Initialize ("test", null);
95 Assert.AreEqual (provider, col["test"], "A1");
99 public void Get_nonexistant ()
101 ProviderCollection col = new ProviderCollection();
102 TestProvider provider;
104 provider = new TestProvider();
105 provider.Initialize ("test", null);
110 Assert.AreEqual (provider, col["test"], "A1");
111 Assert.IsNull (col["test2"], "A2");
115 public void Ctor_2 ()
117 SettingsProperty q = new SettingsProperty ("property",
122 SettingsSerializeAs.Binary,
123 new SettingsAttributeDictionary(),
127 SettingsProperty p = new SettingsProperty (q);
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");
141 [ExpectedException (typeof (ArgumentNullException))]
142 public void Ctor_2_ArgNull ()
144 /* same as above, but a null
145 * SettingsAttributeDictionary, which causes a
146 * ANE in the ctor. */
147 SettingsProperty q = new SettingsProperty ("property",
152 SettingsSerializeAs.Binary,
157 SettingsProperty p = new SettingsProperty (q);
161 public void Ctor_3 ()
163 SettingsProperty p = new SettingsProperty ("property");
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");