Beispiel #1
0
        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);
        }
Beispiel #2
0
        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.");
        }
Beispiel #3
0
        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.");
        }
Beispiel #4
0
        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.");
        }
Beispiel #5
0
        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.");
        }