Ejemplo n.º 1
0
        public async Task PublishEventsThroughEventBusAsync_PendingEvents_EventsArePublished(
            [Frozen] Mock <IIntegrationEventLogService> mockEventLogService,
            [Frozen] Mock <IEventBus> mockEventBus,
            SalesOrderIntegrationEventService sut,
            Guid transactionId,
            UserCheckoutAcceptedIntegrationEvent integrationEvent
            )
        {
            //Arrange
            var eventLogs = Enumerable.Repeat(
                new IntegrationEventLogEntry(integrationEvent, transactionId), 3
                )
                            .ToList();

            mockEventLogService.Setup(_ => _.RetrieveEventLogsPendingToPublishAsync(
                                          It.IsAny <Guid>()
                                          ))
            .ReturnsAsync(eventLogs);

            //Act
            await sut.PublishEventsThroughEventBusAsync(transactionId);

            //Assert
            mockEventLogService.Verify(_ => _.MarkEventAsInProgressAsync(It.IsAny <Guid>()),
                                       Times.Exactly(eventLogs.Count)
                                       );

            mockEventBus.Verify(_ => _.Publish(It.IsAny <IntegrationEvent>()),
                                Times.Exactly(eventLogs.Count)
                                );

            mockEventLogService.Verify(_ => _.MarkEventAsPublishedAsync(It.IsAny <Guid>()),
                                       Times.Exactly(eventLogs.Count)
                                       );
        }
Ejemplo n.º 2
0
        public async Task PublishEventsThroughEventBusAsync_FirstEventFails_OtherEventsShouldBePublished(
            [Frozen] Mock <IIntegrationEventLogService> mockEventLogService,
            [Frozen] Mock <IEventBus> mockEventBus,
            SalesOrderIntegrationEventService sut,
            Guid transactionId,
            List <UserCheckoutAcceptedIntegrationEvent> integrationEvents
            )
        {
            //Arrange
            var eventLogs = integrationEvents.Select(e => new IntegrationEventLogEntry(
                                                         e, transactionId
                                                         ))
                            .ToList();

            eventLogs.ForEach(e =>
                              e.DeserializeJsonContent(typeof(UserCheckoutAcceptedIntegrationEvent))
                              );

            mockEventLogService.Setup(_ => _.RetrieveEventLogsPendingToPublishAsync(
                                          It.IsAny <Guid>()
                                          ))
            .ReturnsAsync(eventLogs);

            mockEventBus.Setup(_ => _.Publish(It.Is <IntegrationEvent>(e =>
                                                                       e.Id == integrationEvents[0].Id)
                                              ))
            .Throws <Exception>();

            //Act
            await sut.PublishEventsThroughEventBusAsync(transactionId);

            //Assert
            mockEventLogService.Verify(_ => _.MarkEventAsInProgressAsync(It.IsAny <Guid>()),
                                       Times.Exactly(eventLogs.Count)
                                       );

            mockEventBus.Verify(_ => _.Publish(It.IsAny <IntegrationEvent>()),
                                Times.Exactly(eventLogs.Count)
                                );

            mockEventLogService.Verify(_ => _.MarkEventAsPublishedAsync(It.IsAny <Guid>()),
                                       Times.Exactly(eventLogs.Count - 1)
                                       );

            mockEventLogService.Verify(_ => _.MarkEventAsFailedAsync(It.IsAny <Guid>()),
                                       Times.Once
                                       );
        }