public void FixedExpirationCommon()
        {
            var now     = DateTime.Now;
            var expires = now.AddMinutes(30);

            _dtp.Now.Returns(now);
            var cache = new CacheDependencyDateTime(_dtp, expires);

            Assert.IsFalse(cache.HasExpired);
            Assert.IsFalse(cache.Sliding);
            Assert.IsTrue(cache.Expires == expires);
        }
        public void FixedExpirationSlidingTimeSpanCommon()
        {
            var now       = DateTime.Now;
            var expiresIn = new TimeSpan(0, 30, 0);
            var expires   = now.Add(expiresIn);

            _dtp.Now.Returns(now);
            var cache = new CacheDependencyDateTime(_dtp, expiresIn, true);

            Assert.IsFalse(cache.HasExpired);
            Assert.IsTrue(cache.Sliding);
            Assert.IsTrue(cache.Expires == expires);
        }
        public void FixedExpirationHasExpired()
        {
            var now     = DateTime.Now;
            var expires = now.AddMinutes(30);

            _dtp.Now.Returns(now);
            var cache = new CacheDependencyDateTime(_dtp, expires);

            // now move the clock past the expiration
            _dtp.Now.Returns(expires.AddMilliseconds(1));

            Assert.IsTrue(cache.HasExpired);
            Assert.IsTrue(cache.Expires == expires);
            Assert.IsFalse(cache.Sliding);
        }
        public void SimpleDateTimeExpiration()
        {
            var expires = DateTime.Now.AddMinutes(5);

            var exp = new CacheDependencyDateTime(dtp, expires);

            cln.Add(exp);
            Assert.IsTrue(cln.Count == 1);
            Assert.IsFalse(cln.HasAnyExpired());
            Assert.IsFalse(cln.HasAnyChanged());

            dtp.Now.Returns(expires.AddMilliseconds(1));
            Assert.IsTrue(cln.Count == 1);
            Assert.IsTrue(cln.HasAnyExpired());
            Assert.IsTrue(cln.HasAnyChanged());
        }
        public void FixedExpirationSlidingTimeSpanSlideAfterExpiration()
        {
            var now       = DateTime.Now;
            var expiresIn = new TimeSpan(0, 30, 0);
            var expires   = now.Add(expiresIn);

            _dtp.Now.Returns(now);
            var cache = new CacheDependencyDateTime(_dtp, expiresIn, true);

            Assert.IsTrue(cache.Expires == expires);

            var newNow = expires.AddMinutes(5);

            _dtp.Now.Returns(newNow);
            Assert.IsTrue(cache.HasExpired);

            cache.SlideExpiration();

            Assert.IsTrue(cache.HasExpired);
            Assert.IsTrue(cache.Expires == expires);
        }
        public void SlidingDateTimeExpiration()
        {
            var expiresIn = new TimeSpan(0, 30, 0);
            var expires   = dtp.Now.Add(expiresIn);

            var exp = new CacheDependencyDateTime(dtp, expiresIn, true);

            cln.Add(exp);
            Assert.IsTrue(cln.Count == 1);
            Assert.IsFalse(cln.HasAnyExpired());
            Assert.IsFalse(cln.HasAnyChanged());
            var first = (CacheDependencyDateTime)cln[0];

            Assert.IsTrue(first.Expires == expires);

            // move a few minutes forward but within the expiration window
            var newTimeNow = DateTime.Now.AddSeconds(expiresIn.TotalSeconds / 2);

            dtp.Now.Returns(newTimeNow);
            Assert.IsFalse(cln.HasAnyExpired());
            Assert.IsFalse(cln.HasAnyChanged());

            first = (CacheDependencyDateTime)cln[0];
            Assert.IsTrue(first.Expires == expires);

            var newExpires = newTimeNow.Add(expiresIn);

            cln.SlideExpiration();
            Assert.IsFalse(cln.HasAnyExpired());
            Assert.IsFalse(cln.HasAnyChanged());
            Assert.IsTrue(first.Expires == newExpires);

            var expiredTime = newExpires.AddMilliseconds(1);

            dtp.Now.Returns(expiredTime);
            Assert.IsTrue(cln.HasAnyExpired());
            Assert.IsTrue(cln.HasAnyChanged());
        }
Example #7
0
        public void Add(string key, object value, TimeSpan expiresIn, bool sliding = false)
        {
            var expireAction = new CacheDependencyDateTime(_diskManager.DateTime, expiresIn, sliding);

            AddItem(key, value, expireAction);
        }
Example #8
0
        public void Add(string key, object value, DateTime expires)
        {
            var expireAction = new CacheDependencyDateTime(_diskManager.DateTime, expires);

            AddItem(key, value, expireAction);
        }