Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
2008-09-14 Gert Driesen <drieseng@users.sourceforge.net>
* ProviderCollectionTest.cs: Moved from System assembly.
2007-08-31 Gert Driesen <drieseng@users.sourceforge.net>
* ProviderBaseTest.cs: Added tests for Initialize.

View File

@@ -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

View File

@@ -0,0 +1,181 @@
//
// System.Configuration.ProviderCollectionTest.cs - Unit tests for
// System.Configuration.ProviderCollection.
//
// Author:
// Chris Toshok <toshok@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.Text;
using System.Configuration;
using System.Configuration.Provider;
using System.Collections.Specialized;
using NUnit.Framework;
namespace MonoTests.System.Configuration {
class TestProvider : SettingsProvider {
public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context,
SettingsPropertyCollection collection)
{
throw new NotImplementedException ();
}
public override void SetPropertyValues (SettingsContext context,
SettingsPropertyValueCollection collection)
{
throw new NotImplementedException ();
}
public override string ApplicationName {
get {
throw new NotImplementedException ();
}
set {
throw new NotImplementedException ();
}
}
}
class TestProviderBase : ProviderBase {
}
[TestFixture]
public class ProviderCollectionTest {
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Add_duplicate ()
{
ProviderCollection col = new ProviderCollection();
TestProvider provider;
provider = new TestProvider();
provider.Initialize ("test", null);
col.Add (provider);
col.Add (provider);
}
[Test]
public void Add_providerbase ()
{
ProviderCollection col = new ProviderCollection();
TestProviderBase provider;
provider = new TestProviderBase();
provider.Initialize ("test", null);
col.Add (provider);
Assert.AreEqual (provider, col["test"], "A1");
}
[Test]
public void Get_nonexistant ()
{
ProviderCollection col = new ProviderCollection();
TestProvider provider;
provider = new TestProvider();
provider.Initialize ("test", null);
col.Add (provider);
Assert.AreEqual (provider, col["test"], "A1");
Assert.IsNull (col["test2"], "A2");
}
[Test]
public void Ctor_2 ()
{
SettingsProperty q = new SettingsProperty ("property",
typeof (int),
null,
true,
10,
SettingsSerializeAs.Binary,
new SettingsAttributeDictionary(),
true,
false);
SettingsProperty p = new SettingsProperty (q);
Assert.AreEqual ("property", p.Name, "A1");
Assert.AreEqual (typeof (int), p.PropertyType, "A2");
Assert.AreEqual (null, p.Provider, "A3");
Assert.AreEqual (10, (int)p.DefaultValue, "A4");
Assert.AreEqual (SettingsSerializeAs.Binary, p.SerializeAs, "A5");
Assert.IsNotNull (p.Attributes, "A6");
Assert.IsTrue (p.ThrowOnErrorDeserializing, "A7");
Assert.IsFalse (p.ThrowOnErrorSerializing, "A8");
Assert.IsTrue (p.IsReadOnly, "A9");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Ctor_2_ArgNull ()
{
/* same as above, but a null
* SettingsAttributeDictionary, which causes a
* ANE in the ctor. */
SettingsProperty q = new SettingsProperty ("property",
typeof (int),
null,
true,
10,
SettingsSerializeAs.Binary,
null,
true,
false);
SettingsProperty p = new SettingsProperty (q);
}
[Test]
public void Ctor_3 ()
{
SettingsProperty p = new SettingsProperty ("property");
Assert.AreEqual ("property", p.Name, "A1");
Assert.AreEqual (null, p.PropertyType, "A2");
Assert.AreEqual (null, p.Provider, "A3");
Assert.AreEqual (null, p.DefaultValue, "A4");
Assert.AreEqual (SettingsSerializeAs.String, p.SerializeAs, "A5");
Assert.IsNotNull (p.Attributes, "A6");
Assert.IsFalse (p.ThrowOnErrorDeserializing, "A7");
Assert.IsFalse (p.ThrowOnErrorSerializing, "A8");
Assert.IsFalse (p.IsReadOnly, "A9");
}
}
}
#endif

View File

@@ -0,0 +1,75 @@
//
// System.Configuration.AppSettingsSectionTest.cs - Unit tests
// for System.Configuration.AppSettingsSection.
//
// Author:
// Tom Philpot <tom.philpot@logos.com>
//
// Copyright (C) 2014 Logos Bible Software
//
// 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.
//
using System;
using System.Configuration;
using System.IO;
using System.Reflection;
using NUnit.Framework;
namespace MonoTests.System.Configuration
{
using Util;
[TestFixture]
public class AppSettingsSectionTest
{
private string originalCurrentDir;
private string tempFolder;
[SetUp]
public void SetUp ()
{
originalCurrentDir = Directory.GetCurrentDirectory ();
tempFolder = Path.Combine (Path.GetTempPath (), this.GetType ().FullName);
if (!Directory.Exists (tempFolder))
Directory.CreateDirectory (tempFolder);
}
[TearDown]
public void TearDown ()
{
Directory.SetCurrentDirectory (originalCurrentDir);
if (Directory.Exists (tempFolder))
Directory.Delete (tempFolder, true);
}
[Test]
public void TestFile ()
{
Directory.SetCurrentDirectory (tempFolder);
var currentAssembly = Assembly.GetExecutingAssembly ().Location;
var config = ConfigurationManager.OpenExeConfiguration (currentAssembly);
Assert.AreEqual ("Test/appSettings.config", config.AppSettings.File, "#A01");
Assert.AreEqual ("foo", ConfigurationSettings.AppSettings["TestKey1"], "#A02");
Assert.AreEqual ("bar", ConfigurationSettings.AppSettings["TestKey2"], "#A03");
}
}
}

