예제 #1
0
		public void ShouldMatchSimplesSlash()
		{
			PatternRoute route = new PatternRoute("/");
			RouteMatch match = new RouteMatch();
			Assert.AreEqual(1, route.Matches("/", CreateGetContext(), match));
			Assert.AreEqual(1, route.Matches("", CreateGetContext(), match));
			Assert.AreEqual(0, route.Matches("some", CreateGetContext(), match));
			Assert.AreEqual(0, route.Matches("/some", CreateGetContext(), match));
		}
예제 #2
0
        public void ShouldMatchSimplesSlash()
        {
            var route = new PatternRoute("/");
            var match = new RouteMatch();

            Assert.AreEqual(1, route.Matches("/", CreateGetContext(), match));
            Assert.AreEqual(1, route.Matches("", CreateGetContext(), match));
            Assert.AreEqual(0, route.Matches("some", CreateGetContext(), match));
            Assert.AreEqual(0, route.Matches("/some", CreateGetContext(), match));
        }
예제 #3
0
        public void AnythingBut_Restriction()
        {
            var route = new PatternRoute("/<controller>/[action]/[id]")
                        .Restrict("controller").AnythingBut("dummy")
                        .Restrict("id").ValidInteger;

            var match = new RouteMatch();

            Assert.AreEqual(0, route.Matches("/dummy/index", CreateGetContext(), match));
            Assert.AreEqual(0, route.Matches("/DUMMY/list", CreateGetContext(), match));
            Assert.AreEqual(4001, route.Matches("/some/new", CreateGetContext(), match));
            Assert.AreEqual(6000, route.Matches("/some/list/1", CreateGetContext(), match));
        }
예제 #4
0
        public void NamedOptionalParameters()
        {
            var route = new PatternRoute("/<controller>/[action]/[id]");
            var match = new RouteMatch();

            Assert.AreEqual(4001, route.Matches("/some/act", CreateGetContext(), match));
            Assert.AreEqual("some", match.Parameters["controller"]);
            Assert.AreEqual("act", match.Parameters["action"]);

            match = new RouteMatch();
            Assert.AreEqual(6000, route.Matches("/some/act/10", CreateGetContext(), match));
            Assert.AreEqual("some", match.Parameters["controller"]);
            Assert.AreEqual("act", match.Parameters["action"]);
            Assert.AreEqual("10", match.Parameters["id"]);
        }
예제 #5
0
        public void ShouldMatchStatic()
        {
            var route = new PatternRoute("/some/path");
            var match = new RouteMatch();

            Assert.AreEqual(8000, route.Matches("/some/path", CreateGetContext(), match));
        }
예제 #6
0
        public void ShouldMatchStaticWithFileExtension()
        {
            var route = new PatternRoute("/default.aspx");
            var match = new RouteMatch();

            Assert.AreEqual(8000, route.Matches("/default.aspx", CreateGetContext(), match));
        }
예제 #7
0
        public void ShouldMatchHiphensAndUnderlines()
        {
            var route = new PatternRoute("/some/path_to-this");
            var match = new RouteMatch();

            Assert.AreEqual(8000, route.Matches("/some/path_to-this", CreateGetContext(), match));
        }
예제 #8
0
        public void ShouldReturnZeroForMissingRequiredPart()
        {
            var route = new PatternRoute("/<controller>/[action]");

            var match = new RouteMatch();

            Assert.AreEqual(0, route.Matches("/", CreateGetContext(), match));
        }
예제 #9
0
        public void NamedRequiredParametersWithRestrictions()
        {
            var matchGuid =
                "[A-Fa-f0-9]{32}|" +
                "({|\\()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|\\))?|" +
                "({)?[0xA-Fa-f0-9]{3,10}(, {0,1}[0xA-Fa-f0-9]{3,6}){2}, {0,1}({)([0xA-Fa-f0-9]{3,4}, {0,1}){7}[0xA-Fa-f0-9]{3,4}(}})";

            var route = new PatternRoute("/<param>/<key>")
                        .Restrict("key").ValidRegex(matchGuid);

            var match = new RouteMatch();

            Assert.AreEqual(0, route.Matches("/something/zzzzzzzz-c123-11dc-95ff-0800200c9a66", CreateGetContext(), match));
            Assert.AreEqual(4000, route.Matches("/something/173e0970-c123-11dc-95ff-0800200c9a66", CreateGetContext(), match));
            Assert.AreEqual("something", match.Parameters["param"]);
            Assert.AreEqual("173e0970-c123-11dc-95ff-0800200c9a66", match.Parameters["key"]);
        }
