public async Task Test6_Update() { //Arrange var updatedName = "Sandip3"; var fakeCustomerUser = UserFakes.GetFakeCustomerUser(); var userDataForUpdate = new UserDataForUpdate { Id = fakeCustomerUser.Id, Address = fakeCustomerUser.Address, ContactNumber = fakeCustomerUser.ContactNumber, Country = fakeCustomerUser.Country, Email = fakeCustomerUser.Email, PAN = fakeCustomerUser.PAN, Password = fakeCustomerUser.LoginData.Password, State = fakeCustomerUser.State, Name = updatedName }; //Act await _customerUserController.Update(userDataForUpdate); var userResult = await _customerUserController.Get(); //Assert ((userResult as OkObjectResult).Value as User).Name.Should().Be(updatedName); }
public async Task <ActionResult <string> > Update(UserDataForUpdate userDataForUpdate, CancellationToken cancellationToken = default) { return(await _exceptionHandler.HandleExceptionAsync <ActionResult <string> >(async c => { var nameIdentifierClaim = _user.Claims.SingleOrDefault(x => x.Type == ClaimTypes.NameIdentifier); var userId = Convert.ToInt32(nameIdentifierClaim.Value); if (userDataForUpdate.Id != userId) { return BadRequest("User can update only his or her data and not anyone else's data"); } var user = await _userQueryableDomainService.Get().FirstOrDefaultAsync(x => x.Id == userId); if (userDataForUpdate.Password.IsNotNullOrEmpty()) { byte[] passwordHash = null; byte[] passwordSalt = null; PasswordUtility.CreatePasswordHash(userDataForUpdate.Password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; } user.Name = userDataForUpdate.Name; user.Address = userDataForUpdate.Address; user.State = userDataForUpdate.State; user.Country = userDataForUpdate.Country; user.Email = userDataForUpdate.Email; user.PAN = userDataForUpdate.PAN; user.ContactNumber = userDataForUpdate.ContactNumber; await _userCommandDomainServiceAsync.UpdateAsync(user, c).ConfigureAwait(false); return Ok("User data updated successfully"); }, cancellationToken)); }