public void Cache_ThrowsExceptionWhenHttpContextIsNull()
 {
     Mock<IDateTimeProvider> dateTimeProviderMock = new Mock<IDateTimeProvider>();
     DateTime now = DateTime.Now;
     dateTimeProviderMock.SetupGet(x => x.UtcNow).Returns(now);
     HttpResponseCacher httpResponseCacher = new HttpResponseCacher(dateTimeProviderMock.Object);
     Assert.Throws<ArgumentNullException>(() => httpResponseCacher.Cache(null, now));
 }
        public void Cache()
        {
            Mock<IDateTimeProvider> dateTimeProviderMock = new Mock<IDateTimeProvider>();
            DateTime now = DateTime.Now;
            dateTimeProviderMock.SetupGet(x => x.UtcNow).Returns(now);
            HttpResponseStub httpResponseStub = new HttpResponseStub(new MemoryStream());
            HttpRequestStub httpRequestStub = new HttpRequestStub();
            Mock<HttpContextBase> httpContext = HttpContextMockHelper.CreateHttpContext(httpResponseStub, httpRequestStub);

            HttpResponseCacher httpResponseCacher = new HttpResponseCacher(dateTimeProviderMock.Object);
            httpResponseCacher.Cache(httpContext.Object, now);

            Assert.AreEqual("Accept-Encoding", httpResponseStub.CacheStub.VaryByCustom);
            Assert.AreEqual(now, httpResponseStub.CacheStub.LastModifiedDate);
            Assert.AreEqual(true, httpResponseStub.CacheStub.ValidUntilExpires);
            Assert.AreEqual(HttpCacheability.Public, httpResponseStub.CacheStub.Cacheability);
            Assert.AreEqual(now.AddYears(1), httpResponseStub.CacheStub.ExpireDate);
            Assert.AreEqual(TimeSpan.FromDays(365), httpResponseStub.CacheStub.MaxAge);
        }
        private static Mock<HttpContextBase> HandleResource(string resourceGroupName, string fileName, ResourceType resourceType, bool compress, HttpRequestBase httpRequest, HttpResponseBase httpResponseStub, ProcessedResourceGroupInfo processedResourceGroupInfo, HttpResponseCacher httpResponseCacher, HttpResponseCompressor httpResponseCompressor)
        {
            ResourceElementGroup resourceElementGroup = new ResourceElementGroup
                {
                    Name = resourceGroupName,
                    ResourceType = resourceType,
                    Compress = compress,
                    Resources = new ResourceElementCollection {new ResourceElement {FileName = fileName}}
                };
            Mock<IResourceConfigurationProvider> webResourceConfigurationMock = CreateWebResourceConfigurationMock(resourceElementGroup);
            Mock<HttpContextBase> httpContextBaseMock = HttpContextMockHelper.CreateHttpContext(httpResponseStub, httpRequest);

            Mock<IResourceProcessor> resourceProcessorMock = new Mock<IResourceProcessor>();
            resourceProcessorMock.Setup(x => x.ProcessResource(resourceElementGroup, It.IsAny<CompressionType>()))
                                 .Returns(() => processedResourceGroupInfo);

            ResourceHandler resourceHandler = new ResourceHandler(resourceProcessorMock.Object, webResourceConfigurationMock.Object, httpResponseCacher, httpResponseCompressor);
            resourceHandler.HandleResource(httpContextBaseMock.Object, resourceType, resourceGroupName);
            return httpContextBaseMock;
        }