Exemplo n.º 1
0
        private string ReplaceTokens(Dictionary<string, string> testFields, string url, string tabId)
        {
            var defaultAlias = testFields.GetValue("DefaultAlias", String.Empty);
            var httpAlias = testFields.GetValue("Alias", String.Empty);
            var tabName = testFields["Page Name"];
            var vanityUrl = testFields.GetValue("VanityUrl", String.Empty);
            var homeTabId = testFields.GetValue("HomeTabId", String.Empty);

            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();
                }
            }

            return url.Replace("{alias}", httpAlias)
                            .Replace("{usealias}", defaultAlias)
                            .Replace("{tabName}", tabName)
                            .Replace("{tabId}", tabId)
                            .Replace("{portalId}", PortalId.ToString())
                            .Replace("{vanityUrl}", vanityUrl)
                            .Replace("{userId}", userId)
                            .Replace("{defaultPage}", _defaultPage);
        }
        public void GetValue_WhenIWantToRetrieveTheValueOfAKeyInADictionary_ReturnValue()
        {
            //Arrange
            Dictionary<string, string> dictionary = new Dictionary<string, string>()
            {
                { "Value1", "Result1"},
                { "Value2", "Result2"}
            };
            var stringValueExpected = "Result1";
            var stringKey = "Value1";

            //Act
            var value = dictionary.GetValue<string, string>(stringKey);

            //Assert
            Assert.AreEqual(stringValueExpected, value, "Dictionary value test passed");
        }
Exemplo n.º 3
0
        public void AdvancedUrlRewriter_JiraTests(Dictionary<string, string> testFields)
        {
            var testName = testFields.GetValue("Test", String.Empty);

            var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", "Jira_Tests", testName + ".csv");
            var dictionary = UrlTestFactoryClass.GetDictionary("UrlRewrite", "Jira_Tests", testName + "_dic.csv");

            int homeTabId = -1;
            foreach (var keyValuePair in dictionary)
            {
                switch (keyValuePair.Key)
                {
                    case "HomeTabId":
                        homeTabId = UpdateHomeTab(Int32.Parse(keyValuePair.Value));
                        break;
                    default:
                        break;
                }
            }

            ExecuteTest(settings, testFields, true);

            if (homeTabId != -1)
            {
                UpdateHomeTab(homeTabId);
            }

        }
Exemplo n.º 4
0
        public void AdvancedUrlRewriter_VanityUrl(Dictionary<string, string> testFields)
        {
            var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", testFields["TestName"]);
            settings.DeletedTabHandlingType = DeletedTabHandlingType.Do301RedirectToPortalHome;

            var vanityUrl = testFields.GetValue("VanityUrl", String.Empty);
            var userName = testFields.GetValue("UserName", String.Empty);
            var redirectOld = testFields.GetValue("RedirectOldProfileUrl", String.Empty);

            if (!String.IsNullOrEmpty(userName))
            {
                var user = UserController.GetUserByName(PortalId, userName);
                if (user != null)
                {
                    user.VanityUrl = vanityUrl;
                    UserController.UpdateUser(PortalId, user);
                }
            }

            if (!String.IsNullOrEmpty(redirectOld))
            {
                settings.RedirectOldProfileUrl = Convert.ToBoolean(redirectOld);
            }
            ExecuteTest(settings, testFields, true);
        }
Exemplo n.º 5
0
        public void AdvancedUrlRewriter_ReplaceSpace(Dictionary<string, string> testFields)
        {
            var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", testFields["TestName"]);

            string replaceSpaceWith = testFields.GetValue("ReplaceSpaceWith");
            if (!String.IsNullOrEmpty(replaceSpaceWith))
            {
                settings.ReplaceSpaceWith = replaceSpaceWith;
            }

            ExecuteTest(settings, testFields, true);
        }
Exemplo n.º 6
0
        public void AdvancedUrlRewriter_ReplaceChars(Dictionary<string, string> testFields)
        {
            var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", testFields["TestName"]);

            string testPageName = testFields.GetValue("TestPageName");
            TabInfo tab = null;
            if (!String.IsNullOrEmpty(testPageName))
            {
                var tabName = testFields["Page Name"];
                var tc = new TabController();
                tab = tc.GetTabByName(tabName, PortalId);
                tab.TabName = testPageName;
                tc.UpdateTab(tab);

                //Refetch tab from DB
                tab = tc.GetTab(tab.TabID, tab.PortalID, false);
            }

            settings.PortalId = PortalId;

            string autoAscii = testFields.GetValue("AutoAscii");

            if (!String.IsNullOrEmpty(autoAscii))
            {
                settings.AutoAsciiConvert = Convert.ToBoolean(autoAscii);
            }

            TestUtil.GetReplaceCharDictionary(testFields, settings.ReplaceCharacterDictionary);

            SetDefaultAlias(testFields);

            ExecuteTestForTab(tab, settings, testFields);
        }
