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.
34 using System.Configuration;
35 using System.Configuration.Provider;
36 using System.Collections.Specialized;
37 using NUnit.Framework;
39 namespace MonoTests.System.Configuration {
41 class TestProvider : SettingsProvider {
42 public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context,
43 SettingsPropertyCollection collection)
45 throw new NotImplementedException ();
48 public override void SetPropertyValues (SettingsContext context,
49 SettingsPropertyValueCollection collection)
51 throw new NotImplementedException ();
54 public override string ApplicationName {
56 throw new NotImplementedException ();
59 throw new NotImplementedException ();
64 class TestProviderBase : ProviderBase {
68 public class ProviderCollectionTest {
71 [ExpectedException (typeof (ArgumentException))]
72 public void Add_duplicate ()
74 ProviderCollection col = new ProviderCollection();
75 TestProvider provider;
77 provider = new TestProvider();
78 provider.Initialize ("test", null);
86 public void Add_providerbase ()
88 ProviderCollection col = new ProviderCollection();
89 TestProviderBase provider;
91 provider = new TestProviderBase();
92 provider.Initialize ("test", null);
96 Assert.AreEqual (provider, col["test"], "A1");
100 public void Get_nonexistant ()
102 ProviderCollection col = new ProviderCollection();
103 TestProvider provider;
105 provider = new TestProvider();
106 provider.Initialize ("test", null);
111 Assert.AreEqual (provider, col["test"], "A1");
112 Assert.IsNull (col["test2"], "A2");
116 public void Ctor_2 ()
118 SettingsProperty q = new SettingsProperty ("property",
123 SettingsSerializeAs.Binary,
124 new SettingsAttributeDictionary(),
128 SettingsProperty p = new SettingsProperty (q);
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");
142 [ExpectedException (typeof (ArgumentNullException))]
143 public void Ctor_2_ArgNull ()
145 /* same as above, but a null
146 * SettingsAttributeDictionary, which causes a
147 * ANE in the ctor. */
148 SettingsProperty q = new SettingsProperty ("property",
153 SettingsSerializeAs.Binary,
158 SettingsProperty p = new SettingsProperty (q);
162 public void Ctor_3 ()
164 SettingsProperty p = new SettingsProperty ("property");
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");