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"]);
        }
		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"]);
        }
		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));
        }
		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"]);
		}
		public void ShouldReturnZeroForMissingRequiredPart()
		{
			PatternRoute route = new PatternRoute("/<controller>/[action]");

			RouteMatch match = new RouteMatch();
			Assert.AreEqual(0, route.Matches("/", CreateGetContext(), match));
		}
		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"));
		}
		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"));
		}
		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));
		}
		public void ShouldMatchStatic()
		{
			PatternRoute route = new PatternRoute("/some/path");
			RouteMatch match = new RouteMatch();
			Assert.AreEqual(8000, route.Matches("/some/path", CreateGetContext(), match));
		}
		public void ShouldMatchStaticWithFileExtension()
		{
			PatternRoute route = new PatternRoute("/default.aspx");
			RouteMatch match = new RouteMatch();
			Assert.AreEqual(8000, route.Matches("/default.aspx", CreateGetContext(), match));
		}
		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"]);
		}
		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)); 
		}
		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));
		}
		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"]);
		}
		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"]);
		}