public void GenericOnDemandRefreshCache_Defaults_Tests()
 {
     var timespan = TimeSpan.FromDays(1);
     using (var cache = new SpecificBackgroundRefreshCache<string, object>(timespan))
     {
         Assert.IsNull(cache.Get("non-existant"));
     }
 }
        public void RefreshAction_Populates_MissingCacheValues()
        {
            var timespan = TimeSpan.FromMilliseconds(50);
            var strategy = Expires.Always<int>();
            Func<string, int> factory = (key) => int.Parse(key);
            var cache = new SpecificBackgroundRefreshCache<string, int>(timespan, strategy, factory);

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

            System.Threading.Thread.Sleep(100);
            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(4, cache.Statistics.Hits.Value);
            Assert.AreEqual(4, cache.Statistics.Updates.Value);
            Assert.AreEqual(0, cache.Statistics.Misses.Value);
        }
        public void SpecificBackgroundRefreshCache_Enumeration_Works()
        {
            var strategy = Expires.Never<object>();
            var cache = new SpecificBackgroundRefreshCache<string, object>(
                TimeSpan.FromDays(1), strategy, key => (object)int.Parse(key))
            {
                { "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();
        }