public async Task HandleAsync_WhenChallengeParticipantRegisteredIntegrationEventIsValid_ShouldBeCompletedTask()
        {
            // Arrange
            var participantId = new ParticipantId();

            TestMock.UserService.Setup(userService => userService.SendEmailAsync(It.IsAny <UserId>(), It.IsAny <string>(), It.IsAny <object>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            var handler = new ChallengeParticipantRegisteredIntegrationEventHandler(TestMock.UserService.Object, TestMock.SendgridOptions.Object);

            var integrationEvent = new ChallengeParticipantRegisteredIntegrationEvent
            {
                Participant = new ChallengeParticipantDto
                {
                    ChallengeId    = new ChallengeId(),
                    GamePlayerId   = "testId",
                    Id             = participantId,
                    Score          = new DecimalValue(50.0m),
                    SynchronizedAt = DateTime.UtcNow.ToTimestamp(),
                    UserId         = new UserId(),
                    Matches        =
                    {
                        new ChallengeMatchDto
                        {
                            Id            = new MatchId(),
                            ParticipantId = participantId,
                            Score         = DecimalValue.FromDecimal(10)
                        },
                        new ChallengeMatchDto
                        {
                            Id            = new MatchId(),
                            ParticipantId = participantId,
                            Score         = DecimalValue.FromDecimal(10)
                        }
                    }
                }
            };

            // Act
            await handler.HandleAsync(integrationEvent);

            // Assert
            TestMock.UserService.Verify(userService => userService.SendEmailAsync(It.IsAny <UserId>(), It.IsAny <string>(), It.IsAny <object>()), Times.Once);
        }
예제 #2
0
        public async Task HandleAsync_ChallengeParticipantRegisteredIntegrationEventIsValid_ShouldBeCompletedTask()
        {
            // Arrange
            var userId        = new UserId();
            var account       = new Account(userId);
            var participantId = new ParticipantId();

            var mockLogger = new MockLogger <ChallengeParticipantRegisteredIntegrationEventHandler>();

            TestMock.AccountService.Setup(accountService => accountService.AccountExistsAsync(It.IsAny <UserId>())).ReturnsAsync(true).Verifiable();

            TestMock.AccountService.Setup(accountService => accountService.FindAccountAsync(It.IsAny <UserId>())).ReturnsAsync(account).Verifiable();

            TestMock.AccountService
            .Setup(
                accountService => accountService.MarkAccountTransactionAsSucceededAsync(
                    It.IsAny <IAccount>(),
                    It.IsAny <TransactionMetadata>(),
                    It.IsAny <CancellationToken>()))
            .ReturnsAsync(new DomainValidationResult <ITransaction>())
            .Verifiable();

            var handler = new ChallengeParticipantRegisteredIntegrationEventHandler(TestMock.AccountService.Object, mockLogger.Object);

            var integrationEvent = new ChallengeParticipantRegisteredIntegrationEvent
            {
                Participant = new ChallengeParticipantDto
                {
                    ChallengeId    = new ChallengeId(),
                    GamePlayerId   = new PlayerId(),
                    UserId         = userId,
                    Score          = DecimalValue.FromDecimal(20),
                    SynchronizedAt = DateTime.UtcNow.ToTimestamp(),
                    Id             = participantId,
                    Matches        =
                    {
                        new ChallengeMatchDto
                        {
                            Id            = new MatchId(),
                            ParticipantId = participantId,
                            Score         = DecimalValue.FromDecimal(10)
                        },
                        new ChallengeMatchDto
                        {
                            Id            = new MatchId(),
                            ParticipantId = participantId,
                            Score         = DecimalValue.FromDecimal(10)
                        }
                    }
                }
            };

            // Act
            await handler.HandleAsync(integrationEvent);

            // Assert
            TestMock.AccountService.Verify(accountService => accountService.AccountExistsAsync(It.IsAny <UserId>()), Times.Once);
            TestMock.AccountService.Verify(accountService => accountService.FindAccountAsync(It.IsAny <UserId>()), Times.Once);

            TestMock.AccountService.Verify(
                accountService => accountService.MarkAccountTransactionAsSucceededAsync(
                    It.IsAny <IAccount>(),
                    It.IsAny <TransactionMetadata>(),
                    It.IsAny <CancellationToken>()),
                Times.Once);

            mockLogger.Verify(Times.Once());
        }