public void CanCreateCacheItemPolicyWithAbsoluteExpirationByTimeSpanProgrammatically(string cacheItemPolicyName, TimeSpan expectedExpires, bool cacheItemPolicyShouldBeNull)
        {
            // Arrange
            var currentDateTimeUtc = new DateTime(2073, 09, 15, 11, 32, 27);

            var expected =
                (expectedExpires == TimeSpan.MaxValue)
                                        ? ObjectCache.InfiniteAbsoluteExpiration
                                        : new DateTimeOffset(currentDateTimeUtc.Add(expectedExpires));

            var factory = new CacheItemPolicyFactory(_configuration);

            MockCacheItemPolicyDateTimeProvider.Instance.SetUtcNow(currentDateTimeUtc);
            MockCacheItemPolicyDateTimeProvider.Install();
            try
            {
                // Act
                var cacheItemPolicy = factory.Create(cacheItemPolicyName);

                // Assert
                if (cacheItemPolicyShouldBeNull)
                {
                    cacheItemPolicy.ShouldBeNull();
                    return;
                }

                cacheItemPolicy.AbsoluteExpiration.ShouldEqual(expected);
                cacheItemPolicy.SlidingExpiration.ShouldEqual(ObjectCache.NoSlidingExpiration);
            }
            finally
            {
                MockCacheItemPolicyDateTimeProvider.Uninstall();
            }
        }
        public void CanCreateCacheItemPolicyWithSlidingExpirationProgrammatically(string cacheItemPolicyName, TimeSpan expectedExpires, bool cacheItemPolicyShouldBeNull)
        {
            // Arrange
            var expected = expectedExpires;
            var factory  = new CacheItemPolicyFactory(_configuration);

            // Act
            var cacheItemPolicy = factory.Create(cacheItemPolicyName);

            // Assert
            if (cacheItemPolicyShouldBeNull)
            {
                cacheItemPolicy.ShouldBeNull();
                return;
            }

            cacheItemPolicy.SlidingExpiration.ShouldEqual(expected);
            cacheItemPolicy.AbsoluteExpiration.ShouldEqual(ObjectCache.InfiniteAbsoluteExpiration);
        }
        public void CanCreateCacheItemPolicyWithAbsoluteExpirationByDateTimeFromDotNetConfigFile(string cacheItemPolicyName, DateTime expectedExpires, bool cacheItemPolicyShouldBeNull)
        {
            // Arrange
            var expected = new DateTimeOffset(expectedExpires);
            var config = new ConfigFileBasedCacheItemPolicyConfiguration();
            var factory = new CacheItemPolicyFactory(config);

            // Act
            var cacheItemPolicy = factory.Create(cacheItemPolicyName);

            // Assert
            if (cacheItemPolicyShouldBeNull)
            {
                cacheItemPolicy.ShouldBeNull();
                return;
            }

            cacheItemPolicy.AbsoluteExpiration.ShouldEqual(expected);
            cacheItemPolicy.SlidingExpiration.ShouldEqual(ObjectCache.NoSlidingExpiration);
        }
Example #4
0
        public void CanCreateCacheItemPolicyWithAbsoluteExpirationByDateTimeFromDotNetConfigFile(string cacheItemPolicyName, DateTime expectedExpires, bool cacheItemPolicyShouldBeNull)
        {
            // Arrange
            var expected = new DateTimeOffset(expectedExpires);
            var config   = new ConfigFileBasedCacheItemPolicyConfiguration();
            var factory  = new CacheItemPolicyFactory(config);

            // Act
            var cacheItemPolicy = factory.Create(cacheItemPolicyName);

            // Assert
            if (cacheItemPolicyShouldBeNull)
            {
                cacheItemPolicy.ShouldBeNull();
                return;
            }

            cacheItemPolicy.AbsoluteExpiration.ShouldEqual(expected);
            cacheItemPolicy.SlidingExpiration.ShouldEqual(ObjectCache.NoSlidingExpiration);
        }
        public void CanCreateCacheItemPolicyWithAbsoluteExpirationByTimeSpanFromDotNetConfigFile(string cacheItemPolicyName, TimeSpan expectedExpires, bool cacheItemPolicyShouldBeNull)
        {
            // Arrange
            var currentDateTimeUtc = new DateTime(2073, 09, 15, 11, 32, 27);

            var expected =
                (expectedExpires == TimeSpan.MaxValue)
                    ? ObjectCache.InfiniteAbsoluteExpiration
                    : new DateTimeOffset(currentDateTimeUtc.Add(expectedExpires));

            var config = new ConfigFileBasedCacheItemPolicyConfiguration();
            var factory = new CacheItemPolicyFactory(config);
            MockCacheItemPolicyDateTimeProvider.Instance.SetUtcNow(currentDateTimeUtc);
            MockCacheItemPolicyDateTimeProvider.Install();
            try
            {
                // Act
                var cacheItemPolicy = factory.Create(cacheItemPolicyName);

                // Assert
                if (cacheItemPolicyShouldBeNull)
                {
                    cacheItemPolicy.ShouldBeNull();
                    return;
                }

                cacheItemPolicy.AbsoluteExpiration.ShouldEqual(expected);
                cacheItemPolicy.SlidingExpiration.ShouldEqual(ObjectCache.NoSlidingExpiration);
            }
            finally
            {
                MockCacheItemPolicyDateTimeProvider.Uninstall();
            }
        }
        public void CanCreateCacheItemPolicyWithSlidingExpirationProgrammatically(string cacheItemPolicyName, TimeSpan expectedExpires, bool cacheItemPolicyShouldBeNull)
        {
            // Arrange
            var expected = expectedExpires;
            var factory = new CacheItemPolicyFactory(_configuration);

            // Act
            var cacheItemPolicy = factory.Create(cacheItemPolicyName);

            // Assert
            if (cacheItemPolicyShouldBeNull)
            {
                cacheItemPolicy.ShouldBeNull();
                return;
            }

            cacheItemPolicy.SlidingExpiration.ShouldEqual(expected);
            cacheItemPolicy.AbsoluteExpiration.ShouldEqual(ObjectCache.InfiniteAbsoluteExpiration);
        }