コード例 #1
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");
 }
コード例 #2
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");
        }
コード例 #3
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");
        }
コード例 #4
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");
        }