View File

@@ -0,0 +1,109 @@
//
// System.Configuration.CallbackValidatorTest.cs - Unit tests
// for System.Configuration.CallbackValidator.
//
// Author:
// Chris Toshok <toshok@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.Configuration;
using NUnit.Framework;
namespace MonoTests.System.Configuration {
[TestFixture]
public class CallbackValidatorTest
{
[Test]
public void CanValidate ()
{
CallbackValidator v = new CallbackValidator (typeof (int), success);
Assert.IsFalse (v.CanValidate (typeof (string)));
Assert.IsTrue (v.CanValidate (typeof (int)));
Assert.IsFalse (v.CanValidate (typeof (object)));
}
public void NullCallback ()
{
CallbackValidator v = new CallbackValidator (typeof (int), null);
}
public void NullType ()
{
CallbackValidator v = new CallbackValidator (null, success);
}
bool hit_success;
bool hit_failure;
void success (object o)
{
hit_success = true;
}
void failure (object o)
{
hit_failure = true;
throw new Exception ();
}
[Test]
public void TestSuccess ()
{
hit_success = false;
CallbackValidator v = new CallbackValidator (typeof (int), success);
v.Validate (5);
Assert.IsTrue (hit_success, "A1");
}
[Test]
[ExpectedException (typeof (Exception))]
public void TestFailure1 ()
{
CallbackValidator v = new CallbackValidator (typeof (int), failure);
v.Validate (5);
}
[Test]
public void TestFailure2 ()
{
hit_failure = false;
CallbackValidator v = new CallbackValidator (typeof (int), failure);
try {
v.Validate (5);
}
catch { }
finally {
Assert.IsTrue (hit_failure, "A1");
}
}
}
}
#endif

View File

