Exemplo n.º 1
0
        public void GetHashCodeTest()
        {
            var testId1 = new TestId(10);
            var testId2 = new TestId(10);

            Assert.Equal(testId1.GetHashCode(), testId2.GetHashCode());

            var testId3 = new TestId(11);

            Assert.NotEqual(testId1.GetHashCode(), testId3.GetHashCode());
        }
Exemplo n.º 2
0
        public void EqualWhenIdsAreEqual()
        {
            var left  = new TestId(1);
            var right = new TestId(1);

            left.Equals(right as object).Should().BeTrue();
            left.Equals(right).Should().BeTrue();
            (left == right).Should().BeTrue();
            (left != right).Should().BeFalse();
            left.GetHashCode().Should().Be(right.GetHashCode());
        }
 //hash code trait
 public override int GetHashCode()
 {
     unchecked {
         var hash = 0;
         hash = hash * 31 + TestId.GetHashCode();
         hash = hash * 31 + Output.GetHashCode();
         hash = hash * 31 + Duration.GetHashCode();
         hash = hash * 31 + (int)Status;
         return(hash);
     }
 }
Exemplo n.º 4
0
        public void GetHashCode_IsDifferentForIdsWithDifferentValue()
        {
            // Arrange
            var id1 = new TestId("75d9fa21-6209-4960-b8c2-095c817e8e88");
            var id2 = new TestId("75d9fa21-6209-4960-b8c2-095c817e8e89");

            // Act
            var hashCode1 = id1.GetHashCode();
            var hashCode2 = id2.GetHashCode();

            // Assert
            Assert.That(hashCode1, Is.Not.EqualTo(hashCode2));
        }
Exemplo n.º 5
0
        public void GetHashCode_ReturnsSameForIdsWithSameValue()
        {
            // Arrange
            var id1 = new TestId("75d9fa21-6209-4960-b8c2-095c817e8e88");
            var id2 = new TestId("75d9fa21-6209-4960-b8c2-095c817e8e88");

            // Act
            var hashCode1 = id1.GetHashCode();
            var hashCode2 = id2.GetHashCode();

            // Assert
            Assert.That(hashCode1, Is.EqualTo(hashCode2));
        }
Exemplo n.º 6
0
 public override int GetHashCode()
 {
     return(TestId.GetHashCode());
 }