Exemplo n.º 1
0
        public void WHEN_one_composer_exception_with_errors_SHOULD_not_set_context_response()
        {
            // Arrange
            AggregatedComposerExceptionFilter filter = _container.CreateInstance <AggregatedComposerExceptionFilter>();

            var innerException = new ComposerException(new List <ErrorViewModel>
            {
                new ErrorViewModel
                {
                    ErrorCode    = GetRandom.String(1),
                    ErrorMessage = GetRandom.String(1)
                },
                new ErrorViewModel
                {
                    ErrorCode    = GetRandom.String(1),
                    ErrorMessage = GetRandom.String(1)
                }
            });

            var context = new HttpActionExecutedContext
            {
                Exception     = new AggregateException(innerException),
                ActionContext = new HttpActionContext() // required or setting the context response will throw exception...
            };

            // Act
            filter.OnException(context);

            // Assert
            context.Response.Should().NotBeNull();
        }
Exemplo n.º 2
0
        public void WHEN_executed_context_is_null_SHOULD_throw_argument_null_exception()
        {
            // Arrange
            AggregatedComposerExceptionFilter filter = _container.CreateInstance <AggregatedComposerExceptionFilter>();

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => filter.OnException(null));
        }
Exemplo n.º 3
0
        public void WHEN_executed_context_contains_aggregate_exception_with_other_exception_types_SHOULD_not_set_context_response()
        {
            // Arrange
            AggregatedComposerExceptionFilter filter = _container.CreateInstance <AggregatedComposerExceptionFilter>();

            var context = new HttpActionExecutedContext
            {
                Exception     = GetAggregateExceptionWithMixExceptions(),
                ActionContext = new HttpActionContext() // required or setting the context response will throw exception...
            };

            // Act
            filter.OnException(context);

            // Assert
            context.Response.Should().BeNull();
        }
Exemplo n.º 4
0
        public void WHEN_executed_context_contains_aggregate_exception_with_composer_exceptions_only_SHOULD_set_invalid_server_error_status_code_to_context_response()
        {
            // Arrange
            AggregatedComposerExceptionFilter filter = _container.CreateInstance <AggregatedComposerExceptionFilter>();

            var context = new HttpActionExecutedContext
            {
                Exception     = GetAggregateExceptionWithComposerExceptionsOnly(),
                ActionContext = new HttpActionContext() // required or setting the context response will throw exception...
            };

            // Act
            filter.OnException(context);

            // Assert
            context.Response.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
        }