Esempio n. 1
0
        public void RouteMatch()
        {
            // Arrange
            RouteCollection routes = new RouteCollection();

            //RouteConfig.RegisterRoutes(routes);

            routes.MapRoute(
                name: "TestExample",
                url: "test/{action}/{id}",
                defaults: new { controller = "TestController", action = "Index", id = UrlParameter.Optional }
                );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );

            const string url1 = "~/";
            const string url2 = "~/testController/testAction/111";
            const string url3 = "~/test/";

            // Assert
            Assert.IsTrue(RouteTest.RouteMatch(url1, routes, "Index", "Home"));
            Assert.IsTrue(RouteTest.RouteMatch(url2, routes, "testAction", "testController", new { id = 111 }));
            Assert.IsTrue(RouteTest.RouteMatch(url3, routes, "Index", "testController"));
        }
Esempio n. 2
0
 public void TestHomeControllerRoutes()
 {
     // check for the URL that we hope to receive
     RouteTest.TestRouteMatch("~/", "Home", "Index");
     RouteTest.TestRouteMatch("~/Home/Index", "Home", "Index");
     RouteTest.TestRouteMatch("~/Agreement", "Home", "Agreement");
 }
        public void Should_route_a_controller_action()
        {
            var uri = new Uri("http://localhost/Accounts/List");

            var routeTestVane = new RouteTest();
            Vane<RoutingContext> routeVane = VaneFactory.New<RoutingContext>(x => x.Feather(() => routeTestVane));

            var constant = new ConstantFeather(1);
            var vane0 = VaneFactory.New<RoutingContext>(x => x.Feather(() => constant));
            var join1 = new JoinFeather(2, 1, VaneFactory.Success<RoutingContext>());
            var vane1 = VaneFactory.New<RoutingContext>(x => x.Feather(() => join1));
            var join2 = new JoinFeather(3, 2, routeVane);
            var vane2 = VaneFactory.New<RoutingContext>(x => x.Feather(() => join2));

            var segment0 = new SegmentSourceVane(0);

            var dictionary0 = new Dictionary<string, Vane<Tuple<RoutingContext, string>>>();
            dictionary0.Add("/", new LeftVane<RoutingContext, string>(vane0));

            var dictionaryVane0 = VaneFactory.New<Tuple<RoutingContext, string>>(x =>
                x.Feather(() => new DictionaryFeather(dictionary0)));

            var segment0Vane = new SpliceSourceFeather<RoutingContext, string>(dictionaryVane0, segment0);

            var segment1 = new SegmentSourceVane(1);

            var dictionary1 = new Dictionary<string, Vane<Tuple<RoutingContext, string>>>();
            dictionary1.Add("Accounts/", new LeftVane<RoutingContext, string>(vane1));

            var dictionaryVane1 = VaneFactory.New<Tuple<RoutingContext, string>>(x =>
                x.Feather(() => new DictionaryFeather(dictionary1)));

            var segment1Vane = new SpliceSourceFeather<RoutingContext, string>(dictionaryVane1, segment1);

              var segment2 = new SegmentSourceVane(2);

            var dictionary2 = new Dictionary<string, Vane<Tuple<RoutingContext, string>>>();
            dictionary2.Add("List", new LeftVane<RoutingContext, string>(vane2));

            var dictionaryVane2 = VaneFactory.New<Tuple<RoutingContext, string>>(x =>
                x.Feather(() => new DictionaryFeather(dictionary2)));

            var segment2Vane = new SpliceSourceFeather<RoutingContext, string>(dictionaryVane2, segment2);

            var vane = VaneFactory.New<RoutingContext>(x =>
                {
                    x.Feather(() => segment0Vane);
                    x.Feather(() => segment1Vane);
                    x.Feather(() => segment2Vane);
                });

            var context = new RoutingContextImpl(uri);
            vane.Execute(context);
            context.Complete();

            Assert.IsTrue(routeTestVane.ComposeCalled);
            Assert.IsTrue(routeTestVane.ExecuteCalled);
            Assert.IsNotNull(routeTestVane.RoutingContext);
        }
Esempio n. 4
0
 public void TestWebApiAccountProfileRoutes()
 {
     // check for the URL that we hope to receive
     RouteTest.TestRouteMatch("~/accounts/profile", "Profile", "Post", null, "POST");
     RouteTest.TestRouteMatch("~/accounts/profile", "Profile", "Get");
     RouteTest.TestRouteMatch("~/accounts/profile", "Profile", "Put", null, "PUT");
     RouteTest.TestRouteMatch("~/accounts/profile", "Profile", "Delete", null, "DELETE");
 }
Esempio n. 5
0
 public void TestWebApiProjectRoutes()
 {
     // check for the URL that we hope to receive
     RouteTest.TestRouteMatch("~/projects", "Projects", "Post", null, "POST");
     RouteTest.TestRouteMatch("~/projects", "Projects", "Get");
     RouteTest.TestRouteMatch("~/projects/222", "Projects", "Get", new { id = "222" });
     RouteTest.TestRouteMatch("~/projects/222", "Projects", "Put", new { id = "222" }, "PUT");
     RouteTest.TestRouteMatch("~/projects/222", "Projects", "Delete", new { id = "222" }, "DELETE");
 }
Esempio n. 6
0
        public void RouteTester()
        {
            var r = new RouteTest();

            r.Dictionary = new RouteValueDictionary(new { Blah = "test" });

            var cloner = new ObjectCloner();

            Assert.IsNotNull(cloner);

            var n = cloner.Clone(r);

            Assert.IsNotNull(n);
        }
Esempio n. 7
0
        public void RouteNotMatch()
        {
            // Arrange
            RouteCollection routes = new RouteCollection();

            //RouteConfig.RegisterRoutes(routes);

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );

            const string url1 = "~/testController/testAction/111/test-param";

            // Assert
            Assert.IsTrue(RouteTest.RouteNotMatch(url1, routes));
        }
Esempio n. 8
0
 public void TestHomeControllerWrongRoutes()
 {
     // ensure that too many or too few segments fails to match
     RouteTest.TestRouteFail("~/Home/Index/Segment");
 }
Esempio n. 9
0
 public void TestWebApiAccountSessionRoutes()
 {
     // check for the URL that we hope to receive
     RouteTest.TestRouteMatch("~/accounts/session", "Session", "Post", null, "POST");
     RouteTest.TestRouteMatch("~/accounts/session", "Session", "Get");
 }
Esempio n. 10
0
 public void TestWebApiProjectWrongRoutes()
 {
     // ensure that too many or too few segments fails to match
     RouteTest.TestRouteFail("~/projects/add/get/");
 }