public void RedirectWithBypassSecurityWarningAddsCorrectRefreshHeader()
        {
            // Arrange.
            const string RedirectUrl = "https://www.somewebsite.com/admin/protected-content/?testVar=Value1&another=value-2";
            const string ExpectedUrl = @"https://www.somewebsite.com/admin/protected-content/?testVar\x3dValue1\x26another\x3dvalue-2";
            var mockResponse = new Mock<HttpResponseBase>();
            var redirector = new LocationRedirector();

            // Act.
            redirector.Redirect(mockResponse.Object, RedirectUrl, true);

            // Assert.
            mockResponse.Verify(resp => resp.AddHeader("Refresh", "0;URL=" + ExpectedUrl));
        }
        public void RedirectWithoutBypassingSecurityWarningIssuesPermanentRedirect()
        {
            // Arrange.
            const string RedirectUrl = "https://www.somewebsite.com/admin/protected-content/";
            var mockResponse = new Mock<HttpResponseBase>();
            var redirector = new LocationRedirector();

            // Act.
            redirector.Redirect(mockResponse.Object, RedirectUrl, false);

            // Assert.
            mockResponse.VerifySet(resp => resp.StatusCode = 301);
            mockResponse.VerifySet(resp => resp.RedirectLocation = RedirectUrl);
            mockResponse.Verify(resp => resp.End());
        }
        public void RedirectWithBypassSecurityWarningWritesJavascriptLocationUrl()
        {
            // Arrange.
            const string RedirectUrl = "https://www.somewebsite.com/admin/protected-content/?testVar=Value1&another=value-2";
            const string ExpectedUrl = @"https://www.somewebsite.com/admin/protected-content/?testVar\x3dValue1\x26another\x3dvalue-2";
            var mockResponse = new Mock<HttpResponseBase>();
            var redirector = new LocationRedirector();

            // Act.
            redirector.Redirect(mockResponse.Object, RedirectUrl, true);

            // Assert.
            mockResponse.Verify(resp => resp.Write(It.Is<string>(s => s.Contains("window.location"))));
            mockResponse.Verify(resp => resp.Write(It.Is<string>(s => s.Contains(ExpectedUrl))));
        }