예제 #1
0
        public void TestLeastRecentlyUsed()
        {
            int capacity = 8;
            var lruCache = SimpleCache.Build().SpecifyCapacity(capacity);
            var uuid     = Guid.NewGuid();
            var uuid2    = Guid.NewGuid();

            for (int i = 0; i < capacity * 2; i++)
            {
                if (i == 0)
                {
                    lruCache.Set(i, uuid);
                }
                else if (i == 1)
                {
                    lruCache.Set(i, uuid2);

                    Assert.AreEqual(uuid, lruCache.Get(0));
                }
                else
                {
                    Assert.AreEqual(uuid, lruCache.Get(0));
                    Assert.AreEqual(uuid2, lruCache.Get(1));

                    lruCache.Set(i, Guid.NewGuid());
                    Assert.LessOrEqual(lruCache.Count, capacity);

                    if (i >= capacity)
                    {
                        Assert.IsNull(lruCache.Get(i - capacity + 2));
                    }
                }
            }
        }
예제 #2
0
        public void TestSpecifyCapacityException()
        {
            var cacheWithCapcity = SimpleCache.Build().SpecifyCapacity(1);

            Assert.Throws <InvalidOperationException>(() => cacheWithCapcity.SpecifyCapacity(2));

            cache.Set(new object(), new object());
            Assert.Throws <InvalidOperationException>(() => cacheWithCapcity.SpecifyCapacity(3));
        }
예제 #3
0
        public void TestSpecifyCapacity()
        {
            int capacity         = 4;
            var cacheWithCapcity = SimpleCache.Build().SpecifyCapacity(capacity);

            for (int i = 0; i < capacity * 2; i++)
            {
                cacheWithCapcity.Set(i, i * i);
            }
            Assert.AreEqual(cacheWithCapcity.Count, capacity);
        }
        public void TestCreatedOrUpdated()
        {
            var cache = SimpleCache.Build();

            cache.Changed += new EventHandler <CacheEntryChangedEventArgs>(ChangedHandler);
            for (int i = 0; i < testCount; i++)
            {
                cache.Set(keys[i], DateTime.Now);
            }

            for (int i = 0; i < testCount; i++)
            {
                Assert.AreEqual(keys[i], events[CacheEventType.CreatedOrUpdated][i]);
            }
        }
        public void TestRemoved()
        {
            var cache = SimpleCache.Build().SpecifyCapacity(1);

            cache.Changed += new EventHandler <CacheEntryChangedEventArgs>(ChangedHandler);
            for (int i = 0; i < testCount; i++)
            {
                cache.Set(keys[i], DateTime.Now);
            }

            for (int i = 0; i < testCount - 1; i++)
            {
                Assert.AreEqual(keys[i], events[CacheEventType.Removed][i]);
            }
            Assert.IsFalse(events[CacheEventType.Removed].Contains(keys[testCount - 1]));
        }
예제 #6
0
 public void Setup()
 {
     cache = SimpleCache.Build();
 }