Ejemplo n.º 1
0
        public async Task FindRoutes(string method, string path, string aResult)
        {
            HorseMvc mvc = new HorseMvc();

            mvc.Init();
            mvc.CreateRoutes(Assembly.GetExecutingAssembly());
            mvc.Use();

            HttpRequest request = new HttpRequest();

            request.Method = method;
            request.Path   = path;

            HttpResponse response = new HttpResponse();

            RouteMatch match = mvc.RouteFinder.Find(mvc.Routes, request);

            Assert.NotNull(match);

            HorseController controller = mvc.ControllerFactory.CreateInstance(mvc,
                                                                              match.Route.ControllerType,
                                                                              request,
                                                                              response,
                                                                              mvc.ServiceProvider.CreateScope());

            MvcConnectionHandler handler = new MvcConnectionHandler(mvc, null);

            var parameters            = (await handler.FillParameters(request, match)).Select(x => x.Value).ToArray();
            Task <IActionResult> task = (Task <IActionResult>)match.Route.ActionType.Invoke(controller, parameters);

            IActionResult result = task.Result;
            string        url    = Encoding.UTF8.GetString(((MemoryStream)result.Stream).ToArray());

            url.Should().Be(aResult);
        }
Ejemplo n.º 2
0
        public void Run()
        {
            HorseMvc mvc = new HorseMvc();

            HomeController cont = new HomeController();

            Assert.NotNull(cont);

            mvc.Init();
            Assembly asm = Assembly.GetExecutingAssembly();

            mvc.CreateRoutes(asm);
            mvc.Use();

            HorseServer server = new HorseServer(ServerOptions.CreateDefault());

            server.UseMvc(mvc, HttpOptions.CreateDefault());
            server.Start(47442);
            System.Threading.Thread.Sleep(1000);

            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = client.GetAsync("http://127.0.0.1:47442/home/get").Result;

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }