public void Constructor_WithWin32ErrorCodeAndMessage() { var exception = new HttpServerException((Win32Error)5, "The message"); exception.NativeErrorCode.Should().Be(5); exception.Message.Should().Be("The message"); }
public async Task Invoke(HttpContext context, IEnumerable <IHttpServerEventCallback> callbacks) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (callbacks == null) { throw new ArgumentNullException(nameof(callbacks)); } var stopwatch = Stopwatch.StartNew(); callbacks.Invoke(() => HttpServerRequest.Create(context)); try { await _next(context); } catch (HttpException e) { await WriteResponse(context, e.StatusCode, e.Message); } catch (Exception e) { await WriteResponse(context, HttpStatusCode.InternalServerError, "FAIL!"); callbacks.Invoke(() => HttpServerException.Create(context, stopwatch.ElapsedMilliseconds, e)); } callbacks.Invoke(() => HttpServerResponse.Create(context, stopwatch.ElapsedMilliseconds)); }
public void Constructor_WithWin32ErrorCode() { var exception = new HttpServerException((Win32Error)5); exception.NativeErrorCode.Should().Be(5); exception.Message.Should().Be("Accès refusé"); }
public void Constructor_WithMessage() { var lastErrorCode = Marshal.GetLastWin32Error(); var exception = new HttpServerException("The message"); exception.NativeErrorCode.Should().Be(lastErrorCode); exception.Message.Should().Be("The message"); }
public void serialise_server_exception_with_inner_exception() { var httpServerResponse = HttpServerException.Create(_httpContext, 123, new Exception("my-exception", new ApplicationException("inner"))); httpServerResponse.Timestamp = new DateTimeOffset(2016, 11, 18, 19, 52, 6, TimeSpan.Zero).AddTicks(4425454); _testSubject.Invoke(httpServerResponse); _logger.Logs[0].ShouldBe("{\"eventType\":\"HttpServerException\",\"timestamp\":\"2016-11-18T19:52:06.4425454+00:00\",\"uri\":\"/ping?v=1\",\"method\":\"GET\",\"durationMs\":123,\"exception\":{\"type\":\"Exception\",\"message\":\"my-exception\",\"innerException\":{\"type\":\"ApplicationException\",\"message\":\"inner\"}}}"); }
public void serialise_server_exception_with_tag() { var httpServerResponse = HttpServerException.Create(_httpContext, 1729, new Exception("my-exception")); httpServerResponse.Timestamp = new DateTimeOffset(2016, 11, 18, 19, 52, 6, TimeSpan.Zero).AddTicks(4425454); httpServerResponse.Tags.Add("key1", "value1"); httpServerResponse.Tags.Add("key2", "value2"); _testSubject.Invoke(httpServerResponse); _logger.Logs[0].ShouldBe("{\"eventType\":\"HttpServerException\",\"timestamp\":\"2016-11-18T19:52:06.4425454+00:00\",\"uri\":\"/ping?v=1\",\"method\":\"GET\",\"tags\":{\"key1\":\"value1\",\"key2\":\"value2\"},\"durationMs\":1729,\"exception\":{\"type\":\"Exception\",\"message\":\"my-exception\"}}"); }
public void Serialization() { var exception = new HttpServerException((Win32Error)5, "The message"); exception.Should().BeBinarySerializable(); }