Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private void UpdateRoute(RouteBase.GetRouteData.Message message, ITabSetupContext context)
        {
            var model = GetModel(context.GetTabStore());

            // string.Empty is a valid routeName
            if (message.IsMatch && model.MatchedRouteName == null)
            {
                // only update the first matched route
                model.MatchedRouteName = message.RouteName;
            }
        }
Exemplo n.º 3
0
        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 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);
        }
Exemplo n.º 4
0
        private IEnumerable <RouteDataItemModel> ProcessRouteData(MvcRouteValueDictionary dataDefaults, RouteBase.GetRouteData.Message routeMessage)
        {
            if (dataDefaults == null || dataDefaults.Count == 0)
            {
                return(null);
            }

            var routeData = new List <RouteDataItemModel>();

            foreach (var dataDefault in dataDefaults)
            {
                var routeDataItemModel = new RouteDataItemModel();
                routeDataItemModel.PlaceHolder  = dataDefault.Key;
                routeDataItemModel.DefaultValue = dataDefault.Value;

                if (routeMessage != null && routeMessage.Values != null)
                {
                    routeDataItemModel.ActualValue = routeMessage.Values[dataDefault.Key];
                }

                routeData.Add(routeDataItemModel);
            }

            return(routeData);
        }