Exemplo n.º 7
0
        public void AdvancedUrlRewriter_ForceLowerCase(Dictionary<string, string> testFields)
        {
            var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", testFields["TestName"]);

            string forceLowerCaseRegex = testFields.GetValue("ForceLowerCaseRegex");

            if (!String.IsNullOrEmpty(forceLowerCaseRegex))
            {
                settings.ForceLowerCaseRegex = forceLowerCaseRegex;
            }

            settings.PortalId = PortalId;

            ExecuteTest(settings, testFields, true);
        }
Exemplo n.º 8
0
        public void AdvancedUrlRewriter_DeletedTabHandling(Dictionary<string, string> testFields)
        {
            var settings = UrlTestFactoryClass.GetSettings("UrlRewrite", testFields["TestName"]);

            settings.PortalId = PortalId;

            var tc = new TabController();
            var tab = tc.GetTabByName(_testPage, PortalId);
            if (Convert.ToBoolean(testFields["HardDeleted"]))
            {
                DeleteTab(_testPage);
                CacheController.FlushPageIndexFromCache();
            }
            else
            {
                tab.IsDeleted = Convert.ToBoolean(testFields["SoftDeleted"]);
                tab.DisableLink = Convert.ToBoolean(testFields["Disabled"]);
                if (Convert.ToBoolean(testFields["Expired"]))
                {
                    tab.EndDate = DateTime.Now - TimeSpan.FromDays(1);
                }
                UpdateTab(tab);
            }

            string deletedTabHandling = testFields.GetValue("DeletedTabHandling");

            if (!String.IsNullOrEmpty(deletedTabHandling))
            {
                switch (deletedTabHandling)
                {
                    case "Do404Error":
                        settings.DeletedTabHandlingType = DeletedTabHandlingType.Do404Error;
                        break;
                    default:
                        settings.DeletedTabHandlingType = DeletedTabHandlingType.Do301RedirectToPortalHome;
                        break;
                }
            }

            SetDefaultAlias(testFields);

            ExecuteTest(settings, testFields, true);
        }
Exemplo n.º 9
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.º 10
0
        public static void AddPersonFilmIndexes(this List<Person> peopleFilmIndexesToAdd, int filmID, Dictionary<string, string> castCharacters, int roleID )
        {
            foreach (Person person in peopleFilmIndexesToAdd)
            {

                Context.AddToPersonFilmIndexes(
                    new PersonFilmIndex
                        {
                            FilmID = filmID,
                            PersonID = person.PersonID,
                            Character = castCharacters.GetValue(string.Format("{0} {1}", person.FirstName, person.LastName)),
                            RoleID = roleID
                        }
                    );

            }
        }
        public void get_nullable_datetime()
        {
            var collection = new Dictionary<string, DateTime?> { { "startDate", null } };

            var value = collection.GetValue<DateTime?>("startDate");

            Expect(value, Is.Null);
        }
        public void get_null_string_without_default()
        {
            var collection = new Dictionary<string, string> { { "app id", null } };

            var value = collection.GetValue<string>("app id");

            Expect(value, Is.Null);
        }
Exemplo n.º 13
0
 public void GetValue_DictionaryContainsKey_ReturnsExistingValue()
 {
     var key = new object();
     var value = new object();
     var dictionary = new Dictionary<object, object> { {key, value} };
     var result = dictionary.GetValue(key, () => null);
     Assert.That(result, Is.SameAs(value));
 }
Exemplo n.º 14
0
 public void GetValue_DictionaryContainsKey_GetValueToAddIsNotCalled()
 {
     int counter = 0;
     var key = new object();
     var dictionary = new Dictionary<object, object> { { key, null } };
     dictionary.GetValue(key, () =>
                                 {
                                     counter++;
                                     return null;
                                 });
     Assert.That(counter, Is.EqualTo(0));
 }
Exemplo n.º 15
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;
            }
        }