예제 #1
0
        private static IErrorHandlerPlugin CreateErrorHandlerPlugin(int order)
        {
            IErrorHandlerPlugin plugin = Substitute.For <IErrorHandlerPlugin>();

            plugin.Order.Returns(order);
            plugin.CanHandle(null).ReturnsForAnyArgs(false);
            plugin.Process(null, null).ReturnsForAnyArgs((IResponseData)null);
            return(plugin);
        }
예제 #2
0
        public async Task OnErrorShouldInvokeProcessIfCanHandleReturnsTrue()
        {
            Exception           exception = new DivideByZeroException();
            IErrorHandlerPlugin plugin    = CreateErrorHandlerPlugin(1);

            plugin.CanHandle(exception).Returns(true);
            this.bootstrapper.GetErrorHandlers().Returns(new[] { plugin });

            await this.processor.OnError(this.request, exception);

            await plugin.Received().Process(this.request, exception);
        }
예제 #3
0
        public async Task OnErrorShouldInvokeThePluginsInTheCorrectOrder()
        {
            Exception           exception = new DivideByZeroException();
            IErrorHandlerPlugin one       = CreateErrorHandlerPlugin(1);
            IErrorHandlerPlugin two       = CreateErrorHandlerPlugin(2);
            IErrorHandlerPlugin three     = CreateErrorHandlerPlugin(3);

            this.bootstrapper.GetErrorHandlers().Returns(new[] { three, one, two });

            await this.processor.OnError(this.request, exception);

            Received.InOrder(() =>
            {
                one.CanHandle(exception);
                two.CanHandle(exception);
                three.CanHandle(exception);
            });
        }