示例#1
0
        public void Should_support_double_fact_rules()
        {
            var engine = RulesEngineFactory.New(x =>
            {
                x.Rule <SecondRule>();
            });


            FactHandle <Destination>[] destinations;
            using (var session = engine.CreateSession())
            {
                session.Add(new FirstSegmentImpl {
                    SourceId = "public"
                });
                session.Add(new SecondSegmentImpl {
                    Amount = 10001.0m
                });

                session.Run();

                destinations = session.Facts <Destination>().ToArray();
            }

            Assert.AreEqual(1, destinations.Length);
        }
示例#2
0
        public void Should_optimize_rules_of_multiple_types()
        {
            var engine = RulesEngineFactory.New(x =>
            {
                x.Rule <FirstRule>();
                x.Rule <SecondRule>();
            });


            FactHandle <Destination>[] destinations;
            using (var session = engine.CreateSession())
            {
                object first = new FirstSegmentImpl {
                    SourceId = "public"
                };
                session.Add(first);
                object second = new SecondSegmentImpl {
                    Amount = 10001.0m
                };
                session.Add(second);

                session.Run();

                destinations = session.Facts <Destination>().ToArray();
            }

            Assert.AreEqual(2, destinations.Length);

            Assert.AreEqual("90210", destinations[0].Fact.Address);
            Assert.AreEqual("74011", destinations[1].Fact.Address);
        }
示例#3
0
 public void Setup()
 {
     _engine = RulesEngineFactory.New(x =>
     {
         // add our rule
         x.Rule <SingleFactRule>();
         x.Rule <ViolationRule>();
     });
 }
        public void Show_me_the_goods()
        {
            RulesEngine rulesEngine = RulesEngineFactory.New(x =>
            {
                x.Add(_rule);
            });

            rulesEngine.ShowVisualizer();
        }
示例#5
0
        static void Main(string[] args)
        {
            var protocol1 = new Protocol()
            {
                Kv = 200, Ma = 200, Name = "Cardiac"
            };
            var protocol2 = new Protocol()
            {
                Kv = 20, Ma = 200, Name = "Scout"
            };

            Console.WriteLine("P1: " + protocol1);
            Console.WriteLine("P2: " + protocol2);

            var engine = RulesEngineFactory.New(x =>
            {
                x.Rules(r =>
                {
                    r.Add <Temp>();
                    r.Add <Temp2>();
                    //r.Add<MaxKvRule>();
                    //r.Add<MinKvRule>();
                    //r.Add<ScoutKvRule>();
                });
            });

            var visitor = new TextRuntimeVisitor();

            engine.Accept(visitor);
            Console.WriteLine(visitor);

            using (var session = engine.CreateSession())
            {
                session.Add(protocol1);
                session.Add(protocol2);

                session.Run();

                var changes = session.Facts <Changed>().ToArray();

                Console.WriteLine("\n\n");

                foreach (var change in changes)
                {
                    Console.WriteLine("{0} has changed in {1}", change.Fact.Parameter, change.Fact.Name);
                }
            }


            Console.WriteLine("P1: " + protocol1);
            Console.WriteLine("P2: " + protocol2);

            Console.ReadLine();
        }
示例#6
0
        public void Setup()
        {
            _engine = RulesEngineFactory.New(x =>
            {
                x.RegisterPropertySelector(new ValuePropertySelectorFactory());

                x.Rule <NestedValueRule>();
                x.Rule <NestedValueRule2>();
                x.Rule <NullableIntRule>();
                x.Rule <NullableIntRule2>();
            });
        }
示例#7
0
        public void Define_rule()
        {
            var conditions = new RuleCondition[]
            {
                Conditions.GreaterThan((Order x) => x.Amount, 10000.0m),
            };

            var consequences = new RuleConsequence[]
            {
                Consequences.Delegate <Order>((session, x) => { _result = x; }),
            };

            Rule rule = new OdoyuleRule("RuleA", conditions, consequences);

            _engine = RulesEngineFactory.New(x => x.Add(rule));
        }
示例#8
0
        public void Should_not_activate_for_only_other_side()
        {
            _result = null;

            RulesEngine rulesEngine = RulesEngineFactory.New(x => { x.Add(_rule); });

            using (StatefulSession session = rulesEngine.CreateSession())
            {
                session.Add(new Order {
                    Name = "MAMA", Amount = 10001.0m
                });
                session.Run();
            }

            Assert.IsNull(_result);
        }
        public void Define_rule()
        {
            var conditions = new[]
            {
                Conditions.GreaterThan((Order x) => x.Amount, 10000.0m),
            };

            var consequences = new[]
            {
                Consequences.Delegate((Order o) => _result = o),
            };

            Rule rule = new SemanticRule("RuleA", conditions, consequences);

            _engine = RulesEngineFactory.New(x => x.Add(rule));
        }
