public void Construct()
        {
            var sut = new RoutesInspector();

            Assert.NotNull(sut);
            Assert.IsAssignableFrom<IInspector>(sut);
        }
        public void IntergrationTestRouteProxing(RoutesInspector sut, System.Web.Routing.IRouteHandler routeHandler, IInspectorContext context)
        {
            RouteTable.Routes.Clear();
            RouteTable.Routes.Add("Test", new System.Web.Routing.Route("Test", routeHandler));
            RouteTable.Routes.Add("BaseTyped", new NewRouteBase());
            RouteTable.Routes.Add("BaseTestTyped", new NewConstructorRouteBase("Name"));
            RouteTable.Routes.Add("SubTyped", new NewRoute("test", routeHandler));
            RouteTable.Routes.Add("SubTestTyped", new NewConstructorRoute("test", routeHandler, "Name"));
            RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}", new { resource = "Test", pathInfo = "[0-9]" });

            context.Setup(x => x.ProxyFactory).Returns(new CastleDynamicProxyFactory(context.Logger, context.MessageBroker, () => new ExecutionTimer(new Stopwatch()), () => new RuntimePolicy()));

            sut.Setup(context);

            // This test needs to be like this because IProxyTargetAccessor is in Moq and Glimpse
            foreach (var route in RouteTable.Routes)
            {
                var found = false;
                foreach (var routeInterface in route.GetType().GetInterfaces())
                {
                    if (routeInterface.Name == "IProxyTargetAccessor")
                    {
                        found = true;
                    }
                }

                Assert.True(found);
            }
        }
        public void ExtendsMvcRoutes(System.Web.Routing.IRouteHandler routeHandler, RoutesInspector sut, IInspectorContext context, System.Web.Routing.Route newRoute)
        {
            RouteTable.Routes.Clear();
            RouteTable.Routes.Add("Test", new System.Web.Routing.Route("Test", routeHandler));

            context.ProxyFactory.Setup(x => x.ExtendClass<System.Web.Routing.Route>(It.IsAny<IEnumerable<IAlternateMethod>>(), It.IsAny<IEnumerable<object>>(), It.IsAny<object[]>())).Returns(newRoute).Verifiable();

            sut.Setup(context);

            context.ProxyFactory.VerifyAll();
            Assert.Same(newRoute, RouteTable.Routes[0]);
        }
Beispiel #4
0
        public void ReturnRouteInstancesEvenWhenRoutesTableEmpty(Routes tab, ITabContext context, RoutesInspector routeInspector, IInspectorContext routeInspectorContext)
        {
            System.Web.Routing.RouteTable.Routes.Clear();

            routeInspectorContext.Setup(x => x.ProxyFactory).Returns(new CastleDynamicProxyFactory(routeInspectorContext.Logger, routeInspectorContext.MessageBroker, () => new ExecutionTimer(new Stopwatch()), () => new RuntimePolicy()));
            routeInspector.Setup(routeInspectorContext);

            var data = tab.GetData(context) as IList<RouteModel>;

            Assert.NotNull(data);
            Assert.Empty(data);
        }
        public void WrapsMvcRouteDerivedTypes(RoutesInspector sut, System.Web.Routing.IRouteHandler routeHandler, IInspectorContext context, NewRoute route, System.Web.Routing.Route newRoute)
        {
            RouteTable.Routes.Clear();
            RouteTable.Routes.Add("Test", route);

            context.ProxyFactory.Setup(x => x.IsWrapClassEligible(typeof(System.Web.Routing.Route))).Returns(true).Verifiable();
            context.ProxyFactory.Setup(x => x.WrapClass((System.Web.Routing.Route)route, It.IsAny<IEnumerable<IAlternateMethod>>(), It.IsAny<IEnumerable<object>>(), It.IsAny<object[]>())).Returns(newRoute).Verifiable();

            sut.Setup(context);

            context.ProxyFactory.VerifyAll();
            Assert.Same(newRoute, RouteTable.Routes[0]);
        }
Beispiel #6
0
        public void ReturnProperNumberOfInstances(Routes tab, ITabContext context, RoutesInspector routeInspector, IInspectorContext routeInspectorContext)
        {
            System.Web.Routing.RouteTable.Routes.Clear();
            System.Web.Routing.RouteTable.Routes.Ignore("Something");

            routeInspectorContext.Setup(x => x.ProxyFactory).Returns(new CastleDynamicProxyFactory(routeInspectorContext.Logger, routeInspectorContext.MessageBroker, () => new ExecutionTimer(new Stopwatch()), () => new RuntimePolicy()));
            routeInspector.Setup(routeInspectorContext);
            
            var data = tab.GetData(context) as IList<RouteModel>;

            Assert.NotNull(data);
            Assert.Equal(System.Web.Routing.RouteTable.Routes.Count, data.Count);
        }
