Ejemplo n.º 1
0
        public string ProcessOrder()
        {
            var ruleType = typeof(IPaymentRule);
            IEnumerable <IPaymentRule> rules = ruleType.Assembly.GetTypes()
                                               .Where(p => ruleType.IsAssignableFrom(p) && !p.IsInterface)
                                               .Select(r => Activator.CreateInstance(r) as IPaymentRule);

            var engine = new PaymentRuleEngine(rules);

            return(engine.ProcessingRules(payments));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Call the engine to switch to sepcific rule
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        public void DoPayment <T>(T item)
        {
            // Ref - https://garywoodfine.com/get-c-classes-implementing-interface/

            var ruleType = typeof(IPaymentRule);
            IEnumerable <IPaymentRule> rules = this.GetType().Assembly.GetTypes()
                                               .Where(x => ruleType.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract)
                                               .Select(r => Activator.CreateInstance(r) as IPaymentRule);

            var paymentRuleEngine = new PaymentRuleEngine(rules);

            paymentRuleEngine.DoPayment(item);
        }
Ejemplo n.º 3
0
        private void LoadTemperoryRuleEngine(ICacheProvider cacheProvider)
        {
            _RuleEngine = PaymentRuleEngine.Engine(cacheProvider);

            _RuleEngine.Rules.Clear();
            var rules = _PaymentRuleService.GetAllInclude(p => p.Criterias, p => p.Actions);

            if (rules != null)
            {
                foreach (var item in rules)
                {
                    _RuleEngine.Rules.Add(item);
                }
            }
        }
Ejemplo n.º 4
0
        public void TestGenerateComission()
        {
            //Data Set Up
            PaymentInfo payment = new PaymentInfo()
            {
                PaymentType = "Book", CustomerId = 100, OrderId = 10, PaymentId = 101
            };
            PaymentRuleEngine pr = new PaymentRuleEngine();

            //Execute
            var result = pr.ProcessPayment(payment);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Contains("CommisionGenerated"));
        }
Ejemplo n.º 5
0
        public void TestMembershipActivation()
        {
            //Data Set Up
            PaymentInfo payment = new PaymentInfo()
            {
                PaymentType = "Membership", CustomerId = 100, OrderId = 10, PaymentId = 101
            };
            PaymentRuleEngine pr = new PaymentRuleEngine();

            //Execute
            var result = pr.ProcessPayment(payment);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Contains("MembershipActivated"));
        }
Ejemplo n.º 6
0
 public void Cleanup()
 {
     sut = null;
 }