/// <summary> /// Reimplements the supplied <paramref name="method"/> by delegating to /// another <see cref="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="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)); }
/// <summary> /// Initializes a new instance of the <see cref="MockDynamicTypeBuilder"/> class. /// </summary> /// <param name="httpClientFactory"><see cref="IHttpClientFactory"/> that will be used for <see cref="HttpClient"/> building.</param> /// <param name="contentSerializer"><see cref="IContentSerializer"/> that will be used for http content serialization.</param> /// <param name="httpClient">Http client.</param> public MockDynamicTypeBuilder( IHttpClientFactory httpClientFactory, IContentSerializer contentSerializer, IHttpClient?httpClient = null) { _methodReplacer = new MethodReplacer(httpClientFactory, contentSerializer, httpClient); }
public void SunnyDayPath() { IObjectFactory mockFactory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory)); IConfigurableObjectDefinition mockDefinition = (IConfigurableObjectDefinition)mocks.CreateMock(typeof(IConfigurableObjectDefinition)); IMethodReplacer mockReplacer = (IMethodReplacer)mocks.CreateMock(typeof(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 SunnyDayPath() { IObjectFactory mockFactory = A.Fake <IObjectFactory>(); IConfigurableObjectDefinition mockDefinition = A.Fake <IConfigurableObjectDefinition>(); IMethodReplacer mockReplacer = A.Fake <IMethodReplacer>(); const string ReplacerObjectName = "replacer"; A.CallTo(() => mockFactory.GetObject(ReplacerObjectName)).Returns(mockReplacer); ReplacedMethodOverride ovr = new ReplacedMethodOverride("SunnyDayPath", ReplacerObjectName); MethodOverrides overrides = new MethodOverrides(); overrides.Add(ovr); A.CallTo(() => mockDefinition.MethodOverrides).Returns(overrides); A.CallTo(() => mockReplacer.Implement(null, null, null)).WithAnyArguments().Returns(null); DelegatingMethodReplacer replacer = new DelegatingMethodReplacer(mockDefinition, mockFactory); MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); replacer.Implement(this, method, new object[] {}); }