コード例 #1
0
        public void ValidateAllW_True()
        {
            // Arrange
            var rules = new List <Rule>
            {
                new Rule {
                    RuleName = "1", Expression = "(f.Age > 3 && f.Income < 50000) || f.NumberOfChildren > 2"
                },
                new Rule {
                    RuleName = "2", Expression = "(f.Age > 3 && f.Income > 100000) || f.NumberOfChildren > 5"
                }
            };

            var p = new Person {
                Age = 37, Income = 45000, NumberOfChildren = 3
            };
            var ruleEngine = new RuleEngine.Kernel();

            ruleEngine.AddRules(rules);
            // Act
            var result = ruleEngine.ValidateAll(p, "1");

            // Assert
            Assert.True(result);
        }
コード例 #2
0
ファイル: ValidateTests.cs プロジェクト: IoTSharp/RuleEngine
        public void Validate_ByJson_True()
        {
            // Arrange
            const string expression = @"(f.Age > 3 && f.Income < 50000) || f.NumberOfChildren > 2";
            var          p          = new   { Age = 37, Income = 45000, NumberOfChildren = 3 };
            var          jp         = Newtonsoft.Json.Linq.JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(p));
            var          ruleEngine = new RuleEngine.Kernel();
            // Act
            var result = ruleEngine.Validate(jp, expression);

            // Assert
            Assert.True(result);
        }
コード例 #3
0
ファイル: EvaluateTests.cs プロジェクト: IoTSharp/RuleEngine
        public void Evaluate_False()
        {
            // Arrange
            const string expression = @"(f.Age > 3 && f.Income > 100000) || f.NumberOfChildren > 5";
            var          p          = new Person {
                Age = 37, Income = 45000, NumberOfChildren = 3
            };
            var ruleEngine = new RuleEngine.Kernel();
            // Act
            var result = ruleEngine.Evaluate <Person, bool>(p, expression);

            // Assert
            Assert.False(result);
        }
コード例 #4
0
ファイル: ValidateTests.cs プロジェクト: IoTSharp/RuleEngine
        public void Validate_True()
        {
            // Arrange
            const string expression = @"(f.Age > 3 && f.Income < 50000) || f.NumberOfChildren > 2";
            var          p          = new Person {
                Age = 37, Income = 45000, NumberOfChildren = 3
            };
            var ruleEngine = new RuleEngine.Kernel();
            // Act
            var result = ruleEngine.Validate(p, expression);

            // Assert
            Assert.True(result);
        }
コード例 #5
0
        public void ValidateAllWp_True()
        {
            // Arrange
            var rule = new Rule {
                Key = "1", Expression = "(f.Age > 3 && f.Income < 50000) || f.NumberOfChildren > 2"
            };
            var p = new Person {
                Age = 37, Income = 45000, NumberOfChildren = 3
            };
            var ruleEngine = new RuleEngine.Kernel();

            ruleEngine.AddRule(rule);
            // Act
            var result = ruleEngine.ValidateAll(p);

            // Assert
            Assert.True(result);
        }
コード例 #6
0
        public void ValidateCollection_True()
        {
            // Arrange
            var people = new List <Person>
            {
                new Person {
                    Name = "John", Gender = Gender.Male, Age = 23, Income = 24000, NumberOfChildren = 0
                },
                new Person {
                    Name = "Mary", Gender = Gender.Female, Age = 22, Income = 23000, NumberOfChildren = 1
                }
            };

            const string expression = "f.Any(p => p.Name.Equals(\"John\") && p.Age < 24)";
            var          ruleEngine = new RuleEngine.Kernel();
            // Act
            var result = ruleEngine.Validate <IEnumerable <Person> >(people, expression);

            // Assert
            Assert.True(result);
        }