コード例 #1
0
        public static void GetHashCode___Should_not_be_equal___When_objects_have_different_property_values()
        {
            // Arrange
            var typeDescription1A = A.Dummy <TypeDescription>();
            var typeDescription1B = new TypeDescription {
                AssemblyQualifiedName = A.Dummy <string>(), Name = typeDescription1A.Name, Namespace = typeDescription1A.Namespace
            };

            var typeDescription2A = A.Dummy <TypeDescription>();
            var typeDescription2B = new TypeDescription {
                AssemblyQualifiedName = null, Name = typeDescription1A.Name, Namespace = typeDescription1A.Namespace
            };

            var typeDescription3A = A.Dummy <TypeDescription>();
            var typeDescription3B = new TypeDescription {
                AssemblyQualifiedName = typeDescription1A.AssemblyQualifiedName, Name = A.Dummy <string>(), Namespace = typeDescription1A.Namespace
            };

            var typeDescription4A = A.Dummy <TypeDescription>();
            var typeDescription4B = new TypeDescription {
                AssemblyQualifiedName = typeDescription1A.AssemblyQualifiedName, Name = null, Namespace = typeDescription1A.Namespace
            };

            var typeDescription5A = A.Dummy <TypeDescription>();
            var typeDescription5B = new TypeDescription {
                AssemblyQualifiedName = typeDescription1A.AssemblyQualifiedName, Name = typeDescription1A.Name, Namespace = A.Dummy <string>()
            };

            var typeDescription6A = A.Dummy <TypeDescription>();
            var typeDescription6B = new TypeDescription {
                AssemblyQualifiedName = typeDescription1A.AssemblyQualifiedName, Name = typeDescription1A.Name, Namespace = null
            };

            // Act
            var hash1A = typeDescription1A.GetHashCode();
            var hash1B = typeDescription1B.GetHashCode();

            var hash2A = typeDescription2A.GetHashCode();
            var hash2B = typeDescription2B.GetHashCode();

            var hash3A = typeDescription3A.GetHashCode();
            var hash3B = typeDescription3B.GetHashCode();

            var hash4A = typeDescription4A.GetHashCode();
            var hash4B = typeDescription4B.GetHashCode();

            var hash5A = typeDescription5A.GetHashCode();
            var hash5B = typeDescription5B.GetHashCode();

            var hash6A = typeDescription6A.GetHashCode();
            var hash6B = typeDescription6B.GetHashCode();

            // Assert
            hash1A.Should().NotBe(hash1B);
            hash2A.Should().NotBe(hash2B);
            hash3A.Should().NotBe(hash3B);
            hash4A.Should().NotBe(hash4B);
            hash5A.Should().NotBe(hash5B);
            hash6A.Should().NotBe(hash6B);
        }
コード例 #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (TypeDescription.Length != 0)
            {
                hash ^= TypeDescription.GetHashCode();
            }
            if (Query.Length != 0)
            {
                hash ^= Query.GetHashCode();
            }
            if (InlcudeRelatedEntities != false)
            {
                hash ^= InlcudeRelatedEntities.GetHashCode();
            }
            return(hash);
        }
コード例 #3
0
        public static void GetHashCode___Should_be_equal___When_objects_have_the_same_property_values()
        {
            // Arrange
            var typeDescription1A = new TypeDescription();
            var typeDescription1B = new TypeDescription {
                AssemblyQualifiedName = null, Name = null, Namespace = null
            };

            var typeDescription2A = A.Dummy <TypeDescription>();
            var typeDescription2B = new TypeDescription {
                AssemblyQualifiedName = typeDescription2A.AssemblyQualifiedName, Name = typeDescription2A.Name, Namespace = typeDescription2A.Namespace
            };

            // Act
            var hash1A = typeDescription1A.GetHashCode();
            var hash1B = typeDescription1B.GetHashCode();

            var hash2A = typeDescription2A.GetHashCode();
            var hash2B = typeDescription2B.GetHashCode();

            // Assert
            hash1A.Should().Be(hash1B);
            hash2A.Should().Be(hash2B);
        }