public void GetInstallationRedirectUrl_ForStaticFiles_ReturnsNull()
        {
            // arrange
            var module = new InstallationCheckModule(new Mock<IInstallationManager>().Object, new LazyNotNull<HostInfo>(() => null));
            var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost/whatever/foo.jpg"),
                                              true, RequestLocation.Blog, "/");
            // act
            string redirectUrl = module.GetInstallationRedirectUrl(blogRequest);

            // assert
            Assert.IsNull(redirectUrl);
        }
        public void GetInstallationRedirectUrl_WhenHostInfoNotNullAndInstallRequiredButInInstallDirectory_ReturnsNull()
        {
            // arrange
            var installManager = new Mock<IInstallationManager>();
            installManager.Setup(m => m.InstallationActionRequired(It.IsAny<Version>(), null)).Returns(true);
            var module = new InstallationCheckModule(installManager.Object, new LazyNotNull<HostInfo>(CreateHostInfo));
            var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost/Install/foo.aspx"),
                                              true, RequestLocation.Installation, "/");

            // act
            string redirectUrl = module.GetInstallationRedirectUrl(blogRequest);

            // assert
            Assert.IsNull(redirectUrl);
        }
        public void GetInstallationRedirectUrl_WhenHostInfoNotNullInstallationActionRequiredAndInLoginPage_ReturnsInstallDirectory()
        {
            // arrange
            var installManager = new Mock<IInstallationManager>();
            installManager.Setup(m => m.GetInstallationStatus(It.IsAny<Version>())).Returns(
                InstallationState.NeedsInstallation);
            installManager.Setup(m => m.InstallationActionRequired(It.IsAny<Version>(), null)).Returns(true);
            var module = new InstallationCheckModule(installManager.Object, new LazyNotNull<HostInfo>(UnitTestHelper.CreateHostInfo));
            var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost/Install/foo.aspx"),
                                              true, RequestLocation.LoginPage, "/");

            // act
            string redirectUrl = module.GetInstallationRedirectUrl(blogRequest);

            // assert
            Assert.AreEqual("~/install/default.aspx", redirectUrl);
        }
        public void GetInstallationRedirectUrl_WhenUpgradeRequiredAndInSystemMessagesDirectory_ReturnsNull()
        {
            // arrange
            var installManager = new Mock<IInstallationManager>();
            installManager.Setup(m => m.GetInstallationStatus(It.IsAny<Version>())).Returns(
                InstallationState.NeedsUpgrade);
            installManager.Setup(m => m.InstallationActionRequired(It.IsAny<Version>(), null)).Returns(true);
            var module = new InstallationCheckModule(installManager.Object, new LazyNotNull<HostInfo>(UnitTestHelper.CreateHostInfo));
            var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost/Install/foo.aspx"),
                                              true, RequestLocation.SystemMessages, "/");

            // act
            string redirectUrl = module.GetInstallationRedirectUrl(blogRequest);

            // assert
            Assert.IsNull(redirectUrl);
        }
        public void GetInstallationRedirectUrl_WhenHostInfoNull_ReturnsInstallDirectory()
        {
            // arrange
            var module = new InstallationCheckModule(new Mock<IInstallationManager>().Object, new LazyNotNull<HostInfo>(() => null));
            var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost/foo.aspx"), true,
                                              RequestLocation.Blog, "/");

            // act
            string redirectUrl = module.GetInstallationRedirectUrl(blogRequest);

            // assert
            Assert.AreEqual("~/install/default.aspx", redirectUrl);
        }
        public void GetInstallationRedirectUrl_WhenUpgradeRequired_ReturnsUpgradeDirectory()
        {
            // arrange
            var installManager = new Mock<IInstallationManager>();
            installManager.Setup(m => m.GetInstallationStatus(It.IsAny<Version>())).Returns(
                InstallationState.NeedsUpgrade);
            installManager.Setup(m => m.InstallationActionRequired(It.IsAny<Version>(), null)).Returns(true);
            var module = new InstallationCheckModule(installManager.Object);
            var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost/Install/foo.aspx"),
                                              true, RequestLocation.Blog, "/");

            // act
            string redirectUrl = module.GetInstallationRedirectUrl(blogRequest, new HostInfo());

            // assert
            Assert.AreEqual("~/SystemMessages/UpgradeInProgress.aspx", redirectUrl);
        }