コード例 #1
0
        private void TestMatch(string namespaceName, bool ignoreCase, Type targetType, bool shouldMatch)
        {
            NamespaceMatchingRule rule          = new NamespaceMatchingRule(namespaceName, ignoreCase);
            MethodInfo            methodToMatch = targetType.GetMethod("TargetMethod");

            Assert.AreEqual(shouldMatch, rule.Matches(methodToMatch));
        }
コード例 #2
0
        private RuleDrivenPolicy GetCallCountingPolicy()
        {
            RuleDrivenPolicy      typeMatchPolicy = new RuleDrivenPolicy("DALPolicy");
            NamespaceMatchingRule nsMatchRule     = new NamespaceMatchingRule(
                "Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Tests.ObjectsUnderTest");

            typeMatchPolicy.RuleSet.Add(nsMatchRule);
            countHandler = new CallCountHandler();
            typeMatchPolicy.Handlers.Add(countHandler);
            return(typeMatchPolicy);
        }
コード例 #3
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)
        {
            NamespaceMatchingRuleData castedRuleData = (NamespaceMatchingRuleData)objectConfiguration;

            List <MatchingInfo> matches = new List <MatchingInfo>();

            foreach (MatchData matchData in castedRuleData.Matches)
            {
                matches.Add(new MatchingInfo(matchData.Match, matchData.IgnoreCase));
            }

            NamespaceMatchingRule matchingRule = new NamespaceMatchingRule(matches);

            return(matchingRule);
        }
コード例 #4
0
        public void ShouldMatchWithMultipleMatchOptions()
        {
            IMatchingRule rule =
                new NamespaceMatchingRule(new MatchingInfo[]
            {
                new MatchingInfo(TopLevelNamespace),
                new MatchingInfo(ThirdLevelNamespace),
                new MatchingInfo(TopLevelTwoNamespace.ToUpperInvariant(), true)
            });

            Assert.IsTrue(rule.Matches(GetTargetMethod(typeof(TopLevelTarget))));
            Assert.IsFalse(rule.Matches(GetTargetMethod(typeof(SecondLevelTarget))));
            Assert.IsTrue(rule.Matches(GetTargetMethod(typeof(ThirdLevelTarget))));
            Assert.IsFalse(rule.Matches(GetTargetMethod(typeof(SeparateTarget))));
            Assert.IsTrue(rule.Matches(GetTargetMethod(typeof(TopLevelTwoTarget))));
        }
コード例 #5
0
        public void ShouldMatchWithMultipleMatchOptions()
        {
            IMatchingRule rule =
                new NamespaceMatchingRule(new MatchingInfo[]
                                              {
                                                  new MatchingInfo(TopLevelNamespace),
                                                  new MatchingInfo(ThirdLevelNamespace),
                                                  new MatchingInfo(TopLevelTwoNamespace.ToUpperInvariant(), true)
                                              });

            Assert.IsTrue(rule.Matches(GetTargetMethod(typeof(TopLevelTarget))));
            Assert.IsFalse(rule.Matches(GetTargetMethod(typeof(SecondLevelTarget))));
            Assert.IsTrue(rule.Matches(GetTargetMethod(typeof(ThirdLevelTarget))));
            Assert.IsFalse(rule.Matches(GetTargetMethod(typeof(SeparateTarget))));
            Assert.IsTrue(rule.Matches(GetTargetMethod(typeof(TopLevelTwoTarget))));
        }
コード例 #6
0
 void TestMatch(string namespaceName,
                bool ignoreCase,
                Type targetType,
                bool shouldMatch)
 {
     NamespaceMatchingRule rule = new NamespaceMatchingRule(namespaceName, ignoreCase);
     MethodInfo methodToMatch = targetType.GetMethod("TargetMethod");
     Assert.AreEqual(shouldMatch, rule.Matches(methodToMatch));
 }