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)); }
/// <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); }
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); } } }
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")); }
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")); }
public void Cleanup() { sut = null; }