예제 #1
0
        public async Task HandleAsync_WhenClanMemberRemovedIntegrationEventIsValid_ShouldBeCompletedTask()
        {
            // Arrange
            var userId = new UserId();
            var clanId = new ClanId();
            var user   = new User();

            var mockLogger = new MockLogger <ClanMemberRemovedIntegrationEventHandler>();

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

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

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

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

            // Act
            await handler.HandleAsync(integrationEvent);

            // Assert
            TestMock.UserService.Verify(userService => userService.FindByIdAsync(It.IsAny <string>()), Times.Once);
            TestMock.UserService.Verify(userService => userService.RemoveClaimAsync(It.IsAny <User>(), It.IsAny <Claim>()), Times.Once);
            mockLogger.Verify(Times.Once());
        }
        public async Task HandleAsync_WhenClanMemberRemovedIntegrationEventIsValid_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 ClanMemberRemovedIntegrationEventHandler(TestMock.UserService.Object, TestMock.SendgridOptions.Object);

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

            // Act
            await handler.HandleAsync(integrationEvent);

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