public void Matches() { SerializablePerson target = new SerializablePerson(); target.SetAge(27); ControlFlowPointcut cflow = new ControlFlowPointcut(typeof(One), "GetAge"); ProxyFactory factory = new ProxyFactory(target); NopInterceptor nop = new NopInterceptor(); IPerson proxied = (IPerson)factory.GetProxy(); factory.AddAdvisor(new DefaultPointcutAdvisor(cflow, nop)); // not advised, not under One... Assert.AreEqual(target.GetAge(), proxied.GetAge()); Assert.AreEqual(0, nop.Count, "Whoops, appear to be advising when not under One's cflow."); // will be advised... One one = new One(); Assert.AreEqual(27, one.GetAge(proxied)); Assert.AreEqual(1, nop.Count, "Not advising when under One's cflow (must be)."); // won't be advised... Assert.AreEqual(target.GetAge(), new One().NoMatch(proxied)); Assert.AreEqual(1, nop.Count, "Whoops, appear to be advising when under One's cflow scope, BUT NOT under a target method's cflow scope."); Assert.AreEqual(3, cflow.EvaluationCount, "Pointcut not invoked the correct number of times."); }
public void SelectiveApplication() { SerializablePerson target = new SerializablePerson(); target.SetAge(27); NopInterceptor nop = new NopInterceptor(); ControlFlowPointcut cflow = new ControlFlowPointcut(typeof(One)); IPointcut settersUnderOne = Pointcuts.Intersection(SetterPointcut.Instance, cflow); ProxyFactory pf = new ProxyFactory(target); IPerson proxied = (IPerson)pf.GetProxy(); pf.AddAdvisor(new DefaultPointcutAdvisor(settersUnderOne, nop)); // Not advised, not under One target.SetAge(16); Assert.AreEqual(0, nop.Count); // Not advised; under One but not a setter Assert.AreEqual(16, new One().GetAge(proxied)); Assert.AreEqual(0, nop.Count); // Won't be advised new One().Set(proxied); Assert.AreEqual(1, nop.Count); // We saved most evaluations Assert.AreEqual(1, cflow.EvaluationCount); }
public void DynamicMethodMatchWithTypeAndMethodNameSpecifiedInCtorNoMatch() { ControlFlowPointcut cut = new ControlFlowPointcut(GetType(), "KiloRiley"); IMethodMatcher filter = cut.MethodMatcher; Assert.IsFalse(filter.Matches(null, null, null), // args are ingored in this impl... "Must not match - under cflow of Type specified in ctor, but no match on method name."); }
public void DynamicMethodMatchWithJustTypeSpecifiedInCtor() { ControlFlowPointcut cut = new ControlFlowPointcut(GetType()); IMethodMatcher filter = cut.MethodMatcher; Assert.IsTrue(filter.Matches(null, null, null), // args are ingored in this impl... "Must match - under cflow of Type specified in ctor"); }
public void EvaluationCountIncrementedEvenIfPointcutDoesNotMatch() { ControlFlowPointcut cut = new ControlFlowPointcut(typeof(One)); cut.Matches(null, null, null); // args are ingored in this impl... Assert.AreEqual(1, cut.EvaluationCount); cut.Matches(null, null, null); // args are ingored in this impl... Assert.AreEqual(2, cut.EvaluationCount); }
public void EvaluationCountIncrementedOnEveryMatch() { Type oneType = typeof(One); ControlFlowPointcut cut = new ControlFlowPointcut(oneType); MethodInfo method = oneType.GetMethod("GetAge"); cut.Matches(method, oneType, null); Assert.AreEqual(1, cut.EvaluationCount); cut.Matches(method, oneType, null); Assert.AreEqual(2, cut.EvaluationCount); }
public void DefaultClassFilterImplAlwaysMatchesRegardless() { Type oneType = typeof(One); ControlFlowPointcut cut = new ControlFlowPointcut(oneType); ITypeFilter filter = cut.TypeFilter; Assert.IsTrue(filter.Matches(oneType), "Must always match regardless of the supplied argument Type."); Assert.IsTrue(filter.Matches(GetType()), "Must always match even if the supplied argument Type is not " + "a match for the Type supplied in the ctor."); Assert.IsTrue(filter.Matches(null), // args are ingored in this impl... "Must always match even if the supplied argument Type is null"); }
public void StaticMethodMatchImplAlwaysMatchesRegardless() { Type oneType = typeof(One); ControlFlowPointcut cut = new ControlFlowPointcut(oneType); IMethodMatcher filter = cut.MethodMatcher; MethodInfo method = oneType.GetMethod("GetAge"); Assert.IsTrue(filter.Matches(method, oneType), "Must always match regardless of the supplied arguments."); Assert.IsTrue(filter.Matches(method, GetType()), "Must always match even if the supplied argument method and Type are not " + "a match for the name and Type supplied in the ctor."); Assert.IsTrue(filter.Matches(null, null), // args are ingored in this impl... "Must always match even if the supplied arguments are null"); }