/// <summary> /// Constructs a route parser /// </summary> /// <param name="controller">The type of the controller class</param> /// <param name="action">The action method on the controller</param> /// <param name="route">The route attribute applied to the action method</param> public RouteParser(Type controller, MethodInfo action, RouteAttribute route) { m_controller = controller; m_action = action; m_routeAttribute = route; string controllerName = m_controller.Name; if (!controllerName.EndsWith("Controller", StringComparison.InvariantCultureIgnoreCase)) { // MVC requires a controller name throw new ApplicationException(String.Format( "Invalid controller class name {0}: name must end with \"Controller\"", controllerName)); } // MVC ignoes the Controller part of the class name ControllerName = controllerName.Substring(0, controllerName.Length - "Controller".Length); }
public void Setup() { Mock<Type> mockController = new Mock<Type>(); mockController .Setup(x => x.Name) .Returns(c_controllerName + "Controller"); m_mockController = mockController.Object; Mock<MethodInfo> mockAction = new Mock<MethodInfo>(); mockAction .Setup(x => x.Name) .Returns(c_actionName); mockAction .Setup(x => x.DeclaringType) .Returns(m_mockController); mockAction .Setup(x => x.GetCustomAttributes(typeof(RouteDefaultAttribute), true)) .Returns(new RouteDefaultAttribute[] { new RouteDefaultAttribute { Name = "Page", Value = 1 } }); mockAction .Setup(x => x.GetCustomAttributes(typeof(RouteConstraintAttribute), true)) .Returns(new RouteConstraintAttribute[] { new RouteConstraintAttribute { Name = "Numeric", Regex = "^[0-9]$" } }); m_mockAction = mockAction.Object; m_routeAttribute = new RouteAttribute { Name = "HomeLink", Url = "home", Order = 99 }; }