Пример #1
0
        public Response ChangePassword(ChangePasswordRequest request)
        {
            _logger.LogInfo("Method ChangePassword started at: " + DateTime.Now);

            var vr = _validator.Validate(request);
            if (!vr.IsValid)
                return Response.CreateFailureResponse(vr.Message);

            try
            {
                using (var ts = new TransactionScope())
                {
                    var user = _userRepository.Get(request.UserId);
                    if (!_passwordStrengthValidator.IsPasswordGoodEnough(request.NewPassword))
                        return Response.CreateFailureResponse("too weak password");

                    user.ChangePassword(request.NewPassword);
                    _userRepository.Update(user);

                    ts.Complete();
                }
            }
            catch (Exception exception)
            {
                _logger.LogError(exception);
                return Response.CreateFailureResponse(exception.Message);
            }

            _logger.LogInfo("Method ChangePassword ended at: " + DateTime.Now);

            return Response.CreateSuccessfulResponse();
        }
        public void Valid_request()
        {
            var userService = GetUserService();
            var request = new ChangePasswordRequest { UserId = 1, NewPassword = "******" };

            var result = userService.ChangePassword(request);

            Assert.That(result.Succeeded, Is.True);
        }
        public void Invalid_request_with_wrong_user_id()
        {
            var userService = GetUserService();
            var request = new ChangePasswordRequest { UserId = 777, NewPassword = "******" };

            var result = userService.ChangePassword(request);

            Assert.That(result.Succeeded, Is.False);
        }
        public void Invalid_request_with_too_short_password()
        {
            var userService = GetUserService();
            var request = new ChangePasswordRequest { UserId = 1, NewPassword = "******" };

            var result = userService.ChangePassword(request);

            Assert.That(result.Succeeded, Is.False);
        }
Пример #5
0
        static void Main()
        {
            var container = new Bootstrapper().CreateAndConfigureContainer();
            var userService = container.Resolve<UserService>();

            var request = new ChangePasswordRequest { UserId = 1, NewPassword = "******" }; //VALID REQUEST
            //var request = new ChangePasswordRequest { UserId = 1 }; //INVALID - EMPTY PASSWORD
            //var request = new ChangePasswordRequest { UserId = 666, NewPassword = "******" }; //INVALID - WRONG USER ID
            //var request = new ChangePasswordRequest { UserId = 1, NewPassword = "******" }; //INVALID - TOO SHORT PASSWORD

            var result = userService.ChangePassword(request);
            DisplayResult(result);

            System.Console.ReadKey();
        }