* System.Configuration_test.dll.sources: added ProviderBaseTest.cs.
authorGert Driesen <drieseng@users.sourceforge.net>
Fri, 31 Aug 2007 14:15:07 +0000 (14:15 -0000)
committerGert Driesen <drieseng@users.sourceforge.net>
Fri, 31 Aug 2007 14:15:07 +0000 (14:15 -0000)
* ProviderBaseTest.cs: Added tests for Initialize.
* ProviderBase.cs: Remove "description" key from NameValueCollection.
Use provider name as description if description is null or a zero
length string. Modifies exception messages to match MS.
* GenericEnumConverterTest.cs: Remove unused variable.
* ConfigurationManagerTest.cs: Fixed line endings.
* ConnectionStringSettingsTest.cs: Fixed line endings and avoid
ToString override warning.
* KeyValueConfigurationElementTest.cs: Fixed line endings.
* KeyValueConfigurationCollectionTest.cs: Fixed line endings.

svn path=/trunk/mcs/; revision=85126

12 files changed:
mcs/class/System.Configuration/ChangeLog
mcs/class/System.Configuration/System.Configuration.Provider/ChangeLog
mcs/class/System.Configuration/System.Configuration.Provider/ProviderBase.cs
mcs/class/System.Configuration/System.Configuration_test.dll.sources
mcs/class/System.Configuration/Test/System.Configuration.Provider/ChangeLog [new file with mode: 0644]
mcs/class/System.Configuration/Test/System.Configuration.Provider/ProviderBaseTest.cs [new file with mode: 0644]
mcs/class/System.Configuration/Test/System.Configuration/ChangeLog
mcs/class/System.Configuration/Test/System.Configuration/ConfigurationManagerTest.cs
mcs/class/System.Configuration/Test/System.Configuration/ConnectionStringSettingsTest.cs
mcs/class/System.Configuration/Test/System.Configuration/GenericEnumConverterTest.cs
mcs/class/System.Configuration/Test/System.Configuration/KeyValueConfigurationCollectionTest.cs
mcs/class/System.Configuration/Test/System.Configuration/KeyValueConfigurationElementTest.cs

index 350d6d5342bd4a48effb85b9fcd5adf878a179d6..0d3e5401d3bdcce4fcc8539ff4bce0725352235d 100644 (file)
@@ -1,3 +1,7 @@
+2007-08-31  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * System.Configuration_test.dll.sources: added ProviderBaseTest.cs.
+
 2007-06-13  Atsushi Enomoto  <atsushi@ximian.com>
 
        * System.Configuration_test.dll.sources :
index eb99043cdd06464981c45c62f045a6c4c2229bd7..ba45414f293121cd4de34f587baddc3c90c47ed7 100644 (file)
@@ -1,3 +1,9 @@
+2007-08-31  Gert Driesen  <drieseng@users.souceforge.net>
+
+       * ProviderBase.cs: Remove "description" key from NameValueCollection.
+       Use provider name as description if description is null or a zero
+       length string. Modifies exception messages to match MS. 
+
 2006-12-02  Marek Habersack  <grendello@gmail.com>
 
        * ProviderBase.cs: Throw exceptions as per documentation.
index f96ba49f752fd1758c771f8cbd6e01b462da3af3..dee8456b7b948981e350c1d736373d139f5888e0 100644 (file)
@@ -47,16 +47,18 @@ namespace System.Configuration.Provider
                        if (name == null)
                                throw new ArgumentNullException ("name");
                        if (name.Length == 0)
-                               throw new ArgumentException ("name must not be empty");
+                               throw new ArgumentException ("Provider name cannot be null or empty.", "name");
                        if (alreadyInitialized)
-                               throw new InvalidOperationException ("Provider has already been initialized");
+                               throw new InvalidOperationException ("This provider instance has already been initialized.");
                        alreadyInitialized = true;
                        
                        _name = name;
 
-                       if (config != null)
-                               _description = config["description"];
-                       if (_description == null)
+                       if (config != null) {
+                               _description = config ["description"];
+                               config.Remove ("description");
+                       }
+                       if (_description == null || _description.Length == 0)
                                _description = _name;
                }
                
