public void MemberNameMatchingRuleMatchesNameInDoubleDerivedClass() { var rule = new MemberNameMatchingRule("DoSomething"); MethodInfo memberInfo = typeof(DoubleDerivedClass).GetMethod("DoSomething"); Assert.IsTrue(rule.Matches(memberInfo)); }
public void ShouldMatchMultipleMethods() { IMatchingRule rule = new MemberNameMatchingRule( new string[] { "MethodTwo", "Save" }); Assert.IsFalse(rule.Matches(methodOne)); Assert.IsTrue(rule.Matches(methodTwo)); Assert.IsTrue(rule.Matches(save)); }
public void ShouldMatchWithWildcard() { MemberNameMatchingRule rule = new MemberNameMatchingRule("*Reset"); foreach (MethodInfo method in new MethodInfo[] { reset, closeAndReset }) { Assert.IsTrue(rule.Matches(method), "Match failed for method {0}", method.Name); } }
public void ShouldMatchMultipleWildcards() { IMatchingRule rule = new MemberNameMatchingRule( new string[] { "Method*", "*Reset" }); foreach (MethodInfo method in new MethodInfo[] { methodOne, methodTwo, reset, closeAndReset }) { Assert.IsTrue(rule.Matches(method), "Match failed for method {0}", method.Name); } }
private void AddPropertiesPolicy(PolicyInjector factory) { RuleDrivenPolicy policy = new RuleDrivenPolicy("Intercept balance policy"); MemberNameMatchingRule rule = new MemberNameMatchingRule("get_Balance"); policy.RuleSet.Add(rule); countHandler = new CallCountHandler(); policy.Handlers.Add(countHandler); factory.Policies.Add(policy); }
/// <summary> /// Builds an instance of the subtype of the IMatching 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) { MemberNameMatchingRuleData castedRuleData = (MemberNameMatchingRuleData)objectConfiguration; List <MatchingInfo> namesToMatch = new List <MatchingInfo>(); foreach (MatchData matchData in castedRuleData.Matches) { namesToMatch.Add(new MatchingInfo(matchData.Match, matchData.IgnoreCase)); } MemberNameMatchingRule matchingRule = new MemberNameMatchingRule(namesToMatch); return(matchingRule); }
public void ShouldOnlyGetHandlersOnceIfPolicyMatchesBothClassAndInterface() { RuleDrivenPolicy p = new RuleDrivenPolicy(); ICallHandler callHandler = new CallCountHandler(); MemberNameMatchingRule nameRule = new MemberNameMatchingRule("MyMethod"); p.RuleSet.Add(nameRule); p.Handlers.Add(callHandler); MethodInfo myMethod = typeof(MyFooClass).GetMethod("MyMethod"); List <ICallHandler> handlers = new List <ICallHandler>(p.GetHandlersFor(myMethod)); Assert.AreEqual(1, handlers.Count); Assert.AreSame(callHandler, handlers[0]); }
public void ShouldMatchExactName() { MemberNameMatchingRule rule = new MemberNameMatchingRule("Save"); Assert.IsTrue(rule.Matches(save)); }