public async void unhandled_exception___returns_true_and_process_bad_gateway_exception_handler_not_called() { var context = new ApiRequestContext(); bool exHandled = false; var config = new DefaultApiServiceConfiguration { OnException = (ctx, ex) => { exHandled = true; throw new Exception("Error"); } }; var exception = new ApiBadGatewayException(); var processed = await context.ProcessHttpResponseUnhandledException(new ApiRequestContextResolver(), exception, config).ConfigureAwait(false); processed.Should().BeTrue(); context.Response.Should().NotBeNull(); context.Response.ResponseObject.Should().BeNull(); context.Response.StatusCode.Should().Be(502); context.Validation.Errors.Should().NotBeNull(); context.Validation.Errors.Should().HaveCount(0); exHandled.Should().Be(false); context.Runtime.Exceptions.Should().NotBeNull(); context.Runtime.Exceptions.Should().HaveCount(1); context.Runtime.Exceptions[0].Should().Be(exception); }
public void exceptions___api_bad_gateway_exception_ctor_test() { var innerException = new Exception("Inner Exception"); var customMessage = "My Custom Exception"; var expectedHttpStatusCode = 502; var ex = new ApiBadGatewayException(); ex.HttpStatus.Should().Be(expectedHttpStatusCode); ex.Message.Should().Be($"Exception of type '{typeof(ApiBadGatewayException).FullName}' was thrown."); ex.InnerException.Should().BeNull(); ex = new ApiBadGatewayException(customMessage); ex.HttpStatus.Should().Be(expectedHttpStatusCode); ex.Message.Should().Be(customMessage); ex.InnerException.Should().BeNull(); ex = new ApiBadGatewayException(customMessage, innerException); ex.HttpStatus.Should().Be(expectedHttpStatusCode); ex.Message.Should().Be(customMessage); ex.InnerException.Should().BeSameAs(innerException); }