예제 #10
0
		public void NamedRequiredParameters()
		{
			PatternRoute route = new PatternRoute("/<controller>/<action>");
			RouteMatch match = new RouteMatch();
			Assert.AreEqual(4000, route.Matches("/some/act", CreateGetContext(), match));
			Assert.AreEqual("some", match.Parameters["controller"]);
			Assert.AreEqual("act", match.Parameters["action"]);
		}
		public void NamedRequiredParametersForExtension()
		{
			var route = new PatternRoute("/<controller>/<action>.<format>");
			var match = new RouteMatch();
			Assert.AreEqual(6000, route.Matches("/some/act.xml", CreateGetContext(), match));
			Assert.AreEqual("some", match.Parameters["controller"]);
			Assert.AreEqual("act", match.Parameters["action"]);
			Assert.AreEqual("xml", match.Parameters["format"]);
		}
예제 #12
0
        public int Matches(string url, Castle.MonoRail.Framework.IRouteContext context, RouteMatch match)
        {
            if (context.Request.HttpMethod == _httpMethod)
            {
                return(_innerRoute.Matches(url, context, match));
            }

            return(0);
        }
예제 #13
0
        public void NamedRequiredParameters()
        {
            var route = new PatternRoute("/<controller>/<action>");
            var match = new RouteMatch();

            Assert.AreEqual(4000, route.Matches("/some/act", CreateGetContext(), match));
            Assert.AreEqual("some", match.Parameters["controller"]);
            Assert.AreEqual("act", match.Parameters["action"]);
        }
예제 #14
0
        public void ShouldNotMatchWhenRestrictingMultipleVerbs()
        {
            var route = new PatternRoute("/simple")
                        .RestrictTo(Verb.Post | Verb.Put);

            var match = new RouteMatch();

            Assert.AreEqual(0, route.Matches("/simple", CreateGetContext(), match));
        }
예제 #15
0
        public void ShouldMatchWhenRestrictingWithMatchingMultipleVerb()
        {
            var route = new PatternRoute("/simple")
                        .RestrictTo(Verb.Get | Verb.Post);

            var match = new RouteMatch();

            Assert.Less(0, route.Matches("/simple", CreateGetContext(), match));
        }
예제 #16
0
        public void NamedParametersCanHaveUnderlines()
        {
            var route = new PatternRoute("/<controller>/<action>");
            var match = new RouteMatch();

            route.Matches("/some/act_name", CreateGetContext(), match);
            Assert.AreEqual("some", match.Parameters["controller"]);
            Assert.AreEqual("act_name", match.Parameters["action"]);
        }
예제 #17
0
		public void ShouldMatchStaticCaseInsensitive()
		{
			PatternRoute route = new PatternRoute("/default.aspx");
			RouteMatch match = new RouteMatch();
			Assert.AreEqual(8000, route.Matches("/DEFAULT.ASPX", CreateGetContext(), match));

			route = new PatternRoute("/some/path");
			match = new RouteMatch();
			Assert.AreEqual(8000, route.Matches("/SOME/Path", CreateGetContext(), match));
		}
예제 #18
0
        public void ShouldReturnNonZeroForMatchedDefaults()
        {
            var route = new PatternRoute("/[controller]/[action]");

            var match = new RouteMatch();

            Assert.AreEqual(2, route.Matches("/", CreateGetContext(), match));
            Assert.IsTrue(match.Parameters.ContainsKey("controller"));
            Assert.IsTrue(match.Parameters.ContainsKey("action"));
        }
예제 #19
0
        public void ShouldMatchEmptyUrl()
        {
            var route = new PatternRoute("/[controller]/[action]");

            var match = new RouteMatch();

            Assert.AreEqual(2, route.Matches("", CreateGetContext(), match));
            Assert.IsTrue(match.Parameters.ContainsKey("controller"));
            Assert.IsTrue(match.Parameters.ContainsKey("action"));
        }
예제 #20
0
        public void ShouldMatchStaticCaseInsensitive()
        {
            var route = new PatternRoute("/default.aspx");
            var match = new RouteMatch();

            Assert.AreEqual(8000, route.Matches("/DEFAULT.ASPX", CreateGetContext(), match));

            route = new PatternRoute("/some/path");
            match = new RouteMatch();
            Assert.AreEqual(8000, route.Matches("/SOME/Path", CreateGetContext(), match));
        }
