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; } } }
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"); }