public void RuleSetIsValidIfRulesAreValid() { var rule = new Rule { Name = "First Rule", TopCondition = new LogicCondition { Operator = "all" } }; var action1 = new AssignAction { LeftHandSide = "Person.Salutation", Value = "Mr." }; var action2 = new AssignAction { LeftHandSide = "Person.Greeting", Value = "Hello" }; rule.AddAction(action1); rule.AddAction(action2); var rs = new RuleSet { Name = "Whatever" }; rs.AddInput("Person", typeof(TestPerson)); rs.AddRule(rule); Assert.IsTrue(rs.IsValid()); }
public void InvokingWithIncorrectWorkingMemoryThrowsAnException() { var rule = new Rule { Name = "First Rule", TopCondition = new LogicCondition { Operator = "all" } }; var action1 = new AssignAction { LeftHandSide = "Person.Salutation", Value = "Mr." }; rule.AddAction(action1); var rs = new RuleSet { Name = "Whatever" }; rs.AddInput("Person", typeof(TestPerson)); rs.AddRule(rule); IRuleEngine engine = WFRuleEngine.Compile(rs); Assert.Throws(typeof(InvalidWorkflowException), delegate { engine.Invoke(_workingMemory); }); }
private Rule CreateTestRule(ExpressionCondition condition, AssignAction action) { var rule = new Rule { Name = "Rule 1", TopCondition = new LogicCondition { Operator = "all" } }; rule.TopCondition.AddCondition(condition); rule.AddAction(action); return rule; }
private static Sequence CompileActions(Rule rule, Dictionary<string, Type> inputs) { var sequence = new Sequence(); foreach (var action in rule.Actions) { Activity activity; switch (action.GetType().Name) { case "AssignAction": activity = new Assign<string> { To = new OutArgument<string>(new VisualBasicReference<string>(action.LeftHandSide)), Value = new InArgument<string>(action.Value) }; break; default: throw new Exception("The action type '" + action.GetType().Name + "' has not been implemented"); } sequence.Activities.Add(activity); } return sequence; }
public void AddRule(Rule rule) { Rules.Add(rule); }
public void CanAddRulesToRuleSet() { var rs = new RuleSet { Name = "Whatever" }; var rule = new Rule { TopCondition = new LogicCondition { Operator = "all" } }; Assert.DoesNotThrow(delegate { rs.AddRule(rule); }); }