public void Mandatory_Validation_Not_Satisfied_Will_Produce_Validation_Error()
        {
            var user = new User();

            var validator = ServiceLocator.Current.GetInstance<IBusinessRulesValidator>();

            validator.Add(ServiceLocator.Current.GetInstance<IRuleValidator<User>>(), user);

            IEnumerable<ValidationMessage> result = validator.Validate().ToList();

            Assert.IsTrue(result.HasError());

            Assert.AreEqual(4, result.Count());
        }
        /// <summary>
        /// Creates the user.
        /// </summary>
        /// <param name="newUser">The new user.</param>
        /// <returns>
        /// User entity, Contain validation result message if any.
        /// </returns>
        public CreateUserResponse CreateUser(User newUser)
        {
            IEnumerable<ValidationMessage> validationResult = ValidateUser(newUser).ToList();

            if (!validationResult.HasError())
            {
                _userRepository.Create(newUser);
            }

            var response = new CreateUserResponse {User = newUser};

            response.ValidationMessages.AddValidationMessages(validationResult);

            return response;
        }
        public void Create_User_With_Invalid_Data_Produce_Validation_Error()
        {
            var userService = ServiceLocator.Current.GetInstance<IUserManagementService>();

            var user = new User
                           {
                               FirstName = "User 1",
                               LastName = "Last Name",
                               PhoneNumber = "1245232323",
                               Password = "******",
                               ApplyPasswordPolicy = true,
                               SecurityQuestionAnswer = "Test"
                           };

            CreateUserResponse result = userService.CreateUser(user);

            Assert.IsTrue(result.EntityHasError());
        }
        public void Create_User_With_Valid_Data_Sould_Not_Produce_Validation_Error()
        {
            var userService = ServiceLocator.Current.GetInstance<IUserManagementService>();

            var user = new User
                           {
                               UserId = Guid.NewGuid().ToString(),
                               FirstName = "User 1",
                               LastName = "Last Name",
                               Email = "*****@*****.**",
                               PhoneNumber = "1245232323",
                               Password = "******",
                               ApplyPasswordPolicy = true,
                               SecurityQuestion = "Test",
                               SecurityQuestionAnswer = "Test"
                           };

            CreateUserResponse result = userService.CreateUser(user);

            Assert.IsFalse(result.EntityHasError());
        }
        public void Valid_User_Not_Produce_Validation_Error()
        {
            var user = new User
                           {
                               UserId = Guid.NewGuid().ToString(),
                               FirstName = "User 1",
                               LastName = "Last Name",
                               Email = "*****@*****.**",
                               PhoneNumber = "1245232323",
                               Password = "******",
                               ApplyPasswordPolicy = true,
                               SecurityQuestion = "Test",
                               SecurityQuestionAnswer = "Test"
                           };

            var validator = ServiceLocator.Current.GetInstance<IBusinessRulesValidator>();

            validator.Add(ServiceLocator.Current.GetInstance<IRuleValidator<User>>(), user);

            IEnumerable<ValidationMessage> validationResult = validator.Validate();

            Assert.IsFalse(validationResult.HasError());
        }
 public void SetValidationTarget(User target)
 {
     _target = target;
 }
Ejemplo n.º 7
0
 public void Create(User newUser)
 {
     Session.SaveOrUpdate(newUser);
 }
        public CreateUserResponse CreateUser(User newUser)
        {
            CreateUserResponse result = _userManagementService.CreateUser(newUser);

            return result;
        }
        private IEnumerable<ValidationMessage> ValidateUser(User newUser)
        {
            IBusinessRulesValidator businessRuleValidator = new BusinessRulesValidator();
            businessRuleValidator.Add(UserModelValidator, newUser);
            businessRuleValidator.Add(PasswordPolicyRuleValidator, newUser);

            return businessRuleValidator.Validate();
        }