예제 #1
0
        public void TestNamedCache3()
        {
            Assert.AreEqual(0, cache2.Hits);
            Assert.AreEqual(0, cache2.Misses);

            var service = new Service2();
            IEnumerable <string> result;

            result = service.MethodToCache1(2.0);
            Assert.AreEqual(0, cache2.Hits);
            Assert.AreEqual(2, cache2.Misses);
            LinqAssert.AreSame(new[] { "0.9", "1.9" }, result);

            result = service.MethodToCache1(2.0);
            Assert.AreEqual(1, cache2.Hits);
            Assert.AreEqual(2, cache2.Misses);
            LinqAssert.AreSame(new[] { "0.9", "1.9" }, result);

            result = service.MethodToCache1(2);
            Assert.AreEqual(1, cache2.Hits);
            Assert.AreEqual(4, cache2.Misses);
            LinqAssert.AreSame(new[] { "1", "2" }, result);

            result = service.MethodToCache1(2);
            Assert.AreEqual(2, cache2.Hits);
            Assert.AreEqual(4, cache2.Misses);
            LinqAssert.AreSame(new[] { "1", "2" }, result);
        }
예제 #2
0
        public void TestMongoDbCacheObjectMutated()
        {
            var cache = new MongoDbCache(
                "cache1",
                new MongoDbCachePolicy
            {
                DatabaseName = "TestCacheDb",
            });

            cache.ClearAll();

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

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

            IEnumerable <object> result;

            result = cache.Get("key", getter);
            LinqAssert.AreSame(new object[] { "1" }, result);

            value.Add("2");

            result = cache.Get("key", getter);
            LinqAssert.AreSame(new object[] { "1" }, result);
        }
예제 #3
0
        public void TestNamedCache2()
        {
            var service = new Service2();
            var result  = service.MethodToCache1(2);

            LinqAssert.AreSame(new [] { "1", "2" }, result);
            LinqAssert.AreSame(new[] { "1", "2" }, result);
        }
        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);
            LinqAssert.AreSame(new object[] { "1" }, result);

            value.Add("2");

            result = cache.Get("key", getter);
            LinqAssert.AreSame(new object[] { "1" }, result);
        }