Пример #1
0
        public void CanTestTypeKeysEquality(TypeKey key1, TypeKey key2, bool expectedResult)
        {
            //-- act

            var actualResult1      = key1.Equals(key2);
            var actualResult2      = key2.Equals(key1);
            var actualResult1Op    = (key1 == key2);
            var actualResult2Op    = (key2 == key1);
            var actualResult1NotOp = (key1 != key2);
            var actualResult2NotOp = (key2 != key1);

            var hash1 = key1.GetHashCode();
            var hash2 = key2.GetHashCode();

            //-- assert

            actualResult1.Should().Be(expectedResult);
            actualResult2.Should().Be(expectedResult);
            actualResult1Op.Should().Be(expectedResult);
            actualResult2Op.Should().Be(expectedResult);
            actualResult1NotOp.Should().Be(!expectedResult);
            actualResult2NotOp.Should().Be(!expectedResult);

            if (expectedResult)
            {
                hash2.Should().Be(hash1);
            }
        }
Пример #2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        private static void AssertKeysEqual(TypeKey key1, TypeKey key2)
        {
            var hashCode1 = key1.GetHashCode();
            var hashCode2 = key2.GetHashCode();

            Assert.That(hashCode1, Is.EqualTo(hashCode2));

            Assert.That(key1.Equals(key2), Is.True);
            Assert.That(key2.Equals(key1), Is.True);
            Assert.That(key1.Equals((object)key2), Is.True);
            Assert.That(key2.Equals((object)key1), Is.True);
        }
Пример #3
0
        public override int GetHashCode()
        {
            int hashProductNumber = Number == null ? 0 : Number.GetHashCode();

            int hashProductTypeKey  = TypeKey.GetHashCode();
            int hashProductId       = Id.GetHashCode();
            int hashProductInnerId  = InnerId.GetHashCode();
            int hashProductLocation = IsHome.GetHashCode();

            return(hashProductNumber ^
                   hashProductId ^
                   hashProductInnerId ^
                   hashProductTypeKey ^
                   hashProductLocation);
        }
Пример #4
0
            /// <summary>
            /// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
            /// </summary>
            /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
            /// <returns>
            ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
            /// </returns>
            public override bool Equals(object obj)
            {
                if (obj == null)
                {
                    return(false);
                }
                if (ReferenceEquals(this, obj))
                {
                    return(true);
                }
                if (!obj.GetType().Equals(GetType()))
                {
                    return(false);
                }

                bool result = false;

                TypeKey other = (TypeKey)obj;

                if (other.TypeName.Equals(this.TypeName))
                {
                    int localHash = this.GetHashCode();
                    int otherHash = other.GetHashCode();
                    if (localHash == otherHash && other.AsmName == null && this.AsmName == null)
                    {
                        result = true;
                    }
                    else if (localHash == otherHash &&
                             other.AsmName != null && this.AsmName != null &&
                             other.AsmName.KeyPair != null && this.AsmName.KeyPair != null)
                    {
                        result = Arrays.DeepEquals(other.AsmName.KeyPair.PublicKey, this.AsmName.KeyPair.PublicKey);
                    }
                    else if (localHash == otherHash &&
                             other.AsmName != null && this.AsmName != null &&
                             other.AsmName.KeyPair == null && this.AsmName.KeyPair == null)
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }

                return(result);
            }
Пример #5
0
 public override int GetHashCode() => TypeKey.GetHashCode() ^ Id.GetHashCode();
        public void GetHashCodeReturnsHashCode(Type type, string registrationName)
        {
            var typeKey = new TypeKey(type, registrationName);

            typeKey.GetHashCode().Should().Be(typeKey.HashCode);
        }
Пример #7
0
 public override int GetHashCode() =>
 _refKind.GetHashCode() ^ _type.GetHashCode() << 3;