public void TestInMemorySerializedCacheObject()
        {
            var cache = new InMemorySerializedCache("cache1", new TimeSpan(0, 2, 0));

            int hits = 0;

            Func <string> getter = () => { hits++; return(hits.ToString()); };

            string result;

            result = cache.Get("key", getter);
            Assert.AreEqual(1, hits);
            Assert.AreEqual("1", result);

            result = cache.Get("key", getter);
            Assert.AreEqual(1, hits);
            Assert.AreEqual("1", result);
        }
        public void TestInMemorySerializedCacheNull()
        {
            var cache = new InMemorySerializedCache("cache1", new TimeSpan(0, 2, 0));

            int misses = 0;

            Func <string> getter = () => { misses++; return(null); };

            string result;

            result = cache.Get("key", getter);
            Assert.AreEqual(1, misses);
            Assert.AreEqual(null, result);

            result = cache.Get("key", getter);
            Assert.AreEqual(1, misses);
            Assert.AreEqual(null, result);
        }
        public void TestInMemorySerializedCacheStruct()
        {
            var cache = new InMemorySerializedCache("cache1", new TimeSpan(0, 2, 0));

            int hits = 0;

            Func <int> getter = () => { hits++; return(hits); };

            int result;

            result = cache.Get("key", getter);
            Assert.AreEqual(1, hits);
            Assert.AreEqual(1, result);

            result = cache.Get("key", getter);
            Assert.AreEqual(1, hits);
            Assert.AreEqual(1, result);
        }
Example #4
0
        public void TestInMemorySerializedCacheObjectMutated()
        {
            var cache = new InMemorySerializedCache("cache1", new TimeSpan(0, 2, 0));

            List <string> value = new List <string> {
                "1"
            };

            Func <IEnumerable <object> > getter = () => { return(value); };

            IEnumerable <object> result;

            result = cache.Get("key", getter);
            CollectionAssert.AreEqual(new object[] { "1" }, result.ToArray());

            value.Add("2");

            result = cache.Get("key", getter);
            CollectionAssert.AreEqual(new object[] { "1" }, result.ToArray());
        }