Esempio n. 1
0
        public void ShouldReturnValueFromCache()
        {
            RemotingPolicyInjector factory = new RemotingPolicyInjector(GetCachingPolicies());
            CachingTarget          target  = factory.Create <CachingTarget>();

            double input = 12;

            ClearCache(input);
            HttpRuntime.Cache.Add(keyGenerator.CreateCacheKey(calculateMethod, input), new object[] { 100.0 },
                                  null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 5, 0), CacheItemPriority.Normal,
                                  null);

            double result = target.Calculate(input);

            Assert.AreEqual(100.0, result);
        }
Esempio n. 2
0
        public void ShouldAddItemToCache()
        {
            RemotingPolicyInjector factory = new RemotingPolicyInjector(GetCachingPolicies());
            CachingTarget          target  = factory.Create <CachingTarget>();

            double input = 7;

            ClearCache(input);

            Assert.IsNull(HttpRuntime.Cache.Get(keyGenerator.CreateCacheKey(calculateMethod, input)));

            target.Calculate(input);

            object[] cachedValue = (object[])HttpRuntime.Cache.Get(keyGenerator.CreateCacheKey(calculateMethod, input));
            Assert.IsNotNull(cachedValue);
            Assert.IsTrue(cachedValue[0] is double);
            Assert.AreEqual(14.0, (double)cachedValue[0]);
        }