public void Execute_First_Null_Arg_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); Order order = new Order(); string error; engine.Execute(null, ref order, out error); }
internal void Execute(Activity activity, ActivityExecutionContext executionContext) { if (activity == null) { throw new ArgumentNullException("activity"); } Type thisType = activity.GetType(); RuleEngine cachedEngine = null; lock (this.syncLock) { if (((this.cachedEngine == null) || (this.cachedValidation == null)) || (this.cachedValidation.ThisType != thisType)) { RuleValidation validation = new RuleValidation(thisType, null); cachedEngine = new RuleEngine(this, validation, executionContext); this.cachedValidation = validation; this.cachedEngine = cachedEngine; } else { cachedEngine = this.cachedEngine; } } cachedEngine.Execute(activity, executionContext); }
public void Execute_Null_OrderItem_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); Order order = new Order(); string error; engine.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref order, out error); }
public void Execute_InValidRulePath_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); Order order = new Order() { Items = new List<OrderItem>() }; string error; Assert.IsTrue(engine.Execute( "test", ref order, out error)); }
public void Execute_Empty_Object_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); Order order = new Order() { Items = new List<OrderItem>() }; string error; Assert.IsTrue(engine.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref order, out error)); }
public void Execute(RuleExecution ruleExecution) { // we have no way of knowing if the ruleset has been changed, so no caching done if (ruleExecution == null) { throw new ArgumentNullException("ruleExecution"); } if (ruleExecution.Validation == null) { throw new ArgumentException(SR.GetString(SR.Error_MissingValidationProperty), "ruleExecution"); } RuleEngine engine = new RuleEngine(this, ruleExecution.Validation, ruleExecution.ActivityExecutionContext); engine.Execute(ruleExecution); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { XmlReader reader = new XmlTextReader(RuleFilePath); WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); RuleDefinitions ruleDef = (RuleDefinitions)serializer.Deserialize(reader); reader.Close(); // ルートアクティビティを取得 Activity root = this; while (root.Parent != null) root = root.Parent; for (int i = 0; i < ruleDef.RuleSets.Count; i++) { RuleSet myRuleSet = ruleDef.RuleSets[i]; RuleEngine ruleEng = new RuleEngine(myRuleSet, root.GetType()); ruleEng.Execute(root, executionContext); } return base.Execute(executionContext); }
public void Execute_InValidObjectForRule_Test() { RuleEngine<OrderItem> engine = new RuleEngine<OrderItem>(); OrderItem orderItem = new OrderItem(); string error; Assert.IsFalse(engine.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref orderItem, out error)); }
public void Execute_InValidRuleFile_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); Order order = new Order() { Items = new List<OrderItem>() }; string path = Environment.CurrentDirectory + "\\test.txt"; using (var stream = File.Create(path)) { stream.Close(); } string error; Assert.IsTrue(engine.Execute( path, ref order, out error)); }
public void Execute_CustomerMoreThan2_LessThan_890_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); var order = new Order { Id = 1, Customer = new Customer { RegisteredOnUtc = DateTime.UtcNow.AddYears(3) }, Items = new List<OrderItem>() }; order.Items.Add(new OrderItem { BasePricePerItem = 100, Quantity = 8, ItemType = ProductItemType.Apparel }); order.Items.Add(new OrderItem { BasePricePerItem = 90, Quantity = 1, ItemType = ProductItemType.Grocery }); string error; Assert.IsTrue(engine.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref order, out error)); Assert.AreEqual(order.TotalOrderDiscounts, 40D + 40D); }
public void Execute_Affiliate_LessThan_890_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); var order = new Order { Id = 1, Customer = new Customer (), Items = new List<OrderItem>(), AffiliateId = "AFF-10" }; order.Items.Add(new OrderItem { BasePricePerItem = 100, Quantity = 8, ItemType = ProductItemType.Apparel }); order.Items.Add(new OrderItem { BasePricePerItem = 90, Quantity = 1, ItemType = ProductItemType.Grocery }); string error; Assert.IsTrue(engine.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref order, out error)); Assert.AreEqual(order.TotalOrderDiscounts, 80D + 40D); }
public void Execute_EmployeeNoDiscountOnGrocery_LessThan_100_Test() { RuleEngine<Order> engine = new RuleEngine<Order>(); var order = new Order { Id = 1, Customer = new Customer { IsEmployee = true }, Items = new List<OrderItem>() }; order.Items.Add(new OrderItem { BasePricePerItem = 50, Quantity = 1, ItemType = ProductItemType.Grocery }); string error; Assert.IsTrue(engine.Execute( ConfigurationManager.AppSettings["RuleFilePath"], ref order, out error)); Assert.AreEqual(order.TotalOrderDiscounts, 0D); }
public void Execute(RuleExecution ruleExecution) { // we have no way of knowing if the ruleset has been changed, so no caching done if (ruleExecution == null) throw new ArgumentNullException("ruleExecution"); if (ruleExecution.Validation == null) throw new ArgumentException(SR.GetString(SR.Error_MissingValidationProperty), "ruleExecution"); RuleEngine engine = new RuleEngine(this, ruleExecution.Validation, ruleExecution.ActivityExecutionContext); engine.Execute(ruleExecution); }