Beispiel #1
0
        public void DotvvmRoute_Performance()
        {
            var route = new DotvvmRoute("Article/{name}@{domain}/{id:int}", null, null, null, configuration);
            IDictionary <string, object> parameters;

            Assert.IsFalse(route.IsMatch("Article/f" + new string('@', 2000) + "f/4f", out parameters));
        }
Beispiel #2
0
 public void DotvvmRoute_IsMatch_RouteMustNotEndWithSlash()
 {
     Assert.ThrowsException <ArgumentException>(() =>
     {
         var route = new DotvvmRoute("Test/", null, null, null, configuration);
     });
 }
Beispiel #3
0
        public void DotvvmRoute_BuildUrl_Static_TwoParts_TwoParameters_OneOptional_NoValue_Suffix()
        {
            var route = new DotvvmRoute("Article/Test/{Id}/{Id2?}/suffix", null, null, null);

            var result = route.BuildUrl(new { Id = 5 });

            Assert.AreEqual("~/Article/Test/5/suffix", result);
        }
Beispiel #4
0
        public void DotvvmRoute_BuildUrl_UrlTwoParameters()
        {
            var route = new DotvvmRoute("Article/id_{Id}/{Title}", null, null, null);

            var result = route.BuildUrl(new { Id = 15, Title = "Test" });

            Assert.AreEqual("~/Article/id_15/Test", result);
        }
Beispiel #5
0
        public void DotvvmRoute_BuildUrl_Static_TwoParts_OptionalParameter_WithValue()
        {
            var route = new DotvvmRoute("Article/Test/{Id?}", null, null, null);

            var result = route.BuildUrl(new { Id = 5 });

            Assert.AreEqual("~/Article/Test/5", result);
        }
Beispiel #6
0
        public void DotvvmRoute_BuildUrl_Static_TwoParts_TwoParameters_OneOptional_WithValue()
        {
            var route = new DotvvmRoute("Article/Test/{Id}/{Id2?}", null, null, null);

            var result = route.BuildUrl(new { Id = 5, Id2 = "aaa" });

            Assert.AreEqual("~/Article/Test/5/aaa", result);
        }
Beispiel #7
0
        public void DotvvmRoute_BuildUrl_ParameterOnly()
        {
            var route = new DotvvmRoute("{Id?}", null, null, null);

            var result = route.BuildUrl(new { });

            Assert.AreEqual("~/", result);
        }
Beispiel #8
0
        public void DotvvmRoute_BuildUrl_NoParameter()
        {
            var route = new DotvvmRoute("RR", null, null, null, configuration);

            var result = route.BuildUrl(null);

            Assert.AreEqual("~/RR", result);
        }
Beispiel #9
0
        public void DotvvmRoute_BuildUrl_Static_TwoParts_TwoParameters_FirstOptionalOptional_Suffix()
        {
            var route = new DotvvmRoute("Article/Test/{Id?}/{Id2}/suffix", null, null, null);

            var result = route.BuildUrl(new { Id2 = "aaa" });

            Assert.AreEqual("~/Article/Test/aaa/suffix", result);
        }
Beispiel #10
0
        public void DotvvmRoute_BuildUrl_Static_TwoParts()
        {
            var route = new DotvvmRoute("Article/Test", null, null, null);

            var result = route.BuildUrl(new { });

            Assert.AreEqual("~/Article/Test", result);
        }
Beispiel #11
0
        public void DotvvmRoute_BuildUrl_Static_OnePart()
        {
            var route = new DotvvmRoute("Article", null, null, null, configuration);

            var result = route.BuildUrl(new { });

            Assert.AreEqual("~/Article", result);
        }
Beispiel #12
0
        public void DotvvmRoute_BuildUrl_Invalid_UnclosedParameterConstraint()
        {
            Assert.ThrowsException <ArgumentException>(() => {
                var route = new DotvvmRoute("{Id:int", null, null, null, configuration);

                var result = route.BuildUrl(new { });
            });
        }
Beispiel #13
0
        public void DotvvmRoute_IsMatch_UrlOneParameterRequired_TwoSpecified()
        {
            var route = new DotvvmRoute("Article/{Id}", null, null, null);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("Article/15/test", out parameters);

            Assert.IsFalse(result);
        }
Beispiel #14
0
        public void DotvvmRoute_IsMatch_UrlWithoutParametersExactMatch()
        {
            var route = new DotvvmRoute("Hello/Test/Page.txt", null, null, null, configuration);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("Hello/Test/Page.txt", out parameters);

            Assert.IsTrue(result);
        }
Beispiel #15
0
        public void DotvvmRoute_IsMatch_UrlTwoParametersBothRequired_NoMatchWhenOneSpecified()
        {
            var route = new DotvvmRoute("Article/{Id}/{Title}", null, null, null);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("Article/15", out parameters);

            Assert.IsFalse(result);
        }
Beispiel #16
0
        public void DotvvmRoute_RegexConstraint()
        {
            var route = new DotvvmRoute("test/{Name:regex((aa|bb|cc))}", null, null, null, configuration);

            Assert.IsTrue(route.IsMatch("test/aa", out var parameters));
            Assert.IsTrue(route.IsMatch("test/bb", out parameters));
            Assert.IsTrue(route.IsMatch("test/cc", out parameters));
            Assert.IsFalse(route.IsMatch("test/aaaa", out parameters));
        }
