public void Should_Show_Error_When_IdProfile_Invalid(int idProfile) { UserCreateCommand userCreateCommand = new UserCreateCommand(idProfile, Guid.NewGuid().ToString(), _faker.Person.FullName, _faker.Person.Email); userCreateCommand.Validate(); Assert.True(!userCreateCommand.IsValid()); Assert.True(userCreateCommand.Errors?.FirstOrDefault(x => x == "Profile is required") != null); }
public void Should_Show_Error_When_Email_Null_Or_Empty(string email) { UserCreateCommand userCreateCommand = new UserCreateCommand(1, Guid.NewGuid().ToString(), _faker.Person.FullName, email); userCreateCommand.Validate(); Assert.True(!userCreateCommand.IsValid()); Assert.True(userCreateCommand.Errors?.FirstOrDefault(x => x == "E-mail is required") != null); }
public async Task <ObjectResult> PostAsync(UserCreateCommand command) { ValidationResult resultadoValidacao = command.Validate(); if (!resultadoValidacao.IsValid) { throw new Exception("Erro de validação!"); } await _userService.AddAsync(command); return(StatusCode(201, command)); }