Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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));
        }