[Mono-devel-list] Patch for standardizing Mainsoft's ConstraintCollection tests

Eyal Alaluf eyala at mainsoft.com
Tue May 24 09:58:09 EDT 2005


Hi, all.

The attached patch adds a new test under Test/System.Data -
 ConstraintCollectionTest2.cs
This test is a Mono NUnit standardized version of the tests under
  Test/System.Data.Tests.Mainsoft/System.Data/ConstraintCollection
As part of the patch I copied a couple of utility classes from
Test/System.Data.Tests.Mainsoft/GHUtils into a new test utility dir
called:
  Test/System.Data.Test.Utils
These utilities are used to create populated data tables.
It is our intention to standardize all the tests under
  Test/System.Data.Tests.Mainsoft/System.Data in the same manner.

Any comments are welcome.

Eyal.
-------------- next part --------------
Index: Test/System.Data/ConstraintCollectionTest2.cs

===================================================================

--- Test/System.Data/ConstraintCollectionTest2.cs	(revision 0)

+++ Test/System.Data/ConstraintCollectionTest2.cs	(revision 0)

@@ -0,0 +1,280 @@

+// Authors:
+//   Rafael Mizrahi   <rafim at mainsoft.com>
+//   Erez Lotan       <erezl at mainsoft.com>
+//   Oren Gurfinkel   <oreng at mainsoft.com>
+//   Ofer Borstein
+// 
+// Copyright (c) 2004 Mainsoft Co.
+// 
+// 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 NUnit.Framework;
+using MonoTests.System.Data.Test.Utils;
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.Data;
+
+namespace MonoTests.System.Data
+{
+	[TestFixture] public class ConstraintCollectionTest2
+	{
+		private bool CollectionChangedFlag = false;
+
+		[Test] public void CanRemove_ParentForeign()
+		{
+			DataSet ds = DataProvider.CreateForigenConstraint();
+			Assert.AreEqual(false, ds.Tables["parent"].Constraints.CanRemove(ds.Tables["parent"].Constraints[0]), "CN1");
+		}
+
+		[Test] public void CanRemove_ChildForeign()
+		{
+			DataSet ds = DataProvider.CreateForigenConstraint();
+			Assert.AreEqual(true, ds.Tables["child"].Constraints.CanRemove(ds.Tables["child"].Constraints[0]), "CN2");
+		}
+
+		[Test] public void CanRemove_ParentAndChildForeign()
+		{
+			DataSet ds = DataProvider.CreateForigenConstraint();
+			//remove the forigen and ask about the unique
+			ds.Tables["child"].Constraints.Remove(ds.Tables["child"].Constraints[0]);
+			Assert.AreEqual(true, ds.Tables["parent"].Constraints.CanRemove(ds.Tables["parent"].Constraints[0]), "CN3");
+		}
+
+		// FIXME. This test isn't complete.
+		public void CanRemove_Unique()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			//remove the forigen and ask about the unique
+			dt.Constraints.Remove(dt.Constraints[0]);
+			Assert.AreEqual(true, dt.Constraints.CanRemove(dt.Constraints[0]), "CN4");
+		}
+
+		[Test] public void Clear_Foreign()
+		{
+			DataSet ds = DataProvider.CreateForigenConstraint();
+			foreach(DataTable dt in ds.Tables)
+			{
+				dt.Constraints.Clear();
+			}
+			Assert.AreEqual(0, ds.Tables[0].Constraints.Count, "CN5");
+			Assert.AreEqual(0, ds.Tables[0].Constraints.Count, "CN6");
+
+		}
+
+		[Test] public void Clear_Unique()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			int rowsCount = dt.Rows.Count;
+			dt.Constraints.Clear();
+			DataRow dr = dt.NewRow();
+			dr[0] = 1;
+			dt.Rows.Add(dr);
+			Assert.AreEqual(rowsCount+1, dt.Rows.Count, "CN7"); //Just checking that no expection ocuured
+		}
+
+		[Test] public void CollectionChanged()
+		{
+			DataTable dt = DataProvider.CreateParentDataTable();
+			CollectionChangedFlag = false;
+			dt.Constraints.CollectionChanged += new CollectionChangeEventHandler(Constraints_CollectionChangedHandler);	
+			dt = DataProvider.CreateUniqueConstraint(dt);
+			Assert.AreEqual(true, CollectionChangedFlag, "CN8"); 
+		}
+
+		[Test] public void Contains_ByName()
+		{
+			DataSet ds =  DataProvider.CreateForigenConstraint();
+	 
+			//changing the constraints's name
+
+			ds.Tables["child"].Constraints[0].ConstraintName = "name1";
+			ds.Tables["parent"].Constraints[0].ConstraintName = "name2";
+
+
+			Assert.AreEqual(true, ds.Tables["child"].Constraints.Contains("name1"), "CN9");
+			Assert.AreEqual(false, ds.Tables["child"].Constraints.Contains("xxx"), "CN10");
+			Assert.AreEqual(true, ds.Tables["parent"].Constraints.Contains("name2"), "CN11");
+			Assert.AreEqual(false, ds.Tables["parent"].Constraints.Contains("xxx"), "CN12");
+
+		}
+
+		[Test] public void CopyTo()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			dt.Constraints.Add("constraint2",dt.Columns["String1"],true);
+
+			object[] ar = new object[2];
+
+			dt.Constraints.CopyTo(ar,0);
+			Assert.AreEqual(2, ar.Length, "CN13");
+		}
+
+		[Test] public void Count()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			Assert.AreEqual(1, dt.Constraints.Count, "CN14");
+
+			//Add
+
+			dt.Constraints.Add("constraint2",dt.Columns["String1"],false);
+			Assert.AreEqual(2, dt.Constraints.Count, "CN15");
+
+			//Remove
+
+			dt.Constraints.Remove("constraint2");
+			Assert.AreEqual(1, dt.Constraints.Count, "CN16");
+		}
+
+		[Test] public void GetEnumerator()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			dt.Constraints.Add("constraint2",dt.Columns["String1"],false);
+
+			int counter=0;
+			IEnumerator myEnumerator = dt.Constraints.GetEnumerator();
+			while (myEnumerator.MoveNext())
+			{
+				counter++;
+
+			}
+			Assert.AreEqual(2, counter, "CN17");
+		}
+
+		[Test] public void IndexOf()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			Assert.AreEqual(0, dt.Constraints.IndexOf(dt.Constraints[0]), "CN18");
+
+			//Add new constraint
+			Constraint con = new UniqueConstraint(dt.Columns["String1"],false);
+
+			dt.Constraints.Add(con);
+			Assert.AreEqual(1, dt.Constraints.IndexOf(con), "CN19");
+
+			//Remove it and try to look for it 
+
+			dt.Constraints.Remove(con);
+			Assert.AreEqual(-1, dt.Constraints.IndexOf(con), "CN20");
+
+		}
+
+		[Test] public void IndexOf_ByName()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			dt.Constraints[0].ConstraintName="name1";
+			Assert.AreEqual(0, dt.Constraints.IndexOf("name1"), "CN21");
+
+			//Add new constraint
+			Constraint con = new UniqueConstraint(dt.Columns["String1"],false);
+			con.ConstraintName="name2";
+
+			dt.Constraints.Add(con);
+			Assert.AreEqual(1, dt.Constraints.IndexOf("name2"), "CN22");
+
+			//Remove it and try to look for it 
+
+			dt.Constraints.Remove(con);
+			Assert.AreEqual(-1, dt.Constraints.IndexOf("name2"), "CN23");
+
+		}
+
+		[Test] public void IsReadOnly()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			Assert.AreEqual(false, dt.Constraints.IsReadOnly, "CN24"); 
+		}
+
+		[Test] public void IsSynchronized()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			Assert.AreEqual(false, dt.Constraints.IsSynchronized, "CN25");
+	 
+			ConstraintCollection col = (ConstraintCollection)dt.Constraints.SyncRoot;
+
+	//		lock(dt.Constraints.SyncRoot)
+	//		{
+			//	Assert.AreEqual(true, col.IsSynchronized, "CN26");
+
+			//}
+		}
+
+		[Test] public void Remove()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			dt.Constraints.Remove(dt.Constraints[0]);
+			Assert.AreEqual(0, dt.Constraints.Count, "CN27");
+		}
+
+		[Test] public void Remove_ByNameSimple()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			dt.Constraints[0].ConstraintName = "constraint1";
+			dt.Constraints.Remove("constraint1");
+			Assert.AreEqual(0, dt.Constraints.Count, "CN28");
+		}
+
+		[Test] public void Remove_ByNameWithAdd()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			dt.Constraints[0].ConstraintName = "constraint1";
+			Constraint con = new UniqueConstraint(dt.Columns["String1"],false);
+			dt.Constraints.Add(con);
+			dt.Constraints.Remove(con);
+
+			Assert.AreEqual(1, dt.Constraints.Count, "CN29");
+			Assert.AreEqual("constraint1", dt.Constraints[0].ConstraintName, "CN30");
+		}
+
+		[Test] public void Remove_CollectionChangedEvent()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			CollectionChangedFlag = false;
+			dt.Constraints.CollectionChanged += new CollectionChangeEventHandler(Constraints_CollectionChangedHandler);
+			dt.Constraints.Remove(dt.Constraints[0]);
+			Assert.AreEqual(true, CollectionChangedFlag, "CN31"); //Checking that event has raised
+		}
+
+		[Test] public void Remove_ByNameCollectionChangedEvent()
+		{
+			DataTable dt = DataProvider.CreateUniqueConstraint();
+			CollectionChangedFlag = false;
+			dt.Constraints.CollectionChanged += new CollectionChangeEventHandler(Constraints_CollectionChangedHandler);
+			dt.Constraints.Remove("constraint1");
+			Assert.AreEqual(true, CollectionChangedFlag, "CN32"); //Checking that event has raised
+
+		}
+
+		[Test] public void add_CollectionChanged()
+		{
+			DataTable dt = DataProvider.CreateParentDataTable();
+			CollectionChangedFlag = false;
+			dt.Constraints.CollectionChanged += new CollectionChangeEventHandler(Constraints_CollectionChangedHandler);	
+			dt = DataProvider.CreateUniqueConstraint(dt);
+			Assert.AreEqual(true, CollectionChangedFlag, "CN33"); 
+		}
+
+		private void Constraints_CollectionChangedHandler(object sender, CollectionChangeEventArgs e)
+		{
+			CollectionChangedFlag = true;
+		}
+	}
+}
Index: Test/System.Data.Test.Utils/DataProvider.cs

