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();
            }
        }
        static ProgrammaticConfigIntegrationTests()
        {
            // Initialize the programmatic configuration store, _configuration.

            var currentDateTimeUtc = new DateTime(2073, 09, 15, 11, 32, 27);

            MockCacheItemPolicyDateTimeProvider.Instance.SetUtcNow(currentDateTimeUtc);
            MockCacheItemPolicyDateTimeProvider.Install();

            try
            {
                _configuration =
                    new CacheItemPolicyConfiguration(
                        new List <ICacheItemPolicyConfigurationItem>
                {
                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteByTimeSpanWithEnabledAttributeFalse", ObjectCache.InfiniteAbsoluteExpiration, false),
                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteByTimeSpanSetToAllZerosWithEnabledAttributeTrue", ObjectCache.InfiniteAbsoluteExpiration),
                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteByTimeSpanSetToSecondsWithEnabledAttributeTrue", new DateTimeOffset(CacheItemPolicyDateTimeProvider.Current.UtcNow.Add(TimeSpan.FromSeconds(30)))),
                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteByTimeSpanSetToMinutesWithEnabledAttributeTrue", new DateTimeOffset(CacheItemPolicyDateTimeProvider.Current.UtcNow.Add(TimeSpan.FromMinutes(15)))),
                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteByTimeSpanSetToHoursWithEnabledAttributeTrue", new DateTimeOffset(CacheItemPolicyDateTimeProvider.Current.UtcNow.Add(TimeSpan.FromHours(1)))),
                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteByTimeSpanSetToDaysWithEnabledAttributeTrue", new DateTimeOffset(CacheItemPolicyDateTimeProvider.Current.UtcNow.Add(TimeSpan.FromDays(7)))),
                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteByTimeSpanWithoutEnabledAttribute", new DateTimeOffset(CacheItemPolicyDateTimeProvider.Current.UtcNow.Add(TimeSpan.FromMinutes(5)))),

                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteByDateTimeWithEnabledAttributeFalse", new DateTimeOffset(new DateTime(2073, 09, 15, 08, 32, 00)), false),
                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteByDateTimeWithEnabledAttributeTrue", new DateTimeOffset(new DateTime(2073, 09, 15, 08, 32, 00))),
                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteByDateTimeWithoutEnabledAttribute", new DateTimeOffset(new DateTime(2073, 09, 15, 08, 32, 00))),

                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteInfiniteWithEnabledAttributeFalse", ObjectCache.InfiniteAbsoluteExpiration, false),
                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteInfiniteWithEnabledAttributeTrue", ObjectCache.InfiniteAbsoluteExpiration),
                    new CacheItemPolicyConfigurationItem("TestPolicyAbsoluteInfiniteWithoutEnabledAttribute", ObjectCache.InfiniteAbsoluteExpiration),

                    new CacheItemPolicyConfigurationItem("TestPolicySlidingWithEnabledAttributeFalse", TimeSpan.MaxValue, false),
                    new CacheItemPolicyConfigurationItem("TestPolicySlidingSetToZeroWithEnabledAttributeTrue", ObjectCache.InfiniteAbsoluteExpiration),
                    new CacheItemPolicyConfigurationItem("TestPolicySlidingSetToSecondsWithEnabledAttributeTrue", TimeSpan.FromSeconds(30)),
                    new CacheItemPolicyConfigurationItem("TestPolicySlidingWithoutEnabledAttribute", TimeSpan.FromMinutes(5))
                });
            }
            finally
            {
                MockCacheItemPolicyDateTimeProvider.Uninstall();
            }
        }