Example #1
0
        public async void unhandled_exception___returns_true_and_process_service_unavailable_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 ApiServiceUnavailableException();

            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(503);

            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);
        }
Example #2
0
        public void exceptions___api_service_unavailable_exception_ctor_test()
        {
            var innerException         = new Exception("Inner Exception");
            var customMessage          = "My Custom Exception";
            var expectedHttpStatusCode = 503;

            var ex = new ApiServiceUnavailableException();

            ex.HttpStatus.Should().Be(expectedHttpStatusCode);
            ex.Message.Should().Be($"Exception of type '{typeof(ApiServiceUnavailableException).FullName}' was thrown.");
            ex.InnerException.Should().BeNull();

            ex = new ApiServiceUnavailableException(customMessage);
            ex.HttpStatus.Should().Be(expectedHttpStatusCode);
            ex.Message.Should().Be(customMessage);
            ex.InnerException.Should().BeNull();

            ex = new ApiServiceUnavailableException(customMessage, innerException);
            ex.HttpStatus.Should().Be(expectedHttpStatusCode);
            ex.Message.Should().Be(customMessage);
            ex.InnerException.Should().BeSameAs(innerException);
        }