Beispiel #1
0
        public async Task Handle_sends_message_to_all_handlers_even_if_some_handler_fails()
        {
            var handler1 = Mock.Of <IMessageHandler>();
            var handler2 = Mock.Of <IMessageHandler>();
            var sut      = new CompositeMessageHandler(handler1, handler2);
            var message  = new object();
            var envelope = new Envelope(message);

            Mock.Get(handler1)
            .Setup(x => x.Handle(envelope, CancellationToken.None))
            .Throws <InvalidOperationException>();

            try
            {
                await sut.Handle(envelope, CancellationToken.None);
            }
            catch
            {
            }

            Mock.Get(handler1).Verify(
                x => x.Handle(envelope, CancellationToken.None), Times.Once());
            Mock.Get(handler2).Verify(
                x => x.Handle(envelope, CancellationToken.None), Times.Once());
        }
Beispiel #2
0
        public void Handle_throws_aggregate_exception_if_handler_fails()
        {
            // Arrange
            var handler1 = Mock.Of <IMessageHandler>();
            var handler2 = Mock.Of <IMessageHandler>();

            var sut = new CompositeMessageHandler(handler1, handler2);

            var message  = new object();
            var envelope = new Envelope(message);

            var exception1 = new InvalidOperationException();

            Mock.Get(handler1)
            .Setup(x => x.Handle(envelope, CancellationToken.None))
            .Throws(exception1);

            var exception2 = new InvalidOperationException();

            Mock.Get(handler2)
            .Setup(x => x.Handle(envelope, CancellationToken.None))
            .Throws(exception2);

            // Act
            Func <Task> action = () => sut.Handle(envelope, CancellationToken.None);

            // Arrange
            action.ShouldThrow <AggregateException>()
            .Which.InnerExceptions.Should().ContainSingle()
            .Which.Should().BeOfType <AggregateException>()
            .Which.InnerExceptions
            .ShouldAllBeEquivalentTo(new[] { exception1, exception2 });
        }
Beispiel #3
0
        public async Task Handle_sends_message_to_all_handlers()
        {
            var handler1 = Mock.Of <IMessageHandler>();
            var handler2 = Mock.Of <IMessageHandler>();
            var sut      = new CompositeMessageHandler(handler1, handler2);
            var message  = new object();
            var envelope = new Envelope(message);

            await sut.Handle(envelope, CancellationToken.None);

            Mock.Get(handler1).Verify(
                x => x.Handle(envelope, CancellationToken.None), Times.Once());
            Mock.Get(handler2).Verify(
                x => x.Handle(envelope, CancellationToken.None), Times.Once());
        }