public async Task should_get_not_found_if_no_route_matches()
        {
            HttpServer httpServer = HttpServerTestHelper.PrepareHttpServer(ControllerAssemblies);

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    HttpResponseMessage response = await client.GetAsync(
                        "http://www.base.com/not-existed");

                    Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
                }
        }
        public async Task should_only_cares_on_public_controller()
        {
            var httpServer = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute("NonPublicController", "Get", HttpMethod.Get, "non-public"));

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    HttpResponseMessage response = await client.GetAsync("http://www.base.com/non-public");

                    Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
                }
        }
        public async Task should_return_method_not_allowed_for_non_annotated_method()
        {
            var httpServer = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute("ControllerWithoutMethodAnnotation", "Get", HttpMethod.Get, "no-annotation"));

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    HttpResponseMessage response = await client.GetAsync("http://www.base.com/no-annotation");

                    Assert.Equal(HttpStatusCode.MethodNotAllowed, response.StatusCode);
                }
        }
        public async Task should_return_not_found_if_no_controller_is_found()
        {
            var httpServer = HttpServerTestHelper.PrepareHttpServer(
                Array.Empty <Assembly>(),
                new HttpRoute("ControllerWithoutAction", "Get", HttpMethod.Get, "no-controller"));

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    HttpResponseMessage response = await client.GetAsync("http://www.base.com/no-controller");

                    Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
                }
        }
Пример #5
0
        public async Task should_accessing_request()
        {
            HttpServer server = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute("AccessingRequestController", "Get", HttpMethod.Get, "resource"));

            using (server)
                using (var client = new HttpClient(server))
                {
                    await HttpServerTestHelper.AssertStringContent(
                        client,
                        "http://www.base.com/resource",
                        "client is accessing http://www.base.com/resource.");
                }
        }
        public async Task should_get_internal_server_error_when_exception_occurs()
        {
            var httpServer = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute("ControllerWithErrorAction", "Get", HttpMethod.Get, "error"));

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    HttpResponseMessage response = await client.GetAsync(
                        "http://www.base.com/error");

                    Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
                }
        }
        public async Task should_return_internal_server_error_if_ambiguous_found()
        {
            var httpServer = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute(
                    "AmbiguousController",
                    "Get",
                    HttpMethod.Get,
                    "ambiguous"));

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    HttpResponseMessage response = await client.GetAsync("http://www.base.com/ambiguous");

                    Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
                }
        }
Пример #8
0
        public async Task should_get_internal_server_error_for_error()
        {
            HttpServer server = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute(
                    "AccessingRequestController",
                    "GetWithError",
                    HttpMethod.Get,
                    "resource"));

            using (server)
                using (var client = new HttpClient(server))
                {
                    HttpResponseMessage response = await client.GetAsync(
                        "http://www.base.com/resource");

                    Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
                }
        }
Пример #9
0
        public async Task should_accessing_request_async()
        {
            HttpServer server = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute("AccessingRequestController", "GetRequestContent", HttpMethod.Post, "resource"));

            using (server)
                using (var client = new HttpClient(server))
                {
                    const string        expected = "Hello there!";
                    HttpResponseMessage response = await client.PostAsync(
                        "http://www.base.com/resource", new StringContent(expected));

                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                    string content = await response.Content.ReadAsStringAsync();

                    Assert.Equal(expected, content);
                }
        }
        public async Task should_get_method_not_allowed_if_constraint_annotation_mismatch()
        {
            HttpServer httpServer = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute(
                    "ControllerWithMismatchedMethod",
                    "Post",
                    HttpMethod.Post,
                    "controller-with-mismatched-action"));

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    HttpResponseMessage response = await client.PostAsync(
                        "http://www.base.com/controller-with-mismatched-action", null);

                    Assert.Equal(HttpStatusCode.MethodNotAllowed, response.StatusCode);
                }
        }
        public async Task should_get_not_found_if_constraint_mismatch()
        {
            HttpServer httpServer = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute(
                    "ControllerWithPublicAction",
                    "Get",
                    HttpMethod.Get,
                    "controller-with-action"));

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    HttpResponseMessage response = await client.PostAsync(
                        "http://www.base.com/controller-with-action", null);

                    Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
                }
        }
        public async Task should_invoke_method_with_multiple_methods(string method)
        {
            var httpServer = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute(
                    "ControllerWithMultipleMethodAnnotation",
                    "Invoke",
                    new HttpMethod(method),
                    "resource"));

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    HttpResponseMessage response = await client.SendAsync(
                        new HttpRequestMessage(new HttpMethod(method), "http://www.base.com/resource"));

                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                }
        }
        public async Task should_invoke_case_insensitively()
        {
            var httpServer = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute(
                    "controllerwithpublicaction",
                    "GET",
                    HttpMethod.Get,
                    "resource"));

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    HttpResponseMessage response = await client.GetAsync(
                        "http://www.base.com/resource");

                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                }
        }
        public async Task should_get_ok_if_route_is_defined()
        {
            HttpServer httpServer = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute(
                    "ControllerWithPublicAction",
                    "Get",
                    HttpMethod.Get,
                    "controller-with-action"));

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    HttpResponseMessage response = await client.GetAsync(
                        "http://www.base.com/controller-with-action");

                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                }
        }
        public async Task should_get_first_matched_route()
        {
            HttpServer httpServer = HttpServerTestHelper.PrepareHttpServer(
                ControllerAssemblies,
                new HttpRoute(
                    "ControllerWith2DifferentActions",
                    "GetResource1",
                    HttpMethod.Get,
                    "resource"),
                new HttpRoute(
                    "ControllerWith2DifferentActions",
                    "GetResource2",
                    HttpMethod.Get,
                    "resource"));

            using (httpServer)
                using (var client = new HttpClient(httpServer))
                {
                    await HttpServerTestHelper.AssertStringContent(client, "http://www.base.com/resource", "get resource 1");
                }
        }