Example #1
0
        public void SimpleRuleLoaderPersonValidateExpressionRules()
        {
            Person person1 = new Person()
            {
                Name = "Mathias", Age = 35, Children = 2
            };
            Person person2 = new Person()
            {
                Name = "Anna", Age = 32, Children = 2
            };
            ExpressionRuleLoader expressionRuleLoader = new ExpressionRuleLoader();
            // new Rule(" Name = 'mathias' ");
            Rule rule1 = expressionRuleLoader.Load(1);
            // new Rule(" Age = 35 ");
            Rule          rule2         = expressionRuleLoader.Load(2);
            RuleValidator ruleValidator = new RuleValidator();
            var           result        = ruleValidator.ValidateExpressionRules(new Person[] { person1, person2 },
                                                                                new Rule[] { rule1, rule2 });

            foreach (var item in result)
            {
                if (item.Item3)
                {
                    Debug.WriteLine("Value: " + item.Item1.Name + " with ProcessingRule: " + item.Item2.ProcessingRule + item.Item2.Value + " passed.");
                }
                else
                {
                    Debug.WriteLine("Value: " + item.Item1.Name + " with ProcessingRule: " + item.Item2.ProcessingRule + item.Item2.Value + " failed.");
                }
            }
        }
Example #2
0
        public void DynamicObjectTest()
        {
            dynamic person1 = new { Name = "Mathias", Age = 35, Children = 2 };
            dynamic person2 = new { Name = "Anna", Age = 32, Children = 2 };
            dynamic pet1    = new { Name = "lucky", Age = 5, Type = "cat" };
            dynamic pet2    = new { Name = "wuffy", Age = 5, Type = "dog" };
            ExpressionRuleLoader expressionRuleLoader = new ExpressionRuleLoader();
            Rule          rule1         = expressionRuleLoader.Load(1);
            Rule          rule2         = expressionRuleLoader.Load(2);
            RuleValidator ruleValidator = new RuleValidator();
            var           result        = ruleValidator.ValidateExpressionRulesAll(new dynamic[] { person1, person2, pet1, pet2 },
                                                                                   new Rule[] { rule1, rule2 });

            Assert.AreEqual(result, false);
        }
Example #3
0
        public void SimpleRuleLoaderPersonEvaluateExpression()
        {
            Person person1 = new Person()
            {
                Name = "Mathias", Age = 35, Children = 2
            };
            ExpressionRuleLoader expressionRuleLoader = new ExpressionRuleLoader();
            // new Rule(" Name = 'mathias' ");
            Rule rule1 = expressionRuleLoader.Load(1);
            // new Rule(" Age = 35 ");
            Rule          rule2         = expressionRuleLoader.Load(2);
            RuleValidator ruleValidator = new RuleValidator();
            var           result        = ruleValidator.ValidateExpressionRules(person1, rule1);

            Assert.AreEqual(result, true);
            result = ruleValidator.ValidateExpressionRules(person1, rule2);
            Assert.AreEqual(result, true);
        }
Example #4
0
        public void SimpleRuleLoaderPersonEvaluateExpressionAll()
        {
            Person person1 = new Person()
            {
                Name = "Mathias", Age = 35, Children = 2
            };
            Person person2 = new Person()
            {
                Name = "Anna", Age = 32, Children = 2
            };
            ExpressionRuleLoader expressionRuleLoader = new ExpressionRuleLoader();
            // new Rule(" Name = 'mathias' ");
            Rule rule1 = expressionRuleLoader.Load(1);
            // new Rule(" Age = 35 ");
            Rule          rule2         = expressionRuleLoader.Load(2);
            RuleValidator ruleValidator = new RuleValidator();
            var           result        = ruleValidator.ValidateExpressionRulesAll(new Person[] { person1, person2 },
                                                                                   new Rule[] { rule1, rule2 });

            Assert.AreEqual(result, false);
        }