public void ConvertRequestToBlogRequestWithRequestForLoginPage_MatchingInactiveBlog_DoesNotRedirect()
        {
            //arrange
            var service = new Mock<IBlogLookupService>();
            var result = new BlogLookupResult(new Blog {IsActive = false}, null);
            service.Setup(s => s.Lookup(It.IsAny<BlogRequest>())).Returns(result);
            var httpResponse = new Mock<HttpResponseBase>();
            Mock<HttpRequestBase> httpRequest = CreateRequest("example.com", "/", "/login.aspx", true);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.Setup(c => c.Request).Returns(httpRequest.Object);
            httpContext.Setup(c => c.Response).Returns(httpResponse.Object);
            var module = new BlogRequestModule(service.Object);

            //act
            BlogRequest request = module.ConvertRequestToBlogRequest(httpContext.Object);

            //assert
            Assert.IsNotNull(request);
        }
        public void ConvertRequestToBlogRequest_MatchingInactiveBlog_RedirectsToBlogInactivePage()
        {
            //arrange
            var service = new Mock<IBlogLookupService>();
            var result = new BlogLookupResult(new Blog {IsActive = false}, null);
            service.Setup(s => s.Lookup(It.IsAny<BlogRequest>())).Returns(result);
            var httpResponse = new Mock<HttpResponseBase>();
            Mock<HttpRequestBase> httpRequest = CreateRequest("example.com", "/", "/", true);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.Setup(c => c.Request).Returns(httpRequest.Object);
            httpContext.Setup(c => c.Response).Returns(httpResponse.Object);
            var module = new BlogRequestModule(service.Object);

            //act
            BlogRequest request = module.ConvertRequestToBlogRequest(httpContext.Object);

            //assert
            Assert.IsNull(request);
            httpResponse.Verify(r => r.Redirect("~/SystemMessages/BlogNotActive.aspx", true));
        }
        public void ConvertRequestToBlogRequestForStaticImage_WithNoMatchingBlog_DoesNotRedirect()
        {
            //arrange
            var service = new Mock<IBlogLookupService>();
            var result = new BlogLookupResult(null, new Uri("http://localhost/images/blog/services/identiconhandler.ashx"));
            service.Setup(s => s.Lookup(It.IsAny<BlogRequest>())).Returns(result);
            var httpResponse = new Mock<HttpResponseBase>();
            httpResponse.Setup(r => r.Redirect(It.IsAny<string>(), true)).Throws(new InvalidOperationException("Should not redirect"));
            Mock<HttpRequestBase> httpRequest = CreateRequest("example.com", "/", "/images/services/identiconhandler.ashx", true);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.Setup(c => c.Request).Returns(httpRequest.Object);
            httpContext.Setup(c => c.Response).Returns(httpResponse.Object);
            var module = new BlogRequestModule(service.Object);

            //act
            BlogRequest request = module.ConvertRequestToBlogRequest(httpContext.Object);

            //assert
            Assert.IsNotNull(request);
            Assert.IsNull(request.Blog);
            Assert.AreEqual(RequestLocation.StaticFile, request.RequestLocation);
        }