===================================================================

--- Test/System.Data.Test.Utils/DataProvider.cs	(revision 0)

+++ Test/System.Data.Test.Utils/DataProvider.cs	(working copy)

@@ -30,11 +30,10 @@

 using System.Data;
 using System.Data.OleDb ;
 using System.IO;
-using GHTUtils.Data;
 using System.Collections;
 
 // Provide All Data required by the diffderent tests e.g.DataTable, DataRow ...
-namespace GHTUtils
+namespace MonoTests.System.Data.Test.Utils
 {
 
 	public class DataProvider
@@ -49,9 +48,9 @@

 		
 		#endregion
 
-		public static System.Data.DataTable CreateChildDataTable()
+		public static DataTable CreateChildDataTable()
 		{
-			System.Data.DataTable dtChild = new System.Data.DataTable("Child");
+			DataTable dtChild = new DataTable("Child");
 			dtChild.Columns.Add("ParentId",typeof(int));
 			dtChild.Columns.Add("ChildId",typeof(int));
 			dtChild.Columns.Add("String1",typeof(string));
@@ -76,10 +75,10 @@

 
 		}
 
-		public static System.Data.DataTable CreateParentDataTable()
+		public static DataTable CreateParentDataTable()
 		{     
 
-			System.Data.DataTable dtParent = new System.Data.DataTable("Parent");
+			DataTable dtParent = new DataTable("Parent");
 
 			dtParent.Columns.Add("ParentId",typeof(int));
 			dtParent.Columns.Add("String1",typeof(string));
@@ -149,7 +148,7 @@

 
 		public static DataTable CreateUniqueConstraint()
 		{
-			DataTable dt = GHTUtils.DataProvider.CreateParentDataTable();
+			DataTable dt = DataProvider.CreateParentDataTable();
 			return CreateUniqueConstraint(dt);
 		}
 		public static DataTable CreateUniqueConstraint(DataTable dt)
@@ -172,8 +171,8 @@

 		}
 		public static DataSet CreateForigenConstraint()
 		{
-			DataTable parent = GHTUtils.DataProvider.CreateParentDataTable();
-			DataTable child = GHTUtils.DataProvider.CreateChildDataTable(); 
+			DataTable parent = DataProvider.CreateParentDataTable();
+			DataTable child = DataProvider.CreateChildDataTable(); 
 			DataSet ds = new DataSet();
 			ds.Tables.Add(parent); 
 			ds.Tables.Add(child);
@@ -198,4 +197,4 @@

 		}
 
 	} 
