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); }
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); }
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(); }
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(); }
public void Setup() { _engine = RulesEngineFactory.New(x => { x.RegisterPropertySelector(new ValuePropertySelectorFactory()); x.Rule <NestedValueRule>(); x.Rule <NestedValueRule2>(); x.Rule <NullableIntRule>(); x.Rule <NullableIntRule2>(); }); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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); }
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)); }
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); } }
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); }
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); }
public void Setup() { _engine = RulesEngineFactory.New(x => { }); }