public CommandRouteTable( IEnumerable <ICommand> commandComponents, ResponsibilityChain <Type, IEnumerable <string> > routeHandler) { _commandComponents = commandComponents; _routeHandler = routeHandler; }
public QueryRouteTable( IEnumerable <IQuery> queryComponents, ResponsibilityChain <Type, IEnumerable <string> > routeHandler) { _queryComponents = queryComponents; _routeHandler = routeHandler; }
public void Chain_AddTypeThatIsNotAMiddleware_ThrowsException() { var responsibilityChain = new ResponsibilityChain <Exception, bool>(new ActivatorMiddlewareResolver()); PipelineNetAssert.ThrowsException <ArgumentException>(() => { responsibilityChain.Chain(typeof(ResponsibilityChainTests)); }); }
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); }
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); }
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); }
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); }