public async Task HandleAsync_WhenClanMemberAddedIntegrationEventIsValid_ShouldBeCompletedTask()
        {
            // Arrange
            var userId = new UserId();
            var clanId = new ClanId();
            var user   = new User();

            var mockLogger = new MockLogger <ClanMemberAddedIntegrationEventHandler>();

            TestMock.UserService.Setup(userService => userService.FindByIdAsync(It.IsAny <string>())).ReturnsAsync(user).Verifiable();

            TestMock.UserService.Setup(userService => userService.AddClaimAsync(It.IsAny <User>(), It.IsAny <Claim>()))
            .ReturnsAsync(new IdentityResult())
            .Verifiable();

            var handler = new ClanMemberAddedIntegrationEventHandler(TestMock.UserService.Object, mockLogger.Object);

            var integrationEvent = new ClanMemberAddedIntegrationEvent
            {
                Clan = new ClanDto
                {
                    Id      = clanId,
                    Name    = "testClan",
                    OwnerId = userId,
                    Summary = null,
                    Members =
                    {
                        new MemberDto
                        {
                            ClanId = clanId,
                            Id     = new MemberId(),
                            UserId = userId
                        }
                    }
                },
                UserId = new UserId()
            };

            // Act
            await handler.HandleAsync(integrationEvent);

            // Assert
            TestMock.UserService.Verify(userService => userService.FindByIdAsync(It.IsAny <string>()), Times.Once);
            TestMock.UserService.Verify(userService => userService.AddClaimAsync(It.IsAny <User>(), It.IsAny <Claim>()), Times.Once);
            mockLogger.Verify(Times.Once());
        }
예제 #2
0
        public async Task HandleAsync_WhenClanMemberAddedIntegrationEventIsValid_ShouldBeCompletedTask()
        {
            // Arrange
            var userId = new UserId();
            var clanId = new ClanId();

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

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

            var integrationEvent = new ClanMemberAddedIntegrationEvent
            {
                Clan = new ClanDto
                {
                    Id      = clanId,
                    Name    = "testClan",
                    OwnerId = userId,
                    Summary = "",
                    Members =
                    {
                        new MemberDto
                        {
                            ClanId = clanId,
                            Id     = new MemberId(),
                            UserId = userId
                        }
                    }
                },
                UserId = new UserId()
            };

            // Act
            await handler.HandleAsync(integrationEvent);

            // Assert
            TestMock.UserService.Verify(userService => userService.SendEmailAsync(It.IsAny <UserId>(), It.IsAny <string>(), It.IsAny <object>()), Times.Once);
        }