public ActivityRuleModel(ActivityRule rule) : this() { Id = rule.Id; Type = rule.Type; EventType = rule.EventType; CreatedAtUtc = rule.CreatedAtUtc; Conditions = rule.Conditions.ToList(); Branches.Add(new ActivityRuleBranchModel { RuleId = Id, Branch = RuleBranch.Then, AttachedActivities = rule.ThenActivityInfos.Select(x => new AttachedActivityModel(x)).ToList() }); if (rule.Type == RuleType.Normal) { Branches.Add(new ActivityRuleBranchModel { RuleId = Id, Branch = RuleBranch.Else, AttachedActivities = rule.ElseActivityInfos.Select(x => new AttachedActivityModel(x)).ToList() }); } }
public void Can_Evaluate_Expression_With_FuncCondition() { var order = new Order { Price = 10, Message = "Something" }; var condition = new FuncCondition<Order>(o => o.Price < 20); var rule = new ActivityRule(condition, new ActionActivity<Order>(t => { t.Message = "amp"; })); Assert.IsTrue(rule.Evaluate(order)); Assert.AreEqual("amp", order.Message); }
public void Can_Evaluate_Expression_As_ActionActivityRule() { var statement = "return (this.Price > 20 or this.Price < 15)"; var order = new Order { Price = 10, Message = "Soemthing" }; EvaluatorAccessPoint.DslConditionEvaluator = evaluator; var condition = new DslCondition { DslStatement = statement }; var rule = new ActivityRule(condition, new ActionActivity<Order>(t => { t.Message = "amp"; })); Assert.IsTrue(rule.Evaluate(order)); Assert.AreEqual("amp", order.Message); }
public void Can_Evaluate_Expression_With_FuncCondition() { var order = new Order { Price = 10, Message = "Something" }; var condition = new FuncCondition <Order>(o => o.Price < 20); var rule = new ActivityRule(condition, new ActionActivity <Order>(t => { t.Message = "amp"; })); Assert.IsTrue(rule.Evaluate(order)); Assert.AreEqual("amp", order.Message); }
public ActivityModel(IActivity activity, ActivityRule rule, AttachedActivityInfo attachedActivityInfo) { Name = activity.Name; DisplayName = activity.DisplayName; AllowAsyncExecution = activity.AllowAsyncExecution; if (activity is IHasCustomActivityParameterEditor) { EditorVirtualPath = ((IHasCustomActivityParameterEditor)activity).GetEditorVirtualPath(rule, attachedActivityInfo); } else if (activity.Parameters != null && activity.Parameters.Any()) { EditorVirtualPath = "~/Areas/Commerce/Views/Activity/_DefaultParameterEditor.cshtml"; } }
public void TestMethod1() { var order = new Order() { TotalPrice = 200, Discount = 0 }; EvaluatorAccessPoint.DslConditionEvaluator = new RubyEvaluator.RubyEvaluator(); var businessRule = "(this.TotalPrice > 100)"; var businessAction = @"this.Discount = 10"; var condition = new DslCondition { DslStatement = businessRule }; var rule = new ActivityRule(condition, new DslActivity { DslStatement = businessAction }); bool res = rule.Evaluate(order); Assert.AreEqual(res, true); }
public void Can_Evaluate_Expression_With_DslActivity() { var statement = "return (this.Price > 20 or this.Price < 15)"; var order = new Order { Price = 10, Message = "Something" }; EvaluatorAccessPoint.DslConditionEvaluator = evaluator; var condition = new DslCondition { DslStatement = statement }; var rule = new ActivityRule(condition, new DslActivity { DslStatement = @" this.Message = ""dsl""; return true;" }); Assert.IsTrue(rule.Evaluate(order)); Assert.AreEqual("dsl", order.Message); }
public void Can_Evaluate_Expression_As_ActionActivityRule() { var statement = "return (this.Price > 20 or this.Price < 15)"; var order = new Order { Price = 10, Message = "Soemthing" }; EvaluatorAccessPoint.DslConditionEvaluator = evaluator; var condition = new DslCondition { DslStatement = statement }; var rule = new ActivityRule(condition, new ActionActivity <Order>(t => { t.Message = "amp"; })); Assert.IsTrue(rule.Evaluate(order)); Assert.AreEqual("amp", order.Message); }
public ActivityContext(ActivityRule rule, AttachedActivityInfo attachedActivityInfo, bool isAsyncExecution) { Rule = rule; AttachedActivityInfo = attachedActivityInfo; IsAsyncExecution = isAsyncExecution; }
public ActivityDetached(ActivityRule rule, AttachedActivityInfo activity) { Rule = rule; Activity = activity; }