Exemplo n.º 1
0
        private void ProcessRequest(FriendlyUrlSettings settings, UrlTestHelper testHelper)
        {
            var provider = new AdvancedUrlRewriter();

            provider.ProcessTestRequestWithContext(HttpContext.Current,
                                    HttpContext.Current.Request.Url,
                                    true,
                                    testHelper.Result,
                                    settings);
            testHelper.Response = HttpContext.Current.Response;
        }
        private void ExecuteTestForTab(TabInfo tab, FriendlyUrlSettings settings, Dictionary <string, string> testFields)
        {
            var httpAlias      = testFields.GetValue("Alias", String.Empty);
            var scheme         = testFields["Scheme"];
            var url            = testFields["Test Url"];
            var result         = testFields["Expected Url"];
            var expectedStatus = Int32.Parse(testFields["Status"]);
            var redirectUrl    = testFields.GetValue("Final Url");
            var redirectReason = testFields.GetValue("RedirectReason");

            var tabID = (tab == null) ? "-1" : tab.TabID.ToString();

            var expectedResult      = ReplaceTokens(testFields, result, tabID);
            var testurl             = ReplaceTokens(testFields, url, tabID);
            var expectedRedirectUrl = ReplaceTokens(testFields, redirectUrl, tabID);

            CreateSimulatedRequest(new Uri(testurl));

            var request    = HttpContext.Current.Request;
            var testHelper = new UrlTestHelper
            {
                HttpAliasFull = scheme + httpAlias + "/",
                Result        = new UrlAction(request)
                {
                    IsSecureConnection = request.IsSecureConnection,
                    RawUrl             = request.RawUrl
                },
                RequestUri     = new Uri(testurl),
                QueryStringCol = new NameValueCollection()
            };

            ProcessRequest(settings, testHelper);

            //Test expected response status
            Assert.AreEqual(expectedStatus, testHelper.Response.StatusCode);

            switch (expectedStatus)
            {
            case 200:
                //Test expected rewrite path
                if (!String.IsNullOrEmpty(expectedResult))
                {
                    Assert.AreEqual(expectedResult, testHelper.Result.RewritePath.TrimStart('/'));
                }
                break;

            case 301:
            case 302:
                //Test for final Url if redirected
                Assert.AreEqual(expectedRedirectUrl, testHelper.Result.FinalUrl.TrimStart('/'));
                Assert.AreEqual(redirectReason, testHelper.Result.Reason.ToString(), "Redirect reason incorrect");
                break;
            }
        }
Exemplo n.º 3
0
        private void ProcessRequest(FriendlyUrlSettings settings, UrlTestHelper testHelper)
        {
            var provider = new AdvancedUrlRewriter();

            provider.ProcessTestRequestWithContext(HttpContext.Current,
                                                   HttpContext.Current.Request.Url,
                                                   true,
                                                   testHelper.Result,
                                                   settings);
            testHelper.Response = HttpContext.Current.Response;
        }
Exemplo n.º 4
0
        private void ExecuteTestForTab(TabInfo tab, FriendlyUrlSettings settings, Dictionary<string, string> testFields)
        {
            var httpAlias = testFields.GetValue("Alias", String.Empty);
            var scheme = testFields["Scheme"];
            var url = testFields["Test Url"];
            var result = testFields["Expected Url"];
            var expectedStatus = Int32.Parse(testFields["Status"]);
            var redirectUrl = testFields.GetValue("Final Url");
            var redirectReason = testFields.GetValue("RedirectReason");

            var tabID = (tab == null) ? "-1" : tab.TabID.ToString();

            var expectedResult = ReplaceTokens(testFields, result, tabID);
            var testurl = ReplaceTokens(testFields, url, tabID);
            var expectedRedirectUrl = ReplaceTokens(testFields, redirectUrl, tabID);

            CreateSimulatedRequest(new Uri(testurl));

            var request = HttpContext.Current.Request;
            var testHelper = new UrlTestHelper
                    {
                        HttpAliasFull = scheme + httpAlias + "/",
                        Result = new UrlAction(request)
                                        {
                                            IsSecureConnection = request.IsSecureConnection,
                                            RawUrl = request.RawUrl
                                        },
                        RequestUri = new Uri(testurl),
                        QueryStringCol = new NameValueCollection()
                    };

            ProcessRequest(settings, testHelper);

            //Test expected response status
            Assert.AreEqual(expectedStatus, testHelper.Response.StatusCode);

            switch (expectedStatus)
            {
                case 200:
                    //Test expected rewrite path
                    if (!String.IsNullOrEmpty(expectedResult))
                    {
                        Assert.AreEqual(expectedResult, testHelper.Result.RewritePath.TrimStart('/'));
                    }
                    break;
                case 301:
                case 302:
                    //Test for final Url if redirected
                    Assert.AreEqual(expectedRedirectUrl, testHelper.Result.FinalUrl.TrimStart('/'));
                    Assert.AreEqual(redirectReason, testHelper.Result.Reason.ToString(), "Redirect reason incorrect");
                    break;
            }
        }
