Example #1
0
        public void Equals_TwoNullInstances_ReturnsTrue()
        {
            // Arrange
            var comparer = new EntityIdentityComparer <string>();

            // Act
            var result = comparer.Equals(null, null);

            // Assert
            Assert.True(result);
        }
Example #2
0
        public void GetHashCode_NullInstance_ReturnsZero()
        {
            // Arrange
            var comparer = new EntityIdentityComparer <string>();

            // Act
            var result = comparer.GetHashCode(null);

            // Assert
            Assert.Equal(0, result);
        }
Example #3
0
        public void Equals_SecondInstanceNull_ReturnsFalse()
        {
            // Arrange
            var entity1  = new SimpleEntityRepresentation1("test-id");
            var comparer = new EntityIdentityComparer <string>();

            // Act
            var result = comparer.Equals(entity1, null);

            // Assert
            Assert.False(result);
        }
Example #4
0
        public void Equals_DifferentInstanceTypeWithSameIdValue_ReturnsTrue()
        {
            // Arrange
            var entity1  = new SimpleEntityRepresentation1("test-id");
            var entity2  = new SimpleEntityRepresentation2("test-id");
            var comparer = new EntityIdentityComparer <string>();

            // Act
            var result = comparer.Equals(entity1, entity2);

            // Assert
            Assert.True(result);
        }
Example #5
0
        public void Equals_CustomIdentityComparerAndDistinctIdentityValue_ReturnsFalse()
        {
            // Arrange
            var entity1  = new ComplexEntityRepresentation1(new ComplexIdentity("test-id"));
            var entity2  = new ComplexEntityRepresentation1(new ComplexIdentity("test-id2"));
            var comparer = new EntityIdentityComparer <ComplexIdentity>(new ComplexIdentityComparer());

            // Act
            var result = comparer.Equals(entity1, entity2);

            // Assert
            Assert.False(result);
        }
Example #6
0
        public void GetHashCode_CustomIdentityComparerAndEqualIdentityValue_ReturnsSameValue()
        {
            // Arrange
            var entity1  = new ComplexEntityRepresentation1(new ComplexIdentity("test-id"));
            var entity2  = new ComplexEntityRepresentation1(new ComplexIdentity("test-id"));
            var comparer = new EntityIdentityComparer <ComplexIdentity>(new ComplexIdentityComparer());

            // Act
            var result1 = comparer.GetHashCode(entity1);
            var result2 = comparer.GetHashCode(entity2);

            // Assert
            Assert.NotEqual(0, result1);
            Assert.Equal(result1, result2);
        }
Example #7
0
        public void GetHashCode_DifferentInstanceTypeWithSameIdValue_ReturnsSameValue()
        {
            // Arrange
            var entity1  = new SimpleEntityRepresentation1("test-id");
            var entity2  = new SimpleEntityRepresentation2("test-id");
            var comparer = new EntityIdentityComparer <string>();

            // Act
            var result1 = comparer.GetHashCode(entity1);
            var result2 = comparer.GetHashCode(entity2);

            // Assert
            Assert.NotEqual(0, result1);
            Assert.Equal(result1, result2);
        }