public void ValidateAndThrow_UserFirstNameIsNull_ShouldThrowException() { // Arrange var id = new Fixture().Create <int>(); var userDto = GetCorrectUserDto(id); userDto.FirstName = null; // Act & Assert Assert.Throws <ValidationException>(() => _userDtoValidator.ValidateAndThrow(userDto)); }
public async Task <UserLoginDto> SignIn(UserDto dto) { var validator = new UserDtoValidator(); validator.ValidateAndThrow(dto); await IsEmailNull(dto.Email); var user = new User { UserName = dto.Email, Email = dto.Email }; var result = await signInManager.PasswordSignInAsync(dto.Email, dto.Password, true, false); if (result.Succeeded) { var userEntity = await userManager.FindByEmailAsync(dto.Email); var newDto = new UserLoginDto(); _mapper.Map(userEntity, newDto); return(newDto); } else { throw new FormatException("Bad password"); } //foreach (var error in result.Errors) //{ // ModelState.AddModelError(string.Empty, error.Description); //} }
public async Task <UserLoginDto> SignUp(UserDto dto) { var validator = new UserDtoValidator(); validator.ValidateAndThrow(dto); await IsEmalInUse(dto.Email); var user = new User { UserName = dto.Email, Email = dto.Email, FirstName = dto.FirstName, SecondName = dto.SecondName, PositionId = dto.PositionId }; var result = await userManager.CreateAsync(user, dto.Password); if (result.Succeeded) { await signInManager.SignInAsync(user, isPersistent : false); var userEntity = await userManager.FindByEmailAsync(dto.Email); var newDto = new UserLoginDto(); _mapper.Map(userEntity, newDto); return(newDto); } else { throw new FormatException("Bad password"); } //foreach (var error in result.Errors) //{ // ModelState.AddModelError(string.Empty, error.Description); //} }