示例#10
0
        public void Define_rule()
        {
            var conditions = new RuleCondition[]
            {
                Conditions.Equal((Order x) => x.Name, "JOE"),
            };

            var consequences = new RuleConsequence[]
            {
                Consequences.Delegate <Order>((session, x) => { _result = x; }),
            };

            Rule rule = new OdoyuleRule("RuleA", conditions, consequences);

            _engine = RulesEngineFactory.New(x => x.Add(rule));
        }
示例#11
0
        public void Define_rule()
        {
            var conditions = new[]
            {
                Conditions.NotNull((Order x) => x.Customer),
            };

            var consequences = new[]
            {
                Consequences.Delegate((Order o) => _result = o),
            };

            Rule rule = new SemanticRule("RuleA", conditions, consequences);

            _engine = RulesEngineFactory.New(x => x.Add(rule));
        }
示例#12
0
        public void Define_rule()
        {
            _results = new List <Order>();

            var conditions = new[]
            {
                Conditions.Exists((Order x) => x.Lines),
            };

            var consequences = new[]
            {
                Consequences.Delegate((Order o) => _results.Add(o)),
            };

            Rule rule = new SemanticRule("RuleA", conditions, consequences);

            _engine = RulesEngineFactory.New(x => x.Add(rule));
        }
示例#13
0
        public void Define_rule()
        {
            _results = new List <Tuple <OrderLine, int> >();

            var conditions = new[]
            {
                Conditions.Each <Order, IList <OrderLine>, OrderLine>(x => x.Lines),
            };

            var consequences = new[]
            {
                Consequences.Delegate((Token <Token <Order, IList <OrderLine> >, Tuple <OrderLine, int> > x) => _results.Add(x.Item2))
            };

            Rule rule = new SemanticRule("RuleA", conditions, consequences);

            _engine = RulesEngineFactory.New(x => x.Add(rule));
        }
示例#14
0
        public void Should_compile_and_execute()
        {
            _result = null;

            RulesEngine rulesEngine = RulesEngineFactory.New(x => { x.Add(_rule); });

            using (StatefulSession session = rulesEngine.CreateSession())
            {
                session.Add(new Order {
                    Name = "JOE", Amount = 10001.0m, Purchaser = new Customer {
                        AccountNumber = "DIRT"
                    }
                });
                session.Run();
            }

            Assert.IsNotNull(_result);
        }
示例#15
0
        public void Define_rule()
        {
            _results = new List <Order>();

            var conditions = new RuleCondition[]
            {
                Conditions.Exists((Order x) => x.Lines),     //,
                //Conditions.Equal((OrderLine x) => x.ItemNumber == "123"));
            };

            var consequences = new RuleConsequence[]
            {
                Consequences.Delegate <Order>((session, x) => _results.Add(x)),
            };

            Rule rule = new OdoyuleRule("RuleA", conditions, consequences);

            _engine = RulesEngineFactory.New(x => x.Add(rule));
        }
示例#16
0
        public void Should_return_instances_that_implement_said_fact()
        {
            RulesEngine engine = RulesEngineFactory.New(x =>
            {
                x.Rules(r => r.Add <FirstRule>());
            });

            using (Session session = engine.CreateSession())
            {
                session.Add((IA) new A {
                    Name = "Chris"
                });

                session.Run();

                IEnumerable <FactHandle <IA> > ass = session.Facts <IA>();

                Assert.AreEqual(1, ass.Count());
                Assert.AreEqual("Chris", ass.First().Fact.Name);
            }
        }
示例#17
0
        public void Should_not_activate_for_only_other_side()
        {
            _result = null;

            RulesEngine rulesEngine = RulesEngineFactory.New(x => { x.Add(_rule); });

            using (Session session = rulesEngine.CreateSession())
            {
                session.Add(new Order {
                    Name = "MAMA", Amount = 10001.0m
                });
                session.Run();
            }

            var visitor = new TextRuntimeVisitor();

            rulesEngine.Accept(visitor);

            Console.WriteLine(visitor);

            Assert.IsNull(_result);
        }
示例#18
0
        public void Should_compile_and_execute()
        {
            _result = null;

            RulesEngine rulesEngine = RulesEngineFactory.New(x => { x.Add(_rule); });

            using (Session session = rulesEngine.CreateSession())
            {
                session.Add(new Order {
                    Name = "JOE", Amount = 10001.0m
                });
                session.Run();
            }

            var visitor = new TextRuntimeVisitor();

            rulesEngine.Accept(visitor);

            Console.WriteLine(visitor);

            Assert.IsNotNull(_result);
            Assert.IsNotNull(_resultB);
        }
示例#19
0
 public void Setup()
 {
     _engine = RulesEngineFactory.New(x => { });
 }