index dbe18918fd25fe86caf1a88fb4a84854b1677321..eb7687b057b6a5afa9a7d43a46a62713ea75e408 100644 (file)
@@ -28,3 +28,4 @@ System.Configuration/TimeSpanSecondsOrInfiniteConverterTest.cs
 System.Configuration/TimeSpanValidatorTest.cs
 System.Configuration/TypeNameConverterTest.cs
 System.Configuration/WhiteSpaceTrimStringConverterTest.cs
+System.Configuration.Provider/ProviderBaseTest.cs
diff --git a/mcs/class/System.Configuration/Test/System.Configuration.Provider/ChangeLog b/mcs/class/System.Configuration/Test/System.Configuration.Provider/ChangeLog
new file mode 100644 (file)
index 0000000..2ef1bbb
--- /dev/null
@@ -0,0 +1,3 @@
+2007-08-31  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * ProviderBaseTest.cs: Added tests for Initialize.
diff --git a/mcs/class/System.Configuration/Test/System.Configuration.Provider/ProviderBaseTest.cs b/mcs/class/System.Configuration/Test/System.Configuration.Provider/ProviderBaseTest.cs
new file mode 100644 (file)
index 0000000..ccb2e36
--- /dev/null
@@ -0,0 +1,171 @@
+//
+// System.Configuration.Provider.ProviderBaseTest.cs - Unit tests
+// for System.Configuration.Provider.ProviderBase.
+//
+// Author:
+//     Gert Driesen  <drieseng@users.sourceforge.net>
+//
+// Copyright (C) 2007 Gert Driesen
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Collections.Specialized;
+using System.Configuration;
+using System.Configuration.Provider;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Configuration.Provider
+{
+       [TestFixture]
+       public class ProviderBaseTest
+       {
+               [Test]
+               public void Initialize ()
+               {
+                       MockProvider provider = new MockProvider ();
+                       provider.Initialize ("Mono", (NameValueCollection) null);
+                       Assert.IsNotNull (provider.Description, "#A1");
+                       Assert.AreEqual ("Mono", provider.Description, "#A2");
+                       Assert.IsNotNull (provider.Name, "#A3");
+                       Assert.AreEqual ("Mono", provider.Name, "#A4");
+
+                       provider = new MockProvider ();
+                       provider.Initialize (" ", (NameValueCollection) null);
+                       Assert.IsNotNull (provider.Description, "#B1");
+                       Assert.AreEqual (" ", provider.Description, "#B2");
+                       Assert.IsNotNull (provider.Name, "#B3");
+                       Assert.AreEqual (" ", provider.Name, "#B4");
+
+                       NameValueCollection config = new NameValueCollection ();
+                       config ["name"] = "Novell";
+                       config ["description"] = "DESC";
+                       config ["foo"] = "FOO"; 
+
+                       provider = new MockProvider ();
+                       provider.Initialize ("Mono", config);
+                       Assert.IsNotNull (provider.Description, "#C1");
+                       Assert.AreEqual ("DESC", provider.Description, "#C2");
+                       Assert.IsNotNull (provider.Name, "#C3");
+                       Assert.AreEqual ("Mono", provider.Name, "#C4");
+                       Assert.IsTrue (ContainsKey (config, "name"), "#C5");
+                       Assert.IsFalse (ContainsKey (config, "description"), "#C6");
+                       Assert.IsTrue (ContainsKey (config, "foo"), "#C7");
+
+                       config = new NameValueCollection ();
+                       config ["description"] = null;
+
+                       provider = new MockProvider ();
+                       provider.Initialize ("Mono", config);
+                       Assert.IsNotNull (provider.Description, "#D1");
+                       Assert.AreEqual ("Mono", provider.Description, "#D2");
+                       Assert.IsNotNull (provider.Name, "#D3");
+                       Assert.AreEqual ("Mono", provider.Name, "#D4");
+                       Assert.IsFalse (ContainsKey (config, "description"), "#D5");
+
+                       config = new NameValueCollection ();
+                       config ["description"] = string.Empty;
+
+                       provider = new MockProvider ();
+                       provider.Initialize ("Mono", config);
+                       Assert.IsNotNull (provider.Description, "#E1");
+                       Assert.AreEqual ("Mono", provider.Description, "#E2");
+                       Assert.IsNotNull (provider.Name, "#E3");
+                       Assert.AreEqual ("Mono", provider.Name, "#E4");
+                       Assert.IsFalse (ContainsKey (config, "description"), "#E5");
+
+                       config = new NameValueCollection ();
+                       config ["description"] = " ";
+
+                       provider = new MockProvider ();
+                       provider.Initialize ("Mono", config);
+                       Assert.IsNotNull (provider.Description, "#F1");
+                       Assert.AreEqual (" ", provider.Description, "#F2");
+                       Assert.IsNotNull (provider.Name, "#F3");
+                       Assert.AreEqual ("Mono", provider.Name, "#F4");
+                       Assert.IsFalse (ContainsKey (config, "description"), "#F5");
+               }
+
+               [Test]
+               public void Initialize_AlreadyInitialized ()
+               {
+                       MockProvider provider = new MockProvider ();
+                       provider.Initialize ("Mono", (NameValueCollection) null);
+                       try {
+                               provider.Initialize ("Mono", (NameValueCollection) null);
+                               Assert.Fail ("#1");
+                       } catch (InvalidOperationException ex) {
+                               Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                       }
+               }
+
+               [Test]
+               public void Initialize_Name_Null ()
+               {
+                       MockProvider provider = new MockProvider ();
+                       try {
+                               provider.Initialize ((string) null, new NameValueCollection ());
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+                               Assert.AreEqual ("name", ex.ParamName, "#6");
+                       }
+               }
+
+               [Test]
+               public void Initialize_Name_Empty ()
+               {
+                       MockProvider provider = new MockProvider ();
+                       try {
+                               provider.Initialize (string.Empty, new NameValueCollection ());
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+                               Assert.AreEqual ("name", ex.ParamName, "#6");
+                       }
+               }
+
+               static bool ContainsKey (NameValueCollection collection, string searchKey)
+               {
+                       foreach (string key in collection)
+                               if (key == searchKey)
+                                       return true;
+                       return false;
+               }
+
+               class MockProvider : ProviderBase
+               {
+               }
+       }
+}
+
+#endif
index f88363314906a03637f67024a34aec1d5e4e3968..4320acb705ce819d1850a354c6d71dfbc1835874 100644 (file)
@@ -1,3 +1,12 @@
+2007-08-31  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * GenericEnumConverterTest.cs: Remove unused variable.
+       * ConfigurationManagerTest.cs: Fixed line endings.
+       * ConnectionStringSettingsTest.cs: Fixed line endings and avoid
+       ToString override warning.
+       * KeyValueConfigurationElementTest.cs: Fixed line endings.
+       * KeyValueConfigurationCollectionTest.cs: Fixed line endings.
+
 2007-06-20  Atsushi Enomoto  <atsushi@ximian.com>
 
        * ConfigurationManagerTest.cs : Enabled some tests with related to