-}

\ No newline at end of file

+}
Index: Test/System.Data.Test.Utils/DbTypeParameter.cs

===================================================================

--- Test/System.Data.Test.Utils/DbTypeParameter.cs	(revision 0)

+++ Test/System.Data.Test.Utils/DbTypeParameter.cs	(working copy)

@@ -30,7 +30,7 @@

 using System.Data;
 using System.Data.OleDb;
 
-namespace GHTUtils.Data
+namespace MonoTests.System.Data.Tests.Utils
 {
 	/// <summary>
 	/// Represents a parameter type for use in tests of System.Data.
Index: System.Data_test.dll.sources

===================================================================

--- System.Data_test.dll.sources	(revision 44927)

+++ System.Data_test.dll.sources	(working copy)

@@ -1,3 +1,5 @@

+System.Data.Test.Utils/DataProvider.cs
+System.Data.Test.Utils/DbTypeParameter.cs
 System.Data.SqlTypes/SqlBinaryTest.cs
 System.Data.SqlTypes/SqlBooleanTest.cs
 System.Data.SqlTypes/SqlByteTest.cs
@@ -14,6 +16,7 @@

 System.Xml/XmlDataDocumentTest.cs
 System.Xml/XmlDataDocumentTest2.cs
 System.Data/ConstraintCollectionTest.cs
+System.Data/ConstraintCollectionTest2.cs
 System.Data/ConstraintTest.cs
 System.Data/DataColumnCollectionTest.cs
 System.Data/DataColumnTest.cs
@@ -59,20 +62,6 @@

 System.Data.Tests.Mainsoft/GHTUtils/HttpClientBase.cs
 System.Data.Tests.Mainsoft/GHTUtils/ObjectTester.cs
 System.Data.Tests.Mainsoft/GHTUtils/XmlUtils.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_add_CollectionChanged_C.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_CanRemove_C.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_Clear.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_CollectionChanged.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_Contains_S.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_CopyTo_AI.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_Count.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_GetEnumerator.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_IndexOf_C.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_IndexOf_S.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_IsReadOnly.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_IsSynchronized.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_Remove_C.cs
-System.Data.Tests.Mainsoft/System.Data/ConstraintCollection/ConstraintCollection_Remove_S.cs
 System.Data.Tests.Mainsoft/System.Data/ConstraintException/ConstraintException_Generate.cs
 System.Data.Tests.Mainsoft/System.Data/DataColumn/DataColumn_AllowDBNull.cs
 System.Data.Tests.Mainsoft/System.Data/DataColumn/DataColumn_AutoIncrement.cs


More information about the Mono-devel-list mailing list