Example #1
0
        public void OrRule_Tests() {
            var order1 = new Order(id: "123-456-111", value: 10, state: State.Closed, total: 100.0m, paymentMethod: PaymentMethod.CreditCard);
            var order2 = new Order(id: "123-456-222", value: 10, state: State.Open, total: 100.0m, paymentMethod: PaymentMethod.CreditCard);

            Rule rule1 = new GreaterThanRule() { Value = 30 };
            Rule rule2 = new OrderClosedRule();

            var rules = new[] { rule1, rule2 };

            var orRule = new OrRule();
            orRule.AddRules(rules);

            Assert.AreEqual(orRule.Evaluate(order1), true);
            Assert.AreEqual(orRule.Evaluate(order2), false);
        }
Example #2
0
        public void GreaterThanRule_And_OrderClosedRule_Tests() {
            var order = new Order(id: "123-456-111", value: 50, state: State.Closed, total: 100.0m, paymentMethod: PaymentMethod.CreditCard);

            Rule rule1 = new GreaterThanRule() { Value = 30 };
            Rule rule2 = new OrderClosedRule();

            Assert.AreEqual(rule1.Evaluate(order), true);
            Assert.AreEqual(rule2.Evaluate(order), true);

            order.State = State.Open;
            order.Value = 1;

            Assert.AreEqual(rule1.Evaluate(order), false);
            Assert.AreEqual(rule2.Evaluate(order), false);
        }
Example #3
0
        public void CriticalMassRule_Tests() {
            var order1 = new Order(id: "123-456-111", value: 50, state: State.Closed, total: 100.0m, paymentMethod: PaymentMethod.CreditCard);
            var order2 = new Order(id: "123-456-222", value: 10, state: State.Closed, total: 100.0m, paymentMethod: PaymentMethod.CreditCard);
            var order3 = new Order(id: "123-456-333", value: 10, state: State.Open, total: 100.0m, paymentMethod: PaymentMethod.CreditCard);

            Rule rule1 = new GreaterThanRule() { Value = 30 };
            Rule rule2 = new OrderClosedRule();

            var rules = new[] { rule1, rule2 };

            var massRules = new CriticalMassRule(minimunRulesCount: 1);
            massRules.AddRules(rules);

            Assert.AreEqual(massRules.Evaluate(order1), true);
            Assert.AreEqual(massRules.Evaluate(order2), true);
            Assert.AreEqual(massRules.Evaluate(order3), false);

            massRules = new CriticalMassRule(minimunRulesCount: 2);
            massRules.AddRules(rules);

            Assert.AreEqual(massRules.Evaluate(order1), true);
            Assert.AreEqual(massRules.Evaluate(order2), false);
            Assert.AreEqual(massRules.Evaluate(order3), false);
        }