public IActionResult Put([FromBody] UserRegisterRequest value) { if (ModelState.IsValid) { var result = new UserDto() { BirthDate = value.BirthDate, Club = value.Club, ConfirmationPassword = value.ConfirmationPassword, Country = value.Country, DNI = value.DNI, Email = value.Email, Name = value.Name, Nationality = value.Nationality, Password = value.Password, Role = value.Role, SecondName = value.SecondName, SecondSurname = value.SecondSurname, SocialNumber = value.SocialNumber, Street = value.Street, Surname = value.Surname }; //var result = _mapper.Map<UserDto>(value); if (_userBussinesLogic.ValidUser(result)) { if (_userBussinesLogic.CreateNewUserAndSendConfirmationEmail(result)) { return(Ok()); } else { return(new GeneralError(402) { ErrorMessage = "The user cannot be created or the email cannot be send" }); } } else { return(new GeneralError(401) { ErrorMessage = "User not valid" }); } } else { return(BadRequest(ModelState.Values)); } }
public void When_AddParent_WithACorrectAge_And_SendEmail() { //Arrange var fixture = new Fixture(); var user = fixture.Build <UserDto>() .Without <DateTime>(p => p.BirthDate) .Without <RoleUserEnum>(p => p.Role) .Without <string>(p => p.Email) .Create(); user.BirthDate = DateTime.UtcNow.AddYears(18); user.Role = RoleUserEnum.Parent; user.Email = "*****@*****.**"; _userBussinesLogic = new UserBussinesLogic(_userRepository.Object, _mockUoW.Object, _emailConfigurationRepository.Object, _appconfigurationRepository.Object); Action act = () => _userBussinesLogic.CreateNewUserAndSendConfirmationEmail(user); act.Should().NotThrow <Exception>(); _userRepository.Verify(p => p.Add(It.IsAny <User>()), Times.Once); _appconfigurationRepository.Verify(p => p.GetById(It.IsAny <int>()), Times.Once); _emailConfigurationRepository. Verify(e => e.AddEmailConfirmation(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <Guid>(), It.IsAny <TimeSpan>()), Times.Once); }