コード例 #1
0
        public void UpdateCacheEntryOptions_DefaultsTo30SecondsSliding_IfNoEvictionCriteriaIsProvided()
        {
            // Arrange
            var slidingExpiresIn = TimeSpan.FromSeconds(30);
            var storage          = GetStorage();
            var service          = new DistributedCacheTagHelperService(
                storage,
                Mock.Of <IDistributedCacheTagHelperFormatter>(),
                new HtmlTestEncoder(),
                NullLoggerFactory.Instance
                );
            var cacheTagHelper = new DistributedCacheTagHelper(
                service,
                new HtmlTestEncoder());

            // Act
            var cacheEntryOptions = cacheTagHelper.GetDistributedCacheEntryOptions();

            // Assert
            Assert.Equal(slidingExpiresIn, cacheEntryOptions.SlidingExpiration);
        }
コード例 #2
0
        public void UpdateCacheEntryOptions_SetsSlidingExpiration_IfExpiresSlidingIsSet()
        {
            // Arrange
            var expiresSliding = TimeSpan.FromSeconds(37);
            var storage        = GetStorage();
            var service        = new DistributedCacheTagHelperService(
                storage,
                Mock.Of <IDistributedCacheTagHelperFormatter>(),
                new HtmlTestEncoder()
                );
            var cacheTagHelper = new DistributedCacheTagHelper(
                service,
                new HtmlTestEncoder())
            {
                ExpiresSliding = expiresSliding
            };

            // Act
            var cacheEntryOptions = cacheTagHelper.GetDistributedCacheEntryOptions();

            // Assert
            Assert.Equal(expiresSliding, cacheEntryOptions.SlidingExpiration);
        }
コード例 #3
0
        public void UpdateCacheEntryOptions_SetsAbsoluteExpiration_IfExpiresAfterIsSet()
        {
            // Arrange
            var expiresAfter = TimeSpan.FromSeconds(42);
            var storage      = GetStorage();
            var service      = new DistributedCacheTagHelperService(
                storage,
                Mock.Of <IDistributedCacheTagHelperFormatter>(),
                new HtmlTestEncoder()
                );
            var cacheTagHelper = new DistributedCacheTagHelper(
                service,
                new HtmlTestEncoder())
            {
                ExpiresAfter = expiresAfter
            };

            // Act
            var cacheEntryOptions = cacheTagHelper.GetDistributedCacheEntryOptions();

            // Assert
            Assert.Equal(expiresAfter, cacheEntryOptions.AbsoluteExpirationRelativeToNow);
        }
コード例 #4
0
        public void UpdateCacheEntryOptions_SetsAbsoluteExpiration_IfExpiresOnIsSet()
        {
            // Arrange
            var expiresOn = DateTimeOffset.UtcNow.AddMinutes(4);
            var storage   = GetStorage();
            var service   = new DistributedCacheTagHelperService(
                storage,
                Mock.Of <IDistributedCacheTagHelperFormatter>(),
                new HtmlTestEncoder()
                );
            var cacheTagHelper = new DistributedCacheTagHelper(
                service,
                new HtmlTestEncoder())
            {
                ExpiresOn = expiresOn
            };

            // Act
            var cacheEntryOptions = cacheTagHelper.GetDistributedCacheEntryOptions();

            // Assert
            Assert.Equal(expiresOn, cacheEntryOptions.AbsoluteExpiration);
        }
コード例 #5
0
        public void UpdateCacheEntryOptions_SetsSlidingExpiration_IfExpiresSlidingIsSet()
        {
            // Arrange
            var expiresSliding = TimeSpan.FromSeconds(37);
            var storage = GetStorage();
            var service = new DistributedCacheTagHelperService(
                storage,
                Mock.Of<IDistributedCacheTagHelperFormatter>(),
                new HtmlTestEncoder(),
                NullLoggerFactory.Instance
                );
            var cacheTagHelper = new DistributedCacheTagHelper(
                service,
                new HtmlTestEncoder())
            {
                ExpiresSliding = expiresSliding
            };

            // Act
            var cacheEntryOptions = cacheTagHelper.GetDistributedCacheEntryOptions();

            // Assert
            Assert.Equal(expiresSliding, cacheEntryOptions.SlidingExpiration);
        }
コード例 #6
0
        public void UpdateCacheEntryOptions_SetsAbsoluteExpiration_IfExpiresAfterIsSet()
        {
            // Arrange
            var expiresAfter = TimeSpan.FromSeconds(42);
            var storage = GetStorage();
            var service = new DistributedCacheTagHelperService(
                storage,
                Mock.Of<IDistributedCacheTagHelperFormatter>(),
                new HtmlTestEncoder(),
                NullLoggerFactory.Instance
                );
            var cacheTagHelper = new DistributedCacheTagHelper(
                service,
                new HtmlTestEncoder())
            {
                ExpiresAfter = expiresAfter
            };

            // Act
            var cacheEntryOptions = cacheTagHelper.GetDistributedCacheEntryOptions();

            // Assert
            Assert.Equal(expiresAfter, cacheEntryOptions.AbsoluteExpirationRelativeToNow);
        }
コード例 #7
0
        public void UpdateCacheEntryOptions_SetsAbsoluteExpiration_IfExpiresOnIsSet()
        {
            // Arrange
            var expiresOn = DateTimeOffset.UtcNow.AddMinutes(4);
            var storage = GetStorage();
            var service = new DistributedCacheTagHelperService(
                storage,
                Mock.Of<IDistributedCacheTagHelperFormatter>(),
                new HtmlTestEncoder(),
                NullLoggerFactory.Instance
                );
            var cacheTagHelper = new DistributedCacheTagHelper(
                service,
                new HtmlTestEncoder())
            {
                ExpiresOn = expiresOn
            };

            // Act
            var cacheEntryOptions = cacheTagHelper.GetDistributedCacheEntryOptions();

            // Assert
            Assert.Equal(expiresOn, cacheEntryOptions.AbsoluteExpiration);
        }