public async void SetupCustomRouterAndLookForbadRoute()
        {
            var router  = new CustomRouter();
            var service = new Service(new string[] { "/test1/test2/test3/test4/test5" }, "Service1Test", "Address1Test", 10000, "node1", new string[0]);

            router.AddNewService(service);

            var context = new DefaultHttpContext();

            context.Request.Method = "GET";
            context.Request.Path   = "/test2/test2/test3/test4/test5/test6";
            var routeContext = new RouteContext(context);

            await router.RouteAsync(routeContext);

            Assert.Null(routeContext.Handler);
        }
        public async Task CanWeFindARouteAndGetAPage()
        {
            var router  = new CustomRouter();
            var service = new Service(new string[] { "/search" }, "Service1", "www.google.com", 80, "node1", new string[0]);

            router.AddNewService(service);

            var context = new DefaultHttpContext();

            context.Request.Method = "GET";
            context.Request.Path   = "/search";

            var routeContext = new RouteContext(context);

            await router.RouteAsync(routeContext);

            await routeContext.Handler.Invoke(routeContext.HttpContext);

            Assert.Equal(200, routeContext.HttpContext.Response.StatusCode);
        }
Example #3
0
        private static async Task <RouteContext> RouteRequest(CustomRouter router,
                                                              string requestPath)
        {
            var context = new DefaultHttpContext();

            context.Request.Method = "GET";
            context.Request.Path   = requestPath;

            var routeContext = new RouteContext(context);

            await router.RouteAsync(routeContext);

            if (routeContext.Handler == null)
            {
                return(null);
            }

            await routeContext.Handler.Invoke(routeContext.HttpContext);

            return(routeContext);
        }