Exemple #1
0
        public void HasShouldReturnTrueForRulesPresentAndFalseForRulesNotPresent()
        {
            StringBuilder bldr = new StringBuilder();

            bldr.Append(@"<?xml version=""1.0"" encoding=""utf-8"" ?>");
            bldr.Append("<rules>");
            bldr.Append(@"<rule type=""JDT.Calidus.CommonTest.Rules.UnCreatableRule, JDT.Calidus.CommonTest"">");
            bldr.Append("<description>");
            bldr.Append("Description text");
            bldr.Append("</description>");
            bldr.Append("<params>");
            bldr.Append(@"<param name=""param1"" type=""String"">");
            bldr.Append("theValue1");
            bldr.Append(@"</param>");
            bldr.Append(@"<param name=""param2"" type=""String"">");
            bldr.Append("theValue2");
            bldr.Append(@"</param>");
            bldr.Append("</params>");
            bldr.Append("</rule>");
            bldr.Append("</rules>");

            Stream    stream = new MemoryStream(Encoding.Default.GetBytes(bldr.ToString()));
            XmlReader reader = new XmlTextReader(stream);

            FileRuleConfigurationFactory builder = new FileRuleConfigurationFactoryImpl(reader);

            Assert.IsTrue(builder.Has(typeof(UnCreatableRule)));
            Assert.IsFalse(builder.Has(typeof(String)));
        }
Exemple #2
0
        public void RuleTypeDeclarationOfInvalidRuleTypeShouldThrowException()
        {
            StringBuilder bldr = new StringBuilder();

            bldr.Append(@"<?xml version=""1.0"" encoding=""utf-8"" ?>");
            bldr.Append("<rules>");
            bldr.Append(@"<rule type=""NonExistingRule, JDT.Calidus.CommonTest"">");
            bldr.Append("<description>");
            bldr.Append("<![CDATA[Description text]]>");
            bldr.Append("</description>");
            bldr.Append("<params>");
            bldr.Append(@"<param name=""param1"" type=""String"">");
            bldr.Append("theValue");
            bldr.Append(@"</param>");
            bldr.Append("</params>");
            bldr.Append("</rule>");
            bldr.Append("</rules>");

            Stream    stream = new MemoryStream(Encoding.Default.GetBytes(bldr.ToString()));
            XmlReader reader = new XmlTextReader(stream);

            FileRuleConfigurationFactory builder = new FileRuleConfigurationFactoryImpl(reader);

            Assert.Throws <TypeLoadException>(
                delegate
            {
                IRuleConfiguration config = builder.Get(GetType());
            }
                );
        }
Exemple #3
0
        public void ParsingStreamWithRegistrationShouldReturnInformation()
        {
            StringBuilder bldr = new StringBuilder();

            bldr.Append(@"<?xml version=""1.0"" encoding=""utf-8"" ?>");
            bldr.Append("<rules>");
            bldr.Append(@"<rule type=""JDT.Calidus.CommonTest.Rules.UnCreatableRule, JDT.Calidus.CommonTest"">");
            bldr.Append("<description>");
            bldr.Append("Description text");
            bldr.Append("</description>");
            bldr.Append("<params>");
            bldr.Append(@"<param name=""param1"" type=""String"">");
            bldr.Append("theValue1");
            bldr.Append(@"</param>");
            bldr.Append(@"<param name=""param2"" type=""String"">");
            bldr.Append("theValue2");
            bldr.Append(@"</param>");
            bldr.Append("</params>");
            bldr.Append("</rule>");
            bldr.Append("</rules>");

            Stream    stream = new MemoryStream(Encoding.Default.GetBytes(bldr.ToString()));
            XmlReader reader = new XmlTextReader(stream);

            FileRuleConfigurationFactory builder = new FileRuleConfigurationFactoryImpl(reader);
            IRuleConfiguration           actual  = builder.Get(typeof(UnCreatableRule));

            IList <IRuleConfigurationParameter> paramList = new List <IRuleConfigurationParameter>();
            DefaultRuleConfigurationParameter   param1    = new DefaultRuleConfigurationParameter();

            param1.ParameterType = ParameterType.String;
            param1.Name          = "param1";
            param1.Value         = "theValue1";
            paramList.Add(param1);

            DefaultRuleConfigurationParameter param2 = new DefaultRuleConfigurationParameter();

            param2.ParameterType = ParameterType.String;
            param2.Name          = "param2";
            param2.Value         = "theValue2";
            paramList.Add(param2);

            Assert.AreEqual("Description text", actual.Description);
            Assert.AreEqual(Type.GetType("JDT.Calidus.CommonTest.Rules.UnCreatableRule, JDT.Calidus.CommonTest"), actual.Rule);
            CollectionAssert.AreEquivalent(paramList, actual.Parameters);
        }
