コード例 #1
0
        /// <summary>
        /// Returns copy of cached object
        /// </summary>
        public void TestReturnCopyOfCachedOject()
        {
            CacheModel cacheModel = new CacheModel("test", typeof(LruCache).FullName, 60, 1, true);

            Order order = new Order(); 
            order.CardNumber = "CardNumber";
            order.Date = DateTime.Now;
            order.LineItemsCollection = new LineItemCollection();

            LineItem item = new LineItem();
            item.Code = "Code1";
            order.LineItemsCollection.Add(item);

            item = new LineItem();
            item.Code = "Code2";
            order.LineItemsCollection.Add(item);

            CacheKey key = new CacheKey();
            key.Update(order);

            int firstId = HashCodeProvider.GetIdentityHashCode(order);
            cacheModel[ key ] = order;

            Order order2 = cacheModel[ key ] as Order;
            int secondId = HashCodeProvider.GetIdentityHashCode(order2);
            Assert.AreNotEqual(firstId, secondId, "hasCode equal");

        }
コード例 #2
0
        /// <summary>
        /// Returns reference to same instance of cached object
        /// </summary>
        public void TestReturnInstanceOfCachedOject()
        {
            CacheModel cacheModel = new CacheModel("test", typeof(LruCache).FullName, 60, 1, false);

            //cacheModel.FlushInterval = interval;
            //cacheModel.IsReadOnly = true;
            //cacheModel.IsSerializable = false;

            Order order = new Order(); 
            order.CardNumber = "CardNumber";
            order.Date = DateTime.Now;
            order.LineItemsCollection = new LineItemCollection();
            LineItem item = new LineItem();
            item.Code = "Code1";
            order.LineItemsCollection.Add(item);
            item = new LineItem();
            item.Code = "Code2";
            order.LineItemsCollection.Add(item);

            CacheKey key = new CacheKey();
            key.Update(order);

            int firstId = HashCodeProvider.GetIdentityHashCode(order);
            cacheModel[ key ] = order;

            Order order2 = cacheModel[ key ] as Order;
            int secondId = HashCodeProvider.GetIdentityHashCode(order2);
            Assert.AreEqual(firstId, secondId, "hasCode different");
        }
コード例 #3
0
ファイル: CacheKeyTest.cs プロジェクト: techvenky/mybatisnet
        public void CacheKeys_should_not_be_equal_due_to_order()
        {
            CacheKey key1 = new CacheKey(new Object[] { 1, "hello", null });
            CacheKey key2 = new CacheKey(new Object[] { 1, null, "hello" });

            Assert.That(key1, Is.Not.EqualTo(key2));
            Assert.That(key2, Is.Not.EqualTo(key1));
            Assert.That(key1.GetHashCode(), Is.Not.EqualTo(key2.GetHashCode()));
            Assert.That(key1.ToString(), Is.Not.EqualTo(key2.ToString()));
        }
コード例 #4
0
ファイル: CacheKeyTest.cs プロジェクト: techvenky/mybatisnet
        public void CacheKeys_should_not_be_equal()
        {
            DateTime date = DateTime.Now;
            CacheKey key1 = new CacheKey(new Object[] { 1, "hello", null, new DateTime(date.Ticks) });
            CacheKey key2 = new CacheKey(new Object[] { 1, "hello", null, new DateTime(date.Ticks+5) });

            Assert.That(key1, Is.Not.EqualTo(key2));
            Assert.That(key2, Is.Not.EqualTo(key1));
            Assert.That(key1.GetHashCode(), Is.Not.EqualTo(key2.GetHashCode()));
            Assert.That(key1.ToString(), Is.Not.EqualTo(key2.ToString()));
        }
コード例 #5
0
ファイル: CacheTest.cs プロジェクト: jetwind/MyBatisNet
        public void TestCacheHit()
        {
            CacheModel cache = GetCacheModel();

            CacheKey key = new CacheKey();
            key.Update("testKey");

            string value = "testValue";
            cache[key] = value;

            object returnedObject = cache[key];
            Assert.AreEqual(value, returnedObject);
            Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(value), HashCodeProvider.GetIdentityHashCode(returnedObject));
        }
