Exemple #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var validator = new RegisterViewModelValidator();
            var result    = validator.Validate(this);

            return(result.Errors.Select(item => new ValidationResult(item.ErrorMessage, new[] { item.PropertyName })));
        }
Exemple #2
0
        public void ShouldNotRegisterUserIfEmailNotUnique()
        {
            EnsureZeroUsers();

            using (var database = AdminAppIdentityDbContext.Create())
            {
                var user = new AdminAppUser()
                {
                    Email    = "*****@*****.**",
                    UserName = "******"
                };
                database.Users.Add(user);
                database.SaveChanges();
            }

            var newUser = new RegisterViewModel
            {
                Email           = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******"
            };

            var validator         = new RegisterViewModelValidator();
            var validationResults = validator.Validate(newUser);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("A user with the email already exists in the database");
        }
        public bool CanExecute(object parameter)
        {
            var model = parameter as RegisterViewModel;

            if (model is null)
            {
                return(false);
            }
            var resoults = validator.Validate(model);

            model.Errors = string.Join(" ", resoults.Errors);
            return(resoults.IsValid);
        }
        public override Task <OperationResult <UserProfileViewModel> > Handle(RegisterRequest request, CancellationToken cancellationToken)
        {
            var registerViewModelValidator = new RegisterViewModelValidator();
            var result = registerViewModelValidator.Validate(request.Model);

            if (result.IsValid)
            {
                return(_accountService.RegisterAsync(request.Model));
            }

            var operation = OperationResult.CreateResult <UserProfileViewModel>();

            operation.AppendLog(result.Errors.Select(x => x.ErrorMessage));
            return(Task.FromResult(operation));
        }
Exemple #5
0
        public void ShouldNotRegisterUserIfRequiredFieldsEmpty()
        {
            var newUser = new RegisterViewModel();

            var validator         = new RegisterViewModelValidator();
            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);
        }
Exemple #6
0
        public void ShouldNotRegisterUserIfPasswordsDoNotMatch()
        {
            var newUser = new RegisterViewModel
            {
                Email           = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******"
            };

            var validator         = new RegisterViewModelValidator();
            var validationResults = validator.Validate(newUser);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("The password and confirmation password do not match.");
        }
Exemple #7
0
        public void ShouldNotRegisterUserIfEmailNotValid()
        {
            var newUser = new RegisterViewModel
            {
                Email           = "not-a-valid-email",
                Password        = "******",
                ConfirmPassword = "******"
            };

            var validator         = new RegisterViewModelValidator();
            var validationResults = validator.Validate(newUser);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("'Email' is not a valid email address.");
        }
Exemple #8
0
        public void ShouldNotRegisterUserIfPasswordLengthNotValid(string testPassword)
        {
            var newUser = new RegisterViewModel
            {
                Email           = "*****@*****.**",
                Password        = testPassword,
                ConfirmPassword = testPassword
            };

            var validator         = new RegisterViewModelValidator();
            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.");
        }