Пример #1
0
        public void Can_render_AbsoluteExpirationRelativeToNow_as_ttlstrategy()
        {
            TimeSpan forwardTimeSpan = TimeSpan.FromDays(1);
            DistributedCacheEntryOptions entryOptions = new DistributedCacheEntryOptions()
            {
                AbsoluteExpirationRelativeToNow = forwardTimeSpan
            };

            ITtlStrategy ttlStrategy = entryOptions.AsTtlStrategy();

            ttlStrategy.Should().BeOfType <RelativeTtl>();

            Ttl ttl = ttlStrategy.GetTtl(noContext, null);

            ttl.SlidingExpiration.Should().BeFalse();
            ttl.Timespan.Should().BeCloseTo(forwardTimeSpan, 10000);
        }
Пример #2
0
        public void Can_render_SlidingExpiration_as_ttlstrategy()
        {
            TimeSpan forwardTimeSpan = TimeSpan.FromDays(1);
            DistributedCacheEntryOptions entryOptions = new DistributedCacheEntryOptions()
            {
                SlidingExpiration = forwardTimeSpan
            };

            ITtlStrategy ttlStrategy = entryOptions.AsTtlStrategy();

            ttlStrategy.Should().BeOfType <SlidingTtl>();

            Ttl ttl = ttlStrategy.GetTtl(noContext, null);

            ttl.SlidingExpiration.Should().BeTrue();
            ttl.Timespan.Should().BeCloseTo(forwardTimeSpan);
        }
        public void Can_render_AbsoluteExpiration_as_ttlstrategy()
        {
            TimeSpan forwardTimeSpan = TimeSpan.FromDays(1);
            DateTime date            = DateTime.Now.Add(forwardTimeSpan);
            DistributedCacheEntryOptions entryOptions = new DistributedCacheEntryOptions()
            {
                AbsoluteExpiration = date
            };

            ITtlStrategy ttlStrategy = entryOptions.AsTtlStrategy();

            ttlStrategy.Should().BeOfType <AbsoluteTtl>();

            Ttl ttl = ttlStrategy.GetTtl(noContext);

            ttl.SlidingExpiration.Should().BeFalse();
            ttl.Timespan.Should().BeCloseTo(forwardTimeSpan, 10000);
        }