public void MergeTest() { List<DTRuleElement> testConditions = new List<DTRuleElement> (new DTRuleElement[] { new DTRuleElement { ElementId = Guid.NewGuid().ToString(), State = DTState.Yes }, new DTRuleElement { ElementId = Guid.NewGuid().ToString(), State = DTState.No }, new DTRuleElement { ElementId = Guid.NewGuid().ToString(), State = DTState.No }, new DTRuleElement { ElementId = Guid.NewGuid().ToString(), State = DTState.Yes }, new DTRuleElement { ElementId = Guid.NewGuid().ToString(), State = DTState.No }, new DTRuleElement { ElementId = Guid.NewGuid().ToString(), State = DTState.Yes }}); List<DTRuleElement> testActions = new List<DTRuleElement> (new DTRuleElement[] { new DTRuleElement { ElementId = Guid.NewGuid().ToString(), State = DTState.No }, new DTRuleElement { ElementId = Guid.NewGuid().ToString(), State = DTState.No }, new DTRuleElement { ElementId = Guid.NewGuid().ToString(), State = DTState.Yes }, new DTRuleElement { ElementId = Guid.NewGuid().ToString(), State = DTState.Yes }}); List<DTRuleElement> changedConditions = new List<DTRuleElement> (new DTRuleElement[] { new DTRuleElement { ElementId = testConditions[0].ElementId, State = testConditions[0].State }, new DTRuleElement { ElementId = testConditions[1].ElementId, State = DTState.Yes }, //Changed new DTRuleElement { ElementId = testConditions[2].ElementId, State = DTState.Yes }, //Changed new DTRuleElement { ElementId = testConditions[3].ElementId, State = testConditions[3].State }, new DTRuleElement { ElementId = testConditions[4].ElementId, State = DTState.Yes }, //Changed new DTRuleElement { ElementId = testConditions[5].ElementId, State = DTState.No }}); //Changed List<DTRuleElement> changedActions = new List<DTRuleElement> (new DTRuleElement[] { new DTRuleElement { ElementId = testActions[0].ElementId, State = testActions[0].State }, new DTRuleElement { ElementId = testActions[1].ElementId, State = DTState.Yes }, //Changed new DTRuleElement { ElementId = testActions[2].ElementId, State = DTState.No }, //Changed new DTRuleElement { ElementId = testActions[3].ElementId, State = testActions[3].State }}); int ruleIndex = 0; DTRule target = new DTRule(ruleIndex, testConditions, testActions); DTRule mergeRule = new DTRule(1, changedConditions, changedActions); target.Merge(mergeRule); //Conditions should be merged Assert.AreEqual(target.GetState(testConditions[0].ElementId), testConditions[0].State); Assert.AreEqual(target.GetState(testConditions[1].ElementId), DTState.Empty); Assert.AreEqual(target.GetState(testConditions[2].ElementId), DTState.Empty); Assert.AreEqual(target.GetState(testConditions[3].ElementId), testConditions[3].State); Assert.AreEqual(target.GetState(testConditions[4].ElementId), DTState.Empty); Assert.AreEqual(target.GetState(testConditions[5].ElementId), DTState.Empty); //Actions should not be merged Assert.AreEqual(target.GetState(changedActions[0].ElementId), testActions[0].State); Assert.AreEqual(target.GetState(changedActions[1].ElementId), testActions[1].State); Assert.AreEqual(target.GetState(changedActions[2].ElementId), testActions[2].State); Assert.AreEqual(target.GetState(changedActions[3].ElementId), testActions[3].State); }
public void GetStateTest() { int ruleIndex = 0; IEnumerable<DTRuleElement> conditions = ConditionRuleElements; IEnumerable<DTRuleElement> actions = ActionRuleElements; DTRule target = new DTRule(ruleIndex, conditions, actions); foreach (var condition in ConditionRuleElements) Assert.AreEqual(target.GetState(condition.ElementId), condition.State); foreach (var action in ActionRuleElements) Assert.AreEqual(target.GetState(action.ElementId), action.State); }