示例#1
0
        public void TestMatch(string typeName, Type typeToMatch, bool ignoreCase, bool shouldMatch)
        {
            TypeMatchingRule rule          = new TypeMatchingRule(typeName, ignoreCase);
            MethodInfo       methodToMatch = typeToMatch.GetMethod("TargetMethod");

            Assert.AreEqual(shouldMatch, rule.Matches(methodToMatch));
        }
 public void TestMatch(string typeName,
                       Type typeToMatch,
                       bool ignoreCase,
                       bool shouldMatch)
 {
     TypeMatchingRule rule = new TypeMatchingRule(typeName, ignoreCase);
     MethodInfo methodToMatch = typeToMatch.GetMethod("TargetMethod");
     Assert.AreEqual(shouldMatch, rule.Matches(methodToMatch));
 }
 public void ShouldMatchOneOfMultipleMatchOptions()
 {
     IMatchingRule rule = new TypeMatchingRule(new MatchingInfo[]
                                                   {
                                                       new MatchingInfo(typeof(MyType1).FullName),
                                                       new MatchingInfo("MYTYPE2", true)
                                                   });
     Assert.IsTrue(rule.Matches(typeof(MyType1).GetMethod("TargetMethod")));
     Assert.IsFalse(rule.Matches(typeof(ANestedNamespace.MyType1).GetMethod("TargetMethod")));
     Assert.IsTrue(rule.Matches(typeof(MyType2).GetMethod("TargetMethod")));
 }
        public void ShouldMatchOneOfMultipleMatchOptions()
        {
            IMatchingRule rule = new TypeMatchingRule(new MatchingInfo[]
            {
                new MatchingInfo(typeof(MyType1).FullName),
                new MatchingInfo("MYTYPE2", true)
            });

            Assert.IsTrue(rule.Matches(typeof(MyType1).GetMethod("TargetMethod")));
            Assert.IsFalse(rule.Matches(typeof(ANestedNamespace.MyType1).GetMethod("TargetMethod")));
            Assert.IsTrue(rule.Matches(typeof(MyType2).GetMethod("TargetMethod")));
        }
示例#5
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)
        {
            TypeMatchingRuleData castedRuleData = (TypeMatchingRuleData)objectConfiguration;
            List <MatchingInfo>  matches        = new List <MatchingInfo>();

            foreach (MatchData match in castedRuleData.Matches)
            {
                matches.Add(new MatchingInfo(match.Match, match.IgnoreCase));
            }
            TypeMatchingRule matchingRule = new TypeMatchingRule(matches);

            return(matchingRule);
        }