GetHashCode() public method

public GetHashCode ( ) : int
return int
Ejemplo n.º 1
0
		public void EqualsAndHashCode ()
		{
			UniqueConstraint cst = new UniqueConstraint (new DataColumn [] {
					_table.Columns[0], _table.Columns[1]});
			UniqueConstraint cst2 = new UniqueConstraint (new DataColumn [] {
					 _table.Columns[1], _table.Columns[0]});

			UniqueConstraint cst3 = new UniqueConstraint (_table.Columns [0]);
			UniqueConstraint cst4 = new UniqueConstraint (_table.Columns [2]);
			
			//true
			Assert.That (cst.Equals (cst2), Is.True, "A0");
			
			//false
			Assert.That (cst.Equals (23), Is.False, "A1");
			Assert.That (cst.Equals (cst3), Is.False, "A2");
			Assert.That (cst3.Equals (cst), Is.False, "A3");
			Assert.That (cst.Equals (cst4), Is.False, "A4");

			//true
			Assert.That (cst.GetHashCode (), Is.EqualTo (cst2.GetHashCode ()), "HashEquals");

			//false
			Assert.That (cst.GetHashCode (), Is.Not.EqualTo (cst3.GetHashCode ()), "Hash Not Equals");
		}
		public void EqualsAndHashCode() {
			UniqueConstraint cst = new UniqueConstraint( new DataColumn [] {
					_table.Columns[0], _table.Columns[1]});
			UniqueConstraint cst2 = new UniqueConstraint( new DataColumn [] {
					 _table.Columns[1], _table.Columns[0]});

			UniqueConstraint cst3 = new UniqueConstraint(_table.Columns[0]);
			UniqueConstraint cst4 = new UniqueConstraint(_table.Columns[2]);
			
			//true
			Assert(cst.Equals(cst2) == true);
			
			//false
			Assert("A1", cst.Equals(23) == false);
			Assert("A2", cst.Equals(cst3) == false);
			Assert("A3", cst3.Equals(cst) == false);
			Assert("A4", cst.Equals(cst4) == false);

			//true
			Assert("HashEquals", cst.GetHashCode() == cst2.GetHashCode());

			//false
			Assert("Hash Not Equals", (cst.GetHashCode() == cst3.GetHashCode()) == false);
		}