コード例 #1
0
 public CommandRouteTable(
     IEnumerable <ICommand> commandComponents,
     ResponsibilityChain <Type, IEnumerable <string> > routeHandler)
 {
     _commandComponents = commandComponents;
     _routeHandler      = routeHandler;
 }
コード例 #2
0
 public QueryRouteTable(
     IEnumerable <IQuery> queryComponents,
     ResponsibilityChain <Type, IEnumerable <string> > routeHandler)
 {
     _queryComponents = queryComponents;
     _routeHandler    = routeHandler;
 }
コード例 #3
0
        public void Chain_AddTypeThatIsNotAMiddleware_ThrowsException()
        {
            var responsibilityChain = new ResponsibilityChain <Exception, bool>(new ActivatorMiddlewareResolver());

            PipelineNetAssert.ThrowsException <ArgumentException>(() =>
            {
                responsibilityChain.Chain(typeof(ResponsibilityChainTests));
            });
        }
コード例 #4
0
        private static void RunChain()
        {
            var exceptionHandlersChain = new ResponsibilityChain <Exception, bool>(new ActivatorMiddlewareResolver())
                                         .Chain <OutOfMemoryExceptionHandler>()
                                         .Chain <ArgumentExceptionHandler>()
                                         .Finally((parameter) =>
            {
                Console.WriteLine("Finally");
                return(true);
            });
            var result = exceptionHandlersChain.Execute(new InvalidOperationException());

            Console.WriteLine(result);
        }
コード例 #5
0
        public void Execute_ChainOfMiddlewareThatDoesNotHandleTheException_ChainReturnsDefaultValue()
        {
            var responsibilityChain = new ResponsibilityChain <Exception, bool>(new ActivatorMiddlewareResolver())
                                      .Chain <UnavailableResourcesExceptionHandler>()
                                      .Chain <InvalidateDataExceptionHandler>()
                                      .Chain <MyExceptionHandler>();

            // Creates an ArgumentNullException, that will not be handled by any middleware.
            var excception = new ArgumentNullException();

            // The result should be the default for 'bool'.
            var result = responsibilityChain.Execute(excception);

            Assert.AreEqual(default(bool), result);
        }
コード例 #6
0
        public void Execute_CreateChainOfMiddlewareToHandleException_TheRightMiddleHandlesTheException()
        {
            var responsibilityChain = new ResponsibilityChain <Exception, bool>(new ActivatorMiddlewareResolver())
                                      .Chain <UnavailableResourcesExceptionHandler>()
                                      .Chain <InvalidateDataExceptionHandler>()
                                      .Chain <MyExceptionHandler>();

            // Creates an invalid exception that should be handled by 'InvalidateDataExceptionHandler'.
            var invalidException = new InvalidateDataException();

            var result = responsibilityChain.Execute(invalidException);

            // Check if the given exception was handled
            Assert.IsTrue(result);

            // Check if the correct handler handled the exception.
            Assert.AreEqual(typeof(InvalidateDataExceptionHandler).Name, invalidException.HandlerName);
        }
コード例 #7
0
        public void Execute_ChainOfMiddlewareWithFinallyFunc_FinallyFuncIsExecuted()
        {
            const string ExceptionSource = "EXCEPTION_SOURCE";

            var responsibilityChain = new ResponsibilityChain <Exception, bool>(new ActivatorMiddlewareResolver())
                                      .Chain <UnavailableResourcesExceptionHandler>()
                                      .Chain(typeof(InvalidateDataExceptionHandler))
                                      .Chain <MyExceptionHandler>()
                                      .Finally((ex) =>
            {
                ex.Source = ExceptionSource;
                return(true);
            });

            // Creates an ArgumentNullException, that will not be handled by any middleware.
            var exception = new ArgumentNullException();

            // The result should true, since the finally function will be executed.
            var result = responsibilityChain.Execute(exception);

            Assert.IsTrue(result);

            Assert.AreEqual(ExceptionSource, exception.Source);
        }