private RouteModel GetRouteModelForRoute(ITabContext context, MvcRouteBase routeBase, Dictionary <int, List <RouteDataMessage> > routeMessages, Dictionary <int, Dictionary <int, List <ProcessConstraintMessage> > > constraintMessages) { RouteModel routeModel = new RouteModel(); RouteDataMessage routeMessage = SafeFirstOrDefault(routeMessages.GetValueOrDefault(routeBase.GetHashCode())); if (routeMessage != null) { routeModel.Duration = routeMessage.Duration; routeModel.IsMatch = routeMessage.IsMatch; } MvcRoute route = routeBase as MvcRoute; if (route != null) { routeModel.Area = (route.DataTokens != null && route.DataTokens.ContainsKey("area")) ? route.DataTokens["area"].ToString() : null; routeModel.Url = route.Url; // Append localizations if possible LocalizationCollectionRoute localizationCollectionRoute = null; FieldInfo fieldInfo = route.GetType().GetField("__target"); if (fieldInfo != null) { localizationCollectionRoute = fieldInfo.GetValue(route) as LocalizationCollectionRoute; } if (localizationCollectionRoute != null) { routeModel.Url += " (LocalizationRoute)"; routeModel.Url += Environment.NewLine; foreach (LocalizationRoute localizationRoute in localizationCollectionRoute.LocalizedRoutes.OrderBy(x => x.Culture)) { routeModel.Url += string.Format(Environment.NewLine + "{0} ({1})", localizationRoute.Url(), !string.IsNullOrEmpty(localizationRoute.Culture) ? localizationRoute.Culture : "neutral"); } if (!localizationCollectionRoute.LocalizedRoutes.Any()) { routeModel.Url += Environment.NewLine + "! No translations exists - this route will not be accessible !"; } } routeModel.RouteData = ProcessRouteData(route.Defaults, routeMessage); routeModel.Constraints = ProcessConstraints(context, route, constraintMessages); routeModel.DataTokens = ProcessDataTokens(route.DataTokens); } else { routeModel.Url = routeBase.ToString(); } IRouteNameMixin routeName = routeBase as IRouteNameMixin; if (routeName != null) { routeModel.Name = routeName.Name; } return(routeModel); }
public void PublishMessageWhenExecuted([Frozen] IExecutionTimer timer, IAlternateMethodContext context, IRouteNameMixin mixin) { context.Setup(c => c.Arguments).Returns(new object[5]); context.Setup(c => c.ReturnValue).Returns(new System.Web.Routing.RouteData()); context.Setup(c => c.InvocationTarget).Returns(new System.Web.Routing.Route("Test", null)); context.Setup(c => c.Proxy).Returns(mixin); var impl = new Route.GetRouteData(typeof(T)); impl.NewImplementation(context); timer.Verify(t => t.Time(It.IsAny <Action>())); context.MessageBroker.Verify(mb => mb.Publish(It.IsAny <Route.GetRouteData.Message>())); }