Explorar o código

2005-09-20 Chris Toshok <[email protected]>

	* System.Configuration/SettingsPropertyValueCollectionTest.cs: new
	test.

	* System.Configuration/SettingsPropertyCollectionTest.cs: new
	test.

	* System.Configuration/SettingsPropertyValueTest.cs: new test.


svn path=/trunk/mcs/; revision=50333
Chris Toshok %!s(int64=20) %!d(string=hai) anos
pai
achega
aab0f2a29a

+ 10 - 0
mcs/class/System/Test/ChangeLog

@@ -1,3 +1,13 @@
+2005-09-20  Chris Toshok  <[email protected]>
+
+	* System.Configuration/SettingsPropertyValueCollectionTest.cs: new
+	test.
+
+	* System.Configuration/SettingsPropertyCollectionTest.cs: new
+	test.
+
+	* System.Configuration/SettingsPropertyValueTest.cs: new test.
+
 2005-09-19  Chris Toshok  <[email protected]>
 
 	* System.Configuration/SettingsPropertyTest.cs: new tests.

+ 162 - 0
mcs/class/System/Test/System.Configuration/SettingsPropertyCollectionTest.cs

@@ -0,0 +1,162 @@
+//
+// System.Configuration.SettingsPropertyCollectionTest.cs - Unit tests
+// for System.Configuration.SettingsPropertyCollection.
+//
+// Author:
+//	Chris Toshok  <[email protected]>
+//
+// 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.Collections.Specialized;
+using NUnit.Framework;
+
+namespace MonoTests.System.Configuration {
+
+	[TestFixture]
+	public class SettingsPropertyCollectionTest {
+
+		[Test]
+		public void Add ()
+		{
+			SettingsPropertyCollection col = new SettingsPropertyCollection ();
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+
+			Assert.AreEqual (0, col.Count, "A1");
+
+			col.Add (test_prop);
+
+			Assert.AreEqual (1, col.Count, "A2");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void AddDuplicate ()
+		{
+			SettingsPropertyCollection col = new SettingsPropertyCollection ();
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+
+			col.Add (test_prop);
+
+			Assert.AreEqual (1, col.Count, "A1");
+
+			test_prop = new SettingsProperty ("test_prop");
+
+			col.Add (test_prop);
+
+			Assert.AreEqual (1, col.Count, "A2");
+		}
+
+		[Test]
+		public void Remove ()
+		{
+			SettingsPropertyCollection col = new SettingsPropertyCollection ();
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+
+			col.Add (test_prop);
+
+			Assert.AreEqual (1, col.Count, "A1");
+
+			col.Remove ("test_prop");
+
+			Assert.AreEqual (0, col.Count, "A2");
+		}
+
+		[Test]
+		public void Remove_NonExistant ()
+		{
+			SettingsPropertyCollection col = new SettingsPropertyCollection ();
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+
+			col.Add (test_prop);
+
+			Assert.AreEqual (1, col.Count, "A1");
+
+			col.Remove ("test_prop2");
+
+			Assert.AreEqual (1, col.Count, "A2");
+		}
+
+		[Test]
+		public void Clear ()
+		{
+			SettingsPropertyCollection col = new SettingsPropertyCollection ();
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+
+			col.Add (test_prop);
+
+			Assert.AreEqual (1, col.Count, "A1");
+
+			col.Clear ();
+
+			Assert.AreEqual (0, col.Count, "A2");
+		}
+
+		[Test]
+		[ExpectedException (typeof (NotSupportedException))]
+		public void ReadOnly_Add ()
+		{
+			SettingsPropertyCollection col = new SettingsPropertyCollection ();
+
+			col.SetReadOnly ();
+
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+			col.Add (test_prop);
+		}
+
+		[Test]
+		[ExpectedException (typeof (NotSupportedException))]
+		public void ReadOnly_Remove ()
+		{
+			SettingsPropertyCollection col = new SettingsPropertyCollection ();
+
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+			col.Add (test_prop);
+
+			col.SetReadOnly ();
+
+			col.Remove ("test_prop");
+		}
+
+		[Test]
+		[ExpectedException (typeof (NotSupportedException))]
+		public void ReadOnly_Clear ()
+		{
+			SettingsPropertyCollection col = new SettingsPropertyCollection ();
+
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+			col.Add (test_prop);
+
+			col.SetReadOnly ();
+
+			col.Clear ();
+		}
+	}
+
+}
+
+#endif

+ 168 - 0
mcs/class/System/Test/System.Configuration/SettingsPropertyValueCollectionTest.cs

@@ -0,0 +1,168 @@
+//
+// System.Configuration.SettingsPropertyCollectionTest.cs - Unit tests
+// for System.Configuration.SettingsPropertyCollection.
+//
+// Author:
+//	Chris Toshok  <[email protected]>
+//
+// 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.Collections.Specialized;
+using NUnit.Framework;
+
+namespace MonoTests.System.Configuration {
+
+	[TestFixture]
+	public class SettingsPropertyValueCollectionTest {
+
+		[Test]
+		public void Add ()
+		{
+			SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+			SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
+
+			Assert.AreEqual (0, col.Count, "A1");
+
+			col.Add (val);
+
+			Assert.AreEqual (1, col.Count, "A2");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void AddDuplicate ()
+		{
+			SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+			SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
+
+			col.Add (val);
+
+			Assert.AreEqual (1, col.Count, "A1");
+
+			col.Add (val);
+
+			Assert.AreEqual (1, col.Count, "A2");
+		}
+
+		[Test]
+		public void Remove ()
+		{
+			SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+			SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
+
+			col.Add (val);
+
+			Assert.AreEqual (1, col.Count, "A1");
+
+			col.Remove ("test_prop");
+
+			Assert.AreEqual (0, col.Count, "A2");
+		}
+
+		[Test]
+		public void Remove_NonExistant ()
+		{
+			SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+			SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
+
+			col.Add (val);
+
+			Assert.AreEqual (1, col.Count, "A1");
+
+			col.Remove ("test_prop2");
+
+			Assert.AreEqual (1, col.Count, "A2");
+		}
+
+		[Test]
+		public void Clear ()
+		{
+			SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+			SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
+
+			col.Add (val);
+
+			Assert.AreEqual (1, col.Count, "A1");
+
+			col.Clear ();
+
+			Assert.AreEqual (0, col.Count, "A2");
+		}
+
+		[Test]
+		[ExpectedException (typeof (NotSupportedException))]
+		public void ReadOnly_Add ()
+		{
+			SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
+
+			col.SetReadOnly ();
+
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+			SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
+			col.Add (val);
+		}
+
+		[Test]
+		[ExpectedException (typeof (NotSupportedException))]
+		public void ReadOnly_Remove ()
+		{
+			SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
+
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+			SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
+			col.Add (val);
+
+			col.SetReadOnly ();
+
+			col.Remove ("test_prop");
+		}
+
+		[Test]
+		[ExpectedException (typeof (NotSupportedException))]
+		public void ReadOnly_Clear ()
+		{
+			SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
+
+			SettingsProperty test_prop = new SettingsProperty ("test_prop");
+			SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
+			col.Add (val);
+
+			col.SetReadOnly ();
+
+			col.Clear ();
+		}
+	}
+
+}
+
+#endif

+ 237 - 0
mcs/class/System/Test/System.Configuration/SettingsPropertyValueTest.cs

@@ -0,0 +1,237 @@
+//
+// System.Configuration.SettingsPropertyValueTest.cs - Unit tests for
+// System.Configuration.SettingsPropertyValue.
+//
+// Author:
+//	Chris Toshok  <[email protected]>
+//
+// 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.IO;
+using System.Configuration;
+using System.Collections.Specialized;
+using System.Runtime.Serialization.Formatters.Binary;
+using NUnit.Framework;
+
+namespace MonoTests.System.Configuration {
+
+	[TestFixture]
+	public class SettingsPropertyValueTest {
+
+		[Test]
+		public void Properties ()
+		{
+			SettingsProperty p = new SettingsProperty ("property",
+								   typeof (int),
+								   null,
+								   true,
+								   10,
+								   SettingsSerializeAs.String,
+								   null,
+								   true,
+								   false);
+
+			SettingsPropertyValue v = new SettingsPropertyValue (p);
+
+			Assert.IsFalse (v.Deserialized, "A1");
+			Assert.IsFalse (v.IsDirty, "A2");
+			Assert.AreEqual ("property", v.Name, "A3");
+			Assert.AreEqual (p, v.Property, "A4");
+			Assert.AreEqual ((object)10, v.PropertyValue, "A5");
+			Assert.AreEqual (null, v.SerializedValue, "A6");
+			Assert.IsTrue (v.UsingDefaultValue, "A7");
+
+			/* test that setting v.PropertyValue to
+			 * something else causes SerializedValue to
+			 * become not-null */
+			v.PropertyValue = (object)5;
+			Assert.AreEqual ("5", v.SerializedValue, "A9");
+
+			/* test to see whether or not changing
+			 * SerializeAs causes SerializedValue to
+			 * change */
+			p.SerializeAs = SettingsSerializeAs.Xml;
+			Assert.AreEqual ("5", v.SerializedValue, "A11"); /* nope.. */
+
+			/* only changing PropertyValue does */
+			v.PropertyValue = (object)7;
+			Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<int>7</int>", ((string)v.SerializedValue).Replace ("\r\n", "\n"), "A13");
+		}
+
+		[Test]
+		public void Dirty ()
+		{
+			SettingsProperty p = new SettingsProperty ("property",
+								   typeof (int),
+								   null,
+								   true,
+								   10,
+								   SettingsSerializeAs.String,
+								   null,
+								   true,
+								   false);
+
+			SettingsPropertyValue v = new SettingsPropertyValue (p);
+
+			Assert.AreEqual (10, v.PropertyValue, "A0");
+			Assert.IsFalse (v.IsDirty, "A1");
+
+			/* set PropertyValue to something else */
+			v.PropertyValue = 5;
+			Assert.IsTrue (v.IsDirty, "A2");
+			v.IsDirty = false;
+
+			/* set PropertyValue to the same thing */
+			v.PropertyValue = 5;
+			Assert.IsTrue (v.IsDirty, "A3");
+
+
+#if notyet
+			/* the msdn docs say that
+			 * SettingsPropertyValue pessimistically sets
+			 * IsDirty to true when you use
+			 * v.PropertyValue on non-primitive types */
+
+			/* try out a non-value type */
+			p = new SettingsProperty ("property",
+						  typeof (StringWriter),
+						  null,
+						  true,
+						  null,
+						  SettingsSerializeAs.String,
+						  null,
+						  true,
+						  false);
+			v = new SettingsPropertyValue (p);
+
+			Assert.IsNull (v.PropertyValue, "A5");
+
+			Console.WriteLine (v.PropertyValue);
+			Assert.IsTrue (v.IsDirty, "A6");
+#endif
+		}
+
+		[Test]
+		public void UsingDefaultValue ()
+		{
+			SettingsProperty p = new SettingsProperty ("property",
+								   typeof (int),
+								   null,
+								   true,
+								   10,
+								   SettingsSerializeAs.String,
+								   null,
+								   true,
+								   false);
+
+			SettingsPropertyValue v = new SettingsPropertyValue (p);
+
+			/* this is wonky... ms returns false for all of the below cases */
+			Assert.IsFalse (v.UsingDefaultValue, "A1");
+
+			/* set PropertyValue to something else */
+			v.PropertyValue = 5;
+			Assert.IsFalse (v.UsingDefaultValue, "A2");
+
+			/* set PropertyValue back to the default */
+			v.PropertyValue = 10;
+			Assert.IsFalse (v.UsingDefaultValue, "A3");
+
+
+			/* let's try again */
+			v = new SettingsPropertyValue (p);
+			
+			Assert.AreEqual (10, v.PropertyValue, "A4");
+			Assert.IsTrue (v.UsingDefaultValue, "A5");
+		}
+
+		[Test]
+		public void String_Xml_Serialize ()
+		{
+			SettingsProperty p = new SettingsProperty ("property",
+								   typeof (int),
+								   null,
+								   true,
+								   10,
+								   SettingsSerializeAs.String,
+								   null,
+								   true,
+								   false);
+
+			SettingsPropertyValue v = new SettingsPropertyValue (p);
+
+			v.PropertyValue = 10;
+			Assert.AreEqual (10, v.PropertyValue, "A1");
+			Assert.AreEqual ("10", v.SerializedValue, "A2");
+
+			v.PropertyValue = 10;
+			p.SerializeAs = SettingsSerializeAs.Xml;
+			
+			Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<int>10</int>", ((string)v.SerializedValue).Replace ("\r\n", "\n"), "A3");
+
+		}
+
+		[Test]
+		public void Binary_Serialize ()
+		{
+			SettingsProperty p = new SettingsProperty ("property",
+								   typeof (int),
+								   null,
+								   true,
+								   10,
+								   SettingsSerializeAs.Binary,
+								   null,
+								   true,
+								   false);
+
+			SettingsPropertyValue v = new SettingsPropertyValue (p);
+			byte[] foo;
+
+			v.PropertyValue = 10;
+
+			Assert.AreEqual (typeof (byte[]), v.SerializedValue.GetType(), "A1");
+			foo = (byte[])v.SerializedValue;
+
+			v.PropertyValue = 5;
+			Assert.AreEqual (5, v.PropertyValue, "A2");
+
+
+			BinaryFormatter bf = new BinaryFormatter ();
+			MemoryStream ms = new MemoryStream (foo);
+			Assert.AreEqual (10, bf.Deserialize (ms), "A3");
+			
+#if notyet
+			v.Deserialized = false;
+			v.SerializedValue = foo;
+
+			Assert.AreEqual (10, v.PropertyValue, "A4");
+#endif
+		}
+	}
+
+}
+
+#endif