public void Should_Fail_On_Incorrect_Sex() { var validator = new CreateUserRequestValidator(); var mockRequest = new CreateUserRequest() { FirstName = new string('*', 8), LastName = new string('*', 8), Email = "*****@*****.**", Address = new string('*', 8), Phone = new string('1', 8), Sex = 0, Password = "******" }; var result = validator.Validate(mockRequest); result.IsValid.Should().Be(false); result.Errors.FirstOrDefault(e => e.ErrorMessage == "Sex should be greater than or equal to 1.").Should().NotBeNull(); mockRequest = new CreateUserRequest() { FirstName = new string('*', 8), LastName = new string('*', 8), Email = "*****@*****.**", Address = new string('*', 8), Phone = new string('1', 8), Sex = 3, Password = "******" }; result = validator.Validate(mockRequest); result.IsValid.Should().Be(false); result.Errors.FirstOrDefault(e => e.ErrorMessage == "Sex should be lesser than or equal to 2.").Should().NotBeNull(); }
public void ReturnValidWhenAllPropsCorrect() { var createUser = new Fixture().Build <CreateUserRequest>() .Create(); _validator.Validate(createUser).IsValid.Should().BeTrue(); }
public ActionResult <int> AddUser(CreateUserRequest createdUser) { if (!_validator.Validate(createdUser)) { return(BadRequest(new { error = "username and password must be valid" })); } var newUser = _userRepository.AddUser(createdUser.Username, createdUser.Password); return(Created($"api/users/{newUser.Id}", newUser)); }
public void ShouldFailIfFirstNameIsInvalid(string name) { var request = CreateUserRequest.Example(); request.FirstName = name; var result = _validator.Validate(request); Assert.False(result.IsValid); }
public ActionResult AddUser(CreateUserRequest createRequest) { if (_validator.Validate(createRequest)) { return(BadRequest(new { error = "please enter all fields" })); } var newUser = _repository.AddUser(createRequest.Email, createRequest.FirebaseId, createRequest.Name, createRequest.Street, createRequest.City, createRequest.State, createRequest.ZipCode, createRequest.PhoneNumber, createRequest.IsAdmin); return(Created($"api/users/{newUser.Id}", newUser)); }
public void Should_Fail_On_Last_Name_Too_Long() { var validator = new CreateUserRequestValidator(); var mockRequest = new CreateUserRequest() { FirstName = new string('*', 8), LastName = new string('*', 300), Email = "*****@*****.**", Address = new string('*', 8), Phone = new string('1', 8), Sex = 1, Password = "******" }; var result = validator.Validate(mockRequest); result.IsValid.Should().Be(false); result.Errors.FirstOrDefault(e => e.ErrorMessage == "Last cannot be longer than 255 characters.").Should().NotBeNull(); }
public void Should_Fail_On_Empty_Last_Name() { var validator = new CreateUserRequestValidator(); var mockRequest = new CreateUserRequest() { FirstName = new string('*', 8), LastName = string.Empty, Email = "*****@*****.**", Address = new string('*', 8), Phone = new string('1', 8), Sex = 1, Password = "******" }; var result = validator.Validate(mockRequest); result.IsValid.Should().Be(false); result.Errors.FirstOrDefault(e => e.ErrorMessage == "Last name cannot be empty.").Should().NotBeNull(); }
public void Should_Fail_On_Invalid_Passowrd() { var validator = new CreateUserRequestValidator(); var mockRequest = new CreateUserRequest() { FirstName = new string('*', 8), LastName = new string('*', 8), Email = "*****@*****.**", Address = new string('*', 8), Phone = new string('1', 8), Sex = 1, Password = "******" }; var result = validator.Validate(mockRequest); result.IsValid.Should().Be(false); result.Errors.FirstOrDefault(e => e.ErrorMessage == "Password should include at least one capital letter, one digit and one non-alohanumeric character.").Should().NotBeNull(); }
public void Should_Fail_On_Passowrd_Too_Short() { var validator = new CreateUserRequestValidator(); var mockRequest = new CreateUserRequest() { FirstName = new string('*', 8), LastName = new string('*', 8), Email = "*****@*****.**", Address = new string('*', 8), Phone = new string('1', 8), Sex = 1, Password = "******" }; var result = validator.Validate(mockRequest); result.IsValid.Should().Be(false); result.Errors.FirstOrDefault(e => e.ErrorMessage == "Password cannot be shorter than 8 characters.").Should().NotBeNull(); }
public void Should_Fail_On_Invalid_Email() { var validator = new CreateUserRequestValidator(); var mockRequest = new CreateUserRequest() { FirstName = new string('*', 8), LastName = new string('*', 8), Email = "testtesttesttest", Address = new string('*', 8), Phone = new string('1', 8), Sex = 1, Password = "******" }; var result = validator.Validate(mockRequest); result.IsValid.Should().Be(false); result.Errors.FirstOrDefault(e => e.ErrorMessage == "Valid email address shuld be provided.").Should().NotBeNull(); }
public void Should_Pass_On_Correct_Request() { var validator = new CreateUserRequestValidator(); var mockRequest = new CreateUserRequest() { FirstName = new string('*', 8), LastName = new string('*', 8), Email = "*****@*****.**", Address = new string('*', 8), Phone = new string('1', 8), Sex = 1, Password = "******" }; var result = validator.Validate(mockRequest); result.IsValid.Should().Be(true); result.Errors.Count.Should().Be(0); }
public void Should_pass_when_all_fields_are_filled_correctly() { ExecuteInTransaction(s => { var validator = new CreateUserRequestValidator(s); //Arrange var cmd = new CreateUserRequest { Name = "Test", UserName = "******", Password = "******", PasswordConfirmation = "Password1234", Role = "admin" }; //Act var validation = validator.Validate(cmd); //Assert Assert.True(validation.IsValid); }); }
private static CreateUserRequest GetRequestFromUserInput() { var validator = new CreateUserRequestValidator(); while (true) { RequestInput(); var userInput = Printer.ReadLine(); var request = new CreateUserRequest { Username = userInput }; var validationResponse = validator.Validate(request); if (validationResponse.IsValid == false) { validationResponse.ErrorMessages.ForEach(Printer.PrintLine); continue; } return(request); } }
public void Should_fail_when_password_doesnt_match_with_confirmation() { ExecuteInTransaction(s => { var validator = new CreateUserRequestValidator(s); //Arrange var request = new CreateUserRequest { Name = "Test", UserName = "******", Password = "******", PasswordConfirmation = "1234Password" }; //Act var validation = validator.Validate(request); //Assert Assert.False(validation.IsValid); Assert.NotNull(validation.Errors); Assert.NotEmpty(validation.Errors); Assert.NotNull(validation.Errors.FirstOrDefault(x => x.ErrorMessage == "Passwords do not match")); }); }
public void Email_Success() { var result = _validator.Validate(Model); result.IsValid.ShouldBe(true); }