public void LoadAssemblyIntoCache_InvalidCacheAfterTwoLoadAssemblyIntoCacheThatContainsSameGeneric() { // // Step 1 - Save an assembly with 1 generic proxy // var proxyGeneratorModuleScope = new ModuleScope(true, true, ModuleScope.DEFAULT_ASSEMBLY_NAME + "1", "ProxyCache1.dll", ModuleScope.DEFAULT_ASSEMBLY_NAME + "1", "ProxyCache1.dll"); var proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); var generator = new ProxyGenerator(proxyBuilder); generator.CreateInterfaceProxyWithTargetInterface(typeof(IGenericInterface <IInterface1>), new Class1(), new DoNothingInterceptor()); proxyGeneratorModuleScope.SaveAssembly(); // // Step 2 - Save another assembly with 1 generic proxy // note : to reproduce the problem, must load previously saved assembly (in cache) before saving this assembly. // proxyGeneratorModuleScope = new ModuleScope(true, true, ModuleScope.DEFAULT_ASSEMBLY_NAME + "2", "ProxyCache2.dll", ModuleScope.DEFAULT_ASSEMBLY_NAME + "2", "ProxyCache2.dll"); proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); generator = new ProxyGenerator(proxyBuilder); var proxyAssembly = Assembly.LoadFrom("ProxyCache1.dll"); proxyGeneratorModuleScope.LoadAssemblyIntoCache(proxyAssembly); generator.CreateInterfaceProxyWithTargetInterface(typeof(IGenericInterface <IInterface2>), new Class2(), new DoNothingInterceptor()); proxyGeneratorModuleScope.SaveAssembly(); // // Step 3 - Load the last proxy assembly and try to create the first generic proxy (created in step 1) // note : Creating proxy from step 2 works. // exception : Missing method exception, it returns the wrong proxy and the constructor used doesnt match the arguments passed. // proxyGeneratorModuleScope = new ModuleScope(true); proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); generator = new ProxyGenerator(proxyBuilder); proxyAssembly = Assembly.LoadFrom("ProxyCache2.dll"); proxyGeneratorModuleScope.LoadAssemblyIntoCache(proxyAssembly); generator.CreateInterfaceProxyWithTargetInterface(typeof(IGenericInterface <IInterface1>), new Class1(), new DoNothingInterceptor()); }
public void LoadAssemblyIntoCache_DifferentGenerationOptions() { ModuleScope savedScope = new ModuleScope(true); DefaultProxyBuilder builder = new DefaultProxyBuilder(savedScope); ProxyGenerationOptions options1 = new ProxyGenerationOptions(); options1.AddMixinInstance(new DateTime()); ProxyGenerationOptions options2 = ProxyGenerationOptions.Default; Type cp1 = builder.CreateClassProxyType(typeof(object), Type.EmptyTypes, options1); Type cp2 = builder.CreateClassProxyType(typeof(object), Type.EmptyTypes, options2); Assert.AreNotSame(cp1, cp2); Assert.AreSame(cp1, builder.CreateClassProxyType(typeof(object), Type.EmptyTypes, options1)); Assert.AreSame(cp2, builder.CreateClassProxyType(typeof(object), Type.EmptyTypes, options2)); string path = savedScope.SaveAssembly(); CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args) { ModuleScope newScope = new ModuleScope(false); DefaultProxyBuilder newBuilder = new DefaultProxyBuilder(newScope); Assembly assembly = Assembly.LoadFrom((string)args[0]); newScope.LoadAssemblyIntoCache(assembly); ProxyGenerationOptions newOptions1 = new ProxyGenerationOptions(); newOptions1.AddMixinInstance(new DateTime()); ProxyGenerationOptions newOptions2 = ProxyGenerationOptions.Default; Type loadedCP1 = newBuilder.CreateClassProxyType(typeof(object), Type.EmptyTypes, newOptions1); Type loadedCP2 = newBuilder.CreateClassProxyType(typeof(object), Type.EmptyTypes, newOptions2); Assert.AreNotSame(loadedCP1, loadedCP2); Assert.AreEqual(assembly, loadedCP1.Assembly); Assert.AreEqual(assembly, loadedCP2.Assembly); }, path); File.Delete(path); }
public void LoadAssemblyIntoCache_InvalidAssembly() { ModuleScope newScope = new ModuleScope(false); newScope.LoadAssemblyIntoCache(Assembly.GetExecutingAssembly()); }
private void CheckLoadAssemblyIntoCache(ProxyCreator creator) { var savedScope = new ModuleScope(true); var builder = new DefaultProxyBuilder(savedScope); var cp = creator(builder); Assert.AreSame(cp, creator(builder)); var path = savedScope.SaveAssembly(); CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args) { var newScope = new ModuleScope(false); var newBuilder = new DefaultProxyBuilder(newScope); var assembly = Assembly.LoadFrom((string) args[0]); newScope.LoadAssemblyIntoCache(assembly); var loadedCP = assembly.GetType((string) args[1]); Assert.AreSame(loadedCP, ((ProxyCreator) args[2])(newBuilder)); Assert.AreEqual(assembly, ((ProxyCreator) args[2])(newBuilder).Assembly); }, path, cp.FullName, creator); File.Delete(path); }
public void LoadAssemblyIntoCache_DifferentGenerationOptions() { var savedScope = new ModuleScope(true); var builder = new DefaultProxyBuilder(savedScope); var options1 = new ProxyGenerationOptions(); options1.AddMixinInstance(new DateTime()); var options2 = ProxyGenerationOptions.Default; var cp1 = builder.CreateClassProxyType(typeof (object), Type.EmptyTypes, options1); var cp2 = builder.CreateClassProxyType(typeof (object), Type.EmptyTypes, options2); Assert.AreNotSame(cp1, cp2); Assert.AreSame(cp1, builder.CreateClassProxyType(typeof (object), Type.EmptyTypes, options1)); Assert.AreSame(cp2, builder.CreateClassProxyType(typeof (object), Type.EmptyTypes, options2)); var path = savedScope.SaveAssembly(); CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args) { var newScope = new ModuleScope(false); var newBuilder = new DefaultProxyBuilder(newScope); var assembly = Assembly.LoadFrom((string) args[0]); newScope.LoadAssemblyIntoCache(assembly); var newOptions1 = new ProxyGenerationOptions(); newOptions1.AddMixinInstance(new DateTime()); var newOptions2 = ProxyGenerationOptions.Default; var loadedCP1 = newBuilder.CreateClassProxyType(typeof (object), Type.EmptyTypes, newOptions1); var loadedCP2 = newBuilder.CreateClassProxyType(typeof (object), Type.EmptyTypes, newOptions2); Assert.AreNotSame(loadedCP1, loadedCP2); Assert.AreEqual(assembly, loadedCP1.Assembly); Assert.AreEqual(assembly, loadedCP2.Assembly); }, path); File.Delete(path); }
public void LoadAssemblyIntoCache_InvalidAssembly() { var newScope = new ModuleScope(false); Assert.Throws<ArgumentException>(() => newScope.LoadAssemblyIntoCache(Assembly.GetExecutingAssembly()) ); }
public void LoadAssemblyIntoCache_InvalidAssembly() { var newScope = new ModuleScope(false); newScope.LoadAssemblyIntoCache(Assembly.GetExecutingAssembly()); }
public void LoadAssemblyIntoCache_InvalidCacheAfterTwoLoadAssemblyIntoCacheThatContainsSameClass() { // // Step 1 - Save an assembly with 1 class proxy // var proxyGeneratorModuleScope = new ModuleScope( true, true, ModuleScope.DEFAULT_ASSEMBLY_NAME + "5", "ProxyCache5.dll", ModuleScope.DEFAULT_ASSEMBLY_NAME + "5", "ProxyCache5.dll" ); var proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); var generator = new ProxyGenerator(proxyBuilder); generator.CreateClassProxy( typeof(EmptyClass), new[] { typeof(IInterface1) }, new DoNothingInterceptor() ); proxyGeneratorModuleScope.SaveAssembly(); // // Step 2 - Save another assembly with 1 class proxy // note : to reproduce the problem, must load previously saved assembly (in cache) before saving this assembly. // proxyGeneratorModuleScope = new ModuleScope( true, true, ModuleScope.DEFAULT_ASSEMBLY_NAME + "6", "ProxyCache6.dll", ModuleScope.DEFAULT_ASSEMBLY_NAME + "6", "ProxyCache6.dll" ); proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); generator = new ProxyGenerator(proxyBuilder); var proxyAssembly = Assembly.LoadFrom("ProxyCache5.dll"); proxyGeneratorModuleScope.LoadAssemblyIntoCache(proxyAssembly); generator.CreateClassProxy( typeof(EmptyClass), new[] { typeof(IInterface2) }, new DoNothingInterceptor() ); proxyGeneratorModuleScope.SaveAssembly(); // // Step 3 - Load the last proxy assembly and try to create the first class proxy (created in step 1) // note : Creating proxy from step 2 works. // issue : returns the wrong proxy (the one from step 2) // proxyGeneratorModuleScope = new ModuleScope(true); proxyBuilder = new DefaultProxyBuilder(proxyGeneratorModuleScope); generator = new ProxyGenerator(proxyBuilder); proxyAssembly = Assembly.LoadFrom("ProxyCache6.dll"); proxyGeneratorModuleScope.LoadAssemblyIntoCache(proxyAssembly); var invalidProxy = generator.CreateClassProxy( typeof(EmptyClass), new[] { typeof(IInterface1) }, new DoNothingInterceptor() ); if (invalidProxy as IInterface1 == null) { Assert.Fail(); } }