コード例 #6
0
ファイル: CacheKeyTest.cs プロジェクト: techvenky/mybatisnet
        public void CacheKeys_empty_and_null_should_be_equal()
        {
            CacheKey key1 = new CacheKey();
            CacheKey key2 = new CacheKey();

            Assert.That(key1, Is.EqualTo(key2));
            Assert.That(key2, Is.EqualTo(key1));

            key1.Update(null);
            key2.Update(null);

            Assert.That(key1, Is.EqualTo(key2));
            Assert.That(key2, Is.EqualTo(key1));

            key1.Update(null);
            key2.Update(null);

            Assert.That(key1, Is.EqualTo(key2));
            Assert.That(key2, Is.EqualTo(key1));
        }
コード例 #7
0
ファイル: CacheTest.cs プロジェクト: techvenky/mybatisnet
        public void TestCacheHitMiss() 
        {
            CacheModel cache = GetCacheModel();

            CacheKey key = new CacheKey();
            key.Update("testKey");

            string value = "testValue";
            cache[key] = value;

            object returnedObject = cache[key];
            Assert.AreEqual(value, returnedObject);
            Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(value), HashCodeProvider.GetIdentityHashCode(returnedObject));

            CacheKey wrongKey = new CacheKey();
            wrongKey.Update("wrongKey");

            returnedObject = cache[wrongKey];
            Assert.IsTrue(!value.Equals(returnedObject));
            Assert.IsNull(returnedObject) ;
            //Assert.AreEqual(0.5, cache.HitRatio);
        }
コード例 #8
0
ファイル: CacheTest.cs プロジェクト: techvenky/mybatisnet
        public void TestCacheMiss() 
        {
            CacheModel cache = GetCacheModel();

            CacheKey key = new CacheKey();
            key.Update("testKey");

            string value = "testValue";
            cache[key] = value;

            CacheKey wrongKey = new CacheKey();
            wrongKey.Update("wrongKey");

            object returnedObject = cache[wrongKey];
            Assert.IsTrue(!value.Equals(returnedObject));
            Assert.IsNull(returnedObject) ;
            //Assert.AreEqual(0, cache.HitRatio);
        }
コード例 #9
0
ファイル: CacheTest.cs プロジェクト: techvenky/mybatisnet
        public void TestCacheNullObject()
        {
            CacheModel cache = GetCacheModel();
            CacheKey key = new CacheKey();
            key.Update("testKey");

            cache[key] = null;

            object returnedObject = cache[key];
            Assert.AreEqual(CacheModel.NULL_OBJECT, returnedObject);
            Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(CacheModel.NULL_OBJECT), HashCodeProvider.GetIdentityHashCode(returnedObject));
        }
コード例 #10
0
ファイル: CacheKeyTest.cs プロジェクト: techvenky/mybatisnet
        public void CacheKey_with_same_hashcode_shoul_be_equal()
        {
            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. 
        */

            Assert.Ignore("The .NET 2.0 CLR uses a different algorithm for string hashing than the .NET 1.1 CLR.");

        }
コード例 #11
0
ファイル: CacheKeyTest.cs プロジェクト: techvenky/mybatisnet
        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.
        }
コード例 #12
0
ファイル: CacheKeyTest.cs プロジェクト: techvenky/mybatisnet
        public void CacheKey_with_2_params_having_same_hashcode_shoul_not_be_equal()
        {
            CacheKey key1 = new CacheKey();
            CacheKey key2 = new CacheKey();

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

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

            Assert.Ignore("The .NET 2.0 CLR uses a different algorithm for string hashing than the .NET 1.1 CLR.");
        }
コード例 #13
0
ファイル: CacheModel.cs プロジェクト: techvenky/mybatisnet
        /// <summary>
		/// Adds an item with the specified key and value into cached data.
		/// Gets a cached object with the specified key.
		/// </summary>
		/// <value>The cached object or <c>null</c></value>
        public object this[CacheKey key]
        {
            get { return cache[key]; }
            set { cache[key] = value;}
        }