예제 #1
0
        public void Test_Match_CheckConstraints_Success()
        {
            var pattern = new TailUrlMatchingPattern
            {
                Pattern  = "tariff/{geoCode?}/{tariffId?}",
                Defaults = new Dictionary <string, string> {
                    { "action", "Details" }
                },
                Constraints = new Dictionary <string, string> {
                    { "tariffId", "^$|\\d{5,9}" }, { "geoCode", "[a-zA-z_\\-]*" }
                }
            };

            TailUrlMatchResult tailUrlMatchResult = pattern.Match("tariff/ru-RU/12345");

            Assert.IsTrue(tailUrlMatchResult.IsMatch);

            Assert.AreEqual(tailUrlMatchResult.Values.Keys.Count, 3);

            Assert.IsTrue(tailUrlMatchResult.Values.ContainsKey("action"));
            Assert.AreEqual(tailUrlMatchResult.Values["action"], "Details");

            Assert.IsTrue(tailUrlMatchResult.Values.ContainsKey("tariffId"));
            Assert.AreEqual(tailUrlMatchResult.Values["tariffId"], "12345");

            Assert.IsTrue(tailUrlMatchResult.Values.ContainsKey("geoCode"));
            Assert.AreEqual(tailUrlMatchResult.Values["geoCode"], "ru-RU");
        }
예제 #2
0
        public void Test_Match_VariativePattern_Success()
        {
            var pattern = new TailUrlMatchingPattern
            {
                Pattern = "{action[Archive|Popular]}/{categoryAlias}"
            };

            TailUrlMatchResult tailUrlMatchResult = pattern.Match("Archive/cat");

            Assert.IsTrue(tailUrlMatchResult.IsMatch);

            Assert.AreEqual(tailUrlMatchResult.Values.Keys.Count, 2);

            Assert.IsTrue(tailUrlMatchResult.Values.ContainsKey("action"));
            Assert.AreEqual(tailUrlMatchResult.Values["action"], "Archive");

            Assert.IsTrue(tailUrlMatchResult.Values.ContainsKey("categoryAlias"));
            Assert.AreEqual(tailUrlMatchResult.Values["categoryAlias"], "cat");

            tailUrlMatchResult = pattern.Match("Popular/cat");

            Assert.IsTrue(tailUrlMatchResult.IsMatch);

            Assert.AreEqual(tailUrlMatchResult.Values.Keys.Count, 2);

            Assert.IsTrue(tailUrlMatchResult.Values.ContainsKey("action"));
            Assert.AreEqual(tailUrlMatchResult.Values["action"], "Popular");

            Assert.IsTrue(tailUrlMatchResult.Values.ContainsKey("categoryAlias"));
            Assert.AreEqual(tailUrlMatchResult.Values["categoryAlias"], "cat");
        }
예제 #3
0
        public void Test_Match_VariativePattern_Fail()
        {
            var pattern = new TailUrlMatchingPattern
            {
                Pattern = "{action[Archive|Popular]}/{categoryAlias}"
            };

            TailUrlMatchResult tailUrlMatchResult = pattern.Match("HomeOfCat/littleCat");

            Assert.IsFalse(tailUrlMatchResult.IsMatch);
        }
예제 #4
0
        public void Test_Match_CheckConstraints_Fail()
        {
            var pattern = new TailUrlMatchingPattern
            {
                Pattern  = "tariff/{geoCode}/{tariffId}",
                Defaults = new Dictionary <string, string> {
                    { "action", "Details" }
                },
                Constraints = new Dictionary <string, string> {
                    { "tariffId", "\\d{5,9}" }, { "geoCode", "[a-zA-z_\\-]+" }
                }
            };

            TailUrlMatchResult tailUrlMatchResult = pattern.Match("tariff/ru-RU/qwert");

            Assert.IsFalse(tailUrlMatchResult.IsMatch);
        }
예제 #5
0
        public void Test_Match_CheckConstraints_EmptyRegex_Throw()
        {
            var pattern = new TailUrlMatchingPattern
            {
                Pattern  = "tariff/{geoCode}/{tariffId}",
                Defaults = new Dictionary <string, string> {
                    { "action", "Details" }
                },
                Constraints = new Dictionary <string, string> {
                    { "tariffId", "^$" }, { "geoCode", "[a-zA-z_\\-]*" }
                }
            };

            Assert.ThrowsException <IncorrectConstraintOrPatternException>(() =>
            {
                TailUrlMatchResult tailUrlMatchResult = pattern.Match("tariff/ru-RU/");
            });
        }
예제 #6
0
        public void Test_Match_VariativePattern_EmptyVariativePattern()
        {
            var pattern = new TailUrlMatchingPattern
            {
                Pattern = "{action[]}/{categoryAlias}"
            };

            TailUrlMatchResult tailUrlMatchResult = pattern.Match("HomeOfCat/littleCat");

            Assert.IsTrue(tailUrlMatchResult.IsMatch);

            Assert.AreEqual(tailUrlMatchResult.Values.Keys.Count, 2);

            Assert.IsTrue(tailUrlMatchResult.Values.ContainsKey("action"));
            Assert.AreEqual(tailUrlMatchResult.Values["action"], "HomeOfCat");

            Assert.IsTrue(tailUrlMatchResult.Values.ContainsKey("categoryAlias"));
            Assert.AreEqual(tailUrlMatchResult.Values["categoryAlias"], "littleCat");
        }