public UserDTO UpdateUser(UserDTO userDTO) { ValidateUser(userDTO); User user = userRepository.GetByKey(userDTO.ID); user = ReflectUtil.UpdateNotEmptyValues(userDTO, user); userRepository.Update(user); RepositoryContext.Commit(); return(Mapper.Map <User, UserDTO>(user)); }
public void UpdateAllNotNullOrEmptyTest() { User user = new User("qianlifeng", "qlf", "*****@*****.**", "test", null); UserDTO userDTO = new UserDTO { UserName = "******", NickName = "qlf2" }; User userNew = ReflectUtil.UpdateNotEmptyValues(userDTO, user); Assert.IsTrue(userNew.UserName == userDTO.UserName); Assert.IsTrue(userNew.NickName == userDTO.NickName); Assert.IsTrue(userNew.Email != userDTO.Email); }