public void WillGetAndSetResponseFilterIfXHtmlContent()
        {
            var module  = new RequestReduceModule();
            var context = new Mock <HttpContextBase>();
            var config  = new Mock <IRRConfiguration>();

            config.Setup(x => x.ResourceAbsolutePath).Returns("/Virtual");
            context.Setup(x => x.Items.Contains(ResponseFilter.ContextKey)).Returns(false);
            context.Setup(x => x.Request.Url).Returns(new Uri("http://host/Content/blah"));
            context.Setup(x => x.Response.ContentType).Returns("application/xhtml+xml");
            context.Setup(x => x.Request.QueryString).Returns(new NameValueCollection());
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);
            RRContainer.Current = new Container(x =>
            {
                x.For <IRRConfiguration>().Use(config.Object);
                x.For <IHostingEnvironmentWrapper>().Use(new Mock <IHostingEnvironmentWrapper>().Object);
                x.For <AbstractFilter>().Use(new Mock <AbstractFilter>().Object);
            });

            module.InstallFilter(context.Object);

            context.VerifyGet(x => x.Response.Filter, Times.Once());
            context.VerifySet(x => x.Response.Filter = It.IsAny <Stream>(), Times.Once());
            RRContainer.Current = null;
        }
        public void WillSetContextKeyIfNotSetBefore()
        {
            RRContainer.Current = null;
            var module  = new RequestReduceModule();
            var context = new Mock <HttpContextBase>();
            var config  = new Mock <IRRConfiguration>();

            config.Setup(x => x.SpriteVirtualPath).Returns("/Virtual");
            context.Setup(x => x.Items.Contains(RequestReduceModule.CONTEXT_KEY)).Returns(false);
            context.Setup(x => x.Response.ContentType).Returns("type");
            context.Setup(x => x.Request.QueryString).Returns(new NameValueCollection());
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);
            context.Setup(x => x.Response.ContentType).Returns("text/html");
            context.Setup(x => x.Request.RawUrl).Returns("/content/blah");
            RRContainer.Current = new Container(x =>
            {
                x.For <IRRConfiguration>().Use(config.Object);
                x.For <AbstractFilter>().Use(new Mock <AbstractFilter>().Object);
            });

            module.InstallFilter(context.Object);

            context.Verify(x => x.Items.Add(RequestReduceModule.CONTEXT_KEY, It.IsAny <Object>()), Times.Once());
            RRContainer.Current = null;
        }
        public void WillSetResponseFilterIfJustCssProcessingIsDisabledFromConfig()
        {
            var module = new RequestReduceModule();
            var config = new Mock <IRRConfiguration>();

            config.Setup(x => x.SpriteVirtualPath).Returns("/Virtual");
            config.Setup(x => x.CssProcessingDisabled).Returns(true);
            var context = new Mock <HttpContextBase>();

            context.Setup(x => x.Items.Contains(RequestReduceModule.CONTEXT_KEY)).Returns(false);
            context.Setup(x => x.Response.ContentType).Returns("text/html");
            context.Setup(x => x.Request.QueryString).Returns(new NameValueCollection());
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);
            context.Setup(x => x.Request.RawUrl).Returns("/NotVirtual/blah");
            RRContainer.Current = new Container(x =>
            {
                x.For <IRRConfiguration>().Use(config.Object);
                x.For <AbstractFilter>().Use(new Mock <AbstractFilter>().Object);
            });

            module.InstallFilter(context.Object);

            context.VerifySet(x => x.Response.Filter = It.IsAny <Stream>(), Times.Once());
            RRContainer.Current = null;
        }
        public void WillNotSetResponseFilterIfStatusIs302Or301(int status)
        {
            RRContainer.Current = null;
            var module  = new RequestReduceModule();
            var context = new Mock <HttpContextBase>();
            var config  = new Mock <IRRConfiguration>();

            config.Setup(x => x.SpriteVirtualPath).Returns("/Virtual");
            context.Setup(x => x.Items.Contains(RequestReduceModule.CONTEXT_KEY)).Returns(false);
            context.Setup(x => x.Response.ContentType).Returns("text/html");
            context.Setup(x => x.Request.QueryString).Returns(new NameValueCollection());
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);
            context.Setup(x => x.Request.RawUrl).Returns("/content/blah");
            context.Setup(x => x.Response.StatusCode).Returns(status);
            RRContainer.Current = new Container(x =>
            {
                x.For <IRRConfiguration>().Use(config.Object);
                x.For <AbstractFilter>().Use(new Mock <AbstractFilter>().Object);
            });

            module.InstallFilter(context.Object);

            context.VerifySet(x => x.Response.Filter = It.IsAny <Stream>(), Times.Never());
            RRContainer.Current = null;
        }
        public void WillSetResponseFilterOnce()
        {
            var module  = new RequestReduceModule();
            var context = new Mock <HttpContextBase>();
            var config  = new Mock <IRRConfiguration>();

            config.Setup(x => x.SpriteVirtualPath).Returns("/Virtual");
            context.Setup(x => x.Items.Contains(RequestReduceModule.CONTEXT_KEY)).Returns(true);
            RRContainer.Current = new Container(x =>
            {
                x.For <IRRConfiguration>().Use(config.Object);
                x.For <AbstractFilter>().Use(new Mock <AbstractFilter>().Object);
            });

            module.InstallFilter(context.Object);

            context.VerifySet((x => x.Response.Filter = It.IsAny <Stream>()), Times.Never());
            RRContainer.Current = null;
        }
        public void WillSetPhysicalPathToMappedVirtualPath()
        {
            var module  = new RequestReduceModule();
            var context = new Mock <HttpContextBase>();
            var config  = new Mock <IRRConfiguration>();

            config.Setup(x => x.SpriteVirtualPath).Returns("/Virtual");
            context.Setup(x => x.Items.Contains(RequestReduceModule.CONTEXT_KEY)).Returns(false);
            context.Setup(x => x.Response.ContentType).Returns("text/html");
            context.Setup(x => x.Server.MapPath("/Virtual")).Returns("physical");
            context.Setup(x => x.Request.QueryString).Returns(new NameValueCollection());
            context.Setup(x => x.Request.RawUrl).Returns("/content/blah");
            RRContainer.Current = new Container(x =>
            {
                x.For <IRRConfiguration>().Use(config.Object);
                x.For <AbstractFilter>().Use(new Mock <AbstractFilter>().Object);
            });

            module.InstallFilter(context.Object);

            config.VerifySet(x => x.SpritePhysicalPath = "physical", Times.Once());
            RRContainer.Current = null;
        }
        public void WillNotSetResponseFilterIfFaviconIco()
        {
            RRContainer.Current = null;
            var module  = new RequestReduceModule();
            var context = new Mock <HttpContextBase>();
            var config  = new Mock <IRRConfiguration>();

            config.Setup(x => x.ResourceVirtualPath).Returns("/Virtual");
            context.Setup(x => x.Items.Contains(ResponseFilter.ContextKey)).Returns(false);
            context.Setup(x => x.Response.ContentType).Returns("text/html");
            context.Setup(x => x.Request.QueryString).Returns(new NameValueCollection());
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);
            context.Setup(x => x.Request.Url).Returns(new Uri("http://host/favicon.ico"));
            RRContainer.Current = new Container(x =>
            {
                x.For <IRRConfiguration>().Use(config.Object);
                x.For <AbstractFilter>().Use(new Mock <AbstractFilter>().Object);
            });

            module.InstallFilter(context.Object);

            context.VerifySet(x => x.Response.Filter = It.IsAny <Stream>(), Times.Never());
            RRContainer.Current = null;
        }