Exemplo n.º 1
0
        public void TestValidationManyRulesOneCondition()
        {
            var          container   = GetConfiguredContainer();
            IRuleManager ruleManager = container.Resolve <IRuleManager>();

            // Rule created to Item 1
            RuleDefinition rule_1 = new RuleDefinition(null, null, 1, "My Rule 1");

            ruleManager.AddRule(rule_1);

            RuleConditionDefinition condition_1 = new RuleConditionDefinition(null, "Division", "=", "BTL", rule_1.Id);

            ruleManager.AddCondition(condition_1);

            RuleDefinition rule_2 = new RuleDefinition(null, null, 1, "My Rule 2");

            ruleManager.AddRule(rule_2);

            RuleConditionDefinition condition_2 = new RuleConditionDefinition(null, "Entity", "=", "ENT_1", rule_2.Id);

            ruleManager.AddCondition(condition_2);

            MyDummyDtObject myDummyDtObject = new MyDummyDtObject();
            RuleContext     ruleContext     = new RuleContext(myDummyDtObject, RuleConstants.EmptyRuleConstants);

            //The division and entity field are null here
            bool isValid = ruleManager.IsRuleValid(1, ruleContext);

            //The rule should NOT be valid here.
            Assert.IsFalse(isValid);

            //The division is set to "BTL" here
            myDummyDtObject.Division = "BTL";
            ruleContext = new RuleContext(myDummyDtObject, RuleConstants.EmptyRuleConstants);
            //The rule should be valid as it match 1 rule
            isValid = ruleManager.IsRuleValid(1, ruleContext);
            Assert.IsTrue(isValid);

            //The entity is set to "ENT_1" here
            myDummyDtObject.Entity = "ENT_1";
            ruleContext            = new RuleContext(myDummyDtObject, RuleConstants.EmptyRuleConstants);
            //The rule should be valid now (2 rules valid)
            isValid = ruleManager.IsRuleValid(1, ruleContext);
            Assert.IsTrue(isValid);

            //The division is set to "UNKNOWN_ENT" here
            myDummyDtObject.Entity   = "UNKNOWN_ENT";
            myDummyDtObject.Division = "DIV";
            ruleContext = new RuleContext(myDummyDtObject, RuleConstants.EmptyRuleConstants);
            //The rule should NOT be valid anymore
            isValid = ruleManager.IsRuleValid(1, ruleContext);
            Assert.IsFalse(isValid);
        }
Exemplo n.º 2
0
        public void TestValidationOneRuleOneCondition()
        {
            var          container   = GetConfiguredContainer();
            IRuleManager ruleManager = container.Resolve <IRuleManager>();

            // Rule created to Item 1
            RuleDefinition rule = new RuleDefinition(null, null, 1, "My Rule 1");

            ruleManager.AddRule(rule);

            RuleConditionDefinition condition = new RuleConditionDefinition(null, "Division", "=", "BTL", rule.Id);

            ruleManager.AddCondition(condition);

            MyDummyDtObject myDummyDtObject = new MyDummyDtObject();
            RuleContext     ruleContext     = new RuleContext(myDummyDtObject, RuleConstants.EmptyRuleConstants);

            //The division field is null here
            bool isValid = ruleManager.IsRuleValid(1, ruleContext);

            //The rule should NOT be valid here.
            Assert.IsFalse(isValid);

            //The division is set to "BTL" here
            myDummyDtObject.Division = "BTL";
            ruleContext = new RuleContext(myDummyDtObject, RuleConstants.EmptyRuleConstants);
            //The rule should be valid now
            isValid = ruleManager.IsRuleValid(1, ruleContext);
            Assert.IsTrue(isValid);
        }
Exemplo n.º 3
0
        public void AddRule(WfActivityDefinition wfActivity, RuleDefinition ruleDefinition, List <RuleConditionDefinition> conditions)
        {
            Debug.Assert(wfActivity != null);
            Debug.Assert(ruleDefinition != null);
            Debug.Assert(conditions != null);
            // --
            ruleDefinition.ItemId = wfActivity.WfadId;
            _ruleManager.AddRule(ruleDefinition);

            foreach (RuleConditionDefinition ruleConditionDefinition in conditions)
            {
                ruleConditionDefinition.RudId = ruleDefinition.Id;
                _ruleManager.AddCondition(ruleConditionDefinition);
            }
        }