public void Setup() { _called = null; var configurator = new RuntimeConfiguratorImpl(); var productionNode = new DelegateProductionNode <A>(16, (session, x) => _called = x); var constantNode = new ConstantNode <A>(42); var joinNode = configurator.CreateNode(id => new JoinNode <A>(id, constantNode)); var constantNode2 = new ConstantNode <A>(27); var joinNode2 = configurator.CreateNode(id => new JoinNode <A>(id, constantNode2)); joinNode2.AddActivation(productionNode); joinNode.AddActivation(joinNode2); var engine = new OdoyuleRulesEngine(configurator); AlphaNode <A> alphaNode = engine.GetAlphaNode <A>(); alphaNode.AddActivation(joinNode); using (StatefulSession session = engine.CreateSession()) { session.Add(new A()); session.Run(); } }
public void FirstTestName() { var engine = new MagnumRulesEngine(); RuleDeclaration rule = CreateOnlineOrderRule(); engine.Add(rule); rule = CreateCustomerExistsRule(); engine.Add(rule); rule = CreateActiveNotPreferredRule(); engine.Add(rule); rule = CreatePreferredRule(); engine.Add(rule); var visitor = new StringNodeVisitor(); engine.Visit(visitor); Trace.WriteLine(visitor.Result); using (StatefulSession session = engine.CreateSession()) { session.Assert(CurrentOrder); session.Run(); } }
public void Should_be_able_to_add_pure_expressions_as_well_for_ease() { RuleSet ruleSet = Rule.Declare <OrderSubmitted>(rule => { rule.Then(x => Trace.WriteLine("Order Amount: " + x.Object.Amount)); rule.When(x => x.Amount > 100.00m) .Then(x => Trace.WriteLine("Order is over the limit")) .Then(x => x.RequestApproval()); rule.When(x => x.Amount > 1000m) .Then(x => x.RequestClearance()); }); // RuleSet ruleSet2 = Rule.Declare<OrderSubmitted>(rule => // { // rule.When(x => x.Amount > 100.00m) // .Then(x => Trace.WriteLine("BING")); // }); _engine.Add(ruleSet); // _engine.Add(ruleSet2); using (StatefulSession session = _engine.CreateSession()) { session.Assert(new OrderSubmitted { Amount = 123.45m }); session.Run(); } }
public void Should_match_a_list_with_two_items() { _results.Clear(); using (StatefulSession session = _engine.CreateSession()) { session.Add(new Order { Lines = new List <OrderLine> { new OrderLine { ItemNumber = "123" }, new OrderLine { ItemNumber = "123" } } }); session.Run(); } Assert.AreEqual(2, _results.Count); Assert.AreEqual(0, _results[0].Item2); Assert.AreEqual(1, _results[1].Item2); }
public void Should_be_able_to_create_a_session() { using (StatefulSession session = _engine.CreateSession()) { session.Add(new A()); session.Run(); } }
public void Should_not_match_null_values() { _result = null; using (StatefulSession session = _engine.CreateSession()) { session.Add(new Order()); session.Run(); } Assert.IsNull(_result); }
public void Should_not_match_or_crash_on_null_reference_types() { _result = null; using (StatefulSession session = _engine.CreateSession()) { session.Add(new Order()); session.Run(); } Assert.IsNull(_result); }
public void Should_match_not_null_references() { _result = null; using (StatefulSession session = _engine.CreateSession()) { session.Add(new Order { Customer = new Account() }); session.Run(); } Assert.IsNotNull(_result); }
public void Should_match_equal_values() { _result = null; using (StatefulSession session = _engine.CreateSession()) { session.Add(new Order { Name = "JOE" }); session.Run(); } Assert.IsNotNull(_result); }
public void Should_match_less_than_values() { _result = null; using (StatefulSession session = _engine.CreateSession()) { session.Add(new Order { Amount = 9999.9m }); session.Run(); } Assert.IsNotNull(_result); }
public void Should_not_match_an_empty_list() { _results.Clear(); using (StatefulSession session = _engine.CreateSession()) { session.Add(new Order { Lines = new List <OrderLine> { } }); session.Run(); } Assert.AreEqual(0, _results.Count); }
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 Should_not_match_inequal_values() { _result = null; using (StatefulSession session = _engine.CreateSession()) { session.Add(new Order { Customer = new Account { ContactName = "BOB" } }); session.Run(); } Assert.IsNull(_result); }
public void Should_match_the_alpha_node() { _result = null; using (StatefulSession session = _engine.CreateSession()) { session.Add(new Order { OrderId = "123", Amount = 10001.0m }); session.Run(); List <FactHandle <Violation> > violations = session.Facts <Violation>().ToList(); Assert.AreEqual(1, violations.Count); Assert.IsNotNull(_result); Assert.AreEqual("123", _result.Value); } }
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 Should_be_able_to_add_them_into_a_set_of_rules() { RuleSet ruleSet = Rule.Declare <OrderSubmitted>(rule => { rule.Then <LogOrderDetails>(); rule.When <OrderAmountIsOverLimit>() .Then <RequestOrderApproval>(); }); _engine.Add(ruleSet); using (StatefulSession session = _engine.CreateSession()) { session.Assert(new OrderSubmitted { Amount = 123.45m }); session.Run(); } }
public void Setup() { _called = null; var configurator = new RuntimeConfiguratorImpl(); var engine = configurator.RulesEngine; PropertyNode <A, decimal> propertyNode = configurator.Property <A, decimal>(x => x.Amount); ConditionNode <Token <A, decimal> > conditionNode = configurator.Condition <A, decimal>(x => x > 10000.0m); propertyNode.AddActivation(conditionNode); AlphaNode <Token <A, decimal> > edgeAlpha = configurator.Alpha <A, decimal>(); conditionNode.AddActivation(edgeAlpha); AlphaNode <A> alphaNode = configurator.GetAlphaNode <A>(); alphaNode.AddActivation(propertyNode); JoinNode <A> joinNode = configurator.Join(alphaNode); DelegateProductionNode <A> productionNode = configurator.Delegate <A>((session, x) => _called = x); joinNode.AddActivation(productionNode); LeftJoinNode <A, decimal> leftNode = configurator.Left <A, decimal>(alphaNode); leftNode.AddActivation(joinNode); edgeAlpha.AddActivation(leftNode); using (StatefulSession session = engine.CreateSession()) { session.Add(new A(10001.0m)); session.Run(); } }
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(); } var visitor = new TextRuntimeModelVisitor(); 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 (StatefulSession session = rulesEngine.CreateSession()) { session.Add(new Order { Name = "JOE", Amount = 10001.0m }); session.Run(); } var visitor = new TextRuntimeModelVisitor(); rulesEngine.Accept(visitor); Console.WriteLine(visitor); Assert.IsNotNull(_result); Assert.IsNotNull(_resultB); }