Esempio n. 1
0
        public void ShouldCreateCorrectMatchingRule()
        {
            PolicyData policyData = new PolicyData("Validate Parameters");

            policyData.Handlers.Add(new ValidationCallHandlerData());
            ParameterTypeMatchingRuleData matchingRuleData = GetParameterTypeMatchingRuleData();

            policyData.MatchingRules.Add(matchingRuleData);

            PolicyInjectionSettings settings = new PolicyInjectionSettings();

            settings.Policies.Add(policyData);

            DictionaryConfigurationSource configSource = new DictionaryConfigurationSource();

            configSource.Add(PolicyInjectionSettings.SectionName, settings);

            PolicySetFactory factory  = new PolicySetFactory(configSource);
            PolicySet        policies = factory.Create();

            Policy policy = policies[1];

            Assert.IsTrue(policy is RuleDrivenPolicy);
            RuleDrivenPolicy validateRule = (RuleDrivenPolicy)policy;

            Assert.IsTrue(validateRule.RuleSet[0] is ParameterTypeMatchingRule);
            ParameterTypeMatchingRule rule = (ParameterTypeMatchingRule)(validateRule.RuleSet[0]);

            Assert.AreEqual(3, rule.ParameterMatches.Count);
            for (int i = 0; i < matchingRuleData.Matches.Count; ++i)
            {
                AssertMatchDataEqual(matchingRuleData.Matches[i], rule.ParameterMatches[i], "Mismatch at element {0}", i);
            }
        }
 public void ShouldMatchOnOutParams()
 {
     ParameterTypeMatchingRule rule = new ParameterTypeMatchingRule(
         new ParameterTypeMatchingInfo[]
             {
                 new ParameterTypeMatchingInfo("System.Int32", false, ParameterKind.Output)
             });
     Assert.IsTrue(rule.Matches(targetWithOutParams));
     Assert.IsFalse(rule.Matches(targetMethodInt));
 }
 public void ShouldMatchOnReturnType()
 {
     ParameterTypeMatchingRule rule = new ParameterTypeMatchingRule(
         new ParameterTypeMatchingInfo[]
             {
                 new ParameterTypeMatchingInfo("System.String", false, ParameterKind.ReturnValue)
             });
     Assert.IsFalse(rule.Matches(targetMethodString));
     Assert.IsTrue(rule.Matches(returnsAString));
 }
Esempio n. 4
0
        /// <summary>
        /// Builds an instance of the subtype of IMatchingRule type the receiver knows how to build, based on
        /// a configuration object.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of the IMatchingRule subtype.</returns>
        public IMatchingRule Assemble(IBuilderContext context, MatchingRuleData objectConfiguration,
                                      IConfigurationSource configurationSource,
                                      ConfigurationReflectionCache reflectionCache)
        {
            ParameterTypeMatchingRuleData ruleData     = (ParameterTypeMatchingRuleData)objectConfiguration;
            ParameterTypeMatchingRule     matchingRule =
                new ParameterTypeMatchingRule(ConvertFromConfigToRuntimeInfo(ruleData));

            return(matchingRule);
        }
Esempio n. 5
0
        public void ShouldMatchInOrOut()
        {
            ParameterTypeMatchingRule rule = new ParameterTypeMatchingRule(
                new ParameterTypeMatchingInfo[]
            {
                new ParameterTypeMatchingInfo("System.Int32", false, ParameterKind.InputOrOutput)
            });

            Assert.IsTrue(rule.Matches(targetWithOutParams));
            Assert.IsTrue(rule.Matches(targetMethodInt));
        }
Esempio n. 6
0
        public void ShouldMatchOnReturnType()
        {
            ParameterTypeMatchingRule rule = new ParameterTypeMatchingRule(
                new ParameterTypeMatchingInfo[]
            {
                new ParameterTypeMatchingInfo("System.String", false, ParameterKind.ReturnValue)
            });

            Assert.IsFalse(rule.Matches(targetMethodString));
            Assert.IsTrue(rule.Matches(returnsAString));
        }
Esempio n. 7
0
        public void ShouldMatchOnSingleInputParameter()
        {
            ParameterTypeMatchingRule rule = new ParameterTypeMatchingRule(
                new ParameterTypeMatchingInfo[]
            {
                new ParameterTypeMatchingInfo("System.String", false, ParameterKind.Input)
            });

            Assert.IsTrue(rule.Matches(targetMethodString));
            Assert.IsFalse(rule.Matches(targetMethodInt));
        }
        public void ShouldMatchOnSingleInputParameter()
        {
            ParameterTypeMatchingRule rule = new ParameterTypeMatchingRule(
                new ParameterTypeMatchingInfo[]
                    {
                        new ParameterTypeMatchingInfo("System.String", false, ParameterKind.Input)
                    });

            Assert.IsTrue(rule.Matches(targetMethodString));
            Assert.IsFalse(rule.Matches(targetMethodInt));
        }