예제 #21
0
        public void NamedOptionalParametersWithDefaults()
        {
            var route = new PatternRoute("/<controller>/[action]/[id]")
                        .DefaultFor("action").Is("index").DefaultFor("id").Is("0");
            var match = new RouteMatch();

            Assert.AreEqual(2002, route.Matches("/some", CreateGetContext(), match));
            Assert.AreEqual("some", match.Parameters["controller"]);
            Assert.AreEqual("index", match.Parameters["action"]);
            Assert.AreEqual("0", match.Parameters["id"]);
        }
예제 #22
0
        public void NamedOptionalParametersWithRestrictions()
        {
            var route = new PatternRoute("/<controller>/[action]/[id]")
                        .Restrict("action").AnyOf("index", "list")
                        .Restrict("id").ValidInteger;

            var match = new RouteMatch();

            Assert.AreEqual(4001, route.Matches("/some/index", CreateGetContext(), match));
            Assert.AreEqual(4001, route.Matches("/some/list", CreateGetContext(), match));
            Assert.AreEqual(0, route.Matches("/some/new", CreateGetContext(), match));
            Assert.AreEqual(0, route.Matches("/some/index/foo", CreateGetContext(), match));
            Assert.AreEqual(0, route.Matches("/some/list/bar", CreateGetContext(), match));
            Assert.AreEqual(6000, route.Matches("/some/list/1", CreateGetContext(), match));
        }
예제 #23
0
		public void NamedOptionalParameters()
		{
			PatternRoute route = new PatternRoute("/<controller>/[action]/[id]");
			RouteMatch match = new RouteMatch();
			Assert.AreEqual(4001, route.Matches("/some/act", CreateGetContext(), match));
			Assert.AreEqual("some", match.Parameters["controller"]);
			Assert.AreEqual("act", match.Parameters["action"]);

			match = new RouteMatch();
			Assert.AreEqual(6000, route.Matches("/some/act/10", CreateGetContext(), match));
			Assert.AreEqual("some", match.Parameters["controller"]);
			Assert.AreEqual("act", match.Parameters["action"]);
			Assert.AreEqual("10", match.Parameters["id"]);
		}
예제 #24
0
		public void ShouldReturnZeroForMissingRequiredPart()
		{
			PatternRoute route = new PatternRoute("/<controller>/[action]");

			RouteMatch match = new RouteMatch();
			Assert.AreEqual(0, route.Matches("/", CreateGetContext(), match));
		}
예제 #25
0
		public void ShouldMatchEmptyUrl()
		{
			PatternRoute route = new PatternRoute("/[controller]/[action]");

			RouteMatch match = new RouteMatch();
			Assert.AreEqual(2, route.Matches("", CreateGetContext(), match));
			Assert.IsTrue(match.Parameters.ContainsKey("controller"));
			Assert.IsTrue(match.Parameters.ContainsKey("action"));
		}
예제 #26
0
		public void ShouldReturnNonZeroForMatchedDefaults()
		{
			PatternRoute route = new PatternRoute("/[controller]/[action]");

			RouteMatch match = new RouteMatch();
			Assert.AreEqual(2, route.Matches("/", CreateGetContext(), match));
			Assert.IsTrue(match.Parameters.ContainsKey("controller"));
			Assert.IsTrue(match.Parameters.ContainsKey("action"));
		}
예제 #27
0
		public void AnythingBut_Restriction()
		{
			PatternRoute route = new PatternRoute("/<controller>/[action]/[id]")
				.Restrict("controller").AnythingBut("dummy")
				.Restrict("id").ValidInteger;

			RouteMatch match = new RouteMatch();
			Assert.AreEqual(0, route.Matches("/dummy/index", CreateGetContext(), match));
			Assert.AreEqual(0, route.Matches("/DUMMY/list", CreateGetContext(), match));
			Assert.AreEqual(4001, route.Matches("/some/new", CreateGetContext(), match));
			Assert.AreEqual(6000, route.Matches("/some/list/1", CreateGetContext(), match));
		}
		public void ShouldMatchWhenRestrictingWithMatchingMultipleVerb()
		{
			var route = new PatternRoute("/simple")
				.RestrictTo(Verb.Get | Verb.Post);

			var match = new RouteMatch();
			Assert.Less(0, route.Matches("/simple", CreateGetContext(), match));
		}
		public void ShouldNotMatchWhenRestrictingMultipleVerbs()
		{
			var route = new PatternRoute("/simple")
				.RestrictTo(Verb.Post | Verb.Put);

			var match = new RouteMatch();
			Assert.AreEqual(0, route.Matches("/simple", CreateGetContext(), match));
		}
