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