Exemple #4
0
        public void ParsingStreamWithRegistrationShouldSupportMultipleRules()
        {
            StringBuilder bldr = new StringBuilder();

            bldr.Append(@"<?xml version=""1.0"" encoding=""utf-8"" ?>");
            bldr.Append("<rules>");
            bldr.Append(@"<rule type=""JDT.Calidus.CommonTest.Rules.UnCreatableRule, JDT.Calidus.CommonTest"">");
            bldr.Append("<description>");
            bldr.Append("Description text");
            bldr.Append("</description>");
            bldr.Append("<params>");
            bldr.Append(@"<param name=""param1"" type=""String"">");
            bldr.Append("theValue1");
            bldr.Append(@"</param>");
            bldr.Append(@"<param name=""param2"" type=""String"">");
            bldr.Append("theValue2");
            bldr.Append(@"</param>");
            bldr.Append("</params>");
            bldr.Append("</rule>");
            bldr.Append(@"<rule type=""JDT.Calidus.CommonTest.CreateableRule, JDT.Calidus.CommonTest"">");
            bldr.Append("<description>");
            bldr.Append("Description text");
            bldr.Append("</description>");
            bldr.Append("<params>");
            bldr.Append("</params>");
            bldr.Append("</rule>");
            bldr.Append("</rules>");

            Stream    stream = new MemoryStream(Encoding.Default.GetBytes(bldr.ToString()));
            XmlReader reader = new XmlTextReader(stream);

            FileRuleConfigurationFactory builder = new FileRuleConfigurationFactoryImpl(reader);
            IRuleConfiguration           one     = builder.Get(typeof(UnCreatableRule));
            IRuleConfiguration           two     = builder.Get(typeof(CreateableRule));

            Assert.IsNotNull(one);
            Assert.IsNotNull(two);
        }
Exemple #5
0
        public void BooleanTypeParameterShouldParseAsBoolean()
        {
            StringBuilder bldr = new StringBuilder();

            bldr.Append(@"<?xml version=""1.0"" encoding=""utf-8"" ?>");
            bldr.Append("<rules>");
            bldr.Append(@"<rule type=""JDT.Calidus.CommonTest.Rules.UnCreatableRule, JDT.Calidus.CommonTest"">");
            bldr.Append("<description>");
            bldr.Append("Description text");
            bldr.Append("</description>");
            bldr.Append("<params>");
            bldr.Append(@"<param name=""param1"" type=""Boolean"">");
            bldr.Append("false");
            bldr.Append(@"</param>");
            bldr.Append("</params>");
            bldr.Append("</rule>");
            bldr.Append("</rules>");

            Stream    stream = new MemoryStream(Encoding.Default.GetBytes(bldr.ToString()));
            XmlReader reader = new XmlTextReader(stream);

            FileRuleConfigurationFactory builder = new FileRuleConfigurationFactoryImpl(reader);
            IRuleConfiguration           actual  = builder.Get(typeof(UnCreatableRule));

            IList <IRuleConfigurationParameter> paramList = new List <IRuleConfigurationParameter>();
            DefaultRuleConfigurationParameter   param     = new DefaultRuleConfigurationParameter();

            param.ParameterType = ParameterType.Boolean;
            param.Name          = "param1";
            param.Value         = false;
            paramList.Add(param);

            Assert.AreEqual("Description text", actual.Description);
            Assert.AreEqual(Type.GetType("JDT.Calidus.CommonTest.Rules.UnCreatableRule, JDT.Calidus.CommonTest"), actual.Rule);
            CollectionAssert.AreEquivalent(paramList, actual.Parameters);
        }