Пример #1
0
 public void CheckAndSetCache_Clean_Works()
 {
     var strategy = new GenericExpirationStrategy<object>(v => (int)v.Value == 2);
     using (var cache = new CheckAndSetCache<string, object>(strategy))
     {
         cache.Add("1", 1);
         cache.Add("2", 2);
         cache.Add("3", 3);
         Assert.AreEqual(3, cache.Count);
         cache.Clean();
         Assert.AreEqual(2, cache.Count);
     }
 }
Пример #2
0
 public void CheckAndSetCache_Clear_Works()
 {
     var strategy = Expires.Always<object>();
     using (var cache = new CheckAndSetCache<string, object>(strategy))
     {
         cache.Add("1", 1);
         cache.Add("2", 2);
         cache.Add("3", 3);
         Assert.AreEqual(3, cache.Count);
         cache.Clear();
         Assert.AreEqual(0, cache.Count);
     }
 }
Пример #3
0
        public void CheckAndSetCache_AddAndRemove_Works()
        {
            using (var cache = new CheckAndSetCache<string, object>())
            {
                cache.Add("1", 1);
                cache.Add("2", (k) => (object)int.Parse(k));
                cache.Add("3", 3, (k) => (object)int.Parse(k));
                Assert.AreEqual(3, cache.Count);

                var result = new List<string> { "1", "2", "3" }.All(cache.Remove);
                Assert.IsTrue(result);
                Assert.AreEqual(0, cache.Count);
            }
        }
Пример #4
0
 public void CheckAndSetCache_GetExpired_Works()
 {
     var strategy = Expires.Always<object>();
     var cache = new CheckAndSetCache<string, object>(strategy);
     cache.Add("1", 1);
     Assert.AreEqual(null, cache.Get("1"));
     Assert.AreEqual(null, cache.Get("2"));
 }