Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
        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();
            }
        }