예제 #1
0
        public async Task Handle(Boolean userServiceResult)
        {
            Random random = new Random();
            String userId = random.GetAlphanumericString();

            var userIdTokenExtractorMock = new Mock <IUserIdTokenExtractor>(MockBehavior.Strict);

            userIdTokenExtractorMock.Setup(x => x.GetUserId(true)).Returns(random.NextGuid().ToString()).Verifiable();

            var localUserServiceMock = new Mock <ILocalUserService>(MockBehavior.Strict);

            localUserServiceMock.Setup(x => x.GetUserAmount()).ReturnsAsync(random.Next(3, 10)).Verifiable();
            localUserServiceMock.Setup(x => x.CheckIfUserExists(userId)).ReturnsAsync(true).Verifiable();

            localUserServiceMock.Setup(x => x.DeleteUser(userId)).ReturnsAsync(userServiceResult).Verifiable();

            var handler = new DeleteLocalUserCommandHandler(
                userIdTokenExtractorMock.Object, localUserServiceMock.Object,
                Mock.Of <ILogger <DeleteLocalUserCommandHandler> >());

            Boolean result = await handler.Handle(new DeleteLocalUserCommand(userId), CancellationToken.None);

            Assert.Equal(userServiceResult, result);

            localUserServiceMock.Verify();
            userIdTokenExtractorMock.Verify();
        }
예제 #2
0
        public async Task Handle_Failed_DontDeleteOwnAccount()
        {
            Random random = new Random();
            String userId = random.GetAlphanumericString();

            var userIdTokenExtractorMock = new Mock <IUserIdTokenExtractor>(MockBehavior.Strict);

            userIdTokenExtractorMock.Setup(x => x.GetUserId(true)).Returns(userId).Verifiable();

            var handler = new DeleteLocalUserCommandHandler(
                userIdTokenExtractorMock.Object, Mock.Of <ILocalUserService>(MockBehavior.Strict),
                Mock.Of <ILogger <DeleteLocalUserCommandHandler> >());

            Boolean result = await handler.Handle(new DeleteLocalUserCommand(userId), CancellationToken.None);

            Assert.False(result);

            userIdTokenExtractorMock.Verify();
        }