public void OutputCacheSetsVaryByValues()
        {
            // Arrange
            var timestamp = new DateTime(2011, 1, 1, 0, 0, 0);
            var context   = new Mock <HttpContextBase>();

            context.SetupGet(c => c.Timestamp).Returns(timestamp);
            var response = new Mock <HttpResponseBase>().Object;

            var varyByParams          = new HttpCacheVaryByParams();
            var varyByHeader          = new HttpCacheVaryByHeaders();
            var varyByContentEncoding = new HttpCacheVaryByContentEncodings();

            var cache = new Mock <HttpCachePolicyBase>();

            cache.SetupGet(c => c.VaryByParams).Returns(varyByParams);
            cache.SetupGet(c => c.VaryByHeaders).Returns(varyByHeader);
            cache.SetupGet(c => c.VaryByContentEncodings).Returns(varyByContentEncoding);

            // Act
            ResponseExtensions.OutputCache(context.Object, cache.Object, 20, false, new[] { "foo" }, new[] { "bar", "bar2" },
                                           new[] { "baz", "baz2" }, HttpCacheability.Public);

            // Assert
            Assert.Equal(varyByParams["foo"], true);
            Assert.Equal(varyByHeader["bar"], true);
            Assert.Equal(varyByHeader["bar2"], true);
            Assert.Equal(varyByContentEncoding["baz"], true);
            Assert.Equal(varyByContentEncoding["baz2"], true);
        }
        public void OutputCacheSetsExpirationTimeBasedOnCurrentContext()
        {
            // Arrange
            var timestamp = new DateTime(2011, 1, 1, 0, 0, 0);
            var context   = new Mock <HttpContextBase>();

            context.SetupGet(c => c.Timestamp).Returns(timestamp);
            var response = new Mock <HttpResponseBase>().Object;

            var cache = new Mock <HttpCachePolicyBase>();

            cache
            .Setup(
                c =>
                c.SetCacheability(
                    It.Is <HttpCacheability>(p => p == HttpCacheability.Public)
                    )
                )
            .Verifiable();
            cache
            .Setup(c => c.SetExpires(It.Is <DateTime>(p => p == timestamp.AddSeconds(20))))
            .Verifiable();
            cache
            .Setup(c => c.SetMaxAge(It.Is <TimeSpan>(p => p == TimeSpan.FromSeconds(20))))
            .Verifiable();
            cache.Setup(c => c.SetValidUntilExpires(It.Is <bool>(p => p == true))).Verifiable();
            cache.Setup(c => c.SetLastModified(It.Is <DateTime>(p => p == timestamp))).Verifiable();
            cache.Setup(c => c.SetSlidingExpiration(It.Is <bool>(p => p == false))).Verifiable();

            // Act
            ResponseExtensions.OutputCache(
                context.Object,
                cache.Object,
                20,
                false,
                null,
                null,
                null,
                HttpCacheability.Public
                );

            // Assert
            cache.VerifyAll();
        }