private static DynamicProxyResult GenerateInterfaceProxy(Type typeToProxy, FakeObject fakeObject) { var result = new DynamicProxyResult(typeToProxy); result.Proxy = (IFakedProxy)proxyGenerator.CreateInterfaceProxyWithoutTarget(typeToProxy, interfacesToImplement, CreateFakeObjectInterceptor(fakeObject), result); return(result); }
private static DynamicProxyResult GenerateClassProxy(Type typeToProxy, IEnumerable <object> argumentsForConstructor, FakeObject fakeObject) { var result = new DynamicProxyResult(typeToProxy); result.Proxy = (IFakedProxy)proxyGenerator.CreateClassProxy(typeToProxy, interfacesToImplement, new ProxyGenerationOptions(), argumentsForConstructor.ToArray(), CreateFakeObjectInterceptor(fakeObject), result); return(result); }
/// <summary> /// Gets a value indicating if a proxy of the specified type can be generated and sets the generated proxy /// to the out parameter if it can. /// </summary> /// <param name="typeToProxy">The type to generate a proxy for.</param> /// <param name="fakeObject">The generated proxy must implement the IFakedProxy interface and this is the fake object /// that should be returned for the call to GetFakeObject().</param> /// <param name="container">A fake object container the proxy generator can use to get arguments for constructor.</param> /// <returns>True if the proxy could be generated.</returns> /// <exception cref="ArgumentException">The arguments in argumentsForConstructor does not match any constructor /// of the proxied type.</exception> public ProxyResult GenerateProxy(Type typeToProxy, FakeObject fakeObject, IFakeObjectContainer container) { ProxyResult result = null; if (!this.TryGenerateProxy(typeToProxy, fakeObject, container, out result)) { result = new DynamicProxyResult(typeToProxy, string.Empty); } return result; }
/// <summary> /// Gets a value indicating if a proxy of the specified type can be generated and sets the generated proxy /// to the out parameter if it can. /// </summary> /// <param name="typeToProxy">The type to generate a proxy for.</param> /// <param name="fakeObject">The generated proxy must implement the IFakedProxy interface and this is the fake object /// that should be returned for the call to GetFakeObject().</param> /// <param name="argumentsForConstructor">Arguments to use for the constructor of the proxied type.</param> /// <returns>True if the proxy could be generated.</returns> /// <exception cref="ArgumentException">The arguments in argumentsForConstructor does not match any constructor /// of the proxied type.</exception> public ProxyResult GenerateProxy(Type typeToProxy, FakeObject fakeObject, IEnumerable<object> argumentsForConstructor) { ProxyResult result = null; if (!this.TryGenerateProxy(typeToProxy, fakeObject, argumentsForConstructor, out result)) { result = new DynamicProxyResult(typeToProxy, string.Empty); } return result; }