public void shoud_post_users() { var userServiceMock = new Mock <IUserService>(); var mapperMock = new Mock <IMapper>(); var user = new CreateUserRequestValidation() { Name = "teste", Email = "*****@*****.**", Password = "******" }; var userId = 1; userServiceMock.Setup(x => x.Save(It.IsAny <User>())).Returns(userId); var userController = new UserController(userServiceMock.Object, mapperMock.Object); var expectedUserList = userController.Post(user); var result = expectedUserList.Result as OkObjectResult; Assert.NotNull(expectedUserList); Assert.Equal(200, result.StatusCode); Assert.Equal(userId, result.Value); }
void shoud_validate_no_password_data() { var validCreateUserRequestValidation = new CreateUserRequestValidation() { Name = "Nome", Email = "*****@*****.**", }; var result = ValidateModel(validCreateUserRequestValidation); Assert.Contains(result, v => v.MemberNames.Contains("Password") && v.ErrorMessage.Contains("É necessário informar a senha do usuário")); }
void shoud_validate_no_email_data() { var validCreateUserRequestValidation = new CreateUserRequestValidation() { Name = "Nome", Password = "******" }; var result = ValidateModel(validCreateUserRequestValidation); Assert.Contains(result, v => v.MemberNames.Contains("Email") && v.ErrorMessage.Contains("É necessário informar o email do usuário")); }
void shoud_validate_invalid_email_data() { var validCreateUserRequestValidation = new CreateUserRequestValidation() { Name = "Nome", Email = "email invalido", Password = "******" }; var result = ValidateModel(validCreateUserRequestValidation); Assert.Contains(result, v => v.MemberNames.Contains("Email") && v.ErrorMessage.Contains("Email inválido")); }
void shoud_validate_correct_input_with_valid_data() { var validCreateUserRequestValidation = new CreateUserRequestValidation() { Name = "Exemplo", Email = "*****@*****.**", Password = "******" }; var result = ValidateModel(validCreateUserRequestValidation); Assert.True(result.Count == 0); }
public async Task <IActionResult> CreateUser(CreateUserRequest request) { var result = new CreateUserRequestValidation().Validate(request); if (!result.IsValid) { foreach (var failure in result.Errors) { ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage); } var errors = ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)).ToList(); _telemetryClient.TrackTrace(new TraceTelemetry( $"CreateUserRequest validation failed: {string.Join(Separator, errors)}", SeverityLevel.Error)); return(BadRequest(ModelState)); } try { var adUserAccount = await _userAccountService.CreateUserAsync(request.FirstName, request.LastName, request.RecoveryEmail, request.IsTestUser); var response = new NewUserResponse { UserId = adUserAccount.UserId, Username = adUserAccount.Username, OneTimePassword = adUserAccount.OneTimePassword }; return(CreatedAtRoute("GetUserByAdUserId", new { userId = adUserAccount.UserId }, response)); } catch (UserExistsException e) { return(new ConflictObjectResult(new { Message = "User already exists", Code = "UserExists", e.Username })); } }
public ActionResult <int> Post([FromBody] CreateUserRequestValidation user) { var UserId = service.Save(mapper.Map <User>(user)); return(Ok(UserId)); }
public void OneTimeSetUp() { _validator = new CreateUserRequestValidation(); }