public void EmptyResponsePageTest()
        {
            Action<IAppBuilder> config = (builder) =>
            {
                builder.Use(typeof(EmptyResponseApplication));
            };

            using (var server = new FosSelfHost(config))
            {
                server.Bind(ListenOn, ListenPort);
                server.Start(true);

                System.Threading.Thread.Sleep(100);

                // Make the request and expect the empty response page with 500 status code
                var browser = new Browser(ListenOn, ListenPort);
                using (var response = browser.ExecuteRequest("http://localhost/", "GET"))
                {
                    var emptyResponsePage = new EmptyResponsePage();

                    //Assert.AreNotEqual(0, response.AppStatusCode);
                    Assert.AreEqual(500, response.HttpStatusCode);
                    Assert.AreEqual(emptyResponsePage.Contents, ReadStream(response.ResponseBody));
                }
            }
        }
Example #2
0
 public static void FastCgi(int port)
 {
     var startup = new Startup();
     using (var fosServer = new FosSelfHost(startup.Configuration))
     {
         fosServer.Bind(System.Net.IPAddress.Loopback, port);
         fosServer.Start(false);
     }
 }
Example #3
0
        protected FosSelfHost GetHelloWorldBoundServer()
        {
            Action<IAppBuilder> config = (builder) =>
            {
                builder.Use(typeof(Fos.Tests.Middleware.HelloWorldApplication));
            };

            var server = new FosSelfHost(config);
            server.Bind(ListenOn, ListenPort);

            return server;
        }
Example #4
0
        public void StartAndDispose()
        {
            int port = 9007; // Let's hope this is not being used..

            FosSelfHost server;
            using (server = new FosSelfHost(app => {}))
            {
                server.Bind(System.Net.IPAddress.Loopback, port);

                server.Start(true);
                Assert.AreEqual(true, server.IsRunning);
            }

            Assert.AreEqual(false, server.IsRunning);
        }
Example #5
0
        public void StartAndDisposeUnixSocket()
        {
            FosSelfHost server;
            using (server = new FosSelfHost(app => {}))
            {
                server.Bind("./.FosTestSocket");

                server.Start(true);
                Assert.AreEqual(true, server.IsRunning);
            }

            using (server = new FosSelfHost(app => {}))
            {
                server.Bind("./.FosTestSocket");

                server.Start(true);
                Assert.AreEqual(true, server.IsRunning);
            }

            Assert.AreEqual(false, server.IsRunning);
        }
        public void ErrorPageTest()
        {
            Action<IAppBuilder> config = (builder) =>
            {
                builder.Use(typeof(ThrowsExceptionApplication));
            };

            using (var server = new FosSelfHost(config))
            {
                server.Bind(ListenOn, ListenPort);
                server.Start(true);

                //System.Threading.Thread.Sleep(1000000);
                // Make the request and expect the empty response page with 500 status code
                var browser = new Browser(ListenOn, ListenPort);
                var response = browser.ExecuteRequest("http://localhost/", "GET");

                //Assert.AreNotEqual(0, response.AppStatusCode);
                Assert.AreEqual(500, response.HttpStatusCode);
                Assert.That(ReadStream(response.ResponseBody).Contains("An error occured in the application. On purpose."));
            }
        }