public void Given_registered_user_make_password_change_request_when_User_Name_is_incorrect_then_command_execution_fails_with_message_User_credentials_not_verified()
        {
            var command = new ChangePasswordCommand { UserId = "1", UserName = "******", OldPassword = "******" };
            var commandHandler = new ChangePasswordCommandHandler(_mockDbContext.Object);

            var result =commandHandler.Execute(command);
            Assert.That(result.CommandExecuted, Is.EqualTo(false));
            Assert.That(result.Message, Is.EqualTo("User credentials not verified"));
        }
        public void Given_registered_user_make_password_change_request_when_user_Id_not_found_then_command_execution_fails_with_message_user_not_found()
        {
            var command = new ChangePasswordCommand { UserId = "2"};
            var commandHandler = new ChangePasswordCommandHandler(_mockDbContext.Object);

            var result  =  commandHandler.Execute(command);
            Assert.That(result.CommandExecuted, Is.EqualTo(false));
            Assert.That(result.Message, Is.EqualTo("User Id Not Found"));
        }
        public void Given_change_password_request_when_ChangePasswordCommand_is_invalid_then_return_InvalidModelStateResult()
        {
            var inValidChangePasswordCommand = new ChangePasswordCommand {};

            var controller = GetTarget();
            controller.ModelState.AddModelError("UserId", "UserId is required."); //Mocks the model state
            var response = controller.ChangePassword(inValidChangePasswordCommand);

            Assert.IsInstanceOf<InvalidModelStateResult>(response);
        }
        public void Given_change_password_request_when_ChangePasswordCommand_is_valid_then_return_OkResult()
        {
            var validChangePasswordCommand = new ChangePasswordCommand { UserId = "1"};

            var commandResultViewModel = new CommandResultViewModel { CommandExecuted = true};
            _mockCommandDispatcher.Setup(
                c => c.Dispatch<ChangePasswordCommand, CommandResultViewModel>(validChangePasswordCommand))
                .Returns(commandResultViewModel);

            var controller = GetTarget();
            var response = controller.ChangePassword(validChangePasswordCommand);

            Assert.IsInstanceOf<OkResult>(response);
        }
예제 #5
0
        public IHttpActionResult ChangePassword(ChangePasswordCommand changePasswordCommand)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            var resposne = _commandDispatcher.Dispatch<ChangePasswordCommand, CommandResultViewModel>(changePasswordCommand);

            if (!resposne.CommandExecuted)
            {
                ModelState.AddModelError("Invalid Request",resposne.Message);
                return BadRequest(ModelState);
            }

            return Ok();
        }
        public void Given_change_password_request_when_ChangePasswordCommand_is_valid_then_ChangePasswordCommand_is_dispatched_sucessfully()
        {
            ChangePasswordCommand dispatchedChangePasswordCommand = null;

            var validChangePasswordCommand = new ChangePasswordCommand { UserId = "1" };
            var commandResultViewModel = new CommandResultViewModel { CommandExecuted = true};

            _mockCommandDispatcher.Setup(c => c.Dispatch<ChangePasswordCommand, CommandResultViewModel>(validChangePasswordCommand))
                .Returns(commandResultViewModel)
                .Callback<ChangePasswordCommand>(x => dispatchedChangePasswordCommand = x);

            var controller = GetTarget();
            var response = controller.ChangePassword(validChangePasswordCommand);

            Assert.AreEqual(validChangePasswordCommand.UserId, dispatchedChangePasswordCommand.UserId);
        }
        public void Given_registered_user_make_password_change_request_when_User_credientials_are_verified_then_old_password_change()
        {
            _mockDbContext.Setup(x => x.Save()).Returns(1); //You need to mock db context save changes return value
            _mockEmailExtensionWrapper.Setup(m => m.SendPasswordChangedEmail(It.IsAny<AspNetUser>()));

            //credentials i.e. UserName and OldPassword
            var command = new ChangePasswordCommand { UserId = "1", UserName = "******", OldPassword = "******", NewPassword = "******", ConfirmNewPassword = "******" };
            var commandHandler = new ChangePasswordCommandHandler(_mockDbContext.Object);

            //Password before executing command
            var oldPassword = _mockUserMock.Object.ToList()[0].PasswordHash;

               var result = commandHandler.Execute(command);

            Assert.That(result.CommandExecuted, Is.EqualTo(true));
            Assert.That(_mockUserMock.Object.ToList()[0].PasswordHash, !Is.EqualTo(oldPassword));
        }