Example #1
0
        public async Task It_Catches_Errors_If_Any()
        {
            var exception         = new MyCustomException();
            var receivedCommand   = default(IDynamicCommand);
            var receivedException = default(Exception);

            var testStrategy = new TestCommandStrategy(
                onExecute: (_, __, ___) => throw exception
                );

            var strategy = new ErrorHandlerCommandStrategy(new DynamicCommandErrorHandler((ct, c, e) =>
            {
                receivedCommand   = c;
                receivedException = e;

                return(Task.CompletedTask);
            }))
            {
                InnerStrategy = testStrategy
            };

            var command = new DynamicCommand(DefaultCommandName, strategy);

            await command.Execute();

            receivedCommand.Should().Be(command);
            receivedException.Should().Be(exception);
        }
        private IErrorResult GetErrorResult(MyCustomException exception)
        {
            var exceptionType = exception.GetType();
            var executorType  = _exceptionHandlerExecutor.GetType();

            return((IErrorResult)executorType
                   .GetMethod(nameof(IExceptionHandlerExecutor.Execute))
                   .MakeGenericMethod(exceptionType)
                   .Invoke(_exceptionHandlerExecutor, new [] { exception }));
        }
        public string ThrowsTypedCustomFaultException()
        {
            // Throw a typed FaultException with a custom exception
            var fault = new MyCustomException
            {
                MyMessage = "ThrowsTypedCustomFaultException: FaultException<MyCustomException>"
            };

            throw new FaultException <MyCustomException>(fault, new FaultReason("No reason!"));
        }