With the class RouteRegister is possible to register the controllers in ASP.NET MVC without strings calling the method "Register<PrivateController>("private/{path}", c => c.Private(null))".

[TestClass]
public class FooRoutingTest : RoutingTest
{
	public FooRoutingTest()
	{
		new FooRouteRegister(Routes);
	}

	[TestMethod]
	public void CheckRouting()
	{
		ControllerActionForUrl<PublicController>("~/", c => c.Index());
		ControllerActionForUrl<PrivateController>("~/private/test", c => c.Private(null));
	}

	private class FooRouteRegister : RouteRegister
	{
		public FooRouteRegister(RouteCollection routes)
			: base(routes)
		{
		}

		protected override void RegisterRoutes()
		{
			Register<PrivateController>("private/{path}", c => c.Private(null));
			Register<PublicController>();
		}
	}

	private class PrivateController : Controller
	{
		public void Private(string user)
		{
		}
	}

	private class PublicController : Controller
	{
		public void Index()
		{
		}
	}
}

Last edited Jul 29, 2011 at 2:58 PM by teoarch, version 1

Comments

No comments yet.