Пример #1
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     TimeServiceMock.Setup(s => s.UtcTime).Returns(StartTime);
     NotificationReporter.Report(Message, ShortDescription, LongDescription);
     Notification = NotificationReporter.Notifications.SingleOrDefault();
 }
Пример #2
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     LaterTime = StartTime.Add(TimeSpan.FromSeconds(1));
     TimeServiceMock.Setup(s => s.UtcTime).Returns(LaterTime);
     NotificationReporter.Report("message", "shortDescription", "longDescription");
 }
Пример #3
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     LifeTime = ExpirationTime.Add(NotificationReporter.LifeTime).AddTicks(1);
     TimeServiceMock.Setup(s => s.UtcTime).Returns(LifeTime);
     TimerServiceMock.Raise(s => s.Elapsed += null, EventArgs.Empty);
 }
Пример #4
0
        public void TestDisposeOnSlidingExpiration()
        {
            this.app.GetConfig <ScheduledEventsConfig>().ExecutionCheck = TimeSpan.FromMilliseconds(1);
            this.app.GetConfig <MemoryCachingConfig>().ExpirationCheck  = TimeSpan.FromMilliseconds(1);
            this.app.Reinitialize();
            var timeService = new TimeServiceMock(this.app);

            this.app.Container.Register(timeService);

            var disposed = false;

            var cache = this.app.GetMemoryCache();

            cache.Set(nameof(TestDisposeOnSlidingExpiration), this, dispose: () => disposed = true, slidingExpiration: TimeSpan.FromMilliseconds(50));
            var item = cache.Get(nameof(TestDisposeOnSlidingExpiration));

            item.Should().Be(this, "returned item should be the same as the original");

            for (int i = 0; i < 75; i++)
            {
                item = cache.Get(nameof(TestDisposeOnSlidingExpiration));
                item.Should().Be(this, $"returned item should be the same as the original after {i} retries");
                disposed.Should().BeFalse($"the item should not have expired after {i} retries");
                Thread.Sleep(1);
            }

            timeService.SetTime(timeService.GetTime().AddMilliseconds(51));
            new Func <bool>(() => disposed).ShouldReturn(true, TimeSpan.FromMilliseconds(1000), "the item should have expired");
            item = cache.Get(nameof(TestDisposeOnSlidingExpiration));
            item.Should().BeNull("the item shold have been removed from the cache");
        }
Пример #5
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     TimeServiceMock.Setup(s => s.UtcTime).Returns(StartTime);
     Exception = new Exception("exception message");
     NotificationReporter.Report(Message, Exception);
     Notification = NotificationReporter.Notifications.SingleOrDefault();
 }
Пример #6
0
        public void TestMixedExpiration()
        {
            this.app.GetConfig <ScheduledEventsConfig>().ExecutionCheck = TimeSpan.FromMilliseconds(1);
            this.app.GetConfig <MemoryCachingConfig>().ExpirationCheck  = TimeSpan.FromMilliseconds(1);
            this.app.Reinitialize();
            var timeService = new TimeServiceMock(this.app);

            this.app.Container.Register(timeService);

            var cache = this.app.GetMemoryCache();

            cache.Set(nameof(TestMixedExpiration), this, absoluteExpiration: TimeSpan.FromMilliseconds(50), slidingExpiration: TimeSpan.FromMilliseconds(25));
            var item = cache.Get(nameof(TestMixedExpiration));

            item.Should().Be(this, "returned item should be the same as the original");

            timeService.SetTime(timeService.GetTime().AddMilliseconds(51));
            new Func <object>(() => cache.Get(nameof(TestMixedExpiration)))
            .ShouldReturn(null, TimeSpan.FromMilliseconds(1000), "the item shold have been removed from the cache");
        }