Exemple #1
0
        public void Enable_Should_LogError_For_Application()
        {
            var browser = new Browser(new ConfigurableBootstrapper(config =>
            {
                config.ApplicationStartup((container, pipelines) =>
                {
                    RequestLogging.Enable(pipelines, _requestLogger.Object);
                });
                config.Module <TestModule>();
            }));

            Assert.Throws <Exception>(() => browser.Get("/test/error", config =>
            {
                config.HostName("localhost");
                config.HttpRequest();
                config.Header("Accept", "text/html");
            }));

            _requestLogger.Verify(x => x.LogError(
                                      It.Is <RequestData>(r =>
                                                          r.Url == new Uri("http://localhost/test/error") &&
                                                          r.HttpMethod == "GET" &&
                                                          r.Header.ContainsKey("Accept") &&
                                                          r.Header["Accept"].Any(y => y.Contains("text/html")) &&
                                                          r.Content.Length == 0),
                                      It.Is <ResponseData>(r =>
                                                           r.StatusCode == 0 &&
                                                           r.ReasonPhrase == null &&
                                                           r.Header.Count == 0 &&
                                                           r.Content.Length == 0),
                                      It.Is <Exception>(ex => ex.Message == "ERROR")),
                                  Times.Once);
        }
Exemple #2
0
        public void Enable_Should_Log_DELETE_Request_For_Application()
        {
            var browser = new Browser(new ConfigurableBootstrapper(config =>
            {
                config.ApplicationStartup((container, pipelines) =>
                {
                    RequestLogging.Enable(pipelines, _requestLogger.Object);
                });
                config.Module <TestModule>();
            }));

            browser.Delete("/test", config =>
            {
                config.HostName("localhost");
                config.HttpRequest();
                config.Header("Accept", "text/html");
            });

            _requestLogger.Verify(x => x.Log(
                                      It.Is <RequestData>(r =>
                                                          r.Url == new Uri("http://localhost/test") &&
                                                          r.HttpMethod == "DELETE" &&
                                                          r.Header.ContainsKey("Accept") &&
                                                          r.Header["Accept"].Any(y => y.Contains("text/html")) &&
                                                          r.Content.Length == 0),
                                      It.Is <ResponseData>(r =>
                                                           r.StatusCode == 200 &&
                                                           r.ReasonPhrase == "OK" &&
                                                           r.Header.ContainsKey("X-Test") &&
                                                           r.Header["X-Test"][0] == "TEST" &&
                                                           r.Content.SequenceEqual(Encoding.UTF8.GetBytes("TEST")))),
                                  Times.Once);
        }
Exemple #3
0
 public TestWithLoggerModule(IRequestLogger requestLogger)
 {
     RequestLogging.Enable(this, requestLogger);
 }
Exemple #4
0
 public void Enable_When_RequestLogger_IsNull_ShouldThrow_ArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => RequestLogging.Enable(new Pipelines(), null));
     Assert.Throws <ArgumentNullException>(() => RequestLogging.Enable(new ConfigurableNancyModule(), null));
 }
Exemple #5
0
 public void Enable_When_Pipelines_IsNull_ShouldThrow_ArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => RequestLogging.Enable((IPipelines)null, _requestLogger.Object));
     Assert.Throws <ArgumentNullException>(() => RequestLogging.Enable((NancyModule)null, _requestLogger.Object));
 }