public void MatchConstraintMessageToRoute(Routes tab, ITabContext context, System.Web.Routing.IRouteConstraint constraint) { var route = new System.Web.Routing.Route("url", new System.Web.Routing.RouteValueDictionary { { "Test", "Other" } }, new System.Web.Routing.RouteValueDictionary { { "Test", constraint } }, new System.Web.Routing.RouteValueDictionary { { "Data", "Tokens" } }, new System.Web.Routing.PageRouteHandler("~/Path")); System.Web.Routing.RouteTable.Routes.Clear(); System.Web.Routing.RouteTable.Routes.Add(route); var routeMessage = new RouteBase.GetRouteData.Message(route.GetHashCode(), new System.Web.Routing.RouteData(), "routeName") .AsSourceMessage(route.GetType(), null) .AsTimedMessage(new TimerResult { Duration = TimeSpan.FromMilliseconds(19) }); var constraintMessage = new RouteBase.ProcessConstraint.Message(new RouteBase.ProcessConstraint.Arguments(new object[] { (HttpContextBase)null, constraint, "test", (System.Web.Routing.RouteValueDictionary)null, System.Web.Routing.RouteDirection.IncomingRequest }), route.GetHashCode(), true) .AsTimedMessage(new TimerResult { Duration = TimeSpan.FromMilliseconds(25) }) .AsSourceMessage(route.GetType(), null); context.TabStore.Setup(mb => mb.Contains(typeof(IList<RouteBase.ProcessConstraint.Message>).AssemblyQualifiedName)).Returns(true).Verifiable(); context.TabStore.Setup(mb => mb.Contains(typeof(IList<RouteBase.GetRouteData.Message>).AssemblyQualifiedName)).Returns(true).Verifiable(); context.TabStore.Setup(mb => mb.Get(typeof(IList<RouteBase.ProcessConstraint.Message>).AssemblyQualifiedName)).Returns(new List<RouteBase.ProcessConstraint.Message> { constraintMessage }).Verifiable(); context.TabStore.Setup(mb => mb.Get(typeof(IList<RouteBase.GetRouteData.Message>).AssemblyQualifiedName)).Returns(new List<RouteBase.GetRouteData.Message> { routeMessage }).Verifiable(); var model = tab.GetData(context) as List<RouteModel>; var itemModel = model[0]; Assert.NotNull(model); Assert.Equal(1, model.Count); Assert.NotNull(itemModel.Constraints); Assert.True(itemModel.IsMatch); Assert.Equal("Test", ((List<RouteConstraintModel>)itemModel.Constraints)[0].ParameterName); Assert.Equal(true, ((List<RouteConstraintModel>)itemModel.Constraints)[0].IsMatch); Assert.NotNull(itemModel.DataTokens); Assert.Equal("Tokens", itemModel.DataTokens["Data"]); Assert.NotNull(itemModel.RouteData); Assert.Equal("Other", ((List<RouteDataItemModel>)itemModel.RouteData)[0].DefaultValue); }
public void MatchConstraintMessageToRoute(Routes tab, ITabContext context, System.Web.Routing.IRouteConstraint constraint, RoutesInspector routeInspector, IInspectorContext routeInspectorContext) { var route = new System.Web.Routing.Route("url", new System.Web.Routing.RouteValueDictionary { { "Test", "Other" } }, new System.Web.Routing.RouteValueDictionary { { "Test", constraint } }, new System.Web.Routing.RouteValueDictionary { { "Data", "Tokens" } }, new System.Web.Routing.PageRouteHandler("~/Path")); System.Web.Routing.RouteTable.Routes.Clear(); System.Web.Routing.RouteTable.Routes.Add(route); routeInspectorContext.Setup(x => x.ProxyFactory).Returns(new CastleDynamicProxyFactory(routeInspectorContext.Logger, routeInspectorContext.MessageBroker, () => new ExecutionTimer(new Stopwatch()), () => new RuntimePolicy())); routeInspector.Setup(routeInspectorContext); route = (System.Web.Routing.Route)System.Web.Routing.RouteTable.Routes[0]; var routeMessage = new RouteDataMessage(route.GetHashCode(), new System.Web.Routing.RouteData(), "routeName") .AsSourceMessage(route.GetType(), null) .AsTimedMessage(new TimerResult { Duration = TimeSpan.FromMilliseconds(19) }); var constraintMessage = new ProcessConstraintMessage(route.GetHashCode(), constraint.GetHashCode(), true, "test", constraint, (System.Web.Routing.RouteValueDictionary)null, System.Web.Routing.RouteDirection.IncomingRequest) .AsTimedMessage(new TimerResult { Duration = TimeSpan.FromMilliseconds(25) }) .AsSourceMessage(route.GetType(), null); context.TabStore.Setup(mb => mb.Contains(typeof(IList <ProcessConstraintMessage>).AssemblyQualifiedName)).Returns(true).Verifiable(); context.TabStore.Setup(mb => mb.Contains(typeof(IList <RouteDataMessage>).AssemblyQualifiedName)).Returns(true).Verifiable(); context.TabStore.Setup(mb => mb.Get(typeof(IList <ProcessConstraintMessage>).AssemblyQualifiedName)).Returns(new List <ProcessConstraintMessage> { constraintMessage }).Verifiable(); context.TabStore.Setup(mb => mb.Get(typeof(IList <RouteDataMessage>).AssemblyQualifiedName)).Returns(new List <RouteDataMessage> { routeMessage }).Verifiable(); var model = tab.GetData(context) as List <RouteModel>; var itemModel = model[0]; Assert.NotNull(model); Assert.Equal(1, model.Count); Assert.NotNull(itemModel.Constraints); Assert.True(itemModel.IsMatch); Assert.Equal("Test", ((List <RouteConstraintModel>)itemModel.Constraints)[0].ParameterName); Assert.Equal(true, ((List <RouteConstraintModel>)itemModel.Constraints)[0].IsMatch); Assert.NotNull(itemModel.DataTokens); Assert.Equal("Tokens", itemModel.DataTokens["Data"]); Assert.NotNull(itemModel.RouteData); Assert.Equal("Other", ((List <RouteDataItemModel>)itemModel.RouteData)[0].DefaultValue); }
private IEnumerable <RouteConstraintModel> ProcessConstraints(ITabContext context, MvcRoute route, Dictionary <int, Dictionary <int, List <RouteBase.ProcessConstraint.Message> > > constraintMessages) { if (route.Constraints == null || route.Constraints.Count == 0) { return(null); } var counstraintRouteMessages = constraintMessages.GetValueOrDefault(route.GetHashCode()); var result = new List <RouteConstraintModel>(); foreach (var constraint in route.Constraints) { var model = new RouteConstraintModel(); model.ParameterName = constraint.Key; model.Constraint = constraint.Value.ToString(); if (counstraintRouteMessages != null) { var counstraintMessage = SafeFirstOrDefault(counstraintRouteMessages.GetValueOrDefault(constraint.Value.GetHashCode())); model.IsMatch = false; if (counstraintMessage != null) { model.IsMatch = counstraintMessage.IsMatch; } } result.Add(model); } return(result); }
public void MatchConstraintMessageToRoute(Routes tab, ITabContext context, System.Web.Routing.IRouteConstraint constraint) { var route = new System.Web.Routing.Route("url", new System.Web.Routing.RouteValueDictionary { { "Test", "Other" } }, new System.Web.Routing.RouteValueDictionary { { "Test", constraint } }, new System.Web.Routing.RouteValueDictionary { { "Data", "Tokens" } }, new System.Web.Routing.PageRouteHandler("~/Path")); System.Web.Routing.RouteTable.Routes.Clear(); System.Web.Routing.RouteTable.Routes.Add(route); var routeMessage = new RouteBase.GetRouteData.Message(route.GetHashCode(), new System.Web.Routing.RouteData(), "routeName") .AsSourceMessage(route.GetType(), null) .AsTimedMessage(new TimerResult { Duration = TimeSpan.FromMilliseconds(19) }); var constraintMessage = new RouteBase.ProcessConstraint.Message(new RouteBase.ProcessConstraint.Arguments(new object[] { (HttpContextBase)null, constraint, "test", (System.Web.Routing.RouteValueDictionary)null, System.Web.Routing.RouteDirection.IncomingRequest }), route.GetHashCode(), true) .AsTimedMessage(new TimerResult { Duration = TimeSpan.FromMilliseconds(25) }) .AsSourceMessage(route.GetType(), null); context.TabStore.Setup(mb => mb.Contains(typeof(IList <RouteBase.ProcessConstraint.Message>).AssemblyQualifiedName)).Returns(true).Verifiable(); context.TabStore.Setup(mb => mb.Contains(typeof(IList <RouteBase.GetRouteData.Message>).AssemblyQualifiedName)).Returns(true).Verifiable(); context.TabStore.Setup(mb => mb.Get(typeof(IList <RouteBase.ProcessConstraint.Message>).AssemblyQualifiedName)).Returns(new List <RouteBase.ProcessConstraint.Message> { constraintMessage }).Verifiable(); context.TabStore.Setup(mb => mb.Get(typeof(IList <RouteBase.GetRouteData.Message>).AssemblyQualifiedName)).Returns(new List <RouteBase.GetRouteData.Message> { routeMessage }).Verifiable(); var model = tab.GetData(context) as List <RouteModel>; var itemModel = model[0]; Assert.NotNull(model); Assert.Equal(1, model.Count); Assert.NotNull(itemModel.Constraints); Assert.True(itemModel.IsMatch); Assert.Equal("Test", ((List <RouteConstraintModel>)itemModel.Constraints)[0].ParameterName); Assert.Equal(true, ((List <RouteConstraintModel>)itemModel.Constraints)[0].IsMatch); Assert.NotNull(itemModel.DataTokens); Assert.Equal("Tokens", itemModel.DataTokens["Data"]); Assert.NotNull(itemModel.RouteData); Assert.Equal("Other", ((List <RouteDataItemModel>)itemModel.RouteData)[0].DefaultValue); }
public void MatchConstraintMessageToRoute(Routes tab, ITabContext context, System.Web.Routing.IRouteConstraint constraint, RoutesInspector routeInspector, IInspectorContext routeInspectorContext) { var route = new System.Web.Routing.Route("url", new System.Web.Routing.RouteValueDictionary { { "Test", "Other" } }, new System.Web.Routing.RouteValueDictionary { { "Test", constraint } }, new System.Web.Routing.RouteValueDictionary { { "Data", "Tokens" } }, new System.Web.Routing.PageRouteHandler("~/Path")); System.Web.Routing.RouteTable.Routes.Clear(); System.Web.Routing.RouteTable.Routes.Add(route); routeInspectorContext.Setup(x => x.ProxyFactory).Returns(new CastleDynamicProxyFactory(routeInspectorContext.Logger, routeInspectorContext.MessageBroker, () => new ExecutionTimer(new Stopwatch()), () => new RuntimePolicy())); routeInspector.Setup(routeInspectorContext); route = (System.Web.Routing.Route) System.Web.Routing.RouteTable.Routes[0]; var routeMessage = new RouteDataMessage(route.GetHashCode(), new System.Web.Routing.RouteData(), "routeName") .AsSourceMessage(route.GetType(), null) .AsTimedMessage(new TimerResult { Duration = TimeSpan.FromMilliseconds(19) }); var constraintMessage = new ProcessConstraintMessage(route.GetHashCode(), constraint.GetHashCode(), true, "test", constraint, (System.Web.Routing.RouteValueDictionary)null, System.Web.Routing.RouteDirection.IncomingRequest) .AsTimedMessage(new TimerResult { Duration = TimeSpan.FromMilliseconds(25) }) .AsSourceMessage(route.GetType(), null); context.TabStore.Setup(mb => mb.Contains(typeof(IList<ProcessConstraintMessage>).AssemblyQualifiedName)).Returns(true).Verifiable(); context.TabStore.Setup(mb => mb.Contains(typeof(IList<RouteDataMessage>).AssemblyQualifiedName)).Returns(true).Verifiable(); context.TabStore.Setup(mb => mb.Get(typeof(IList<ProcessConstraintMessage>).AssemblyQualifiedName)).Returns(new List<ProcessConstraintMessage> { constraintMessage }).Verifiable(); context.TabStore.Setup(mb => mb.Get(typeof(IList<RouteDataMessage>).AssemblyQualifiedName)).Returns(new List<RouteDataMessage> { routeMessage }).Verifiable(); var model = tab.GetData(context) as List<RouteModel>; var itemModel = model[0]; Assert.NotNull(model); Assert.Equal(1, model.Count); Assert.NotNull(itemModel.Constraints); Assert.True(itemModel.IsMatch); Assert.Equal("Test", ((List<RouteConstraintModel>)itemModel.Constraints)[0].ParameterName); Assert.Equal(true, ((List<RouteConstraintModel>)itemModel.Constraints)[0].IsMatch); Assert.NotNull(itemModel.DataTokens); Assert.Equal("Tokens", itemModel.DataTokens["Data"]); Assert.NotNull(itemModel.RouteData); Assert.Equal("Other", ((List<RouteDataItemModel>)itemModel.RouteData)[0].DefaultValue); }