Ejemplo n.º 1
0
 public void testReflectionHierarchyHashCode()
 {
     Assert.AreEqual(17 * 37 * 37, HashCodeBuilder.ReflectionHashCode(new TestSubObject(0, 0, 0)));
     Assert.AreEqual(17 * 37 * 37 * 37, HashCodeBuilder.ReflectionHashCode(new TestSubObject(0, 0, 0), true));
     Assert.AreEqual((17 * 37 + 7890) * 37 + 123456,
                     HashCodeBuilder.ReflectionHashCode(new TestSubObject(123456, 7890, 0)));
     Assert.AreEqual(((17 * 37 + 7890) * 37 + 0) * 37 + 123456,
                     HashCodeBuilder.ReflectionHashCode(new TestSubObject(123456, 7890, 0), true));
 }
Ejemplo n.º 2
0
 public void testReflectionHierarchyHashCodeEx2()
 {
     try
     {
         HashCodeBuilder.ReflectionHashCode(2, 2, new TestSubObject(0, 0, 0), true);
     }
     catch (ArgumentException ex)
     {
         return;
     }
     Assert.Fail();
 }
Ejemplo n.º 3
0
 public void testReflectionHashCodeEx3()
 {
     try
     {
         HashCodeBuilder.ReflectionHashCode(13, 19, null, true);
     }
     catch (ArgumentException ex)
     {
         return;
     }
     Assert.Fail();
 }
Ejemplo n.º 4
0
 public void testReflectionHashCodeEx1()
 {
     try
     {
         HashCodeBuilder.ReflectionHashCode(0, 0, new TestObject(0), true);
     }
     catch (ArgumentException ex)
     {
         return;
     }
     Assert.Fail();
 }
Ejemplo n.º 5
0
        public void ReflectionHashCode_should_calculate_different_hashcode_when_object_are_different()
        {
            //Arrange
            var vehicle1 = new Vehicle("11-D-214", "BMW S6", "1212");
            var vehicle2 = new Vehicle("11-D-214", "BMW S6", "1313");

            //Act
            var firstPersonHashCode  = HashCodeBuilder.ReflectionHashCode(vehicle1);
            var secondPersonHashCode = HashCodeBuilder.ReflectionHashCode(vehicle2);

            //Assert
            firstPersonHashCode.Should().NotBe(secondPersonHashCode);
        }
Ejemplo n.º 6
0
        public void ReflectionHashCode_should_calculate_same_hash_code_When_objects_are_same()
        {
            //Arrange
            var person1 = new Person(1, "Hadi", "Ahmadi", new DateTime(1991, 1, 7));
            var person2 = new Person(1, "Hadi", "Ahmadi", new DateTime(1991, 1, 7));

            //Act
            var firstPersonHashCode  = HashCodeBuilder.ReflectionHashCode(person1);
            var secondPersonHashCode = HashCodeBuilder.ReflectionHashCode(person2);

            //Assert
            firstPersonHashCode.Should().Be(secondPersonHashCode);
        }
Ejemplo n.º 7
0
 public override int GetHashCode()
 {
     return(HashCodeBuilder.ReflectionHashCode(this));
 }
Ejemplo n.º 8
0
 public void testReflectionHashCode()
 {
     Assert.AreEqual(17 * 37, HashCodeBuilder.ReflectionHashCode(new TestObject(0)));
     Assert.AreEqual(17 * 37 + 123456, HashCodeBuilder.ReflectionHashCode(new TestObject(123456)));
 }