Equals() public method

Gets a value indicating whether the current is identical to the specified object.
public Equals ( object key ) : bool
key object
return bool
コード例 #1
0
		[Test] public void Equals()
		{
			DataSet ds = new DataSet();
			DataTable dtParent = DataProvider.CreateParentDataTable();
			DataTable dtChild = DataProvider.CreateChildDataTable();
			ds.Tables.Add(dtParent);
			ds.Tables.Add(dtChild);
			dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns[0]};
			ds.EnforceConstraints = true;

			ForeignKeyConstraint fc1,fc2;
			fc1 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);

			fc2 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[1]);
			// different columnn
			Assert.AreEqual(false, fc1.Equals(fc2), "FKC3");

			//Two System.Data.ForeignKeyConstraint are equal if they constrain the same columns.
			// same column
			fc2 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
			Assert.AreEqual(true, fc1.Equals(fc2), "FKC4");
		}
コード例 #2
0
		public void EqualsAndHashCode()
		{
			DataTable tbl = _ds.Tables[0];
			DataTable tbl2 = _ds.Tables[1];

			ForeignKeyConstraint fkc = new ForeignKeyConstraint( 
				new DataColumn[] {tbl.Columns[0], tbl.Columns[1]} ,
				new DataColumn[] {tbl2.Columns[0], tbl2.Columns[1]} );

			ForeignKeyConstraint fkc2 = new ForeignKeyConstraint( 
				new DataColumn[] {tbl.Columns[0], tbl.Columns[1]} ,
				new DataColumn[] {tbl2.Columns[0], tbl2.Columns[1]} );

			ForeignKeyConstraint fkcDiff = 
				new ForeignKeyConstraint( tbl.Columns[1], tbl.Columns[2]);
		
			Assert.IsTrue( fkc.Equals(fkc2) , "Equals Assert.IsTrue.Failed. 1");
			Assert.IsTrue( fkc2.Equals(fkc) , "Equals Assert.IsTrue.Failed. 2");
			Assert.IsTrue( fkc.Equals(fkc) , "Equals Assert.IsTrue.Failed. 3");

			Assert.IsTrue( fkc.Equals(fkcDiff) == false , "Equals Assert.IsTrue.Failed diff. 1");

			//Assert.IsTrue( "Hash Code Assert.IsTrue.Failed. 1", fkc.GetHashCode() == fkc2.GetHashCode() );
			Assert.IsTrue( fkc.GetHashCode() != fkcDiff.GetHashCode() , "Hash Code Assert.IsTrue.Failed. 2");
	
		}
コード例 #3
0
	//Activate This Construntor to log All To Standard output
	//public TestClass():base(true){}

	//Activate this constructor to log Failures to a log file
	//public TestClass(System.IO.TextWriter tw):base(tw, false){}


	//Activate this constructor to log All to a log file
	//public TestClass(System.IO.TextWriter tw):base(tw, true){}

	//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES

	public void run()
	{
		Exception exp = null;
		DataSet ds = new DataSet();
		DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
		DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
		ds.Tables.Add(dtParent);
		ds.Tables.Add(dtChild);
		dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns[0]};
		ds.EnforceConstraints = true;

		ForeignKeyConstraint fc1,fc2;
		fc1 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);

		fc2 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[1]);
		try
		{
			BeginCase("different columnn");
			Compare(fc1.Equals(fc2),false);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}

		//Two System.Data.ForeignKeyConstraint are equal if they constrain the same columns.
		try
		{
			BeginCase("same column");
			fc2 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
			Compare(fc1.Equals(fc2),true);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
	}