Exemplo n.º 5
0
        private void ExecuteTestForTab(TabInfo tab, FriendlyUrlSettings settings, Dictionary <string, string> testFields)
        {
            var defaultAlias   = testFields.GetValue("DefaultAlias", String.Empty);
            var httpAlias      = testFields.GetValue("Alias", String.Empty);
            var tabName        = testFields["Page Name"];
            var scheme         = testFields["Scheme"];
            var url            = testFields["Test Url"];
            var result         = testFields["Expected Url"];
            var expectedStatus = Int32.Parse(testFields["Status"]);
            var redirectUrl    = testFields.GetValue("Final Url");
            var redirectReason = testFields.GetValue("RedirectReason");
            var vanityUrl      = testFields.GetValue("VanityUrl", String.Empty);

            var tabID = (tab == null) ? "-1" : tab.TabID.ToString();

            var    userName = testFields.GetValue("UserName", String.Empty);
            string userId   = String.Empty;

            if (!String.IsNullOrEmpty(userName))
            {
                var user = UserController.GetUserByName(PortalId, userName);
                if (user != null)
                {
                    userId = user.UserID.ToString();
                }
            }

            var expectedResult      = ReplaceTokens(result, httpAlias, defaultAlias, tabName, tabID, PortalId.ToString(), vanityUrl, userId);
            var testurl             = ReplaceTokens(url, httpAlias, defaultAlias, tabName, tabID, PortalId.ToString(), vanityUrl, userId);
            var expectedRedirectUrl = ReplaceTokens(redirectUrl, httpAlias, defaultAlias, tabName, tabID, PortalId.ToString(), vanityUrl, userId);

            CreateSimulatedRequest(new Uri(testurl));

            var testHelper = new UrlTestHelper
            {
                HttpAliasFull = scheme + httpAlias + "/",
                Result        = new UrlAction(scheme, scheme + httpAlias, Globals.ApplicationMapPath)
                {
                    IsSecureConnection = HttpContext.Current.Request.IsSecureConnection,
                    RawUrl             = HttpContext.Current.Request.RawUrl
                },
                RequestUri     = new Uri(testurl),
                QueryStringCol = new NameValueCollection()
            };

            ProcessRequest(settings, testHelper);

            //Test expected response status
            Assert.AreEqual(expectedStatus, testHelper.Response.StatusCode);

            switch (expectedStatus)
            {
            case 200:
                //Test expected rewrite path
                if (!String.IsNullOrEmpty(expectedResult))
                {
                    Assert.AreEqual(expectedResult, testHelper.Result.RewritePath);
                }
                break;

            case 301:
            case 302:
                //Test for final Url if redirected
                Assert.AreEqual(expectedRedirectUrl, testHelper.Result.FinalUrl);
                Assert.AreEqual(redirectReason, testHelper.Result.Reason.ToString(), "Redirect reason incorrect");
                break;
            }
        }
Exemplo n.º 6
0
        private void ExecuteTestForTab(TabInfo tab, FriendlyUrlSettings settings, Dictionary<string, string> testFields)
        {
            var defaultAlias = testFields.GetValue("DefaultAlias", String.Empty);
            var httpAlias = testFields.GetValue("Alias", String.Empty);
            var tabName = testFields["Page Name"];
            var scheme = testFields["Scheme"];
            var url = testFields["Test Url"];
            var result = testFields["Expected Url"];
            var expectedStatus = Int32.Parse(testFields["Status"]);
            var redirectUrl = testFields.GetValue("Final Url");
            var redirectReason = testFields.GetValue("RedirectReason");
            var vanityUrl = testFields.GetValue("VanityUrl", String.Empty);

            var tabID = (tab == null) ? "-1" : tab.TabID.ToString();

            var userName = testFields.GetValue("UserName", String.Empty);
            string userId = String.Empty;
            if (!String.IsNullOrEmpty(userName))
            {
                var user = UserController.GetUserByName(PortalId, userName);
                if (user != null)
                {
                    userId = user.UserID.ToString();
                }
            }

            var expectedResult = ReplaceTokens(result, httpAlias, defaultAlias, tabName, tabID, PortalId.ToString(), vanityUrl, userId);
            var testurl = ReplaceTokens(url, httpAlias, defaultAlias, tabName, tabID, PortalId.ToString(), vanityUrl, userId);
            var expectedRedirectUrl = ReplaceTokens(redirectUrl, httpAlias, defaultAlias, tabName, tabID, PortalId.ToString(), vanityUrl, userId);

            CreateSimulatedRequest(new Uri(testurl));

            var testHelper = new UrlTestHelper
                    {
                        HttpAliasFull = scheme + httpAlias + "/",
                        Result = new UrlAction(scheme, scheme + httpAlias, Globals.ApplicationMapPath)
                                    {
                                        IsSecureConnection = HttpContext.Current.Request.IsSecureConnection,
                                        RawUrl = HttpContext.Current.Request.RawUrl
                                    },
                        RequestUri = new Uri(testurl),
                        QueryStringCol = new NameValueCollection()
                    };

            ProcessRequest(settings, testHelper);

            //Test expected response status
            Assert.AreEqual(expectedStatus, testHelper.Response.StatusCode);

            switch (expectedStatus)
            {
                case 200:
                    //Test expected rewrite path
                    if (!String.IsNullOrEmpty(expectedResult))
                    {
                        Assert.AreEqual(expectedResult, testHelper.Result.RewritePath);
                    }
                    break;
                case 301:
                case 302:
                    //Test for final Url if redirected
                    Assert.AreEqual(expectedRedirectUrl, testHelper.Result.FinalUrl);
                    Assert.AreEqual(redirectReason, testHelper.Result.Reason.ToString(), "Redirect reason incorrect");
                    break;
            }
        }