public void ShouldNotAddUserIfRequiredFieldsEmpty() { var newUser = new AddUserModel(); var validator = new AddUserModelValidator(); var validationResults = validator.Validate(newUser); validationResults.IsValid.ShouldBe(false); validationResults.Errors.Select(x => x.ErrorMessage).ShouldBe(new List <string> { "'Email' must not be empty.", "'Password' must not be empty.", "'Confirm Password' must not be empty." }, false); }
public void ShouldNotAddUserIfPasswordsDoNotMatch() { var newUser = new AddUserModel { Email = "*****@*****.**", Password = "******", ConfirmPassword = "******" }; var validator = new AddUserModelValidator(); var validationResults = validator.Validate(newUser); validationResults.IsValid.ShouldBe(false); validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("The password and confirmation password do not match."); }
public void ShouldNotAddUserIfEmailNotValid() { var newUser = new AddUserModel { Email = "not-a-valid-email", Password = "******", ConfirmPassword = "******" }; var validator = new AddUserModelValidator(); var validationResults = validator.Validate(newUser); validationResults.IsValid.ShouldBe(false); validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("'Email' is not a valid email address."); }
public void ShouldNotAddUserIfPasswordLengthNotValid(string testPassword) { var newUser = new AddUserModel { Email = "*****@*****.**", Password = testPassword, ConfirmPassword = testPassword }; var validator = new AddUserModelValidator(); var validationResults = validator.Validate(newUser); validationResults.IsValid.ShouldBe(false); validationResults.Errors.Single().ErrorMessage.ShouldContain($"'Password' must be between 6 and 100 characters. You entered {testPassword.Length} characters."); }
public void ShouldNotAddUserIfEmailNotUnique() { ResetUsers(); var existingUser = SetupUsers(1).Single(); var newUser = new AddUserModel { Email = existingUser.Email, Password = "******", ConfirmPassword = "******" }; var validator = new AddUserModelValidator(); var validationResults = validator.Validate(newUser); validationResults.IsValid.ShouldBe(false); validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("A user with this email address already exists in the database."); }