/// <summary> /// Changes Password /// </summary> /// <param name="viewModel">Injected <see cref="SecurityPasswordChange"/></param> /// <returns>Instance of <see cref="Task{ViewApplicationUser}"/></returns> public async Task <ViewApplicationUser> ChangePassword(SecurityPasswordChange @viewModel) { ApplicationUser @applicationUser = await FindApplicationUserByEmail(@viewModel.ApplicationUser.Email); IdentityResult @identityResult = await UserManager.ChangePasswordAsync(@applicationUser, @viewModel.CurrentPassword, @viewModel.NewPassword); if (@identityResult.Succeeded) { @applicationUser.ApplicationUserTokens.Add(new ApplicationUserToken { Name = Guid.NewGuid().ToString(), LoginProvider = JwtSettings.Value.JwtIssuer, ApplicationUser = @applicationUser, UserId = @applicationUser.Id, Value = TokenService.WriteJwtToken(TokenService.GenerateJwtToken(@applicationUser)) }); // Log string @logData = @applicationUser.GetType().Name + " with Email " + @applicationUser.Email + " restored its Password at " + DateTime.Now.ToShortTimeString(); Logger.WritePasswordRestoredLog(@logData); return(Mapper.Map <ViewApplicationUser>(@applicationUser)); } else { throw new Exception("Security Error"); } }
public void ChangePassword() { SecurityPasswordChange viewModel = new SecurityPasswordChange() { CurrentPassword = "******", NewPassword = "******", ApplicationUser = new ViewApplicationUser { Id = Context.ApplicationUser.FirstOrDefault(x => x.Email == "*****@*****.**").Id, Email = Context.ApplicationUser.FirstOrDefault(x => x.Email == "*****@*****.**").Email } }; Exception exception = Assert.ThrowsAsync <Exception>(async() => await Service.ChangePassword(viewModel)); Assert.Pass(); }