Example #1
0
 public void Cascade_with_app_calls_through()
 {
     var app = new FakeApp("200 OK", "Hello world");
     app.Headers["Content-Type"] = "text/plain";
     var cascade = AppBuilder.BuildConfiguration(b => b.Cascade(app.AppDelegate));
     var host = new FakeHost(cascade);
     var response = host.GET("/");
     Assert.That(response.Status, Is.EqualTo("200 OK"));
     Assert.That(response.BodyText, Is.EqualTo("Hello world"));
     Assert.That(app.AppDelegateInvoked, Is.True);
 }
Example #2
0
        public void HttpContextBase_is_added_to_environment()
        {
            SetRequestPaths("http://localhost/", "/");

            var app = new FakeApp("200 OK", "Hello World");
            var appHandler = new AppHandler(app.AppDelegate);

            ProcessRequest(appHandler);

            Assert.That(app.Env["aspnet.HttpContextBase"], Is.SameAs(_httpContext));
        }
Example #3
0
        public void Static_calls_down_the_chain_if_URL_root_is_unknown()
        {
            var app = new FakeApp("200 OK", "Hello World");
            app.Headers.SetHeader("Content-Type", "text/plain");
            var config = AppBuilder.BuildPipeline(b => b.UseStatic().Run(app.AppDelegate));
            var host = new FakeHost(config);
            var response = host.GET("/johnson/and/johnson");

            Assert.That(response.Status, Is.EqualTo("200 OK"));
            Assert.That(response.BodyText, Is.EqualTo("Hello World"));
            Assert.That(app.AppDelegateInvoked, Is.True);
        }
Example #4
0
        public void AppHandler_can_be_created_and_invoked()
        {
            SetRequestPaths("http://localhost/", "/");

            var app = new FakeApp("200 OK", "Hello World");
            var appHandler = new AppHandler(app.AppDelegate);

            ProcessRequest(appHandler);

            Assert.That(app.AppDelegateInvoked, Is.True);
            Assert.That(_httpResponse.Status, Is.EqualTo("200 OK"));
            Assert.That(ResponseOutputText, Is.EqualTo("Hello World"));
        }
Example #5
0
 public void Cascade_works_when_result_is_not_on_same_thread()
 {
     var app1 = new FakeApp("404 Not Found", "") {SendAsync = true};
     var app2 = new FakeApp("200 OK", "Hello world") {SendAsync = true};
     app2.Headers["Content-Type"] = "text/plain";
     var app3 = new FakeApp("404 Not Found", "") {SendAsync = true};
     var cascade = AppBuilder.BuildConfiguration(b => b.Cascade(app1.AppDelegate, app2.AppDelegate, app3.AppDelegate));
     var host = new FakeHost(cascade);
     var response = host.GET("/");
     Assert.That(response.Status, Is.EqualTo("200 OK"));
     Assert.That(response.BodyText, Is.EqualTo("Hello world"));
     Assert.That(app1.AppDelegateInvoked, Is.True);
     Assert.That(app2.AppDelegateInvoked, Is.True);
     Assert.That(app3.AppDelegateInvoked, Is.False);
 }
Example #6
0
 public void Cascade_will_pass_along_to_first_non_404_app()
 {
     var app1 = new FakeApp("404 Not Found", "");
     var app2 = new FakeApp("200 OK", "Hello world");
     app2.Headers["Content-Type"] = "text/plain";
     var app3 = new FakeApp("404 Not Found", "");
     var cascade = AppBuilder.BuildConfiguration(b => b.Cascade(app1.AppDelegate, app2.AppDelegate, app3.AppDelegate));
     var host = new FakeHost(cascade);
     var response = host.GET("/");
     Assert.That(response.Status, Is.EqualTo("200 OK"));
     Assert.That(response.BodyText, Is.EqualTo("Hello world"));
     Assert.That(app1.AppDelegateInvoked, Is.True);
     Assert.That(app2.AppDelegateInvoked, Is.True);
     Assert.That(app3.AppDelegateInvoked, Is.False);
 }
Example #7
0
        public void Normal_request_should_pass_through_unchanged()
        {
            var app = new FakeApp("200 OK", "Hello");
            app.Headers.SetHeader("Content-Type", "text/plain");

            var stack = Build(b => b
                .UseShowExceptions()
                .Run(app.AppDelegate));

            var host = new FakeHost(stack);

            var response = host.GET("/");

            Assert.That(response.Status, Is.EqualTo("200 OK"));
            Assert.That(response.BodyText, Is.EqualTo("Hello"));
        }
Example #8
0
        public void Request_fault_should_be_500_with_html_body()
        {
            var app = new FakeApp(new ApplicationException("Kaboom"));

            var stack = Build(b => b
                .UseShowExceptions()
                .Run(app.AppDelegate));

            var host = new FakeHost(stack);

            var response = host.GET("/");

            Assert.That(response.Status, Is.EqualTo("500 Internal Server Error"));
            Assert.That(response.Headers.GetHeader("Content-Type"), Is.EqualTo("text/html"));
            Assert.That(response.BodyText, Is.StringContaining("ApplicationException"));
            Assert.That(response.BodyText, Is.StringContaining("Kaboom"));
        }
