コード例 #1
0
        public void Test_GetLifeTime_When_Options_Null_Default_SlidingExpiration_Used()
        {
            var provider = new Mock <ICouchbaseCacheBucketProvider>();

            var cache = new CouchbaseCache(provider.Object, new CouchbaseCacheOptions());

            var result = CouchbaseCacheExtensions.GetLifetime(cache);

            Assert.Equal(result, TimeSpan.FromMinutes(20));
        }
コード例 #2
0
        public void Test_GetLifeTime_AbsoluteExpiration()
        {
            var provider = new Mock <ICouchbaseCacheBucketProvider>();

            var cache = new CouchbaseCache(provider.Object, new CouchbaseCacheOptions());

            var absoluteExpiration = DateTime.UtcNow.AddDays(1);
            var result             = CouchbaseCacheExtensions.GetLifetime(cache, new DistributedCacheEntryOptions
            {
                AbsoluteExpiration = new DateTimeOffset(absoluteExpiration)
            });

            Assert.Equal(new DateTime(result.Ticks), absoluteExpiration);
        }
コード例 #3
0
        public void Test_GetLifeTime_SlidingExpiration()
        {
            var provider = new Mock <ICouchbaseCacheBucketProvider>();

            var cache = new CouchbaseCache(provider.Object, new CouchbaseCacheOptions());

            var slidingExpiration = TimeSpan.FromSeconds(10);
            var result            = CouchbaseCacheExtensions.GetLifetime(cache, new DistributedCacheEntryOptions
            {
                SlidingExpiration = slidingExpiration
            });

            output.WriteLine(new DateTime(result.Ticks).ToString(CultureInfo.InvariantCulture));
            Assert.Equal(new DateTime(result.Ticks), new DateTime(slidingExpiration.Ticks));
        }
コード例 #4
0
        public void Test_GetLifeTime_AbsoluteExpirationRelativeToNow()
        {
            var provider = new Mock <ICouchbaseCacheBucketProvider>();

            var cache = new CouchbaseCache(provider.Object, new CouchbaseCacheOptions());

            var absoluteExpirationRelativeToNow = TimeSpan.FromDays(1);
            var result = CouchbaseCacheExtensions.GetLifetime(cache, new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow
            });

            output.WriteLine(new DateTime(result.Ticks).ToShortDateString());
            Assert.Equal(new DateTime(result.Ticks).ToShortDateString(),
                         DateTime.UtcNow.AddTicks(absoluteExpirationRelativeToNow.Ticks).ToShortDateString());
        }
コード例 #5
0
        public void Test_GetLifeTime_AbsoluteExpiration()
        {
            var provider = new Mock <ICouchbaseCacheBucketProvider>();

            var cache = new CouchbaseCache(provider.Object, new CouchbaseCacheOptions());

            var now = DateTime.UtcNow;

            var timerIncrement = 1;

            var absoluteExpiration = now.AddDays(timerIncrement);

            var result = CouchbaseCacheExtensions.GetLifetime(cache, new DistributedCacheEntryOptions
            {
                AbsoluteExpiration = new DateTimeOffset(absoluteExpiration)
            });

            Assert.Equal(TimeSpan.FromDays(timerIncrement).Ticks, (long)Math.Round((double)result.Ticks / 1000000000) * 1000000000);
        }
コード例 #6
0
        public void Test_GetLifeTime_AbsoluteExpirationRelativeToNow()
        {
            var provider = new Mock <ICouchbaseCacheCollectionProvider>();

            var cache = new CouchbaseCache(provider.Object, new CouchbaseCacheOptions());

            var now = DateTime.UtcNow;

            var timerIncrement = 15;

            var absoluteExpirationRelativeToNow = TimeSpan.FromMinutes(timerIncrement);

            var result = CouchbaseCacheExtensions.GetLifetime(cache, new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow
            });

            Assert.Equal(absoluteExpirationRelativeToNow.Ticks, (long)Math.Round((double)result.Ticks / 1000000000) * 1000000000);
        }