@@ -0,0 +1,105 @@
2010-01-15 Jonathan Pobst <monkey@jpobst.com>
* ConfigurationErrorsExceptionTest.cs: Mark 4 failing tests as NotWorking.
Filed as bug #571226.
2009-07-17 Gonzalo Paniagua Javier <gonzalo@novell.com>
* ConfigurationSectionTest.cs: New test.
2008-09-14 Gert Driesen <drieseng@users.sourceforge.net>
* ConfigurationManagerTest.cs: Added test for bug #323622.
2008-07-02 Gert Driesen <drieseng@users.sourceforge.net>
* ConfigurationManagerTest.cs: Added/improved tests for
OpenExeConfiguration. Enabled tests that were previously failed.
2008-06-27 Atsushi Enomoto <atsushi@ximian.com>
* ConfigurationErrorsExceptionTest.cs : actually
remove ignored tests.
2008-06-27 Atsushi Enomoto <atsushi@ximian.com>
* ConfigurationErrorsExceptionTest.cs : mark couple
of tests as [Ignore] that blocks us from decent
implementation in the name of silly .NET compatibility.
2008-06-26 Gert Driesen <drieseng@users.sourceforge.net>
* ConfigurationErrorsExceptionTest.cs: Added tests for ctors and
GetFilename/GetLineNumber overloads.
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
roaming user config. Marked some tests for negative check as
[NotWorking] (they are rather uncovered bugs than enbug).
2007-06-13 Atsushi Enomoto <atsushi@ximian.com>
* ConfigurationSectionGroupTest.cs : new (my change is with tests.)
2007-04-17 Atsushi Enomoto <atsushi@ximian.com>
* ConfigurationManagerTest.cs : added SectionCollectionEnumerator().
Fixed NotWorking test OpenMachineConfiguration().
2006-09-18 Boris Kirzner <borisk@mainsoft.com>
* TimeSpanMinutesConverterTest.cs,
TimeSpanSecondsOrInfiniteConverterTest.cs,
KeyValueConfigurationElementTest.cs,
TimeSpanSecondsConverterTest.cs,
KeyValueConfigurationCollectionTest.cs,
InfiniteTimeSpanConverterTest.cs,ConfigurationManagerTest.cs,
TimeSpanMinutesOrInfiniteConverterTest.cs,
ConnectionStringSettingsTest.cs,InfiniteIntConverterTest.cs :
marked not working tests.
2006-05-09 Boris Kirzner <borisk@mainsoft.com>
* ConfigurationManagerTest.cs: small fixes for TARGET_JVM.
2006-05-09 Boris Kirzner <borisk@mainsoft.com>
* ConfigurationManagerTest.cs, ConfigurationPermissionTest.cs:
fixes for TARGET_JVM.
2006-07-07 Atsushi Enomoto <atsushi@ximian.com>
* ConfigurationManagerTest.cs :
OpenExeConfiguration(null) should be allowed.
2006-05-14 Atsushi Enomoto <atsushi@ximian.com>
* ConfigurationManagerTest.cs :
duh, why I overwrote it before commit :( Fix the build.
2006-05-12 Atsushi Enomoto <atsushi@ximian.com>
* ConfigurationManagerTest.cs :
added test for OpenMachineConfiguration().
2006-05-10 Atsushi Enomoto <atsushi@ximian.com>
* StringValidatorTest.cs : added NullZero().
2006-05-10 Atsushi Enomoto <atsushi@ximian.com>
(first ChangeLog entry here).
* ConfigurationManagerTest.cs :
added GetSectionReturnsNativeObject().

View File

@@ -0,0 +1,124 @@
//
// System.Configuration.CommaDelimitedStringCollectionConverterTest.cs - Unit tests
// for System.Configuration.CommaDelimitedStringCollectionConverter.
//
// Author:
// Chris Toshok <toshok@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.Configuration;
using NUnit.Framework;
namespace MonoTests.System.Configuration {
[TestFixture]
public class CommaDelimitedStringCollectionConverterTest
{
[Test]
public void CanConvertFrom ()
{
CommaDelimitedStringCollectionConverter cv = new CommaDelimitedStringCollectionConverter ();
Assert.IsTrue (cv.CanConvertFrom (null, typeof (string)), "A1");
Assert.IsFalse (cv.CanConvertFrom (null, typeof (TimeSpan)), "A2");
Assert.IsFalse (cv.CanConvertFrom (null, typeof (int)), "A3");
Assert.IsFalse (cv.CanConvertFrom (null, typeof (object)), "A4");
}
[Test]
public void CanConvertTo ()
{
CommaDelimitedStringCollectionConverter cv = new CommaDelimitedStringCollectionConverter ();
Assert.IsTrue (cv.CanConvertTo (null, typeof (string)), "A1");
Assert.IsFalse (cv.CanConvertTo (null, typeof (TimeSpan)), "A2");
Assert.IsFalse (cv.CanConvertTo (null, typeof (int)), "A3");
Assert.IsFalse (cv.CanConvertTo (null, typeof (object)), "A4");
}
[Test]
public void ConvertFrom ()
{
CommaDelimitedStringCollectionConverter cv = new CommaDelimitedStringCollectionConverter ();
object o;
CommaDelimitedStringCollection col;
o = cv.ConvertFrom (null, null, "hi,bye");
Assert.AreEqual (typeof (CommaDelimitedStringCollection), o.GetType(), "A1");
col = (CommaDelimitedStringCollection)o;
Assert.AreEqual (2, col.Count, "A2");
Assert.AreEqual ("hi", col[0], "A3");
Assert.AreEqual ("bye", col[1], "A4");
col = (CommaDelimitedStringCollection)cv.ConvertFrom (null, null, "hi, bye");
Assert.AreEqual (2, col.Count, "A5");
Assert.AreEqual ("hi", col[0], "A6");
Assert.AreEqual ("bye", col[1], "A7");
}
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void ConvertFrom_TypeError ()
{
CommaDelimitedStringCollectionConverter cv = new CommaDelimitedStringCollectionConverter ();
object o;
o = cv.ConvertFrom (null, null, 59);
Assert.IsNull (o, "A1");
}
[Test]
public void ConvertTo ()
{
CommaDelimitedStringCollectionConverter cv = new CommaDelimitedStringCollectionConverter ();
CommaDelimitedStringCollection col = new CommaDelimitedStringCollection();
col.Add ("hi");
col.Add ("bye");
Assert.AreEqual ("hi,bye", cv.ConvertTo (null, null, col, typeof (string)), "A1");
}
[Test]
public void ConvertTo_NullError ()
{
CommaDelimitedStringCollectionConverter cv = new CommaDelimitedStringCollectionConverter ();
Assert.AreEqual (null, cv.ConvertTo (null, null, null, typeof (string)), "A1");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConvertTo_TypeError ()
{
CommaDelimitedStringCollectionConverter cv = new CommaDelimitedStringCollectionConverter ();
Assert.AreEqual ("59", cv.ConvertTo (null, null, 59, typeof (string)), "A1");
}
}
}
#endif

View File

@@ -0,0 +1,135 @@
//
// System.Configuration.CommaDelimitedStringCollectionTest.cs - Unit tests
// for System.Configuration.CommaDelimitedStringCollection.
//
// Author:
// Chris Toshok <toshok@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.Configuration;
using NUnit.Framework;
namespace MonoTests.System.Configuration {
[TestFixture]
public class CommaDelimitedStringCollectionTest
{
[Test]
public void Defaults ()
{
CommaDelimitedStringCollection c = new CommaDelimitedStringCollection ();
Assert.IsFalse (c.IsModified, "A1");
Assert.IsFalse (c.IsReadOnly, "A1");
}
[Test]
public void Manipulations ()
{
CommaDelimitedStringCollection c = new CommaDelimitedStringCollection ();
c.Add ("1");
Assert.AreEqual ("1", c.ToString(), "A1");
c.Add ("2");
c.Add ("3");
Assert.AreEqual ("1,2,3", c.ToString(), "A2");
c.Remove ("2");
Assert.AreEqual ("1,3", c.ToString(), "A3");
c.Insert (1, "2");
Assert.AreEqual ("1,2,3", c.ToString(), "A4");
c.Clear ();
Assert.AreEqual (null, c.ToString(), "A5");
string[] foo = new string[3];
foo[0] = "1";
foo[1] = "2";
foo[2] = "3";
c.AddRange (foo);
Assert.AreEqual ("1,2,3", c.ToString(), "A6");
}
[Test]
[ExpectedException (typeof (ConfigurationErrorsException))]
public void RO_Add ()
{
CommaDelimitedStringCollection c = new CommaDelimitedStringCollection ();
c.SetReadOnly ();
c.Add ("hi");
}
[Test]
[ExpectedException (typeof (ConfigurationErrorsException))]
public void RO_AddRange ()
{
CommaDelimitedStringCollection c = new CommaDelimitedStringCollection ();
string[] foo = new string[2];
foo[0] = "hi";
foo[1] = "bye";
c.SetReadOnly ();
c.AddRange (foo);
}
[Test]
[ExpectedException (typeof (ConfigurationErrorsException))]
public void RO_Clear ()
{
CommaDelimitedStringCollection c = new CommaDelimitedStringCollection ();
c.SetReadOnly ();
c.Clear ();
}
[Test]
[ExpectedException (typeof (ConfigurationErrorsException))]
public void RO_Remove ()
{
CommaDelimitedStringCollection c = new CommaDelimitedStringCollection ();
c.SetReadOnly ();
c.Clear ();
}
[Test]
[ExpectedException (typeof (ConfigurationErrorsException))]
public void RO_Insert ()
{
CommaDelimitedStringCollection c = new CommaDelimitedStringCollection ();
c.Add ("hi");
c.SetReadOnly ();
c.Insert (0, "bye");
}
}
}
#endif

View File

@@ -0,0 +1,52 @@
//
// System.Configuration.ConfigurationElementTest.cs - Unit tests
// for System.Configuration.ConfigurationElement.
//
// Author:
// Chris Toshok <toshok@ximian.com>
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
// 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.Configuration;
using NUnit.Framework;
namespace MonoTests.System.Configuration {
[TestFixture]
public class ConfigurationElementTest
{
[Test]
public void ElementInformation_validator () {
/* pick a Configuration class that doesn't
* specify an ElementInformation override */
DefaultSection sect = new DefaultSection();
ElementInformation info = sect.ElementInformation;
Assert.AreEqual (typeof (DefaultValidator), info.Validator.GetType(), "A1");
}
}
}
#endif

View File

@@ -0,0 +1,179 @@
//
// System.Configuration.ConfigurationLockCollectionTest.cs - Unit
// tests for System.Configuration.ConfigurationLockCollection.
//
// Author:
// Chris Toshok <toshok@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.Configuration;
using System.Collections;
using NUnit.Framework;
using SysConfig = System.Configuration.Configuration;
namespace MonoTests.System.Configuration {
[TestFixture]
public class ConfigurationLockCollectionTest
{
[Test]
public void InitialState ()
{
SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
ConfigurationLockCollection col;
col = cfg.AppSettings.LockAttributes;
Assert.AreEqual (0, col.Count, "A1");
Assert.IsFalse (col.Contains ("file"), "A2");
Assert.IsFalse (col.HasParentElements, "A4");
Assert.IsFalse (col.IsModified, "A5");
Assert.IsFalse (col.IsSynchronized, "A6");
Assert.AreEqual (col, col.SyncRoot, "A7");
col = cfg.AppSettings.LockElements;
Assert.AreEqual (0, col.Count, "A8");
Assert.IsFalse (col.HasParentElements, "A11");
Assert.IsFalse (col.IsModified, "A12");
Assert.IsFalse (col.IsSynchronized, "A13");
Assert.AreEqual (col, col.SyncRoot, "A14");
col = cfg.ConnectionStrings.LockAttributes;
Assert.AreEqual (0, col.Count, "A8");
Assert.IsFalse (col.HasParentElements, "A11");
Assert.IsFalse (col.IsModified, "A12");
Assert.IsFalse (col.IsSynchronized, "A13");
Assert.AreEqual (col, col.SyncRoot, "A14");
col = cfg.ConnectionStrings.LockElements;
Assert.AreEqual (0, col.Count, "A8");
Assert.IsFalse (col.HasParentElements, "A11");
Assert.IsFalse (col.IsModified, "A12");
Assert.IsFalse (col.IsSynchronized, "A13");
Assert.AreEqual (col, col.SyncRoot, "A14");
}
[Test]
[ExpectedException (typeof (ConfigurationErrorsException))]
public void NonExistantItem ()
{
SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
ConfigurationLockCollection col;
col = cfg.AppSettings.LockAttributes;
Assert.IsFalse (col.IsReadOnly ("file"), "A3");
}
[Test]
public void Populate ()
{
SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
col.Add ("file");
Assert.AreEqual (1, col.Count, "A1");
Assert.IsFalse (col.HasParentElements, "A2");
Assert.IsTrue (col.IsModified, "A3");
Assert.IsTrue (col.Contains ("file"), "A4");
}
[Test]
[ExpectedException (typeof (ConfigurationErrorsException))]
public void Populate_Error ()
{
SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
col.Add ("boo");
}
[Test]
public void Enumerator ()
{
SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
col.Add ("file");
IEnumerator e = col.GetEnumerator ();
Assert.IsTrue (e.MoveNext (), "A1");
Assert.AreEqual ("file", (string)e.Current, "A2");
Assert.IsFalse (e.MoveNext (), "A3");
}
[Test]
public void SetFromList ()
{
SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
ConfigurationLockCollection col = cfg.AppSettings.LockAttributes;
col.SetFromList ("file");
Assert.AreEqual (1, col.Count, "A1");
Assert.IsTrue (col.Contains ("file"), "A2");
col.Clear ();
Assert.AreEqual (0, col.Count, "A5");
col.SetFromList (" file ");
Assert.AreEqual (1, col.Count, "A1");
Assert.IsTrue (col.Contains ("file"), "A2");
}
[Test]
public void DuplicateAdd ()
{
SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
AppSettingsSection app = cfg.AppSettings;
app.LockAttributes.Clear ();
app.LockAttributes.Add ("file");
app.LockAttributes.Add ("file");
Assert.AreEqual (1, app.LockAttributes.Count, "A1");
}
[Test]
public void IsReadOnly ()
{
SysConfig cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
AppSettingsSection app = cfg.AppSettings;
app.LockAttributes.Clear ();
app.LockAllAttributesExcept.Clear ();
app.LockAttributes.Add ("file");
Assert.IsFalse (app.LockAttributes.IsReadOnly ("file"), "A1");
app.LockAllAttributesExcept.Add ("file");
Assert.IsFalse (app.LockAllAttributesExcept.IsReadOnly ("file"), "A2");
}
}
}
#endif

View File

@@ -0,0 +1,179 @@
//
// System.Configuration.ConfigurationPermissionTest.cs - Unit tests
// for System.Configuration.ConfigurationPermission.
//
// Author:
// Chris Toshok <toshok@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.
//
using System;
using System.Configuration;
using System.Security;
using System.Security.Permissions;
using NUnit.Framework;
namespace MonoTests.System.Configuration {
[TestFixture]
public class ConfigurationPermissionTest
{
[Test]
public void Unrestricted ()
{
ConfigurationPermission p = new ConfigurationPermission (PermissionState.Unrestricted);
Assert.IsTrue (p.IsUnrestricted(), "A1");
p = new ConfigurationPermission (PermissionState.None);
Assert.IsFalse (p.IsUnrestricted(), "A2");
}
[Test]
public void Intersect ()
{
ConfigurationPermission p1 = new ConfigurationPermission (PermissionState.Unrestricted);
ConfigurationPermission p2 = new ConfigurationPermission (PermissionState.None);
IPermission p3 = p1.Intersect (p2);
Assert.AreEqual (typeof (ConfigurationPermission), p3.GetType(), "A1");
Assert.IsFalse (((ConfigurationPermission)p3).IsUnrestricted(), "A2");
}
[Test]
public void Intersect_null ()
{
ConfigurationPermission p1 = new ConfigurationPermission (PermissionState.Unrestricted);
IPermission p3 = p1.Intersect (null);
Assert.IsNull (p3, "A1");
}
#if !TARGET_JVM
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Intersect_wrongtype ()
{
ConfigurationPermission p1 = new ConfigurationPermission (PermissionState.Unrestricted);
IPermission p3 = p1.Intersect (new StrongNameIdentityPermission (PermissionState.Unrestricted));
}
#endif
[Test]
public void Union ()
{
ConfigurationPermission p1 = new ConfigurationPermission (PermissionState.Unrestricted);
ConfigurationPermission p2 = new ConfigurationPermission (PermissionState.None);
IPermission p3 = p1.Union (p2);
Assert.AreEqual (typeof (ConfigurationPermission), p3.GetType(), "A1");
Assert.IsTrue (((ConfigurationPermission)p3).IsUnrestricted(), "A2");
}
[Test]
public void Union_null ()
{
ConfigurationPermission p1 = new ConfigurationPermission (PermissionState.Unrestricted);
IPermission p3 = p1.Union (null);
Assert.AreEqual (typeof (ConfigurationPermission), p3.GetType(), "A1");
Assert.IsTrue (((ConfigurationPermission)p3).IsUnrestricted(), "A2");
}
#if !TARGET_JVM
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Union_wrongtypee ()
{
ConfigurationPermission p1 = new ConfigurationPermission (PermissionState.Unrestricted);
IPermission p3 = p1.Union (new StrongNameIdentityPermission (PermissionState.Unrestricted));
}
#endif
[Test]
public void Subset ()
{
ConfigurationPermission p1 = new ConfigurationPermission (PermissionState.Unrestricted);
ConfigurationPermission p2 = new ConfigurationPermission (PermissionState.None);
Assert.IsFalse (p1.IsSubsetOf (p2), "A1");
Assert.IsTrue (p1.IsSubsetOf (p1), "A2");
Assert.IsTrue (p2.IsSubsetOf (p1), "A3");
Assert.IsTrue (p2.IsSubsetOf (p2), "A4");
Assert.IsFalse (p1.IsSubsetOf (null), "A5");
Assert.IsTrue (p2.IsSubsetOf (null), "A6");
}
#if !TARGET_JVM
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Subset_wrongtype ()
{
ConfigurationPermission p1 = new ConfigurationPermission (PermissionState.Unrestricted);
Assert.IsFalse (p1.IsSubsetOf (new StrongNameIdentityPermission (PermissionState.Unrestricted)));
}
#endif
[Test]
#if TARGET_JVM
[Category("NotWorking")]
#endif
public void ToXml ()
{
ConfigurationPermission p = new ConfigurationPermission (PermissionState.Unrestricted);
#if NET_4_0
Assert.AreEqual(
"<IPermission class=\"System.Configuration.ConfigurationPermission, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\nversion=\"1\"\nUnrestricted=\"true\"/>\n",
p.ToString().Replace ("\r\n", "\n"), "A1");
#else
Assert.AreEqual (
"<IPermission class=\"System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\nversion=\"1\"\nUnrestricted=\"true\"/>\n",
p.ToString ().Replace ("\r\n", "\n"), "A1");
#endif
p = new ConfigurationPermission (PermissionState.None);
#if NET_4_0
Assert.AreEqual (
"<IPermission class=\"System.Configuration.ConfigurationPermission, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\nversion=\"1\"/>\n",
p.ToString().Replace ("\r\n", "\n"), "A2");
#else
Assert.AreEqual (
"<IPermission class=\"System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\nversion=\"1\"/>\n",
p.ToString ().Replace ("\r\n", "\n"), "A2");
#endif
}
}
}

View File

@@ -0,0 +1,67 @@
//
// System.Configuration.ConfigurationElementTest.cs - Unit tests
// for System.Configuration.ConfigurationElement.
//
// Author:
// Konstantin Triger <kostat@mainsoft.com>
//
// Copyright (C) 2006 Mainsoft, Inc (http://www.mainsoft.com)
//
// 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.Configuration;
using NUnit.Framework;
namespace MonoTests.System.Configuration {
[TestFixture]
public class ConfigurationPropertyTest
{
[Test]
[ExpectedException(typeof(ConfigurationErrorsException))]
public void CostructorTest () {
ConfigurationProperty poker = new ConfigurationProperty("Name", typeof(char), 5);
}
[Test]
public void CostructorTest1 () {
ConfigurationProperty poker = new ConfigurationProperty("Name", typeof(String));
Assert.IsNotNull (poker.Validator, "A1");
Assert.IsNotNull (poker.Converter, "A2");
}
[Test]
public void DefaultValueTest () {
ConfigurationProperty poker = new ConfigurationProperty("Name", typeof(char));
Assert.AreEqual (typeof (char), poker.DefaultValue.GetType(), "A1");
ConfigurationProperty poker1 = new ConfigurationProperty("Name", typeof(ConfigurationProperty));
Assert.AreEqual (null, poker1.DefaultValue, "A2");
ConfigurationProperty poker2 = new ConfigurationProperty("Name", typeof(String));
Assert.AreEqual (String.Empty, poker2.DefaultValue, "A1");
}
}
}
#endif

View File

@@ -0,0 +1,63 @@
//
// ConfigurationSectionGroupTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
//
// 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.Configuration;
using NUnit.Framework;
using Config = System.Configuration.Configuration;
namespace MonoTests.System.Configuration
{
[TestFixture]
public class ConfigurationSectionGroupTest
{
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void EditBeforeAdd ()
{
UserSettingsGroup u = new UserSettingsGroup ();
ClientSettingsSection c = new ClientSettingsSection ();
u.Sections.Add ("mine", c);
}
[Test]
public void EditAfterAdd ()
{
Config cfg = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
UserSettingsGroup u = new UserSettingsGroup ();
cfg.SectionGroups.Add ("userSettings", u);
ClientSettingsSection c = new ClientSettingsSection ();
u.Sections.Add ("mine", c);
}
}
}
#endif

View File

@@ -0,0 +1,123 @@
//
// System.Configuration.ConfigurationSectionTest.cs - Unit tests
//
// Author:
// Greg Smolyn
// Gonzalo Paniagua Javier <gonzalo@novell.com
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.Configuration;
using System.IO;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.Configuration {
[TestFixture]
public class ConfigurationElementCollectionTest
{
[Test]
public void TwoConfigElementsInARow () // Bug #521231
{
string config = @"<fooconfig><foos><foo id=""1"" /></foos><bars><bar id=""1"" /></bars></fooconfig>";
var fooSection = new FooConfigSection ();
fooSection.Load (config);
}
class FooConfigSection : ConfigurationSection
{
public void Load (string xml)
{
Init ();
using (StringReader sr = new StringReader(xml))
using (XmlReader reader = new XmlTextReader(sr)) {
DeserializeSection (reader);
}
}
[ConfigurationProperty("foos")]
[ConfigurationCollection(typeof(FooConfigElementCollection), AddItemName="foo")]
public FooConfigElementCollection Foos {
get { return (FooConfigElementCollection)base["foos"]; }
set { base["foos"] = value; }
}
[ConfigurationProperty("bars")]
[ConfigurationCollection(typeof(BarConfigElementCollection), AddItemName="bar")]
public BarConfigElementCollection Bars {
get { return (BarConfigElementCollection)base["bars"]; }
set { base["bars"] = value; }
}
}
class FooConfigElementCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement ()
{
return new FooConfigElement();
}
protected override object GetElementKey (ConfigurationElement element)
{
return ((FooConfigElement)element).Id;
}
}
class FooConfigElement : ConfigurationElement
{
[ConfigurationProperty("id")]
public int Id {
get { return (int)base["id"]; }
set { base["id"] = value; }
}
}
class BarConfigElementCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement ()
{
return new BarConfigElement();
}
protected override object GetElementKey (ConfigurationElement element)
{
return ((BarConfigElement)element).Id;
}
}
class BarConfigElement : ConfigurationElement
{
[ConfigurationProperty("id")]
public int Id {
get { return (int)base["id"]; }
set { base["id"] = value; }
}
}
}
}
#endif

