Example #1
0
        public void TestTryLoadExistingRulesList()
        {
            DirectoryInfo   di = new DirectoryInfo(rulesFolder);
            RulesRepository rr = new RulesRepository("testRules", di);

            string ruleListFile = string.Format("{0}{1}{2}.rul", rulesFolder, Path.DirectorySeparatorChar, rr.Name);

            if (!File.Exists(ruleListFile))
            {
                rr.TryLoadNewRulesList();
                rr.TrySaveRulesList();
                if (!File.Exists(ruleListFile))
                {
                    Assert.Fail("Can not run test TestTryLoadExistingRulesList.  No existing rule file was found, and a new one could not be created");
                }
            }

            rr.TryLoadExistingRulesList();
            Assert.AreEqual(2, rr.MyRules.Count, "Invalid number of Rules loaded by TryLoadRulesList");
            foreach (Rule currentRule in rr.MyRules.Values)
            {
                switch (currentRule.FriendlyName)
                {
                case "SetValue":
                case "IncrementValue":
                    break;

                default:
                    Assert.Fail("Unexpected rule file loaded from the Repository.");
                    break;
                }
            }
        }
Example #2
0
        public void TestTrySaveRulesList()
        {
            DirectoryInfo   di = new DirectoryInfo(rulesFolder);
            RulesRepository rr = new RulesRepository("testRules", di);

            string ruleListFile = string.Format("{0}{1}{2}.rul", rulesFolder, Path.DirectorySeparatorChar, rr.Name);

            if (File.Exists(ruleListFile))
            {
                File.SetAttributes(ruleListFile, FileAttributes.Normal);
                File.Delete(ruleListFile);
            }

            //Load a new rule list so that we have something to save.
            rr.TryLoadNewRulesList();
            rr.TrySaveRulesList();
            Assert.IsTrue(File.Exists(ruleListFile), "TrySaveRulesList failed to create the rule file");
        }
Example #3
0
        public void TestProcessRule()
        {
            DirectoryInfo   di = new DirectoryInfo(rulesFolder);
            RulesRepository rr = new RulesRepository("testRules", di);

            //Load a new rule list so that we have rules to execute.
            rr.TryLoadNewRulesList();

            TestClass tc = new TestClass();
            Dictionary <string, object> contextObjects = new Dictionary <string, object>();

            contextObjects.Add("TestObject", tc);

            IBRERuleResult ruleResult;

            rr.ProcessRule("SetValue", contextObjects, out ruleResult);

            Assert.AreEqual(5, tc.MyValue, "The rule processed, but did not correctly set the value on the test object");
        }
Example #4
0
        public void TestTryLoadNewRulesList()
        {
            DirectoryInfo   di = new DirectoryInfo(rulesFolder);
            RulesRepository rr = new RulesRepository("testRules", di);

            rr.TryLoadNewRulesList();
            Assert.AreEqual(2, rr.MyRules.Count, "Invalid number of Rules loaded by TryLoadRulesList");
            foreach (Rule currentRule in rr.MyRules.Values)
            {
                switch (currentRule.FriendlyName)
                {
                case "SetValue":
                case "IncrementValue":
                    break;

                default:
                    Assert.Fail("Unexpected rule file loaded from the Repository.");
                    break;
                }
            }
        }
Example #5
0
        public void TestProcessRule()
        {
            DirectoryInfo di = new DirectoryInfo(rulesFolder);
            RulesRepository rr = new RulesRepository("testRules", di);

            //Load a new rule list so that we have rules to execute.
            rr.TryLoadNewRulesList();

            TestClass tc = new TestClass();
            Dictionary<string, object> contextObjects = new Dictionary<string, object>();
            contextObjects.Add("TestObject", tc);

            IBRERuleResult ruleResult;
            rr.ProcessRule("SetValue", contextObjects, out ruleResult);

            Assert.AreEqual(5, tc.MyValue, "The rule processed, but did not correctly set the value on the test object");
        }
Example #6
0
        public void TestTrySaveRulesList()
        {
            DirectoryInfo di = new DirectoryInfo(rulesFolder);
            RulesRepository rr = new RulesRepository("testRules", di);

            string ruleListFile = string.Format("{0}{1}{2}.rul", rulesFolder, Path.DirectorySeparatorChar, rr.Name);
            if (File.Exists(ruleListFile))
            {
                File.SetAttributes(ruleListFile, FileAttributes.Normal);
                File.Delete(ruleListFile);
            }

            //Load a new rule list so that we have something to save.
            rr.TryLoadNewRulesList();
            rr.TrySaveRulesList();
            Assert.IsTrue(File.Exists(ruleListFile), "TrySaveRulesList failed to create the rule file");
        }
Example #7
0
        public void TestTryLoadNewRulesList()
        {
            DirectoryInfo di = new DirectoryInfo(rulesFolder);
            RulesRepository rr = new RulesRepository("testRules", di);

            rr.TryLoadNewRulesList();
            Assert.AreEqual(2, rr.MyRules.Count, "Invalid number of Rules loaded by TryLoadRulesList");
            foreach (Rule currentRule in rr.MyRules.Values)
            {
                switch (currentRule.FriendlyName)
                {
                    case "SetValue":
                    case "IncrementValue":
                        break;
                    default:
                        Assert.Fail("Unexpected rule file loaded from the Repository.");
                        break;
                }
            }
        }
Example #8
0
        public void TestTryLoadExistingRulesList()
        {
            DirectoryInfo di = new DirectoryInfo(rulesFolder);
            RulesRepository rr = new RulesRepository("testRules", di);

            string ruleListFile = string.Format("{0}{1}{2}.rul", rulesFolder, Path.DirectorySeparatorChar, rr.Name);
            if (!File.Exists(ruleListFile))
            {
                rr.TryLoadNewRulesList();
                rr.TrySaveRulesList();
                if (!File.Exists(ruleListFile))
                {
                    Assert.Fail("Can not run test TestTryLoadExistingRulesList.  No existing rule file was found, and a new one could not be created");
                }
            }

            rr.TryLoadExistingRulesList();
            Assert.AreEqual(2, rr.MyRules.Count, "Invalid number of Rules loaded by TryLoadRulesList");
            foreach (Rule currentRule in rr.MyRules.Values)
            {
                switch (currentRule.FriendlyName)
                {
                    case "SetValue":
                    case "IncrementValue":
                        break;
                    default:
                        Assert.Fail("Unexpected rule file loaded from the Repository.");
                        break;
                }
            }
        }