public void Matches_MatchingMethodNameNoOverload() { ReplacedMethodOverride methodOverride = new ReplacedMethodOverride("Administer", "replacer"); methodOverride.IsOverloaded = false; Assert.IsTrue(methodOverride.Matches(typeof(Executor).GetMethod("Administer"))); }
public void SunnyDayPath() { IObjectFactory mockFactory = mocks.StrictMock <IObjectFactory>(); IConfigurableObjectDefinition mockDefinition = mocks.StrictMock <IConfigurableObjectDefinition>(); IMethodReplacer mockReplacer = mocks.StrictMock <IMethodReplacer>(); const string ReplacerObjectName = "replacer"; Expect.Call(mockFactory.GetObject(ReplacerObjectName)).Return(mockReplacer); ReplacedMethodOverride ovr = new ReplacedMethodOverride("SunnyDayPath", ReplacerObjectName); MethodOverrides overrides = new MethodOverrides(); overrides.Add(ovr); Expect.Call(mockDefinition.MethodOverrides).Return(overrides); Expect.Call(mockReplacer.Implement(null, null, null)).IgnoreArguments().Return(null); mocks.ReplayAll(); DelegatingMethodReplacer replacer = new DelegatingMethodReplacer(mockDefinition, mockFactory); MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); replacer.Implement(this, method, new object[] {}); mocks.VerifyAll(); }
public void Matches_MatchingMethodNameWithOverloadAndBadTypeIdentifiers() { ReplacedMethodOverride methodOverride = new ReplacedMethodOverride("Execute", "replacer"); methodOverride.AddTypeIdentifier(GetType().FullName); Assert.IsFalse(methodOverride.Matches(typeof(Executor).GetMethod("Execute", new Type[] { typeof(object) }))); }
/// <summary> /// Reimplements the supplied <paramref name="method"/> by delegating to /// another <see cref="Oragon.Spring.Objects.Factory.Support.IMethodReplacer"/> /// looked up in an enclosing IoC container. /// </summary> /// <param name="target"> /// The instance whose <paramref name="method"/> is to be /// (re)implemented. /// </param> /// <param name="method"> /// The method that is to be (re)implemented. /// </param> /// <param name="arguments">The target method's arguments.</param> /// <returns> /// The result of the delegated call to the looked up /// <see cref="Oragon.Spring.Objects.Factory.Support.IMethodReplacer"/>. /// </returns> public override object Implement(object target, MethodInfo method, object[] arguments) { ReplacedMethodOverride ovr = (ReplacedMethodOverride)GetOverride(method); IMethodReplacer methodReplacement = (IMethodReplacer)GetObject(ovr.MethodReplacerObjectName); return(methodReplacement.Implement(target, method, arguments)); }
public void Matches_RequiresAllTypeIdentifiers() { ReplacedMethodOverride methodOverride = new ReplacedMethodOverride("Execute", "replacer"); methodOverride.AddTypeIdentifier(typeof(object).FullName); Assert.IsFalse(methodOverride.Matches(typeof(Executor).GetMethod("Execute", new Type[] { typeof(object), typeof(object) }))); }
public void Matches_TotallyDifferentMethodName() { ReplacedMethodOverride methodOverride = new ReplacedMethodOverride("Execute", "replacer"); Assert.IsFalse(methodOverride.Matches(typeof(Executor).GetMethod("Administer"))); }
public void ToStringWorks() { ReplacedMethodOverride methodOverride = new ReplacedMethodOverride("Execute", "replacer"); Assert.AreEqual(typeof(ReplacedMethodOverride).Name + " for method 'Execute'; will call object 'replacer'.", methodOverride.ToString()); }
public void MatchesWithNullMethod() { ReplacedMethodOverride methodOverride = new ReplacedMethodOverride("Execute", "replacer"); Assert.Throws <ArgumentNullException>(() => methodOverride.Matches(null)); }
public void Matches_MatchingMethodNameWithOverload() { ReplacedMethodOverride methodOverride = new ReplacedMethodOverride("Execute", "replacer"); Assert.IsTrue(methodOverride.Matches(typeof(Executor).GetMethod("Execute", new Type[] {}))); }