View File

@@ -0,0 +1,128 @@
//
// System.Configuration.ConnectionStringSettingsTest.cs - Unit tests
// for System.Configuration.ConnectionStringSettings
//
// Author:
// Chris Toshok <toshok@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.Configuration;
using NUnit.Framework;
namespace MonoTests.System.Configuration
{
[TestFixture]
public class ConnectionStringSettingsTest
{
[Test]
public void Defaults ()
{
ConnectionStringSettings s;
s = new ConnectionStringSettings ();
Assert.AreEqual (null, s.Name, "A1");
Assert.AreEqual ("", s.ProviderName, "A2");
Assert.AreEqual ("", s.ConnectionString, "A3");
s = new ConnectionStringSettings ("name", "connectionString");
Assert.AreEqual ("name", s.Name, "A4");
Assert.AreEqual ("", s.ProviderName, "A5");
Assert.AreEqual ("connectionString", s.ConnectionString, "A6");
s = new ConnectionStringSettings ("name", "connectionString", "provider");
Assert.AreEqual ("name", s.Name, "A7");
Assert.AreEqual ("provider", s.ProviderName, "A8");
Assert.AreEqual ("connectionString", s.ConnectionString, "A9");
}
[Test]
public void NameNull ()
{
ConnectionStringSettings s;
s = new ConnectionStringSettings ("name", "connectionString", "provider");
Assert.AreEqual ("name", s.Name, "A1");
s.Name = null;
Assert.IsNull (s.Name, "A2");
}
[Test]
[ExpectedException (typeof(ConfigurationErrorsException))]
[Category ("NotWorking")]
public void Validators_Name1 ()
{
ConnectionStringSettings s = new ConnectionStringSettings ();
s.Name = "";
}
[Test]
public void Validators_Name2 ()
{
ConnectionStringSettings s = new ConnectionStringSettings ();
s.Name = null;
}
[Test]
public void Validators_ProviderName1 ()
{
ConnectionStringSettings s = new ConnectionStringSettings ();
s.ProviderName = "";
}
[Test]
public void Validators_ProviderName2 ()
{
ConnectionStringSettings s = new ConnectionStringSettings ();
s.ProviderName = null;
}
[Test]
public void Validators_ConnectionString1 ()
{
ConnectionStringSettings s = new ConnectionStringSettings ();
s.ConnectionString = "";
}
[Test]
public void Validators_ConnectionString2 ()
{
ConnectionStringSettings s = new ConnectionStringSettings ();
s.ConnectionString = null;
}
[Test]
public void ToStringTest ()
{
ConnectionStringSettings s = new ConnectionStringSettings (
"name", "connectionString", "provider");
Assert.AreEqual ("connectionString", s.ToString(), "A1");
}
}
}
#endif

