Exemple #1
0
        public void ShouldBeAbleToCacheNullReturnValues()
        {
            RemotingPolicyInjector factory = new RemotingPolicyInjector(GetCachingPolicies());
            CachingTarget          target  = factory.Create <CachingTarget>();

            string result  = target.SometimesReturnsNull(false);
            string result2 = target.SometimesReturnsNull(true);
        }
Exemple #2
0
        public void ShouldNotCacheVoidMethods()
        {
            RemotingPolicyInjector factory = new RemotingPolicyInjector(GetCachingPolicies());
            CachingTarget          target  = factory.Create <CachingTarget>();

            Assert.AreEqual(0, target.Count);
            target.IncrementCount();
            Assert.AreEqual(1, target.Count);
            target.IncrementCount();
            Assert.AreEqual(2, target.Count);
        }
Exemple #3
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);
        }
Exemple #4
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]);
        }