示例#1
0
        public Example8ViewModel()
        {
            Quantity = Validator.Build <int>()
                       .Must(value => value > 0, "Need to specify the quantity");

            var monkeyList = new List <string>();

            monkeyList.Add("Baboon");
            monkeyList.Add("Capuchin Monkey");
            monkeyList.Add("Blue Monkey");
            monkeyList.Add("Squirrel Monkey");
            monkeyList.Add("Golden Lion Tamarin");
            monkeyList.Add("Howler Monkey");
            monkeyList.Add("Japanese Macaque");

            MonkeyList = ValidatorList.Build <string>()
                         .AddItemsSource(monkeyList)
                         .IsRequired("An item is required.")
                         .Must(value =>
            {
                if (MonkeyList.SelectedIndex == 2 && Quantity.Value < 5)    // == blue monkey
                {
                    return(false);
                }

                return(true);
            }, "Minimum quantity of this monkey is 5");

            UnitValidation = new ValidationUnit(Quantity, MonkeyList);
        }
        private void AddValidations()
        {
            Name = new Validatable <string>(
                new NotEmptyRule <string>("").WithMessage("A name is required."),
                new IsNotNullOrEmptyRule <string>().WithMessage(() => "Hi!")
                );

            LastName = Validator.Build <string>()
                       .IsRequired("A last name is required.")
                       .Must(CustomValidation, "Last name need to be longer.")
                       .When(x => Name.Validate());

            //// You can add several Rules by this
            ///
            //Email = new Validatable<string>(
            //    new IsNotNullOrEmptyRule<string>().WithMessage("A email is required."),
            //    new EmailRule()
            //);

            // Or this
            Email = Validator.Build <string>()
                    //.Add(new IsNotNullOrEmptyRule<string>(), "An email is required.")
                    .IsRequired("An email is required.")
                    .WithRule(new EmailRule())
                    .When(x => Name.Validate() && LastName.Validate());

            // Add to the unit
            _validationUnit = new ValidationUnit(Name, LastName, Email);

            //var listValidatables = new List<Validatable<string>> { Name, LastName, Email };
            //_validationUnit = new ValidationUnit(listValidatables);

            // Validator Model
            _testModelValidator = new UserValidator2();
        }
        public Example2ViewModel()
        {
            _user  = new User();
            _unit1 = new ValidationUnit(_user.Name, _user.LastName, _user.Email);

            AddValidations();
        }
        private void InitValidations()
        {
            this.NombresRule   = new ValidatableObject <string>();
            this.ApellidosRule = new ValidatableObject <string>();
            this.CelularRule   = new ValidatableObject <string>();

            this.ValidationUnit = new ValidationUnit(NombresRule, ApellidosRule, CelularRule);

            NombresRule.Validations.Add(new IsNullOrEmpty <string> {
                ValidationMessage = "Los nombres son obligatorios."
            });
            NombresRule.Validations.Add(new PersonNames <string> {
                ValidationMessage = "Los nombres no coinciden con el formato."
            });

            ApellidosRule.Validations.Add(new IsNullOrEmpty <string> {
                ValidationMessage = "Los apellidos son obligatorios."
            });
            ApellidosRule.Validations.Add(new PersonNames <string> {
                ValidationMessage = "Los apellidos no coinciden con el formato."
            });

            CelularRule.Validations.Add(new IsNullOrEmpty <string> {
                ValidationMessage = "El celular es obligatorio."
            });
            CelularRule.Validations.Add(new Cellphone <string> {
                ValidationMessage = "El celular no coincide con el formato."
            });
        }