View File

@@ -0,0 +1,63 @@
//
// System.Configuration.DefaultValidatorTest.cs - Unit tests
// for System.Configuration.DefaultValidator.
//
// Author:
// Chris Toshok <toshok@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.Configuration;
using NUnit.Framework;
namespace MonoTests.System.Configuration {
[TestFixture]
public class DefaultValidatorTest
{
[Test]
public void CanValidate ()
{
DefaultValidator v = new DefaultValidator ();
Assert.IsTrue (v.CanValidate (typeof (string)));
Assert.IsTrue (v.CanValidate (typeof (int)));
Assert.IsTrue (v.CanValidate (typeof (object)));
}
[Test]
public void Validate ()
{
DefaultValidator v = new DefaultValidator ();
v.Validate (5);
v.Validate (5.4);
v.Validate ("hi there");
v.Validate (v);
}
}
}
#endif

View File

@@ -0,0 +1,158 @@
//
// System.Configuration.ExeConfigurationFileMapTest.cs - Unit tests
// for System.Configuration.ExeConfigurationFileMap.
//
// Author:
// Chris Toshok <toshok@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.Configuration;
using NUnit.Framework;
namespace MonoTests.System.Configuration {
using Util;
[TestFixture]
public class ExeConfigurationFileMapTest
{
[Test]
public void Properties ()
{
ExeConfigurationFileMap map = new ExeConfigurationFileMap ();
/* defaults */
Assert.AreEqual ("", map.ExeConfigFilename, "A1");
Assert.AreEqual ("", map.LocalUserConfigFilename, "A2");
Assert.AreEqual ("", map.RoamingUserConfigFilename, "A2");
/* setter */
map.ExeConfigFilename = "foo";
Assert.AreEqual ("foo", map.ExeConfigFilename, "A3");
map.LocalUserConfigFilename = "bar";
Assert.AreEqual ("bar", map.LocalUserConfigFilename, "A4");
map.RoamingUserConfigFilename = "baz";
Assert.AreEqual ("baz", map.RoamingUserConfigFilename, "A5");
/* null setter */
map.ExeConfigFilename = null;
Assert.IsNull (map.ExeConfigFilename, "A6");
map.LocalUserConfigFilename = null;
Assert.IsNull (map.LocalUserConfigFilename, "A7");
map.RoamingUserConfigFilename = null;
Assert.IsNull (map.RoamingUserConfigFilename, "A8");
}
[Test]
public void MissingRoamingFilename ()
{
TestUtil.RunWithTempFile (filename => {
var map = new ExeConfigurationFileMap ();
map.ExeConfigFilename = filename;
try {
ConfigurationManager.OpenMappedExeConfiguration (
map, ConfigurationUserLevel.PerUserRoaming);
Assert.Fail ("#1");
} catch (ArgumentException) {
;
}
});
}
[Test]
public void MissingRoamingFilename2 ()
{
TestUtil.RunWithTempFile (filename => {
var map = new ExeConfigurationFileMap ();
map.LocalUserConfigFilename = filename;
try {
ConfigurationManager.OpenMappedExeConfiguration (
map, ConfigurationUserLevel.PerUserRoamingAndLocal);
Assert.Fail ("#1");
} catch (ArgumentException) {
;
}
});
}
[Test]
public void MissingLocalFilename ()
{
TestUtil.RunWithTempFile (filename => {
var map = new ExeConfigurationFileMap ();
map.ExeConfigFilename = filename;
map.RoamingUserConfigFilename = filename;
try {
ConfigurationManager.OpenMappedExeConfiguration (
map, ConfigurationUserLevel.PerUserRoamingAndLocal);
Assert.Fail ("#1");
} catch (ArgumentException) {
;
}
});
}
[Test]
public void MissingExeFilename ()
{
TestUtil.RunWithTempFiles ((roaming,local) => {
var map = new ExeConfigurationFileMap ();
map.RoamingUserConfigFilename = roaming;
map.LocalUserConfigFilename = local;
try {
ConfigurationManager.OpenMappedExeConfiguration (
map, ConfigurationUserLevel.PerUserRoamingAndLocal);
Assert.Fail ("#1");
} catch (ArgumentException) {
;
}
});
}
[Test]
public void MissingExeFilename2 ()
{
TestUtil.RunWithTempFile ((machine) => {
var map = new ExeConfigurationFileMap ();
map.MachineConfigFilename = machine;
try {
ConfigurationManager.OpenMappedExeConfiguration (
map, ConfigurationUserLevel.None);
Assert.Fail ("#1");
} catch (ArgumentException) {
;
}
});
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More