예제 #30
0
		public void ShouldMatchStatic()
		{
			PatternRoute route = new PatternRoute("/some/path");
			RouteMatch match = new RouteMatch();
			Assert.AreEqual(8000, route.Matches("/some/path", CreateGetContext(), match));
		}
예제 #31
0
		public void ShouldMatchStaticWithFileExtension()
		{
			PatternRoute route = new PatternRoute("/default.aspx");
			RouteMatch match = new RouteMatch();
			Assert.AreEqual(8000, route.Matches("/default.aspx", CreateGetContext(), match));
		}
예제 #32
0
		public void NamedOptionalParametersWithDefaults()
		{
			PatternRoute route = new PatternRoute("/<controller>/[action]/[id]")
				.DefaultFor("action").Is("index").DefaultFor("id").Is("0");
			RouteMatch match = new RouteMatch();
			Assert.AreEqual(2002, route.Matches("/some", CreateGetContext(), match));
			Assert.AreEqual("some", match.Parameters["controller"]);
			Assert.AreEqual("index", match.Parameters["action"]);
			Assert.AreEqual("0", match.Parameters["id"]);
		}
예제 #33
0
		public void ShouldMatchHiphensAndUnderlines()
		{
			PatternRoute route = new PatternRoute("/some/path_to-this");
			RouteMatch match = new RouteMatch();
			Assert.AreEqual(8000, route.Matches("/some/path_to-this", CreateGetContext(), match)); 
		}
예제 #34
0
		public void NamedOptionalParametersWithRestrictions()
		{
			PatternRoute route = new PatternRoute("/<controller>/[action]/[id]")
				.Restrict("action").AnyOf("index", "list")
				.Restrict("id").ValidInteger;

			RouteMatch match = new RouteMatch();
			Assert.AreEqual(4001, route.Matches("/some/index", CreateGetContext(), match));
			Assert.AreEqual(4001, route.Matches("/some/list", CreateGetContext(), match));
			Assert.AreEqual(0, route.Matches("/some/new", CreateGetContext(), match));
			Assert.AreEqual(0, route.Matches("/some/index/foo", CreateGetContext(), match));
			Assert.AreEqual(0, route.Matches("/some/list/bar", CreateGetContext(), match));
			Assert.AreEqual(6000, route.Matches("/some/list/1", CreateGetContext(), match));
		}
예제 #35
0
		public void NamedParametersCanHaveUnderlines()
		{
			PatternRoute route = new PatternRoute("/<controller>/<action>");
			RouteMatch match = new RouteMatch();
			route.Matches("/some/act_name", CreateGetContext(), match);
			Assert.AreEqual("some", match.Parameters["controller"]);
			Assert.AreEqual("act_name", match.Parameters["action"]);
		}
예제 #36
0
		public void NamedRequiredParametersWithRestrictions()
		{
			string matchGuid = 
				"[A-Fa-f0-9]{32}|" +
				"({|\\()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|\\))?|" +
				"({)?[0xA-Fa-f0-9]{3,10}(, {0,1}[0xA-Fa-f0-9]{3,6}){2}, {0,1}({)([0xA-Fa-f0-9]{3,4}, {0,1}){7}[0xA-Fa-f0-9]{3,4}(}})";

			PatternRoute route = new PatternRoute("/<param>/<key>")
				.Restrict("key").ValidRegex(matchGuid);

			RouteMatch match = new RouteMatch();
			Assert.AreEqual(0, route.Matches("/something/zzzzzzzz-c123-11dc-95ff-0800200c9a66", CreateGetContext(), match));
			Assert.AreEqual(4000, route.Matches("/something/173e0970-c123-11dc-95ff-0800200c9a66", CreateGetContext(), match));
			Assert.AreEqual("something", match.Parameters["param"]);
			Assert.AreEqual("173e0970-c123-11dc-95ff-0800200c9a66", match.Parameters["key"]);
		}