예제 #1
0
        public void route_matches_true_with_equivalent_pathinfo_with_params()
        {
            var route   = new Route(typeof(RouteTestingHelper).GetMethod("RouteOne"), HttpMethod.GET, "/path/[param1]/[param2]");
            var context = TestingMocks.MockContext(HttpMethod.GET, "/path/user/234");

            route.Matches(context).ShouldBe(true);
        }
예제 #2
0
        public void route_matches_false_with_pathinfo_params()
        {
            var route   = new Route(typeof(RouteTestingHelper).GetMethod("RouteOne"), "/api/user/[id]");
            var context = TestingMocks.MockContext(HttpMethod.GET, "/api/user/");

            route.Matches(context).ShouldBe(false);
        }
예제 #3
0
        public void route_matches_true_with_equivalent_pathinfo()
        {
            var route   = new Route(typeof(RouteTestingHelper).GetMethod("RouteOne"), HttpMethod.GET);
            var context = TestingMocks.MockContext(HttpMethod.GET, "/path/to/resource");

            route.Matches(context).ShouldBe(true);
        }
예제 #4
0
        public void route_matches_false_with_different_httpmethod()
        {
            var pathinfo = "/path/to/resource";
            var route    = new Route(typeof(RouteTestingHelper).GetMethod("RouteOne"), HttpMethod.GET, pathinfo);
            var context  = TestingMocks.MockContext(HttpMethod.POST, pathinfo);

            route.Matches(context).ShouldBe(false);
        }
예제 #5
0
        public void route_invoke_using_static_method()
        {
            var route   = new Route(typeof(RouteTestingHelper).GetMethod("StaticRoute"));
            var context = TestingMocks.MockContext();

            route.Invoke(context);

            RouteTestingHelper.WhoTriggeredMe().ShouldBe("StaticRoute");
        }
예제 #6
0
        public void route_invoke_using_function_wrapped_method()
        {
            Func <IHttpContext, IHttpContext> function = new RouteTestingHelper().RouteTwo;
            var route   = new Route(function);
            var context = TestingMocks.MockContext();

            route.Invoke(context);

            RouteTestingHelper.WhoTriggeredMe().ShouldBe("RouteTwo");
        }
예제 #7
0
        public void route_matches_false_with_different_pathinfo()
        {
            var verb     = HttpMethod.GET;
            var pathinfo = "/path/to/resource";

            var route   = new Route(typeof(RouteTestingHelper).GetMethod("RouteOne"), verb, $"{pathinfo}1");
            var context = TestingMocks.MockContext(verb, $"{pathinfo}2");

            route.Matches(context).ShouldBe(false);
        }
예제 #8
0
        public void route_matches_true_with_exact_match()
        {
            var pathinfo = "/path/to/resource";
            var verb     = HttpMethod.GET;

            var route   = new Route(typeof(RouteTestingHelper).GetMethod("RouteOne"), verb, pathinfo);
            var context = TestingMocks.MockContext(verb, pathinfo);

            route.Matches(context).ShouldBe(true);
        }
예제 #9
0
        public void router_returns_routes_for_post()
        {
            var router  = new Router().Import <LoadedRouter>();
            var context = TestingMocks.MockContext(HttpMethod.POST);

            var routes = router.RouteFor(context);

            router.RoutingTable.Count.ShouldBe(10);
            routes.Count.ShouldBe(6);
        }
예제 #10
0
        public void router_runs_routes_for_post_context()
        {
            var loaded  = new LoadedRouter();
            var router  = new Router().Import(loaded);
            var context = TestingMocks.MockContext(HttpMethod.POST);

            router.Route(context);

            loaded.GetHits.ShouldBe(0);
            loaded.PostHits.ShouldBe(6);
        }
예제 #11
0
        public void route_invoke_using_function()
        {
            var triggeredBy = "Anon";
            var context     = TestingMocks.MockContext();
            var route       = new Route(ctx =>
            {
                RouteTestingHelper.WasTriggeredBy(triggeredBy);
                return(ctx);
            });

            route.Invoke(context);

            RouteTestingHelper.WhoTriggeredMe().ShouldBe(triggeredBy);
        }
예제 #12
0
        public void router_runs_supplied_routes_for_context()
        {
            var hitme   = false;
            var router  = new Router().Import <LoadedRouter>();
            var context = TestingMocks.MockContext(HttpMethod.POST);

            var routes = router.RouteFor(context);

            routes.Add(new Route(ctx =>
            {
                hitme = true;
                return(ctx);
            }));

            router.Route(context, routes);
            hitme.ShouldBe(true);
        }