Beispiel #1
0
        private void Cb_RuleTemplate_Checkchanged(object sender, RoutedEventArgs e)
        {
            CheckBox     checkBox     = sender as CheckBox;
            RuleTemplate curTemplate  = RuleTemplate.GetByName(checkBox.Content as string);
            Rule         selectedRule = Lv_RulesOverview.SelectedItem as Rule;

            if (curTemplate != null && selectedRule != null && checkBox.IsChecked != null)
            {
                bool hasTemplate = checkBox.IsChecked.Value;

                if (hasTemplate)
                {
                    selectedRule.Templates.Add(curTemplate);
                    selectedRule.CreateTemplateProperties();
                }
                else
                {
                    foreach (string prop in curTemplate.RequiredProperties.Keys)
                    {
                        selectedRule.Properties.Remove(prop);
                    }
                    selectedRule.Templates.Remove(curTemplate);
                }
            }
            StoreChanged = true;
            UpdateLists();
        }
Beispiel #2
0
        public void TestSingleValidation()
        {
            RuleTemplate basicRuleTemplate = RuleTemplate.GetByName("TestTemplate");
            //#1: Invalid because required prop is not present
            Rule inValidRule1 = new Rule(basicRuleTemplate);
            //#2: Invalid because required prop is null
            Rule inValidRule2 = new Rule(basicRuleTemplate);

            inValidRule2.Properties.Add("TestKey", null);
            //#3 Invalid because required prop is wrong type
            Rule inValidRule3 = new Rule(basicRuleTemplate);

            inValidRule3.Properties.Add("TestKey", 1.1);

            //Valid because required prop is set and is of the right type
            Rule validRule = new Rule(basicRuleTemplate);

            validRule.Properties.Add("test", null);
            validRule.Properties.Add("TestKey", 1);

            Assert.IsFalse(inValidRule1.IsValid);
            Assert.IsFalse(inValidRule2.IsValid);
            Assert.IsFalse(inValidRule3.IsValid);
            Assert.IsTrue(validRule.IsValid);
        }
Beispiel #3
0
        public void TestTemplateGetByName()
        {
            RuleTemplate foundTemplate = RuleTemplate.GetByName("bAsIc");
            Rule         rule          = new Rule(foundTemplate);

            Assert.IsTrue(rule.RuleTypeNames.Contains("Basic"));
        }
Beispiel #4
0
        public void TestRuleStore()
        {
            string fileLoc      = "Unittest.json";
            string key          = "password123";
            string templateName = "Empty";
            string saveKey      = "testKey";
            string saveValue    = "testVal";

            if (File.Exists(fileLoc))
            {
                File.Delete(fileLoc);
            }

            RuleStore newStore = RuleStore.Create(fileLoc, key);

            newStore.Rules.Add(
                new Rule(RuleTemplate.GetByName(templateName))
            {
                Properties = new Dictionary <string, object>()
                {
                    { saveKey, saveValue },
                    { "key2", 1 }
                }
            });

            newStore.WriteToDisc();

            var readStore = RuleStore.Open(fileLoc, key);

            Assert.AreEqual(saveValue, readStore.Rules.First().Properties[saveKey]);
            Assert.IsTrue(readStore.Rules.First().Templates.First().Name == templateName);

            File.Delete(fileLoc);
        }
Beispiel #5
0
        public void TestMultipleValidation()
        {
            //Tests case insensitivity and duplicate template detection
            Rule multipleTemplateTest = new Rule(
                RuleTemplate.GetByName("TestTemplate"),
                RuleTemplate.GetByName("ApplicaTION"),
                RuleTemplate.GetByName("tESTteMPLATE"));

            multipleTemplateTest.Properties.Add("TestKey", 1);

            //The rule is not complete and should be invalid (!IsValid)
            Assert.IsFalse(multipleTemplateTest.IsValid);

            //After this change the rule should be valid
            multipleTemplateTest.Properties.Add("Application", "testApplication");
            Assert.IsTrue(multipleTemplateTest.IsValid);
        }
Beispiel #6
0
        public void TestRuleTemplateStore()
        {
            string fileLoc = "Unittest.json";
            string key     = "password123";

            if (File.Exists(fileLoc))
            {
                File.Delete(fileLoc);
            }

            RuleStore newStore = RuleStore.Create(fileLoc, key);
            Rule      rule     = new Rule(RuleTemplate.GetByName("Basic"), RuleTemplate.GetByName("Application"));

            newStore.Rules.Add(rule);
            newStore.WriteToDisc();

            var readStore = RuleStore.Open(fileLoc, key);

            Assert.IsTrue(readStore.Rules.First().Templates.Count() == 2);
            Assert.IsTrue(readStore.Rules.First().Templates.FirstOrDefault(rt => rt.Name == "Basic") != null);
            Assert.IsTrue(readStore.Rules.First().Templates.FirstOrDefault(rt => rt.Name == "Application") != null);

            File.Delete(fileLoc);
        }