示例#1
0
        public void GivenSimpleValues_CorrectValueReturned()
        {
            var cache = new FunctionCacheProvider(new MemoryCache("Test"));

            var result = cache.ExecuteWithCache("Test1", () => SimpleAddition(2, 3), DateTimeOffset.Now.AddSeconds(10));

            Assert.AreEqual(5, result);
        }
示例#2
0
        public void GivenSimpleValues_WithDifferentParams_EnsureCachedSeparately()
        {
            var cache = new FunctionCacheProvider(new MemoryCache("Test"));
            var sw1   = new Stopwatch();

            sw1.Start();
            cache.ExecuteWithCache("Test2", () => SimpleAdditionSlow(2, 3, 2000), DateTimeOffset.Now.AddSeconds(10), 2, 3);
            sw1.Stop();

            var sw2 = new Stopwatch();

            sw2.Start();
            cache.ExecuteWithCache("Test2", () => SimpleAdditionSlow(2, 3, 2000), DateTimeOffset.Now.AddSeconds(10), 2, 4);
            sw2.Stop();

            Assert.IsTrue(sw1.ElapsedMilliseconds >= 2000 && sw2.ElapsedMilliseconds >= 2000);
        }
示例#3
0
        public void GivenSimpleValues_WithSlowMethod_EnsureCacheExpires()
        {
            var cache = new FunctionCacheProvider(new MemoryCache("Test"));
            var sw1   = new Stopwatch();

            sw1.Start();
            cache.ExecuteWithCache("Test3", () => SimpleAdditionSlow(2, 3, 2000), DateTimeOffset.Now.AddSeconds(2));
            sw1.Stop();

            Thread.Sleep(5000);

            var sw2 = new Stopwatch();

            sw2.Start();
            cache.ExecuteWithCache("Test3", () => SimpleAdditionSlow(2, 3, 2000), DateTimeOffset.Now.AddSeconds(2));
            sw2.Stop();

            Assert.IsTrue(sw1.ElapsedMilliseconds >= 2000 && sw2.ElapsedMilliseconds >= 2000);
        }