Beispiel #17
0
        public void DotvvmRoute_IsMatch_UrlWithoutParametersNoMatch()
        {
            var route = new DotvvmRoute("Hello/Test/Page.txt", null, null, null);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("Hello/Test/Page", out parameters);

            Assert.IsFalse(result);
        }
Beispiel #18
0
        public void DotvvmRoute_IsMatch_EmptyRouteMatchesEmptyUrl()
        {
            var route = new DotvvmRoute("", null, null, null);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("", out parameters);

            Assert.IsTrue(result);
        }
Beispiel #19
0
        public void DotvvmRoute_IsMatch_UrlTwoParametersBothRequired_DifferentPart()
        {
            var route = new DotvvmRoute("Article/id_{Id}/{Title}", null, null, null);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("Articles/id_15", out parameters);

            Assert.IsFalse(result);
        }
Beispiel #20
0
        public void DotvvmRoute_IsMatch_TwoParameters_OneOptional_Suffix()
        {
            var route = new DotvvmRoute("Article/Test/{Id?}/{Id2}/suffix", null, null, null, configuration);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("Article/Test/5/suffix", out parameters);

            Assert.IsTrue(result);
            Assert.AreEqual(1, parameters.Count);
        }
Beispiel #21
0
        public void DotvvmRoute_IsMatch_OneOptionalParameter()
        {
            var route = new DotvvmRoute("Article/{Id?}/edit", null, null, null, configuration);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("Article/edit", out parameters);

            Assert.IsTrue(result);
            Assert.AreEqual(0, parameters.Count);
        }
Beispiel #22
0
        public void DotvvmRoute_IsMatch_OneOptionalSuffixedParameter_WithConstraint()
        {
            var route = new DotvvmRoute("Article/{Id?:int}", null, null, null, configuration);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("Article", out parameters);

            Assert.IsTrue(result);
            Assert.AreEqual(0, parameters.Count);
        }
Beispiel #23
0
        public void DotvvmRoute_BuildUrl_CombineParameters_OneOptional()
        {
            var route = new DotvvmRoute("Article/{Id?}", null, null, null);

            var result = route.BuildUrl(new Dictionary <string, object>()
            {
                { "Id", 5 }
            }, new { });

            Assert.AreEqual("~/Article/5", result);
        }
Beispiel #24
0
        public void DotvvmRoute_IsMatch_UrlTwoParametersBothRequired_BothSpecified()
        {
            var route = new DotvvmRoute("Article/id_{Id}/{Title}", null, null, null);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("Article/id_15/test", out parameters);

            Assert.IsTrue(result);
            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual("15", parameters["Id"]);
            Assert.AreEqual("test", parameters["Title"]);
        }
Beispiel #25
0
        public void DotvvmRoute_BuildUrl_OneOptionalPrefixedParameter()
        {
            var route = new DotvvmRoute("{Id?}/Article", null, null, null, configuration);

            var result  = route.BuildUrl(new { });
            var result2 = route.BuildUrl(new Dictionary <string, object> {
                ["Id"] = 0
            });

            Assert.AreEqual("~/Article", result);
            Assert.AreEqual("~/0/Article", result2);
        }
Beispiel #26
0
        public void DotvvmRoute_IsMatch_UrlTwoParametersOneSpecifiedOneDefault()
        {
            var route = new DotvvmRoute("Article/{Id}/{Title}", null, new { Title = "test" }, null);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("Article/15", out parameters);

            Assert.IsTrue(result);
            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual("15", parameters["Id"]);
            Assert.AreEqual("test", parameters["Title"]);
        }
Beispiel #27
0
        public void DotvvmRoute_BuildUrl_NullInParameter()
        {
            var route = new DotvvmRoute("myPage/{Id}/edit", null, null, null, configuration);

            var ex = Assert.ThrowsException <Exception>(() => {
                route.BuildUrl(new Dictionary <string, object> {
                    ["Id"] = null
                });
            });

            Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentNullException));
        }
Beispiel #28
0
        public void DotvvmRoute_BuildUrl_ParameterConstraint_Int()
        {
            var route = new DotvvmRoute("Article/id_{Id:int}/{Title}", null, null, null);

            IDictionary <string, object> parameters;
            var result = route.IsMatch("Article/id_15/test", out parameters);

            Assert.IsTrue(result);
            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual(15, parameters["Id"]);
            Assert.AreEqual("test", parameters["Title"]);
        }
Beispiel #29
0
        public void DotvvmRoute_BuildUrl_ParameterConstraint_Bool()
        {
            var route = new DotvvmRoute("la{bool:bool}eheh", null, null, null, configuration);

            IDictionary <string, object> parameters;

            Assert.IsTrue(route.IsMatch("latrueeheh", out parameters));
            Assert.IsTrue(route.IsMatch("lafALseeheh", out parameters));

            Assert.AreEqual(1, parameters.Count);
            Assert.AreEqual(false, parameters["bool"]);
        }
Beispiel #30
0
        public void DotvvmRoute_BuildUrl_ParameterConstraintAlpha()
        {
            var route = new DotvvmRoute("la1{aplha:alpha}7huh", null, null, null, configuration);

            IDictionary <string, object> parameters;

            Assert.IsTrue(route.IsMatch("la1lala7huh", out parameters));
            Assert.IsTrue(route.IsMatch("la1ahoj7huh", out parameters));

            Assert.AreEqual(1, parameters.Count);
            Assert.AreEqual("ahoj", parameters["aplha"]);
        }