예제 #1
0
        public static void ApplyInitialFlows(ProvisionRule rule, CSEntry csentry, MVEntry mventry)
        {
            if (rule.InitialFlows == null)
            {
                return;
            }

            foreach (var initialFlow in rule.InitialFlows)
            {
                RuleEval.Execute(initialFlow, mventry, csentry);
            }
        }
예제 #2
0
        public static bool PassesCondition(ProvisionRule rule, MVEntry entry)
        {
            if (entry.ObjectType != rule.SourceObject)
            {
                return(false);
            }

            if (rule.RuleType == RuleType.Python)
            {
                var func = Core.GetProvisionFunction(rule.Name);
                return(func(entry));
            }

            throw new NotImplementedException();
        }
예제 #3
0
        public void ProvRules_python_rules_generate_condition_funcs()
        {
            var provRule = new SimpleMIM.ProvisionExt.ProvisionRule()
            {
                Name         = "nana",
                RuleType     = RuleType.Python,
                Agent        = "TestAgent",
                Condition    = "entry['FirstName'].Value == per",
                SourceObject = "person",
                TargetObject = "HRMUser"
            };

            string script = FuncCreator.GenerateFunction(provRule.Name, "entry", provRule.Condition);

            Core.RegisterProvisionScript(script);
            var func = Core.GetProvisionFunction(provRule.Name);

            Assert.IsNotNull(func);
        }
예제 #4
0
        public void ProvRules_handles_condition()
        {
            var provRule = new SimpleMIM.ProvisionExt.ProvisionRule()
            {
                Name         = "nunu",
                RuleType     = RuleType.Python,
                Agent        = "TestAgent",
                Condition    = "entry['FirstName'].Value == 'per'",
                SourceObject = "person",
                TargetObject = "HRMUser",
                InitialFlows = new[] { new FlowRule()
                                       {
                                           Name = "UpperCaser"
                                       } }
            };

            var flowRules = new FileFlowRuleRepo("Samples\\pyFlowRules.json").GetAllRules();

            RuleFactory.SetRules(new List <ProvisionRule>()
            {
                provRule
            }, flowRules);

            string script = FuncCreator.GenerateFunction(provRule.Name, "entry", provRule.Condition);

            Core.RegisterProvisionScript(script);
            var func = Core.GetProvisionFunction(provRule.Name);

            Assert.IsNotNull(func);

            var mventry = new MockMventry("person");

            mventry["FirstName"].Value = "per";

            Assert.IsTrue(ProvisionEval.PassesCondition(provRule, mventry));

            var mventryInvalid = new MockMventry("person");

            mventryInvalid["FirstName"].Value = "sitrus";

            Assert.IsFalse(ProvisionEval.PassesCondition(provRule, mventryInvalid));
        }
예제 #5
0
        public void ProvRules_initialflows_are_set()
        {
            var provRule = new SimpleMIM.ProvisionExt.ProvisionRule()
            {
                Name         = "nunu",
                RuleType     = RuleType.Python,
                Agent        = "TestAgent",
                Condition    = "entry['FirstName'].Value == per",
                SourceObject = "person",
                TargetObject = "HRMUser",
                InitialFlows = new [] { new FlowRule()
                                        {
                                            Name = "UpperCaser"
                                        } }
            };

            var flowRules = new FileFlowRuleRepo("Samples\\pyFlowRules.json").GetAllRules();

            RuleFactory.SetRules(new List <ProvisionRule>()
            {
                provRule
            }, flowRules);

            string script = FuncCreator.GenerateFunction(provRule.Name, "entry", provRule.Condition);

            Core.RegisterProvisionScript(script);
            var func = Core.GetProvisionFunction(provRule.Name);

            Assert.IsNotNull(func);

            var mventry = new MockMventry();

            mventry["FirstName"].Value = "Espen";
            mventry["LastName"].Value  = "Askeladd";

            var csentry = new MockCsentry();

            ProvisionEval.ApplyInitialFlows(provRule, csentry, mventry);

            Assert.AreEqual("ESPEN ASKELADD", csentry["DisplayName"].Value);
        }