Beispiel #7
0
        public void ReturnRouteInstancesEvenWhenContextIsNull(Routes tab, ITabContext context, RoutesInspector routeInspector, IInspectorContext routeInspectorContext)
        {
            context.Setup(x => x.GetRequestContext<HttpContextBase>()).Returns((HttpContextBase)null);

            System.Web.Routing.RouteTable.Routes.Clear();
            System.Web.Routing.RouteTable.Routes.Ignore("Test");
             
            routeInspectorContext.Setup(x => x.ProxyFactory).Returns(new CastleDynamicProxyFactory(routeInspectorContext.Logger, routeInspectorContext.MessageBroker, () => new ExecutionTimer(new Stopwatch()), () => new RuntimePolicy()));
            routeInspector.Setup(routeInspectorContext);

            var data = tab.GetData(context) as IList<RouteModel>;

            Assert.NotNull(data);
            Assert.Equal(System.Web.Routing.RouteTable.Routes.Count, data.Count); 
        }
        public void ExtendsStringConstraints(RoutesInspector sut, IInspectorContext context, NewRoute route, Route newRoute, string routeConstraint)
        {
            route.Constraints = new RouteValueDictionary { { "controller", routeConstraint } };

            RouteTable.Routes.Clear();
            RouteTable.Routes.Add("Test", route);

            context.ProxyFactory.Setup(x => x.IsWrapClassEligible(typeof(Route))).Returns(true).Verifiable();
            context.ProxyFactory.Setup(x => x.WrapClass((Route)route, It.IsAny<IEnumerable<IAlternateMethod>>(), It.IsAny<IEnumerable<object>>(), It.IsAny<object[]>())).Returns(newRoute).Verifiable();

            sut.Setup(context);

            context.ProxyFactory.VerifyAll();
            Assert.Same(typeof(RouteConstraintRegex), route.Constraints["controller"].GetType());
        }
Beispiel #9
0
        public void ReturnAspNetProxiedRouteInstances(Routes tab, ITabContext context, RoutesInspector routeInspector, IInspectorContext routeInspectorContext, System.Web.Routing.IRouteHandler routeHandler)
        {
            System.Web.Routing.RouteTable.Routes.Clear();
            System.Web.Routing.RouteTable.Routes.Add("Test", new System.Web.Routing.Route("Test", routeHandler));
            System.Web.Routing.RouteTable.Routes.Add("BaseTyped", new RoutesInspectorShould.NewRouteBase());
            System.Web.Routing.RouteTable.Routes.Add("BaseTestTyped", new RoutesInspectorShould.NewConstructorRouteBase("Name"));
            System.Web.Routing.RouteTable.Routes.Add("SubTyped", new RoutesInspectorShould.NewRoute("test", routeHandler));
            System.Web.Routing.RouteTable.Routes.Add("SubTestTyped", new RoutesInspectorShould.NewConstructorRoute("test", routeHandler, "Name"));
            System.Web.Routing.RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}", new { resource = "Test", pathInfo = "[0-9]" });

            routeInspectorContext.Setup(x => x.ProxyFactory).Returns(new CastleDynamicProxyFactory(routeInspectorContext.Logger, routeInspectorContext.MessageBroker, () => new ExecutionTimer(new Stopwatch()), () => new RuntimePolicy()));
            routeInspector.Setup(routeInspectorContext);

            var model = tab.GetData(context) as List<RouteModel>;

            Assert.NotNull(model);
            Assert.Equal(6, model.Count);
        }
Beispiel #10
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);
        }
        public void ExtendsRouteConstraintConstraints(RoutesInspector sut, IInspectorContext context, NewRoute route, System.Web.Routing.Route newRoute, IRouteConstraint routeConstraint, IRouteConstraint newRouteConstraint)
        {
            route.Constraints = new RouteValueDictionary { { "controller", routeConstraint } };

            RouteTable.Routes.Clear();
            RouteTable.Routes.Add("Test", route);

            context.ProxyFactory.Setup(x => x.IsWrapClassEligible(typeof(System.Web.Routing.Route))).Returns(true).Verifiable();
            context.ProxyFactory.Setup(x => x.WrapClass((System.Web.Routing.Route)route, It.IsAny<IEnumerable<IAlternateMethod>>(), It.IsAny<IEnumerable<object>>(), It.IsAny<object[]>())).Returns(newRoute).Verifiable();
            context.ProxyFactory.Setup(x => x.IsWrapInterfaceEligible<IRouteConstraint>(typeof(IRouteConstraint))).Returns(true).Verifiable();
            context.ProxyFactory.Setup(x => x.WrapInterface(routeConstraint, It.IsAny<IEnumerable<IAlternateMethod>>(), It.IsAny<IEnumerable<object>>())).Returns(newRouteConstraint).Verifiable();

            sut.Setup(context);

            context.ProxyFactory.VerifyAll();
            Assert.Same(newRouteConstraint, route.Constraints["controller"]);
        }