Ejemplo n.º 1
0
        public void PublishEventsAsync_WithNullEvents_ThrowArgumentNullException()
        {
            // Arrange => Act
            Action act = () => sut.PublishEventsAsync(null).Wait();

            // Assert
            act.Should().Throw <ArgumentNullException>().Where(p => p.ParamName.Equals("eventsToPublish"));
        }
        public async Task PublishEvents_CallsSendMesageMultipleTimes()
        {
            var senderMock = new Mock <IMessageSender>(MockBehavior.Strict);

            senderMock.Setup(r => r.SendMessageAsync(It.IsAny <EventMessage>()))
            .Returns(EmptyTask);
            senderMock.Setup(r => r.Dispose());
            var contextMock = new Mock <IBusContext <string> >(MockBehavior.Strict);

            contextMock.Setup(bc => bc.CreateMessageSender())
            .Returns(senderMock.Object);
            var target = new EventPublisher <string>(contextMock.Object);

            var events = new List <DomainEvent>
            {
                new SomeEvent {
                    SomeNumber = 1
                },
                new SomeOtherEvent {
                    SomeNumber = 2
                },
                new SomeEvent {
                    SomeNumber = 3
                },
            };
            await target.PublishEventsAsync(events);

            senderMock.Verify(r => r.SendMessageAsync(It.IsAny <EventMessage>()), Times.Exactly(3));
        }