Example #9
0
        public void Exception_in_response_body_stream_should_be_formatted_as_it_passes_through()
        {
            var app = new FakeApp { Status = "200 OK" };
            app.Headers.SetHeader("Content-Type", "text/html");
            app.Body = (write, end, cancel) =>
            {
                write(new ArraySegment<byte>(Encoding.UTF8.GetBytes("<p>so far so good</p>")), null);
                end(new ApplicationException("failed sending body"));
            };

            var stack = Build(b => b
                .UseShowExceptions()
                .Run(app.AppDelegate));

            var host = new FakeHost(stack);

            var response = host.GET("/");

            Assert.That(response.Status, Is.EqualTo("200 OK"));
            Assert.That(response.Headers.GetHeader("Content-Type"), Is.EqualTo("text/html"));
            Assert.That(response.BodyText, Is.StringContaining("<p>so far so good</p>"));
            Assert.That(response.BodyText, Is.StringContaining("failed sending body"));
        }
Example #10
0
        public void Path_receives_path_portion_of_request()
        {
            SetRequestPaths("http://localhost/foo/bar", "/");

            var app = new FakeApp("200 OK", "Hello World");
            var appHandler = new AppHandler(app.AppDelegate);

            ProcessRequest(appHandler);

            Assert.That(app.AppDelegateInvoked);
            Assert.That(app.Owin.Path, Is.EqualTo("/foo/bar"));
            Assert.That(app.Owin.PathBase, Is.EqualTo(""));
        }
Example #11
0
        public void Path_and_pathbase_are_rooted()
        {
            SetRequestPaths("http://localhost/", "/");

            var app = new FakeApp("200 OK", "Hello World");
            var appHandler = new AppHandler(app.AppDelegate);

            ProcessRequest(appHandler);

            Assert.That(app.AppDelegateInvoked);
            Assert.That(app.Owin.Path, Is.EqualTo("/"));
            Assert.That(app.Owin.PathBase, Is.EqualTo(""));
        }
Example #12
0
        public void PathBase_receives_leading_portion_when_apprelative_portion_is_shorter()
        {
            SetRequestPaths("http://localhost/foo/bar", "/foo");

            var app = new FakeApp("200 OK", "Hello World");
            var appHandler = new AppHandler(app.AppDelegate);

            ProcessRequest(appHandler);

            Assert.That(app.AppDelegateInvoked);
            Assert.That(app.Owin.Path, Is.EqualTo("/bar"));
            Assert.That(app.Owin.PathBase, Is.EqualTo("/foo"));
        }
Example #13
0
 public static AppDelegate Simple(string status, Action<IDictionary<string, string[]>> headers, Action<Func<ArraySegment<byte>, bool>> body)
 {
     var app = new FakeApp(status, (write, end, cancel) =>
     {
         body(data => write(data, null));
         end(null);
     });
     headers(app.Headers);
     return app.AppDelegate;
 }
Example #14
0
        public void Uri_scheme_http_passes_through_to_environment()
        {
            SetRequestPaths("http://localhost/", "/");

            var app = new FakeApp("200 OK", "Hello World");
            var appHandler = new AppHandler(app.AppDelegate);

            ProcessRequest(appHandler);

            Assert.That(app.AppDelegateInvoked);
            Assert.That(app.Owin.Scheme, Is.EqualTo("http"));
        }
Example #15
0
        public void ServerVariables_that_are_not_headers_are_added_to_environment()
        {
            SetRequestPaths("http://localhost/", "/");
            _httpRequest.ServerVariables["HTTP_HELLO"] = "http.hello.server.variable";
            _httpRequest.ServerVariables["FOO"] = "foo.server.variable";

            var app = new FakeApp("200 OK", "Hello World");
            var appHandler = new AppHandler(app.AppDelegate);

            ProcessRequest(appHandler);

            Assert.That(app.Env["server.FOO"], Is.EqualTo("foo.server.variable"));
            Assert.That(app.Env.ContainsKey("server.HTTP_HELLO"), Is.False);
        }
Example #16
0
        public void Request_headers_dictionary_is_case_insensitive()
        {
            SetRequestPaths("http://localhost/", "/");
            _httpRequest.Headers["Content-Type"] = "text/plain";

            var app = new FakeApp("200 OK", "Hello World");
            var appHandler = new AppHandler(app.AppDelegate);

            ProcessRequest(appHandler);

            Assert.That(app.Env["aspnet.HttpContextBase"], Is.SameAs(_httpContext));

            var headers = new Environment(app.Env).Headers;

            Assert.That(headers["Content-Type"], Is.EqualTo("text/plain"));
            Assert.That(headers["CONTENT-TYPE"], Is.EqualTo("text/plain"));
            Assert.That(headers.Keys.ToArray().Contains("Content-Type"), Is.True);
            Assert.That(headers.Keys.ToArray().Contains("CONTENT-TYPE"), Is.False);
        }
Example #17
0
        public void Remote_host_closed_connection_during_write()
        {
            A.CallTo(() => _httpResponse.OutputStream).Returns(new RemoteHostClosedStream());

            SetRequestPaths("http://localhost/", "/");
            _httpRequest.Headers["Content-Type"] = "text/plain";

            var app = new FakeApp("200 OK", "Hello World");
            var appHandler = new AppHandler(app.AppDelegate);

            var ex = Assert.Throws<AggregateException>(()=>ProcessRequest(appHandler));
            Assert.That(ex.Flatten().InnerExceptions.Count, Is.EqualTo(1));
            Assert.That(ex.Flatten().InnerExceptions[0], Is.TypeOf<HttpException>());
        }