예제 #1
0
 public void Cascade_with_no_apps_should_return_404()
 {
     var cascade = AppBuilder.BuildConfiguration(b => b.Cascade(Enumerable.Empty<AppDelegate>().ToArray()));
     var host = new FakeHost(cascade);
     var response = host.GET("/");
     Assert.That(response.Status, Is.EqualTo("404 Not Found"));
 }
예제 #2
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);
 }
예제 #3
0
        public void Method_is_overridden_if_override_present()
        {
            var result = new FakeHost(AppBuilder.BuildConfiguration(b => b
                .UseMethodOverride()
                .Run(AppUtils.ShowEnvironment))).Invoke(r => {
                    r.Method = "POST";
                    r.Headers = new Dictionary<string, string>() { { "x-http-method-override", "DELETE" } };
                });

            Assert.That(result.BodyXml.Element(Environment.RequestMethodKey).Value, Is.EqualTo("DELETE"));
        }
예제 #4
0
        public void Method_is_overridden_if_override_present()
        {
            var result = new FakeHost(AppBuilder.BuildPipeline(b => b
                .UseMethodOverride()
                .Run(AppUtils.ShowEnvironment))).Invoke(r => {
                    r.Method = "POST";
                    r.Headers = Headers.New().SetHeader("x-http-method-override", "DELETE");
                });

            Assert.That(result.BodyXml.Element(Environment.RequestMethodKey).Value, Is.EqualTo("DELETE"));
        }
예제 #5
0
파일: StaticTests.cs 프로젝트: anurse/gate
        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);
        }
예제 #6
0
        public void Method_is_unchanged_if_override_not_present()
        {
            var result = new FakeHost(AppBuilder.BuildConfiguration(b => b
                .UseMethodOverride()
                .Run(AppUtils.ShowEnvironment))).Invoke(r =>
                {
                    r.Method = "POST";
                    r.Headers = Headers.New();
                });

            Assert.That(result.BodyXml.Element(Environment.RequestMethodKey).Value, Is.EqualTo("POST"));
        }
예제 #7
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);
 }
예제 #8
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);
 }
예제 #9
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"));
        }
예제 #10
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"));
        }
예제 #11
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"));
        }
예제 #12
0
 public void Init()
 {
     _host = new FakeHost("Sample.App.Startup");
 }