public async Task GivenResetPasswordCommandHandler_WhenUserNotFound_ThenShouldThrowRestException()
        {
            _mockUserManager.FindByEmailAsync(_command.Email).ReturnsNullForAnyArgs();

            var resetPasswordCommandHandler =
                new ResetPasswordCommandHandler(_mockUserManager, _mockEventBus, _mockEmailBuilder,
                                                _mockFailedIdentityResult);

            await Assert.ThrowsAsync <RestException>(() =>
                                                     resetPasswordCommandHandler.Handle(_command, CancellationToken.None));
        }
        public async Task GivenResetPasswordCommandHandler_WhenCorrectQueryReceived_ThenShouldUseUserManagerToFindUser()
        {
            _mockUserManager.FindByEmailAsync(_command.Email).ReturnsForAnyArgs(_user);

            var resetPasswordCommandHandler =
                new ResetPasswordCommandHandler(_mockUserManager, _mockEventBus, _mockEmailBuilder,
                                                _mockFailedIdentityResult);

            await resetPasswordCommandHandler.Handle(_command, CancellationToken.None);

            await _mockUserManager.ReceivedWithAnyArgs().FindByEmailAsync(_command.Email);
        }
        public async Task GivenResetPasswordCommandHandler_WhenPasswordHasBeenReset_ThenShouldPublishSendEmailEvent()
        {
            _mockUserManager.FindByEmailAsync(_command.Email).ReturnsForAnyArgs(_user);
            _mockUserManager.ResetPasswordAsync(_user, _command.ResetPasswordToken, _command.NewPassword)
            .ReturnsForAnyArgs(Task.FromResult(IdentityResult.Success));

            var resetPasswordCommandHandler =
                new ResetPasswordCommandHandler(_mockUserManager, _mockEventBus, _mockEmailBuilder,
                                                _mockFailedIdentityResult);

            await resetPasswordCommandHandler.Handle(_command, CancellationToken.None);

            _mockEventBus.Received().Publish(Arg.Any <SendEmailEvent>());
        }
        public async Task GivenResetPasswordCommandHandler_WhenPasswordResetFails_ThenShouldCallFailedIdentityResult()
        {
            _mockUserManager.FindByEmailAsync(_command.Email).ReturnsForAnyArgs(_user);
            _mockUserManager.ResetPasswordAsync(_user, _command.ResetPasswordToken, _command.NewPassword)
            .ReturnsForAnyArgs(Task.FromResult(IdentityResult.Failed()));

            var resetPasswordCommandHandler =
                new ResetPasswordCommandHandler(_mockUserManager, _mockEventBus, _mockEmailBuilder,
                                                _mockFailedIdentityResult);

            await resetPasswordCommandHandler.Handle(_command, CancellationToken.None);

            _mockFailedIdentityResult.Received()
            .Handle(Arg.Any <AppUser>(), Arg.Any <List <IdentityError> >(), Arg.Any <string>());
        }
        GivenResetPasswordCommandHandler_WhenCorrectQueryReceived_ThenShouldUseUserManagerToResetPassword()
        {
            _mockUserManager.FindByEmailAsync(_command.Email).ReturnsForAnyArgs(_user);
            _mockUserManager.ResetPasswordAsync(_user, _command.ResetPasswordToken, _command.NewPassword)
            .ReturnsForAnyArgs(Task.FromResult(IdentityResult.Success));

            var resetPasswordCommandHandler =
                new ResetPasswordCommandHandler(_mockUserManager, _mockEventBus, _mockEmailBuilder,
                                                _mockFailedIdentityResult);

            await resetPasswordCommandHandler.Handle(_command, CancellationToken.None);

            await _mockUserManager.Received()
            .ResetPasswordAsync(_user, _command.ResetPasswordToken, _command.NewPassword);
        }
Esempio n. 6
0
        public void WhenCalled_UpdateUserPassword()
        {
            _sut.Handle(_command, default).Wait();

            _service.Verify(x => x.UpdateUserPassword(_user, _command.NewPassword));
        }