Example #1
0
        public async Task Handle_KeepsType()
        {
            var exception        = new MyBeautifulException();
            var exceptionHandler = new RethrowExceptionHandler();

            await Assert.ThrowsAsync <MyBeautifulException>(() => exceptionHandler.HandleAsync(exception, new object(), DummyHandler));
        }
Example #2
0
        public void KeepsException()
        {
            var binding = Mocks.Create <ILoggerBinding>();

            binding.Setup(b => b.Log(typeof(TestType), It.IsAny <LogLevel>(), It.IsAny <FormattableString>(), It.IsAny <Exception>()));

            var exception             = new MyBeautifulException();
            FormattableString message = $"Oh no, something went wrong!";

            Logger.Binding = binding.Object;
            var logger = new Logger(typeof(TestType));

            logger.Error(exception, message);

            binding.Verify(b => b.Log(typeof(TestType), LogLevel.Error, message, exception), Times.Once());
        }
Example #3
0
        public async Task Execute_OnException_CallsExceptionHandler()
        {
            var exceptionHandler = Mocks.Create <IExceptionHandler>();

            exceptionHandler
            .Setup(h => h.HandleAsync(It.IsAny <Exception>(), It.IsAny <object>(), It.IsAny <MessageHandler>()))
            .Returns(Task.CompletedTask);

            var exception = new MyBeautifulException();
            var message   = 45;

            MessageHandler handler = _ => throw exception;

            var executor = new SequentialExecutor(exceptionHandler: exceptionHandler.Object);
            await executor.ExecuteAsync(message, new MessageHandler[] { handler });

            exceptionHandler.Verify(h => h.HandleAsync(exception, message, handler), Times.Once());
        }
Example #4
0
        public async Task Handle_KeepsInstance()
        {
            var exception        = new MyBeautifulException();
            var exceptionHandler = new RethrowExceptionHandler();

            var caught = false;

            try
            {
                await exceptionHandler.HandleAsync(exception, new object(), DummyHandler);
            }
            catch (MyBeautifulException e)
            {
                caught = true;
                Assert.Same(exception, e);
            }

            Assert.True(caught);
        }
        public async Task KeepsParameters()
        {
            var            expectedException = new MyBeautifulException();
            var            expectedMessage   = new Message();
            MessageHandler expectedHandler   = msg => Task.CompletedTask;

            Exception      actualException = null;
            object         actualMessage   = null;
            MessageHandler actualHandler   = null;

            var handler = new DelegateExceptionHandler(async(ex, msg, h) =>
            {
                actualException = ex;
                actualMessage   = msg;
                actualHandler   = h;
            });
            await handler.HandleAsync(expectedException, expectedMessage, expectedHandler);

            Assert.Same(expectedException, actualException);
            Assert.Same(expectedMessage, actualMessage);
            Assert.Same(expectedHandler, actualHandler);
        }