public IActionResult Index(int delegateId, bool isFromViewDelegatePage) { var delegateUser = userDataService.GetDelegateUserById(delegateId) !; if (string.IsNullOrWhiteSpace(delegateUser.EmailAddress)) { return(View("NoEmail")); } var model = new SetDelegatePasswordViewModel(delegateUser.FullName, delegateId, isFromViewDelegatePage); return(View(model)); }
public async Task IndexAsync_with_invalid_model_returns_initial_form_async() { // Given var model = new SetDelegatePasswordViewModel(); setDelegatePasswordController.ModelState.AddModelError( nameof(SetDelegatePasswordViewModel.Password), "Required" ); // When var result = await setDelegatePasswordController.IndexAsync(model, DelegateId, true); // Then result.Should().BeViewResult().WithDefaultViewName(); }
public async Task IndexAsync_with_valid_model_calls_password_service_and_returns_confirmation_view_async() { // Given var delegateUser = UserTestHelper.GetDefaultDelegateUser(); var model = new SetDelegatePasswordViewModel { Password = Password }; A.CallTo(() => userDataService.GetDelegateUserById(DelegateId)) .Returns(delegateUser); A.CallTo(() => passwordService.ChangePasswordAsync(A <string> ._, A <string> ._)).Returns(Task.CompletedTask); // When var result = await setDelegatePasswordController.IndexAsync(model, DelegateId, true); // Then A.CallTo(() => passwordService.ChangePasswordAsync(delegateUser.EmailAddress !, Password)) .MustHaveHappened(); result.Should().BeViewResult().WithViewName("Confirmation"); }
public IActionResult Index( int delegateId, bool isFromViewDelegatePage, ReturnPageQuery?returnPageQuery = null ) { var delegateUser = userDataService.GetDelegateUserById(delegateId) !; if (string.IsNullOrWhiteSpace(delegateUser.EmailAddress)) { return(View("NoEmail")); } var model = new SetDelegatePasswordViewModel( DisplayStringHelper.GetNonSortableFullNameForDisplayOnly(delegateUser.FirstName, delegateUser.LastName), delegateId, isFromViewDelegatePage, returnPageQuery ); return(View(model)); }
public async Task <IActionResult> IndexAsync( SetDelegatePasswordViewModel model, int delegateId, bool isFromViewDelegatePage ) { if (!ModelState.IsValid) { model.IsFromViewDelegatePage = isFromViewDelegatePage; return(View(model)); } var delegateUser = userDataService.GetDelegateUserById(delegateId) !; if (string.IsNullOrWhiteSpace(delegateUser.EmailAddress)) { return(View("NoEmail")); } await passwordService.ChangePasswordAsync(delegateUser !.EmailAddress !, model.Password !); return(View("Confirmation")); }