Handles action for when a message throws an exception.
Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProcessMessage"/> class.
        /// </summary>
        /// <param name="handler">The handler.</param>
        /// <param name="heartBeatWorkerFactory">The heart beat worker factory.</param>
        /// <param name="messageExceptionHandler">The message exception handler.</param>
        /// <param name="commitMessage">The commit message.</param>
        public ProcessMessage(IHandleMessage handler,
            IHeartBeatWorkerFactory heartBeatWorkerFactory,
            MessageExceptionHandler messageExceptionHandler,
            ICommitMessage commitMessage)
        {
            Guard.NotNull(() => handler, handler);
            Guard.NotNull(() => heartBeatWorkerFactory, heartBeatWorkerFactory);
            Guard.NotNull(() => messageExceptionHandler, messageExceptionHandler);
            Guard.NotNull(() => commitMessage, commitMessage);

            _messageExceptionHandler = messageExceptionHandler;
            _methodToRun = handler;
            _heartBeatWorkerFactory = heartBeatWorkerFactory;
            _commitMessage = commitMessage;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProcessMessageAsync"/> class.
        /// </summary>
        /// <param name="handler">The handler.</param>
        /// <param name="heartBeatWorkerFactory">The heart beat worker factory.</param>
        /// <param name="messageExceptionHandler">The message exception handler.</param>
        /// <param name="commitMessage">The commit message.</param>
        public ProcessMessageAsync(IHandleMessage handler,
                                   IHeartBeatWorkerFactory heartBeatWorkerFactory,
                                   MessageExceptionHandler messageExceptionHandler,
                                   ICommitMessage commitMessage)
        {
            Guard.NotNull(() => handler, handler);
            Guard.NotNull(() => heartBeatWorkerFactory, heartBeatWorkerFactory);
            Guard.NotNull(() => messageExceptionHandler, messageExceptionHandler);
            Guard.NotNull(() => commitMessage, commitMessage);

            _messageExceptionHandler = messageExceptionHandler;
            _methodToRun             = handler;
            _heartBeatWorkerFactory  = heartBeatWorkerFactory;
            _commitMessage           = commitMessage;
        }
        public void Message_Handled_Exception_Throws_Exception()
        {
            var fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
            IReceiveMessagesError error = fixture.Create<ReceiveMessagesErrorWillCrash>();
            fixture.Inject(error);
            var test = new MessageExceptionHandler(error, Substitute.For<ILogFactory>());

            var message = fixture.Create<IReceivedMessageInternal>();
            var context = fixture.Create<IMessageContext>();
            var exception = new Exception();

            Assert.Throws<DotNetWorkQueueException>(
            delegate
            {
                test.Handle(message, context, exception);
            });
        }