示例#5
0
        internal Rule Configure(Core.Validator validator)
        {
            ValidationUnitCollection coll = validator.GetRules(Type);

            coll.Add(ValidationUnit.CreateValidationUnit(ErrorMessage, _CreateValidator(Extractor)));
            return(this);
        }
        public Example1ViewModel()
        {
            Name     = new Validatable <string>();
            LastName = new Validatable <string>();
            Email    = new Validatable <string>();

            _unit1 = new ValidationUnit(Name, LastName, Email);

            AddValidations();
        }
        public Example1ViewModel()
        {
            _name     = new ValidatableObject <string>();
            _lastname = new ValidatableObject <string>();
            _email    = new ValidatableObject <string>();

            _unit1 = new ValidationUnit(_name, _lastname, _email);

            AddValidations();
        }
示例#8
0
        public PhysicalDataViewModel()
        {
            birthday = new ValidatableObject <string>();
            tall     = new ValidatableObject <string>();
            weight   = new ValidatableObject <string>();
            age      = new ValidatableObject <string>();

            _unit1 = new ValidationUnit(birthday, tall, weight, age);

            AddValidations();
        }
示例#9
0
        public EditProfileViewModel()
        {
            userName = new ValidatableObject <string>();
            //email = new ValidatableObject<string>();
            birthday = new ValidatableObject <string>();
            tall     = new ValidatableObject <string>();
            weight   = new ValidatableObject <string>();
            age      = new ValidatableObject <string>();

            _unit1 = new ValidationUnit(userName, birthday, tall, weight, age);
            AddValidations();
        }
示例#10
0
        public MemberViewModel()
        {
            userName        = new ValidatableObject <string>();
            email           = new ValidatableObject <string>();
            password        = new ValidatableObject <string>();
            confirmPassword = new ValidatableObject <string>();
            serialNumber    = new ValidatableObject <string>();


            _unit1 = new ValidationUnit(userName, email, password, confirmPassword);
            AddValidations();


            //AddValidations();
        }
示例#11
0
        public void TestProgrammaticNullValidator()
        {
            var v = new Core.Validator();

            v.AddValidationRule(
                typeof(ProgValid1),
                ValidationUnit.CreateValidationUnit(
                    ErrorMessage.empty,
                    new RequiredValidator(new NamedValueExtractor("StringProperty"))));
            var obj = new ProgValid1();

            Assert.IsFalse(v.ValidateObject(obj), "Programmatic validation does not work");
            obj.StringProperty = "notnullvalue";
            Assert.IsTrue(v.ValidateObject(obj), "Programmatic validation does not work");
        }
示例#12
0
        public void DefineComplexRule1()
        {
            IValueExtractor ve = new BinaryOperatorValueExtractor(
                new NamedValueExtractor("intField1"),
                new NamedValueExtractor("intField2"),
                BinaryOperatorValueExtractor.MathOperation.Addition);
            var v = new Core.Validator();

            v.AddValidationRule(
                typeof(ProgValid1),
                ValidationUnit.CreateValidationUnit(
                    ErrorMessage.empty,
                    new RangeValueValidator(ve, 100, 1000)));
            var obj = new ProgValid1();

            obj.intField1 = 10;
            obj.intField2 = 200;

            Assert.IsTrue(v.ValidateObject(obj), "Programmatic validation does not work");
        }
        public UserValidator()
        {
            LastName = new Validatable <string>();
            Name     = new Validatable <string>();
            Email    = new Validatable <string>();

            _unit1 = new ValidationUnit(Name, LastName, Email);

            // Name validations
            Name.Validations.Add(new IsNotNullOrEmptyRule <string> {
                ValidationMessage = "A name is required."
            });

            //Lastname validations
            LastName.Validations.Add(new IsNotNullOrEmptyRule <string> {
                ValidationMessage = "A lastname is required."
            });

            //Email validations
            Email.Validations.Add(new IsNotNullOrEmptyRule <string> {
                ValidationMessage = "A email is required."
            });
            Email.Validations.Add(new EmailRule());
        }
示例#14
0
 public ForgetPWDViewModel()
 {
     email  = new ValidatableObject <string>();
     _unit1 = new ValidationUnit(email);
     AddValidations();
 }