Beispiel #1
0
            public void RaisesExpiringEventWithCorrectEventArgsWhenItemExpires()
            {
                var key = "1";
                var expirationPolicy   = new SlidingExpirationPolicy(TimeSpan.FromMilliseconds(250));
                var value              = 1;
                var evKey              = (string)null;
                var evExpirationPolicy = default(ExpirationPolicy);
                var evValue            = 0;

                var cache = new CacheStorage <string, int>();

                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
                cache.Expiring += (sender, e) =>
                {
                    evKey = e.Key;
                    evExpirationPolicy = e.ExpirationPolicy;
                    evValue            = e.Value;
                };

                cache.Add(key, value, expirationPolicy);

                ThreadHelper.Sleep(750);

                Assert.AreEqual(key, evKey);
                Assert.AreEqual(expirationPolicy, evExpirationPolicy);
                Assert.AreEqual(value, evValue);
            }
            public void TurnTheIsExpiredPropertyToFalse()
            {
                var policy = new SlidingExpirationPolicy(new TimeSpan(0, 0, 1));

                ThreadHelper.Sleep(1500);

                Assert.IsTrue(policy.IsExpired);

                policy.Reset();
                Assert.IsFalse(policy.IsExpired);
            }