Monorail parse URL to routing values
Is it possible to fire up nvelocity routing mechanism outside the context of request (standalone app, or a testing framework) and get an url from action and routing values from url?
Here is a test, i need to figure out the routingMethod:
var url = routingMethod.ResolveAction<MyController>(c=>c.MyAction("Foo",1))
Assert.AreEqual("/MyController/MyAction.rails?name=Foo&amount=1");
var url = "/MyController/MyAction.rails?name=Foo&amount=1";
I开发者_Python百科Dictionary routingValues = routingMethod.DeriveRouteValuesFrom(url);
Assert.AreEqual("MyController", routingValues["controller"]);
Assert.AreEqual("MyAction", routingValues["action"]);
Assert.AreEqual("Foo", routingValues["name"]);
Assert.AreEqual(1, routingValues["amount"]);
If I understand you correctly, you want to take an URL, run it through the Routing-engine both ways and either get the routing parameters, or create a url from routing parameters?
You can create your own RoutingEngine and register your routes into it, then invoke it with a StubRequest in order to generate urls or parse urls into parameters.
You could also (if you have access to it) use RoutingModuleEx.Engine directly.
RoutingEngine has two methods, one for matching and one for generating urls.
There is also a RouteMatch class that you can use for testing purposes or any other usage in order to test a RouteMatch, however, you cannot generate a url with it.
See bottom of this page: http://www.castleproject.org/monorail/documentation/v20/advanced/routing.html
精彩评论