public OutputDtoAddUser Create(InputDtoAddUser inputDtoAddUser) { //DTO --> Domain var userFromDto = _userFactory.CreateUserFromValues(inputDtoAddUser.Name, inputDtoAddUser.Password, inputDtoAddUser.Email, "user"); //Repository demande un element du domain var usersInDb = _userRepository.Query(); foreach (var user in usersInDb) { if (user.Email == userFromDto.Email || user.Name == userFromDto.Name) { throw new Exception("User already in database"); } } //On crée l'utilisateur var userInDb = _userRepository.Create(userFromDto); //Domain -> DTO return(new OutputDtoAddUser { Id = userInDb.Id, Name = userInDb.Name, Role = userInDb.Role, Email = userInDb.Email, Password = userInDb.Password }); }
public void Update_InputDtoAddUser_AreSame() { _userRepository.HashPassword("admin") .Returns("8C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918"); var inputUpdate = new InputDtoUpdateUser("admin", "admin", "*****@*****.**", "admin"); var hashedPassword = _userRepository.HashPassword("admin"); _userFactory.CreateUserFromValues(inputUpdate.Name, hashedPassword, inputUpdate.Email, "admin") .Returns(new User(inputUpdate.Name, hashedPassword, inputUpdate.Email, "admin")); var iuserUpdated = _userFactory.CreateUserFromValues(inputUpdate.Name, hashedPassword, inputUpdate.Email, "admin"); _userRepository.Update(1, iuserUpdated).Returns(true); var res = _userService.Update(1, inputUpdate); Assert.IsTrue(res); }