public void Item_should_be_removed_on_demand()
        {
            ICache cache = new PerpetualCache();
            cache = new SynchronizedCache(cache);

            cache[0] = 0;
            Assert.That(cache[0], Is.Not.Null);

            cache.Remove(0);
            Assert.That(cache[0], Is.Null);
        }
Example #2
0
        public void Equals_and_hashCode_on_decorated_cache_should_be_equal()
        {
            PerpetualCache cache = new PerpetualCache();
            cache.Id = "test_cache";

            Assert.That(cache, Is.EqualTo(cache));
            Assert.That(cache.Equals( new SynchronizedCache(cache) ), Is.True );
            Assert.That(cache.Equals( new SharedCache(cache) ), Is.True );
            Assert.That(cache.Equals( new LoggingCache(cache) ), Is.True );
            Assert.That(cache.Equals( new ScheduledCache(cache, long.MinValue) ), Is.True );
        }
        public void Demonstrate_that_copies_are_equals()
        {
            ICache cache = new PerpetualCache();
            cache = new SharedCache(cache);

            for (int i = 0; i < 100000; i++)
            {
                cache[i] = i;
                Assert.That(cache[i], Is.EqualTo(i));
            }
        }
        public void Item_should_be_removed_on_demand()
        {
            ICache cache = new PerpetualCache();
            cache = new ScheduledCache(cache, 60000);
            cache = new LoggingCache(cache);

            cache[0] = 0;
            Assert.That(cache[0], Is.Not.Null);

            cache.Remove(0);
            Assert.That(cache[0], Is.Null);
        }
        public void Demonstrate_how_all_objects_are_kept()
        {
            ICache cache = new PerpetualCache();
            cache = new SynchronizedCache(cache);

            for (int i = 0; i < 100000; i++)
            {
                cache[i] = i;
                Assert.That(cache[i], Is.EqualTo(i));
            }

            Assert.That(cache.Size, Is.EqualTo(100000));
        }
 public void All_objects_should_be_flush_after_a_certain_time()
 {
     ICache cache = new PerpetualCache();
     cache = new ScheduledCache(cache, 1);
     cache = new LoggingCache(cache);
     for (int i = 0; i < 100; i++)
     {
         cache[i] = i;
         Assert.That(cache[i], Is.EqualTo(i));
     }
     Thread.Sleep(new TimeSpan(0,0,1,5));
     Assert.That(cache.Size, Is.EqualTo(0));
 }
        public void Cache_should_be_clear_on_demand()
        {
            ICache cache = new PerpetualCache();
            cache = new SynchronizedCache(cache);

            for (int i = 0; i < 5; i++)
            {
                cache[i] = i;
            }

            Assert.That(cache[0], Is.Not.Null);
            Assert.That(cache[4], Is.Not.Null);
            cache.Clear();
            Assert.That(cache[0], Is.Null);
            Assert.That(cache[4], Is.Null);
        }