/// <summary> /// Sends instructions to the given email address on how to reset it's Customer's password /// </summary> /// <param name="param"></param> public virtual async Task SendResetPasswordInstructionsAsync(SendResetPasswordInstructionsParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (string.IsNullOrWhiteSpace(param.Email)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Email)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } var request = new ResetPasswordRequest { Email = param.Email, ScopeId = param.Scope }; var response = await OvertureClient.SendAsync(request).ConfigureAwait(false); if (response.Success) { return; } throw new ComposerException(errorCode: "SendResetPasswordInstructionsFailed"); }
public void WHEN_bad_request_SHOULD_throw_composer_exception() { //Arrange var expectedEmail = GetRandom.Email(); var customerRepository = _container.CreateInstance <CustomerRepository>(); _container.GetMock <IOvertureClient>() .Setup(r => r.SendAsync(It.Is <ResetPasswordRequest>( param => string.IsNullOrWhiteSpace(param.Username) && string.IsNullOrWhiteSpace(param.Password) && string.IsNullOrWhiteSpace(param.PasswordAnswer) && param.Email == expectedEmail))) .ReturnsAsync(new ResetPasswordResponse { Success = false }); //Act and Assert var sendResetParam = new SendResetPasswordInstructionsParam { Email = expectedEmail, Scope = GetRandom.String(32) }; Assert.ThrowsAsync <ComposerException>(() => customerRepository.SendResetPasswordInstructionsAsync(sendResetParam)); }
public void WHEN_Email_is_Empty_SHOULD_throw_ArgumentException(string email) { //Arrange var customerRepository = _container.CreateInstance <CustomerRepository>(); //Act var sendResetParam = new SendResetPasswordInstructionsParam { Email = email, Scope = GetRandom.String(32) }; var ex = Assert.ThrowsAsync <ArgumentException>(() => customerRepository.SendResetPasswordInstructionsAsync(sendResetParam)); //Assert ex.Message.Should().ContainEquivalentOf("email"); }
/// <summary> /// Send instructions to the customer on how to reset it's password. /// /// Note: To avoid divulging information, the default implementation of ForgotPasswordAsync always succeed; /// It ignore all errors and return a success without the Customer information /// /// </summary> /// <param name="param">Service call params <see cref="ForgotPasswordParam"/></param> /// <returns> /// The Customer who received the instructions and a status representing a possible cause of errors /// </returns> public virtual async Task <ForgotPasswordViewModel> ForgotPasswordAsync(ForgotPasswordParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (string.IsNullOrWhiteSpace(param.Email)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Email)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } try { var resetParam = new SendResetPasswordInstructionsParam { Email = param.Email, Scope = param.Scope }; await CustomerRepository.SendResetPasswordInstructionsAsync(resetParam).ConfigureAwait(false); } //TODO: process exception catch (Exception) { // To avoid divulging information, the default implementation of ForgotPasswordAsync always succeed; // It ignore all errors and return a success } return(GetForgotPasswordViewModelAsync(new GetForgotPasswordViewModelParam { Status = MyAccountStatus.Success, CultureInfo = param.CultureInfo, EmailSentTo = param.Email, })); }