コード例 #1
0
        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));
                }
            }
        }
コード例 #2
0
ファイル: NormalConnectionClosing.cs プロジェクト: knocte/Fos
        public void ApplicationErrorLogging()
        {
            var logger = new OneRequestTestLogger();

            using (var server = GetApplicationErrorBoundServer())
            {
                server.SetLogger(logger);
                server.Start(true);

                // A Request for the root dir /
                var browser = new Browser(ListenOn, ListenPort);
                browser.ExecuteRequest("http://localhost/", "GET");
            }

            Assert.IsNotNull(logger.ApplicationError);
            Assert.That(logger.ApplicationError.ToString().Contains("An error occured in the application. On purpose."));
            Assert.That(logger.RequestInfo != null && logger.RequestInfo.RelativePath == "/" && logger.RequestInfo.ResponseStatusCode == 500);
        }
コード例 #3
0
ファイル: NormalConnectionClosing.cs プロジェクト: knocte/Fos
        public void CheckBasicLoggingData()
        {
            var logger = new OneRequestTestLogger();

            using (var server = GetHelloWorldBoundServer())
            {
                server.SetLogger(logger);
                server.Start(true);

                // A Request for the root dir /
                using (var browser = new Browser(ListenOn, ListenPort))
                {
                    browser.ExecuteRequest("http://localhost/", "GET");
                }

                Assert.IsTrue(logger.ConnectionWasReceived);
                Assert.IsTrue(logger.ConnectionClosedNormally);
                Assert.That(logger.RequestInfo.RelativePath == "/" && logger.RequestInfo.ResponseStatusCode == 200);
                Assert.IsFalse(logger.ConnectionClosedAbruptlyWithoutUrl);
            }
        }
コード例 #4
0
        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."));
            }
        }