public async Task UserTriesToChangePassword_EverythingValid_Successful() { var customerProfileClient = new Mock <ICustomerProfileClient>(); customerProfileClient.Setup(c => c.CustomerProfiles.GetByCustomerIdAsync(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())) .ReturnsAsync( new CustomerProfileResponse { Profile = new CustomerProfile { Email = "*****@*****.**" } }); var credentialsClient = new Mock <ICredentialsClient>(); credentialsClient.Setup(c => c.Api.ChangePasswordAsync(It.IsAny <CredentialsUpdateRequest>())) .ReturnsAsync(new CredentialsUpdateResponse()); var postProcessService = new Mock <IPostProcessService>(); var customerFlagsRepository = new Mock <ICustomerFlagsRepository>(); customerFlagsRepository .Setup(c => c.GetByCustomerIdAsync(It.IsAny <string>())) .ReturnsAsync(new CustomerFlagsEntity { IsBlocked = false }); var sessionsServiceClient = new Mock <ISessionsServiceClient>(); CustomersService customersService; using (var logFactory = LogFactory.Create().AddUnbufferedConsole()) { customersService = new CustomersService( credentialsClient.Object, postProcessService.Object, customerProfileClient.Object, customerFlagsRepository.Object, sessionsServiceClient.Object, _passwordSuccessfulChangeEmailTemplateId, _passwordSuccessfulChangeEmailSubjectTemplateId, logFactory, MaxBatchValue, _publisher.Object, _customerBlockEmailTemplateId, _customerUnBlockEmailTemplateId, _customerBlockSubjectTemplateId, _customerUnBlockSubjectTemplateId, _customerSupportPhoneNumber); } var expected = new ChangePasswordResultModel(); var actual = await customersService.ChangePasswordAsync("customerId", "password"); Assert.Equal(expected.Error, actual.Error); }
public async Task <ChangePasswordResultModel> ChangePassword(string userId, string oldPassword, string newPassword) { var result = new ChangePasswordResultModel { Result = await UserManager.ChangePasswordAsync(userId, oldPassword, newPassword) }; if (result.IsSucceeded) { var user = await UserManager.FindByIdAsync(userId); if (user != null) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); } result.MessageId = ManageMessageId.ChangePasswordSuccess; } return(result); }
public async Task <ChangePasswordResultModel> ChangePasswordAsync( string userId, ChangePasswordInputModel changePasswordInput) { var changePasswordResultModel = new ChangePasswordResultModel(); var user = await this.userManager.FindByIdAsync(userId); if (user == null) { changePasswordResultModel.Succeeded = false; changePasswordResultModel.Errors.Add(InvalidCredentialsErrorMessage); return(changePasswordResultModel); } var identityResult = await this.userManager.ChangePasswordAsync( user, changePasswordInput.CurrentPassword, changePasswordInput.NewPassword); if (!identityResult.Succeeded) { changePasswordResultModel.Succeeded = false; var errors = identityResult.Errors.Select(e => e.Description).ToList(); errors.ForEach(error => { changePasswordResultModel.Errors.Add(error); }); return(changePasswordResultModel); } changePasswordResultModel.Succeeded = true; return(changePasswordResultModel); }
public async Task UserTriesToChangePassword_PasswordIsNotInValidFormat_BusinessErrorIsReturned() { var customerProfileClient = new Mock <ICustomerProfileClient>(); customerProfileClient.Setup(c => c.CustomerProfiles.GetByCustomerIdAsync(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())) .ReturnsAsync( new CustomerProfileResponse { Profile = new CustomerProfile { Email = "*****@*****.**" } }); var credentialsClient = new Mock <ICredentialsClient>(); var errorResponse = new ErrorResponse { ModelErrors = new Dictionary <string, List <string> > { { nameof(CredentialsCreateRequest.Password), new List <string>() } } }; var invalidPasswordException = new ClientApiException(HttpStatusCode.BadRequest, errorResponse); var postProcessService = new Mock <IPostProcessService>(); credentialsClient.Setup(c => c.Api.ChangePasswordAsync(It.IsAny <CredentialsUpdateRequest>())) .ThrowsAsync(invalidPasswordException); var customerFlagsRepository = new Mock <ICustomerFlagsRepository>(); customerFlagsRepository .Setup(c => c.GetByCustomerIdAsync(It.IsAny <string>())) .ReturnsAsync(new CustomerFlagsEntity { IsBlocked = false }); var sessionsServiceClient = new Mock <ISessionsServiceClient>(); CustomersService customersService; using (var logFactory = LogFactory.Create().AddUnbufferedConsole()) { customersService = new CustomersService( credentialsClient.Object, postProcessService.Object, customerProfileClient.Object, customerFlagsRepository.Object, sessionsServiceClient.Object, _passwordSuccessfulChangeEmailTemplateId, _passwordSuccessfulChangeEmailSubjectTemplateId, logFactory, MaxBatchValue, _publisher.Object, _customerBlockEmailTemplateId, _customerUnBlockEmailTemplateId, _customerBlockSubjectTemplateId, _customerUnBlockSubjectTemplateId, _customerSupportPhoneNumber); } var expected = new ChangePasswordResultModel(ServicesError.InvalidPasswordFormat); var actual = await customersService.ChangePasswordAsync("customerId", "password"); Assert.Equal(expected.Error, actual.Error); }