public void GenericOnDemandRefreshCache_Defaults_Tests()
 {
     using (var cache = new GenericOnDemandRefreshCache<string, object>())
     {
         Assert.IsNull(cache.Get("non-existant"));
     }
 }
        public void GenericOnDemandRefreshCache_Enumeration_Works()
        {
            var strategy = Expires.Never<int>();
            var cache = new GenericOnDemandRefreshCache<string, int>(
                strategy, int.Parse)
            {
                { "1", 1 },
                { "2", 2 },
                { "3", 3 },
            };

            foreach (var item in cache)
            {
                Assert.AreEqual(item.Value.Value, (int)cache[item.Key]);
            }

            // just to get 100%
            var enumerable = ((System.Collections.IEnumerable)cache).GetEnumerator();
        }
        public void RefreshAction_Populates_MissingCacheValues()
        {
            var strategy = Expires.Always<int>();
            Func<string, int> factory = (key) => int.Parse(key);
            var cache = new GenericOnDemandRefreshCache<string, int>(strategy, factory);

            Assert.AreEqual(1, cache.Get("1"));
            Assert.AreEqual(2, cache.Get("2"));
            Assert.AreEqual(1, cache.Get("1"));
            Assert.AreEqual(2, cache.Get("2"));
            Assert.AreEqual(2, cache.Count);

            Assert.AreEqual(0, cache.Statistics.Cleanings.Value);
            Assert.AreEqual(0, cache.Statistics.Evictions.Value);
            Assert.AreEqual(4, cache.Statistics.Requests.Value);
            Assert.AreEqual(2, cache.Statistics.Hits.Value);
            Assert.AreEqual(4, cache.Statistics.Updates.Value);
            Assert.AreEqual(2, cache.Statistics.Misses.Value);
        }