Exemple #1
0
        public void ExecutesFallbackWhenExceptionIsThrownAndExceptionTypeIsContainedInFilter()
        {
            // Arrange
            var handler   = new TestQueryHandlerWithFormatExceptionFallback();
            var decorator = new FallbackPolicyDecorator <IQuery <TestQuery.Result>, TestQuery.Result>();

            _handlerRegistry.Register <TestQuery, TestQuery.Result, TestQueryHandlerWithFormatExceptionFallback>();
            _handlerFactory.Setup(x => x.Create(typeof(TestQueryHandlerWithFormatExceptionFallback))).Returns(handler);

            var decoratorType = typeof(FallbackPolicyDecorator <IQuery <TestQuery.Result>, TestQuery.Result>);

            _decoratorFactory.Setup(x => x.Create <IQueryHandlerDecorator <IQuery <TestQuery.Result>, TestQuery.Result> >(decoratorType)).Returns(decorator);

            // Act
            var result = _queryProcessor.Execute(new TestQuery());

            // Assert
            result.ShouldNotBeNull();
            handler.Context.ShouldNotBeNull();
            handler.Context.Bag["Fallback_Exception_Cause"].ShouldBeAssignableTo <FormatException>();
            handler.Context.Bag.ShouldContainKeyAndValue("Check1", true);
            handler.Context.Bag.ShouldContainKeyAndValue("Check2", true);
            _handlerFactory.Verify(x => x.Release(handler), Times.Once);
            _decoratorFactory.Verify(x => x.Release <IQueryHandlerDecorator <IQuery <TestQuery.Result>, TestQuery.Result> >(decorator), Times.Once);
        }
Exemple #2
0
        public void DoesNotExecuteFallbackWhenExceptionIsThrownAndExceptionTypeIsNotContainedInFilter()
        {
            // Arrange
            var handler   = new TestQueryHandlerWithoutFormatExceptionFallback();
            var decorator = new FallbackPolicyDecorator <IQueryRequest <TestQuery.Response>, TestQuery.Response>();

            _handlerRegistry.Register <TestQuery, TestQuery.Response, TestQueryHandlerWithoutFormatExceptionFallback>();
            _handlerFactory.Setup(x => x.Create <dynamic>(typeof(TestQueryHandlerWithoutFormatExceptionFallback))).Returns(handler);

            var decoratorType = typeof(FallbackPolicyDecorator <IQueryRequest <TestQuery.Response>, TestQuery.Response>);

            _decoratorFactory.Setup(x => x.Create <IQueryHandlerDecorator <IQueryRequest <TestQuery.Response>, TestQuery.Response> >(decoratorType)).Returns(decorator);

            // Act
            Assert.Throws <FormatException>(() => _queryProcessor.Execute(new TestQuery()));

            // Assert
            handler.Context.ShouldNotBeNull();
            handler.Context.Bag.ShouldNotContainKey("Fallback_Exception_Cause");
            handler.Context.Bag.ShouldContainKeyAndValue("Check1", true);
            handler.Context.Bag.ShouldNotContainKey("Check2");
        }
Exemple #3
0
        public void ExecutesFallbackWhenExceptionIsThrown()
        {
            // Arrange
            var handler   = new TestQueryHandlerWithCatchAllFallback();
            var decorator = new FallbackPolicyDecorator <IQueryRequest <TestQuery.Response>, TestQuery.Response>();

            _handlerRegistry.Register <TestQuery, TestQuery.Response, TestQueryHandlerWithCatchAllFallback>();
            _handlerFactory.Setup(x => x.Create <dynamic>(typeof(TestQueryHandlerWithCatchAllFallback))).Returns(handler);

            var decoratorType = typeof(FallbackPolicyDecorator <IQueryRequest <TestQuery.Response>, TestQuery.Response>);

            _decoratorFactory.Setup(x => x.Create <IQueryHandlerDecorator <IQueryRequest <TestQuery.Response>, TestQuery.Response> >(decoratorType)).Returns(decorator);

            // Act
            var response = _queryProcessor.Execute(new TestQuery());

            // Assert
            response.ShouldNotBeNull();
            handler.Context.ShouldNotBeNull();
            handler.Context.Bag["Fallback_Exception_Cause"].ShouldBeAssignableTo <FormatException>();
            handler.Context.Bag.ShouldContainKeyAndValue("Check1", true);
            handler.Context.Bag.ShouldContainKeyAndValue("Check2", true);
        }