Esempio n. 9
0
        public void ShouldMatchOnOneOfManyParameters()
        {
            ParameterTypeMatchingRule rule = new ParameterTypeMatchingRule(
                new ParameterTypeMatchingInfo[]
            {
                new ParameterTypeMatchingInfo("System.Int32", false, ParameterKind.Input)
            });

            Assert.IsTrue(rule.Matches(targetMethodInt));
            Assert.IsTrue(rule.Matches(targetMethodIntString));
            Assert.IsTrue(rule.Matches(targetMethodStringInt));
            Assert.IsFalse(rule.Matches(returnsAString));
        }
        public void ShouldMatchOnOneOfManyParameters()
        {
            ParameterTypeMatchingRule rule = new ParameterTypeMatchingRule(
                new ParameterTypeMatchingInfo[]
                    {
                        new ParameterTypeMatchingInfo("System.Int32", false, ParameterKind.Input)
                    });

            Assert.IsTrue(rule.Matches(targetMethodInt));
            Assert.IsTrue(rule.Matches(targetMethodIntString));
            Assert.IsTrue(rule.Matches(targetMethodStringInt));
            Assert.IsFalse(rule.Matches(returnsAString));
        }
Esempio n. 11
0
        public void ShouldMatchOr()
        {
            ParameterTypeMatchingRule rule = new ParameterTypeMatchingRule(
                new ParameterTypeMatchingInfo[]
            {
                new ParameterTypeMatchingInfo("System.Int32", false, ParameterKind.InputOrOutput),
                new ParameterTypeMatchingInfo("String", false, ParameterKind.InputOrOutput),
            });

            Assert.IsTrue(rule.Matches(targetMethodString));
            Assert.IsTrue(rule.Matches(targetMethodInt));
            Assert.IsTrue(rule.Matches(targetMethodIntString));
            Assert.IsTrue(rule.Matches(targetWithOutParams));
            Assert.IsFalse(rule.Matches(returnsAString));
        }
        public void ShouldCreateCorrectMatchingRule()
        {
            ValidationFactory.SetDefaultConfigurationValidatorFactory(new ConfigurationValidatorFactory(new DictionaryConfigurationSource()));

            PolicyData policyData = new PolicyData("Validate Parameters");

            policyData.Handlers.Add(new ValidationCallHandlerData());
            ParameterTypeMatchingRuleData matchingRuleData = GetParameterTypeMatchingRuleData();

            policyData.MatchingRules.Add(matchingRuleData);

            PolicyInjectionSettings settings = new PolicyInjectionSettings();

            settings.Policies.Add(policyData);

            DictionaryConfigurationSource configSource = new DictionaryConfigurationSource();

            configSource.Add(PolicyInjectionSettings.SectionName, settings);

            IUnityContainer container = new UnityContainer().AddNewExtension <Interception>();

            settings.ConfigureContainer(container);

            RuleDrivenPolicy     policy = container.Resolve <RuleDrivenPolicy>("Validate Parameters");
            List <IMatchingRule> rules  = RuleCreationFixture.GetRules(policy);

            Assert.IsNotNull(policy);
            Assert.IsTrue(rules[0] is ParameterTypeMatchingRule);
            ParameterTypeMatchingRule rule = (ParameterTypeMatchingRule)(rules[0]);

            Assert.AreEqual(3, rule.ParameterMatches.Count());
            for (int i = 0; i < matchingRuleData.Matches.Count; ++i)
            {
                AssertMatchDataEqual(
                    matchingRuleData.Matches[i],
                    rule.ParameterMatches.ElementAt(i),
                    "Mismatch at element {0}",
                    i);
            }
        }
        public void ShouldMatchOr()
        {
            ParameterTypeMatchingRule rule = new ParameterTypeMatchingRule(
                new ParameterTypeMatchingInfo[]
                    {
                        new ParameterTypeMatchingInfo("System.Int32", false, ParameterKind.InputOrOutput),
                        new ParameterTypeMatchingInfo("String", false, ParameterKind.InputOrOutput),
                    });

            Assert.IsTrue(rule.Matches(targetMethodString));
            Assert.IsTrue(rule.Matches(targetMethodInt));
            Assert.IsTrue(rule.Matches(targetMethodIntString));
            Assert.IsTrue(rule.Matches(targetWithOutParams));
            Assert.IsFalse(rule.Matches(returnsAString));
        }