index dfb229727f8fe67f2b09acfe57e718b0ffa1ae51..bc8ef90f4582be211bf90ef20db2319b128dd1eb 100644 (file)
@@ -69,7 +69,7 @@ namespace MonoTests.System.Configuration {
                        Assert.AreEqual ("user.config", fi.Name);
                }
 
-               [Test]\r
+               [Test]
                [Category ("NotWorking")]
                public void UserLevelPerRoamingAndLocal ()
                {
@@ -131,7 +131,7 @@ namespace MonoTests.System.Configuration {
 
                }
 
-               [Test]\r
+               [Test]
                public void mapped_UserLevelPerRoaming ()
                {
                        ExeConfigurationFileMap map = new ExeConfigurationFileMap ();
@@ -156,7 +156,7 @@ namespace MonoTests.System.Configuration {
                        ConfigurationManager.OpenMappedExeConfiguration (map, ConfigurationUserLevel.PerUserRoaming);
                }
 
-               [Test]\r
+               [Test]
                public void mapped_UserLevelPerRoamingAndLocal ()
                {
                        ExeConfigurationFileMap map = new ExeConfigurationFileMap ();
@@ -184,7 +184,7 @@ namespace MonoTests.System.Configuration {
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]\r
+               [ExpectedException (typeof (ArgumentException))]
                [Category ("NotWorking")]
                public void mapped_UserLevelPerRoamingAndLocal_no_roaminguser ()
                {
@@ -230,7 +230,7 @@ namespace MonoTests.System.Configuration {
 #endif
                }
 
-               [Test]\r
+               [Test]
                [Category ("NotWorking")]
                public void mapped_ExeConfiguration_null ()
                {
@@ -245,7 +245,7 @@ namespace MonoTests.System.Configuration {
 #endif
                }
 
-               [Test]\r
+               [Test]
                [Category ("NotWorking")]
                public void mapped_MachineConfig_null ()
                {
@@ -262,7 +262,7 @@ namespace MonoTests.System.Configuration {
                        Assert.IsTrue (ConfigurationManager.GetSection ("appSettings") is NameValueCollection);
                }
 
-               [Test] // test for bug #78372.\r
+               [Test] // test for bug #78372.
                public void OpenMachineConfiguration ()
                {
                        SysConfig cfg = ConfigurationManager.OpenMachineConfiguration ();
index d6eb4d84249af61405b79fc2599291908b8fa183..ba3e904dee21ad75d7902ca31059b032f16b4237 100644 (file)
@@ -33,7 +33,8 @@ using System;
 using System.Configuration;
 using NUnit.Framework;
 
-namespace MonoTests.System.Configuration {
+namespace MonoTests.System.Configuration
+{
        [TestFixture]
        public class ConnectionStringSettingsTest
        {
@@ -71,7 +72,7 @@ namespace MonoTests.System.Configuration {
                }
 
                [Test]
-               [ExpectedException (typeof(ConfigurationErrorsException))]\r
+               [ExpectedException (typeof(ConfigurationErrorsException))]
                [Category ("NotWorking")]
                public void Validators_Name1 ()
                {
@@ -115,12 +116,10 @@ namespace MonoTests.System.Configuration {
                }
 
                [Test]
-               public void ToString ()
+               public void ToStringTest ()
                {
-                       ConnectionStringSettings s;
-
-                       s = new ConnectionStringSettings ("name", "connectionString", "provider");
-
+                       ConnectionStringSettings s = new ConnectionStringSettings (
+                               "name", "connectionString", "provider");
                        Assert.AreEqual ("connectionString", s.ToString(), "A1");
                }
        }
index e2a82c66b517b876cf65779b0d4ff33fa692f962..1d74eb976eea2b26d0863ddac8527c90a525d137 100644 (file)
@@ -119,7 +119,6 @@ namespace MonoTests.System.Configuration {
                public void ConvertTo ()
                {
                        GenericEnumConverter cv = new GenericEnumConverter (typeof (FooEnum));
-                       TimeSpan ts;
 
                        Assert.AreEqual ("Foo", cv.ConvertTo (null, null, FooEnum.Foo, typeof (string)), "A1");
                        Assert.AreEqual ("Bar", cv.ConvertTo (null, null, FooEnum.Bar, typeof (string)), "A2");
index 74552ffe0fc9cd857557adbec9adf9407f8a1ad7..002cf937ef092e635cf352f44f50658f52e58b9c 100644 (file)
@@ -166,7 +166,7 @@ namespace MonoTests.System.Configuration {
                        Assert.AreEqual ("foo", p.DoGetElementKey (ep), "A1");
                }
 
-               [Test]\r
+               [Test]
                [Category ("NotWorking")]
                public void GetElementKey_withoutAdd()
                {
index d720f0aa8c10f7679492b87077114be5ce550554..088ba56a0f6115dbe6011535445ae4e7c2388107 100644 (file)
@@ -57,7 +57,7 @@ namespace MonoTests.System.Configuration {
                }
 
 
-               [Test]\r
+               [Test]
                [NUnit.Framework.Category ("NotWorking")]
                public void Properties ()
                {