private static bool MatchesActionArguments(this TRoute route, ICollection <Type> actionArguments) { if (actionArguments == null) { return(true); } // When specifying arguments, it must be an action level attribute route with a single action descriptor TActionDescriptor actionDescriptor = ((TActionDescriptor[])route.DataTokens[RouteDataTokenKeys.Actions]).Single(); ICollection <TParameterDescriptor> parameterInfos = actionDescriptor.GetParameters(); if (parameterInfos.Count() != actionArguments.Count) { return(false); } for (int i = 0; i < actionArguments.Count; i++) { if (actionArguments.ElementAt(i) != parameterInfos.ElementAt(i).ParameterType) { return(false); } } return(true); }
public void GetNamedRoute_NoRouteExists_ReturnsNull() { // Arrange ICollection <RouteEntry> routeEntries = new List <RouteEntry>(); // Act TIRoute route = routeEntries.GetNamedRoute("Route1"); // Assert Assert.IsNull(route); }
private static bool MatchesNamespace(this TRoute route, string controllerNamespace) { if (string.IsNullOrEmpty(controllerNamespace)) { return(true); } TActionDescriptor[] actionDescriptors = (TActionDescriptor[])route.DataTokens[RouteDataTokenKeys.Actions]; TControllerDescriptor controllerDescriptor = actionDescriptors.First().ControllerDescriptor; return(controllerDescriptor.ControllerType.Namespace == controllerNamespace); }
public void GetNamedRoute_RouteExistsAndHasNoTranslation_ReturnsRoute() { // Arrange LocalizationCollectionRoute route1 = CreateCollectionRouteForControllerAndAction <HomeController>("Home", x => x.Index()); ICollection <RouteEntry> routeEntries = new List <RouteEntry>() { new RouteEntry("Route1", route1) }; // Act TIRoute route = routeEntries.GetNamedRoute("Route1"); // Assert Assert.AreSame(route1, route); }
private static bool MatchesControllerAndAction(this TRoute route, string controller, string action) { #if ASPNETWEBAPI // Controller is only set on controller level attributes if (route.DataTokens.ContainsKey(RouteDataTokenKeys.Controller)) { return(((TControllerDescriptor)route.DataTokens[RouteDataTokenKeys.Controller]).ControllerName == controller && string.IsNullOrEmpty(action)); } #else // Controller / Action level attributes are distinguished by TargetIsAction if (((bool?)route.DataTokens[RouteDataTokenKeys.TargetIsAction]) != true) { return (((TActionDescriptor[])route.DataTokens[RouteDataTokenKeys.Actions]).First().ControllerDescriptor.ControllerName == controller && string.IsNullOrEmpty(action)); } #endif TActionDescriptor httpActionDescriptor = ((TActionDescriptor[])route.DataTokens[RouteDataTokenKeys.Actions]).Single(); return(httpActionDescriptor.ControllerDescriptor.ControllerName == controller && httpActionDescriptor.ActionName == action); }