public void Verify_that_equals_returns_expected_result()
        {
            this.cachekey_1 = new CacheKey(this.guid_1, null);
            this.cachekey_2 = new CacheKey(this.guid_1, null);
            Assert.IsTrue(cachekey_1.Equals(cachekey_2));

            this.cachekey_1 = new CacheKey(this.guid_1, null);
            this.cachekey_2 = new CacheKey(this.guid_2, null);
            Assert.IsFalse(cachekey_1.Equals(cachekey_2));

            this.cachekey_1 = new CacheKey(this.guid_1, this.guid_2);
            this.cachekey_2 = new CacheKey(this.guid_1, this.guid_2);
            Assert.IsTrue(cachekey_1.Equals(cachekey_2));

            this.cachekey_1 = new CacheKey(this.guid_1, this.guid_2);
            this.cachekey_2 = new CacheKey(this.guid_2, this.guid_1);
            Assert.IsFalse(cachekey_1.Equals(cachekey_2));

            this.cachekey_1 = new CacheKey(this.guid_1, this.guid_2);
            this.cachekey_2 = new CacheKey(this.guid_1, null);
            Assert.IsFalse(cachekey_1.Equals(cachekey_2));

            this.cachekey_1 = new CacheKey(this.guid_1, null);
            this.cachekey_2 = new CacheKey(this.guid_1, this.guid_2);
            Assert.IsFalse(cachekey_1.Equals(cachekey_2));
        }
Esempio n. 2
0
        public void Equals_WithNullReference_ReturnsFalse()
        {
            var subjectA = new CacheKey("OK", 0, 0);
            var subjectB = (CacheKey)null;

            Assert.That(subjectA.Equals(subjectB), Is.False);
        }
Esempio n. 3
0
        public void Equals_WithIdenticalCacheKeys_ReturnsTrue([Values(0, 1, 2)] int stateKey, [Values(0, 1, 2)] int location)
        {
            var subjectA = new CacheKey("OK", stateKey, location);
            var subjectB = new CacheKey("OK", stateKey, location);

            Assert.That(subjectA.Equals(subjectB), Is.True);
        }
Esempio n. 4
0
        public void Equals_WithDifferentCacheKeys_ReturnsFalse()
        {
            var subjectA = new CacheKey("OK", 0, 0);
            var subjectB = new CacheKey("OK", 1, 0);

            Assert.That(subjectA.Equals(subjectB), Is.False);
        }
Esempio n. 5
0
        /// <summary>
        /// Compara a instancia o objeto informado.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            bool            flag        = false;
            MetaInformation information = obj as MetaInformation;

            if (information != null)
            {
                flag = CacheKey.Equals(information.CacheKey);
            }
            return(flag);
        }
Esempio n. 6
0
        private static void DoTestClassEquals(long firstLong, long secondLong)
        {
            // Two cache keys are equal except for the parameter.
            CacheKey key = new CacheKey();

            key.Update(firstLong);

            CacheKey aDifferentKey = new CacheKey();

            key.Update(secondLong);

            Assert.IsFalse(aDifferentKey.Equals(key));             // should not be equal.
        }
        public void KeysShouldBeEqualWhenItemAndProviderAreEqual()
        {
            // Arrange
            const int itemId     = 1;
            const int providerId = 2;

            var a = new CacheKey(providerId, itemId);
            var b = new CacheKey(providerId, itemId);

            // Act
            var ab = a.Equals(b);
            var ba = b.Equals(a);

            // Assert
            Assert.True(ab);
            Assert.True(ba);
        }
        public void KeysShouldBeDifferentWhenDifferentItemIdIsUsed()
        {
            // Arrange
            const int providerId = 1;
            const int itemA      = 2;
            const int itemB      = 3;

            var a = new CacheKey(providerId, itemA);
            var b = new CacheKey(providerId, itemB);

            // Act
            var ab = a.Equals(b);
            var ba = b.Equals(a);

            // Assert
            Assert.False(ab);
            Assert.False(ba);
        }
        public void KeysShouldBeDifferentWhenDifferentProviderIsUsed()
        {
            // Arrange
            const string providerA = "1";
            const string providerB = "2";
            const string itemId    = "3";

            var a = new CacheKey(providerA, itemId);
            var b = new CacheKey(providerB, itemId);

            // Act
            var ab = a.Equals(b);
            var ba = b.Equals(a);

            // Assert
            Assert.False(ab);
            Assert.False(ba);
        }
Esempio n. 10
0
        public void CacheKeyWithTwoParamsSameHashcode()
        {
            CacheKey key1 = new CacheKey();
            CacheKey key2 = new CacheKey();

            key1.Update("HS1CS001");
            key1.Update("HS1D4001");

            key2.Update("HS1D4001");
            key2.Update("HS1CS001");

#if dotnet2
            Assert.Ignore("The .NET 2.0 CLR uses a different algorithm for string hashing than the .NET 1.1 CLR.");
#else
            Assert.AreEqual(key1.GetHashCode(), key2.GetHashCode(), "Expect same hashcode.");
            Assert.IsFalse(key1.Equals(key2), "Expect not equal");
#endif
        }
Esempio n. 11
0
        public void CacheKeyWithSameHashcode()
        {
            CacheKey key1 = new CacheKey();
            CacheKey key2 = new CacheKey();

            key1.Update("HS1CS001");
            key2.Update("HS1D4001");

            /*
             * The string hash algorithm is not an industry standard and is not guaranteed to produce the same behaviour between versions.
             * And in fact it does not. The .NET 2.0 CLR uses a different algorithm for string hashing than the .NET 1.1 CLR.
             */

#if dotnet2
            Assert.Ignore("The .NET 2.0 CLR uses a different algorithm for string hashing than the .NET 1.1 CLR.");
#else
            Assert.AreEqual(key1.GetHashCode(), key2.GetHashCode(), "Expect same hashcode.");
            Assert.IsFalse(key1.Equals(key2), "Expect not equal");
#endif
        }