Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }