コード例 #1
0
        public void Validate_a_rule_with_invalid_data_and_fieldcomparison_compared_arrays_different_length()
        {
            Rule r = new Rule()
            {
                Name = "Test rule",
                FieldName = "StringArray",
                FieldPath = "TestEntity",
                FieldComparisonList = new List<FieldComparison>()
                    {
                        new FieldComparison()
                            {
                                FieldName = "AnotherSub",
                                FieldPath = "SubEntity"
                            }
                    }
            };

            TestEntity t = new TestEntity()
            {
                StringArray = new string[] { "valor1" }
            };

            SubEntity t1 = new SubEntity()
            {
                AnotherSub = new string[] { "valor1", "valor2" }
            };

            bool validationResult = r.Validate(t, t1);

            Assert.IsFalse(validationResult);
        }
コード例 #2
0
        public void Test_validate_succeed()
        {
            Validator v = GetValidator();

            TestEntity t = new TestEntity()
                {
                    SubClassArray = new SubEntity[]
                        {
                            new SubEntity()
                                {
                                    TestProp = "this is a TEST"
                                }
                        }
                };

            ValidationResult validationResult = v.Execute(t);

            Assert.IsTrue(validationResult.SucceededRules.Count == 1);
        }
コード例 #3
0
        public void Validate_a_ruleset_with_invalid_data_and_oninvalid_delegate_and_fieldcompare()
        {
            RuleSet rs = new RuleSet()
                {
                    OnInvalid = (prop) =>
                        {
                            //do nothing
                        },
                    Rules = new List<Rule>()
                        {
                            new Rule()
                                {
                                    Name = "Test rule",
                                    FieldName = "StringArray",
                                    FieldPath = "TestEntity",
                                    FieldComparisonList = new List<FieldComparison>()
                                        {
                                            new FieldComparison()
                                                {
                                                    FieldName = "AnotherSub",
                                                    FieldPath = "SubEntity"
                                                }
                                        }
                                }
                        }
                };

            TestEntity t = new TestEntity()
                {
                    StringArray = new string[] {"valor1", "valor1"}
                };

            SubEntity t1 = new SubEntity()
                {
                    AnotherSub = new string[] {"valor1", "valor2"}
                };

            bool validationResult = rs.Run(t, t1);

            Assert.IsFalse(validationResult);
        }
コード例 #4
0
        public void Validate_a_ruleset_with_invalid_data_and_oninvalid_delegate_and_regex()
        {
            RuleSet rs = new RuleSet()
                {
                    OnInvalid = (prop) =>
                    {
                        //do nothing
                    },
                    Rules = new List<Rule>()
                        {
                            new Rule()
                                {
                                    Name = "Test rule",
                                    ValidationExpression = "^.*TEST.*$",
                                    FieldName = "TestProp",
                                    FieldPath = "TestEntity.SubClassArray",
                                    ArrayIndex = 0
                                }
                        }
                };

            TestEntity t = new TestEntity()
            {
                SubClassArray = new SubEntity[]
                        {
                            new SubEntity()
                                {
                                    TestProp = "this is a not a...."
                                }
                        }
            };

            bool validationResult = rs.Run(t);

            Assert.IsFalse(validationResult);
        }
コード例 #5
0
        public void Validate_a_rule_with_invalid_data_and_subclass_array_allpositions()
        {
            Rule r = new Rule()
            {
                Name = "Test rule",
                ValidationExpression = "^.*TEST.*$",
                FieldName = "StringArray",
                FieldPath = "TestEntity",
            };

            TestEntity t = new TestEntity()
            {
                StringArray = new string[] { "some value", "this is a TEST" }
            };

            bool validationResult = r.Validate(t);

            Assert.IsFalse(validationResult);
        }
コード例 #6
0
        public void Validate_a_rule_with_valid_data_and_subclass_not_array()
        {
            Rule r = new Rule()
            {
                Name = "Test rule",
                ValidationExpression = "^.*TEST.*$",
                FieldName = "TestProp",
                FieldPath = "TestEntity.SubClass",
            };

            TestEntity t = new TestEntity()
            {
                SubClass = new SubEntity
                        {
                            TestProp = "some value TEST"
                        }
            };

            bool validationResult = r.Validate(t);

            Assert.IsTrue(validationResult);
        }
コード例 #7
0
        public void Validate_a_rule_with_valid_data_and_subclass_array()
        {
            Rule r = new Rule()
                {
                    Name = "Test rule",
                    ValidationExpression = "^.*TEST.*$",
                    FieldName = "TestProp",
                    FieldPath = "TestEntity.SubClassArray",
                    ArrayIndex = 0
                };

            TestEntity t = new TestEntity()
                {
                    SubClassArray = new SubEntity[]
                        {
                            new SubEntity()
                                {
                                    TestProp = "this is a TEST"
                                }
                        }
                };

            bool validationResult = r.Validate(t);

            Assert.IsTrue(validationResult);
        }
コード例 #8
0
        public void Validate_a_rule_with_valid_data_and_customvalidator()
        {
            Rule r = new Rule()
            {
                Name = "Test rule",
                FieldName = "TestProp",
                FieldPath = "TestEntity.SubClass",
                CustomValidator = (prop) =>
                    {
                        return true;
                    }
            };

            TestEntity t = new TestEntity()
            {
                SubClass = new SubEntity
                {
                    TestProp = "some value TEST"
                }
            };

            bool validationResult = r.Validate(t);

            Assert.IsTrue(validationResult);
        }
コード例 #9
0
        public void Validate_a_rule_with_valid_data_and_basetype_array()
        {
            Rule r = new Rule()
            {
                Name = "Test rule",
                ValidationExpression = "^.*TEST.*$",
                FieldName = "StringArray",
                FieldPath = "TestEntity",
                ArrayIndex = 1
            };

            TestEntity t = new TestEntity()
            {
                StringArray = new string[] { "some value", "this is a TEST" }
            };

            bool validationResult = r.Validate(t);

            Assert.IsTrue(validationResult);
        }
コード例 #10
0
        public void Validate_a_rule_with_non_existing_field()
        {
            Rule r = new Rule()
            {
                Name = "Test rule",
                ValidationExpression = "^.*TEST.*$",
                FieldName = "Unexistent prop",
                FieldPath = "TestEntity.SubClass",
            };

            TestEntity t = new TestEntity()
            {
                SubClass = new SubEntity
                {
                    TestProp = "some value TEST"
                }
            };

            bool validationResult = r.Validate(t);

            Assert.IsFalse(validationResult);
        }
コード例 #11
0
        public void Validate_a_rule_with_invalid_data_and_subclass_array_with_string_array_prop_allpositions()
        {
            Rule r = new Rule()
            {
                Name = "Test rule",
                ValidationExpression = "^.*TEST.*$",
                FieldName = "AnotherSub",
                FieldPath = "TestEntity.SubClassArray",
            };

            TestEntity t = new TestEntity()
            {
                SubClassArray = new SubEntity[]
                        {
                            new SubEntity()
                                {
                                    AnotherSub = new string[]
                                        {
                                            "array pos 1", "array pos 2"
                                        }
                                }
                        }
            };

            bool validationResult = r.Validate(t);

            Assert.IsFalse(validationResult);
        }