Esempio n. 1
0
        public void DynamicBaseClassCollectionNotInTest()
        {
            DynamicBaseClass person = new DynamicBaseClass()
            {
                Name = "Person", ReferenceName = "person", Type = ObjectType.Object
            };

            person.Fields.Add(new { Name = "Joe", Country = "Ireland", Age = 25 });

            DynamicBaseClass collection = new DynamicBaseClass()
            {
                Name = "CollectionPerson", ReferenceName = "collectionperson", Type = ObjectType.Collection
            };

            collection.Fields.Add(new { Name = "Joe", Country = "Ireland", Age = 20 });
            collection.Fields.Add(new { Name = "Bert", Country = "USA", Age = 40 });
            collection.Fields.Add(new { Name = "Carl", Country = "USA", Age = 50 });
            collection.Fields.Add(new { Name = "Carol", Country = "Germany", Age = 60 });

            ExpressionRuleLoader expressionRuleLoader = new ExpressionRuleLoader();
            Rule          rule1         = new Rule(" person[Age] notin collectionperson[Age] ");
            RuleValidator ruleValidator = new RuleValidator();
            var           result        = ruleValidator.ValidateExpressionRulesAll(
                new DynamicBaseClass[] { person, collection },
                new Rule[] { rule1 });

            Assert.AreEqual(result, true);
        }
Esempio n. 2
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.");
                }
            }
        }
Esempio n. 3
0
        public void DynamicBaseClassSimpleTest()
        {
            DynamicBaseClass person = new DynamicBaseClass()
            {
                Name = "Person", ReferenceName = "person", Type = ObjectType.Object
            };

            person.Fields.Add(new { Name = "Joe", Country = "Ireland", Age = 25 });

            DynamicBaseClass collection = new DynamicBaseClass()
            {
                Name = "PersonCollection", ReferenceName = "personcollection", Type = ObjectType.Object
            };

            collection.Fields.Add(new { Total = 100, AverageAge = 99, Min = 1, Max = 100 });

            ExpressionRuleLoader expressionRuleLoader = new ExpressionRuleLoader();
            Rule rule1 = new Rule(
                " (person[Name].lower = 'joe' && " +
                "person[Age] <= personcollection[AverageAge]) ");
            RuleValidator ruleValidator = new RuleValidator();
            var           result        = ruleValidator.ValidateExpressionRulesAll(
                new DynamicBaseClass[] { person, collection },
                new Rule[] { rule1 });

            Assert.AreEqual(result, true);
        }
Esempio n. 4
0
        public void DynamicObjectFieldTest()
        {
            dynamic person1 = new { Name = "Mathias", Age = 35, Children = 2 };
            ExpressionRuleLoader expressionRuleLoader = new ExpressionRuleLoader();
            Rule          rule1         = new Rule(" Field[Name] = 'Mathias' ");
            RuleValidator ruleValidator = new RuleValidator();
            bool          result        = ruleValidator.ValidateExpressionRulesDynamic(person1,
                                                                                       rule1);

            Assert.AreEqual(result, true);
        }
Esempio n. 5
0
        public void DynamicObjectCollectionAverageTest()
        {
            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         = new Rule(" Field[Age] > Collection[Age].Average ");
            RuleValidator ruleValidator = new RuleValidator();
            var           result        = ruleValidator.ValidateExpressionRules(person1,
                                                                                new dynamic[] { person2, pet1, pet2 }, rule1);

            Assert.AreEqual(result, true);
        }
Esempio n. 6
0
        public void DynamicObjectCollectionInAndConstantTest()
        {
            dynamic person1 = new { Name = "Mathias", Age = 35, Children = 2 };
            dynamic person2 = new { Name = "Mathias", 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         = new Rule(" Field[Age] > 40 && Field[Name] in Collection[Name] ");
            RuleValidator ruleValidator = new RuleValidator();
            var           result        = ruleValidator.ValidateExpressionRules(person1,
                                                                                new dynamic[] { person2, pet1, pet2 }, rule1);

            Assert.AreEqual(result, false);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        public void DynamicBaseClassFilterCountTest()
        {
            DynamicBaseClass collection = new DynamicBaseClass()
            {
                Name = "CollectionPerson", ReferenceName = "collectionperson", Type = ObjectType.Collection
            };

            collection.Fields.Add(new { Name = "Joe", Country = "Ireland", Age = 25 });
            collection.Fields.Add(new { Name = "Bert", Country = "USA", Age = 60 });
            collection.Fields.Add(new { Name = "Carl", Country = "USA", Age = 30 });
            collection.Fields.Add(new { Name = "Eric", Country = "Sweden", Age = 30 });

            ExpressionRuleLoader expressionRuleLoader = new ExpressionRuleLoader();
            Rule          rule1         = new Rule(" collectionperson.Filter[Age > 30].Count >= 1 ");
            RuleValidator ruleValidator = new RuleValidator();
            var           result        = ruleValidator.ValidateExpressionRulesAll(
                new DynamicBaseClass[] { collection },
                new Rule[] { rule1 });

            Assert.AreEqual(result, true);
        }
Esempio n. 11
0
        public void DynamicBaseClassComplexTest()
        {
            DynamicBaseClass person = new DynamicBaseClass()
            {
                Name = "Person", ReferenceName = "person", Type = ObjectType.Object
            };

            person.Fields.Add(new { Name = "Joe", Country = "Ireland", Age = 25 });

            DynamicBaseClass collection = new DynamicBaseClass()
            {
                Name = "CollectionPerson", ReferenceName = "collectionperson", Type = ObjectType.Object
            };

            collection.Fields.Add(new { Total = 100, AverageAge = 99, Min = 1, Max = 100 });

            DynamicBaseClass averagePerson = new DynamicBaseClass()
            {
                Name = "AveragePerson", ReferenceName = "averageperson", Type = ObjectType.Object
            };

            averagePerson.Fields.Add(new { AverageAge = 30, StandardDeviation = 7 });

            ExpressionRuleLoader expressionRuleLoader = new ExpressionRuleLoader();
            Rule rule1 = new Rule(
                " (person[Name] = 'Joei' && " +
                "person[Age] <= averageperson[AverageAge]) " +
                "|| (person[Age] > collectionperson[Total]) " +
                "|| collectionperson[Total] = 100 ");
            RuleValidator ruleValidator = new RuleValidator();
            var           result        = ruleValidator.ValidateExpressionRulesAll(
                new DynamicBaseClass[] { person, collection, averagePerson },
                new Rule[] { rule1 });

            Assert.AreEqual(result, true);
        }