public void Setup_WithRandomizer() { var now = DateTime.Now; var scp = new SlidingCachePolicy { Duration = new TimeSpan(0, 1, 0), RandomizerOffset = new TimeSpan(0, 0, 30) }; scp.Reset(); Assert.IsTrue(scp.Expiry.HasValue); Assert.IsTrue(scp.Expiry.Value > now.AddSeconds(60) && scp.Expiry.Value < now.AddSeconds(90)); }
public void SlideWithMaxGap() { var scp = new SlidingCachePolicy { Duration = new TimeSpan(0, 0, 1), MaxDuration = new TimeSpan(0, 0, 2) }; scp.Reset(); Assert.IsFalse(((ICachePolicy)scp).HasExpired()); Thread.Sleep(350); Assert.IsFalse(((ICachePolicy)scp).HasExpired()); Thread.Sleep(1100); Assert.IsTrue(((ICachePolicy)scp).HasExpired()); Thread.Sleep(450); Assert.IsTrue(((ICachePolicy)scp).HasExpired()); }
public void Slide() { var scp = new SlidingCachePolicy { Duration = new TimeSpan(0, 0, 1) }; scp.Reset(); Assert.IsFalse(((ICachePolicy)scp).HasExpired()); Thread.Sleep(500); Assert.IsFalse(((ICachePolicy)scp).HasExpired()); Thread.Sleep(500); Assert.IsFalse(((ICachePolicy)scp).HasExpired()); Thread.Sleep(500); Assert.IsFalse(((ICachePolicy)scp).HasExpired()); Thread.Sleep(1500); Assert.IsTrue(scp.IsExpired); }