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 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 Ctor_CacheName()
        {
            LoggingCache <int, string> loggingCache;
            ICache <int, string>       cache;
            const string cacheName = "foo";

            cache = new Mock <ICache <int, string> >().Object;

            loggingCache = new LoggingCache <int, string>(cache, cacheName);

            Assert.That(loggingCache, Has.Property("InnerCache").EqualTo(cache));
            Assert.That(loggingCache, Has.Property("Name").EqualTo(cacheName));
            Assert.That(loggingCache, Has.Property("MetricReporter").Not.Null);
        }
        public void Ctor_CacheNameCategorySync()
        {
            LoggingCache <int, string> loggingCache;
            ICache <int, string>       cache;
            const string cacheName = "foo";
            ILoggingCacheMetricReporter metricReporter;

            cache          = new Mock <ICache <int, string> >().Object;
            metricReporter = new Mock <ILoggingCacheMetricReporter>().Object;

            loggingCache = new LoggingCache <int, string>(cache, cacheName, metricReporter);

            Assert.That(loggingCache, Has.Property("InnerCache").EqualTo(cache));
            Assert.That(loggingCache, Has.Property("Name").EqualTo(cacheName));
            Assert.That(loggingCache, Has.Property("MetricReporter").EqualTo(metricReporter));
        }
        public void Cache_should_be_clear_on_demand()
        {
            ICache cache = new PerpetualCache();

            cache = new ScheduledCache(cache, 60000);
            cache = new LoggingCache(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);
        }
        public void Indexer_CacheHit()
        {
            LoggingCache <int, int>    loggingCache;
            DictionaryCache <int, int> dictionaryCache;
            const string cacheName = "Cache";
            const int    testKey   = 1;
            const int    testValue = 2;
            Mock <ILoggingCacheMetricReporter> metricReporterMock;

            metricReporterMock = new Mock <ILoggingCacheMetricReporter>(MockBehavior.Strict);
            metricReporterMock.Setup(lcmr => lcmr.AddSizeCallback(cacheName, It.IsAny <Func <long> >()));
            metricReporterMock.Setup(lcmr => lcmr.AddHitsAndMissesCallback(cacheName, It.IsAny <Func <HitsAndMisses> >()));
            metricReporterMock.Setup(lcmr => lcmr.NotifyHitsAndMissesChange(cacheName));

            dictionaryCache          = new DictionaryCache <int, int>();
            dictionaryCache[testKey] = testValue;
            loggingCache             = new LoggingCache <int, int>(dictionaryCache, cacheName, metricReporterMock.Object);

            Assert.That(loggingCache[testKey], Is.EqualTo(testValue));
            metricReporterMock.VerifyAll();
        }
        public void BasicTest()
        {
            LoggingCache <int, int>    loggingCache;
            DictionaryCache <int, int> dictionaryCache;
            const int maxCached = 200;

            using (AsynchronousLoggingCacheMetricReporter metricReporter = new AsynchronousLoggingCacheMetricReporter())
            {
                dictionaryCache = new DictionaryCache <int, int>();
                loggingCache    = new LoggingCache <int, int>(dictionaryCache, "test", metricReporter);
                for (int i = 0; i < maxCached; i++)
                {
                    loggingCache.Add(i, i);
                }

                // Hits
                int b = loggingCache[20];
                int c = loggingCache[21];

                // Misses
                int d = loggingCache[maxCached + 1];
                int e = loggingCache[maxCached + 2];
            }
        }