Example #1
0
        public void ToHashCode_should_calculate_same_hashcode_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 = new HashCodeBuilder()
                                      .Append(person1.Id)
                                      .Append(person1.Firstname)
                                      .Append(person1.Lastname)
                                      .Append(person1.BirthDate)
                                      .ToHashCode();

            var secondPersonHashCode = new HashCodeBuilder()
                                       .Append(person2.Id)
                                       .Append(person2.Firstname)
                                       .Append(person2.Lastname)
                                       .Append(person2.BirthDate)
                                       .ToHashCode();

            //Assert
            firstPersonHashCode.Should().Be(secondPersonHashCode);
        }