示例#1
0
        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 CacheMappingsHoldTypes()
        {
            ModuleScope         scope   = new ModuleScope(true);
            DefaultProxyBuilder builder = new DefaultProxyBuilder(scope);
            Type cp = builder.CreateClassProxyType(typeof(object), Type.EmptyTypes, ProxyGenerationOptions.Default);

            string savedPath = scope.SaveAssembly();

            CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args)
            {
                Assembly assembly = Assembly.LoadFrom((string)args[0]);
                CacheMappingsAttribute attribute =
                    (CacheMappingsAttribute)
                    assembly.GetCustomAttributes(typeof(CacheMappingsAttribute), false)[0];
                Dictionary <CacheKey, string> entries = attribute.GetDeserializedMappings();
                Assert.AreEqual(1, entries.Count);

                CacheKey key = new CacheKey(typeof(object), new Type[0],
                                            ProxyGenerationOptions.Default);
                Assert.IsTrue(entries.ContainsKey(key));
                Assert.AreEqual(args[1], entries[key]);
            },
                                                     savedPath, cp.FullName);

            File.Delete(savedPath);
        }
示例#3
0
        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);
        }
示例#4
0
		public static void RunInOtherAppDomain(Action<object[]> callback, params object[] args)
		{
			CrossAppDomainCaller callbackObject = new CrossAppDomainCaller(callback, args);
			AppDomain newDomain = AppDomain.CreateDomain("otherDomain", AppDomain.CurrentDomain.Evidence,
			                                             AppDomain.CurrentDomain.SetupInformation);
			try
			{
				newDomain.DoCallBack(callbackObject.Run);
			}
			finally
			{
				AppDomain.Unload(newDomain);
			}
		}
示例#5
0
        public static void RunInOtherAppDomain(Action <object[]> callback, params object[] args)
        {
            CrossAppDomainCaller callbackObject = new CrossAppDomainCaller(callback, args);
            AppDomain            newDomain      = AppDomain.CreateDomain("otherDomain", AppDomain.CurrentDomain.Evidence,
                                                                         AppDomain.CurrentDomain.SetupInformation);

            try
            {
                newDomain.DoCallBack(callbackObject.Run);
            }
            finally
            {
                AppDomain.Unload(newDomain);
            }
        }
        public void SavedAssemblyHasCacheMappings()
        {
            ModuleScope scope = new ModuleScope(true);

            scope.ObtainDynamicModuleWithWeakName();

            string savedPath = scope.SaveAssembly();

            CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args)
            {
                Assembly assembly = Assembly.LoadFrom((string)args[0]);
                Assert.IsTrue(assembly.IsDefined(typeof(CacheMappingsAttribute), false));
            },
                                                     savedPath);

            File.Delete(savedPath);
        }