public void createAppDomainAndLoadDll_MainTestCase()
        {
            string fullPathToDllToProcess = DI.config.ExecutingAssembly;  //Path.Combine(hardCodedO2DevelopmentLib, o2DllToProcess + ".exe");

            //AppDomainUtils.findDllInCurrentAppDomain(o2DllToProcess);
            Assert.That(File.Exists(fullPathToDllToProcess),
                        "fullPathToDllToProcess doesn't exist:" + fullPathToDllToProcess);

            // get test AppDomain in temp folder
            var o2AppDomainFactory = new O2AppDomainFactory();

            // load dll from it (this will fail until all dependencies are resolved
            Assert.That(o2AppDomainFactory.load(o2DllToProcess, fullPathToDllToProcess, true),
                        "Dll failed to load into AppDomain");

            // get assemblyDependencies
            Dictionary <string, string> assemblyDependencies =
                new CecilAssemblyDependencies(fullPathToDllToProcess).calculateDependencies();

            DI.log.debug("There are {0} assembly dependencies to load", assemblyDependencies.Count);
            // load them and abort if we were not able to load all)
            Assert.That(o2AppDomainFactory.load(assemblyDependencies).Count == 0,
                        "There were assemblyDependencies that were not loaded");

            // double check that all is OK by dinamcally invoking some methods on the new AppDomain
            Assert.That(null != o2AppDomainFactory.invokeMethod("nameOfCurrentDomainStatic O2Proxy O2_Kernel", new object[0]),
                        "Could not invoke methods inside O2_CoreLib");
            o2AppDomainFactory.invokeMethod("logInfo O2Proxy O2_Kernel",
                                            new object[] { "Hello from createAppDomainInTempFolder UnitTest" });

            AppDomainUtils.closeAppDomain(o2AppDomainFactory.appDomain, onTestCompletionDeleteTempFilesCreated);
        }
Пример #2
0
        public void Test_AppdomainsWithUniqueBaseDirectories()
        {
            string pathToproxyDll    = DI.config.ExecutingAssembly; // Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyName + ".exe");
            string appDomain1TempDir = copyO2ProxyToTempFolder(pathToproxyDll, "appDomain1TempDir");
            string appDomain2TempDir = copyO2ProxyToTempFolder(pathToproxyDll, "appDomain2TempDir");

            Assert.That(
                Directory.Exists(appDomain1TempDir) && Directory.Exists(appDomain2TempDir) &&
                appDomain1TempDir != appDomain2TempDir, "Something is wrong with temp dirs");
            var appDomain1 = new O2AppDomainFactory("appDomain1", appDomain1TempDir);
            var appDomain2 = new O2AppDomainFactory("appDomain2", appDomain2TempDir);

            Assert.That(appDomain1.BaseDirectory != appDomain2.BaseDirectory,
                        "Something is wrong with AppDomain's temp dirs");
            object appDomain1invocationResult =
                appDomain1.invokeMethod(methodToInvoke + " " + typeToCreate + " " + assemblyName);
            object appDomain2invocationResult =
                appDomain2.invokeMethod(methodToInvoke + " " + typeToCreate + " " + assemblyName);

            Assert.That(appDomain1invocationResult != null && appDomain2invocationResult != null,
                        "appDomainXinvocationResult == null");
            DI.log.info("{0} != {1}", appDomain1invocationResult, appDomain2invocationResult);
            Assert.That(appDomain1invocationResult != appDomain2invocationResult,
                        "appDomainXinvocationResult were not different");
        }
Пример #3
0
        public void Test_CreateAppDomainWithO2CoreLibDll()
        {
            const string dynamicCommand_InitialTest = "nameOfCurrentDomain O2Proxy O2_Kernel";

            // get test AppDomain in temp folder
            o2AppDomainFactory =
                CecilAssemblyDependencies.getO2AppDomainFactoryOnTempDirWithAllDependenciesResolved(
                    fullPathToAssemblyToProcess);
            Assert.That(o2AppDomainFactory != null, "o2AppDomainFactory was null");
            // send message to DebugView (will not show in NUnit since this is from a different AppDomain)
            o2AppDomainFactory.invokeMethod("logInfo O2Proxy O2_Kernel",
                                            new object[]
                                            { "Testing appDomain from Test_OpenO2CoreLibFormFromAppDomain UnitTest" });

            //Assert.That(o2AppDomainFactory.load(appDomainProxyDll, fullPathToAppDomainProxyDll, true), "problem loading appDomainProxyDll");
            // do a quick dynamic invokation to confirm that all is
            Assert.That(
                o2AppDomainFactory.appDomain.FriendlyName ==
                (string)o2AppDomainFactory.invokeMethod(dynamicCommand_InitialTest),
                "Problem doing dynamic invoke of method nameOfCurrentDomain which returns the current appDomain name");
            DI.log.info("o2AppDomainFactory is created ready for use :)");
        }
Пример #4
0
        public void Test_LoadingCodeIntoMultipleAppDomains()
        {
            // test current AppDomain
            string pathToproxyDll         = DI.config.ExecutingAssembly; // Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyName + ".exe");
            string testAppDomainDirectory = copyO2ProxyToTempFolder(pathToproxyDll, assemblyName);

            object resultInCurrentAppDomain = LoadTypes.loadTypeAndExecuteMethodInAppDomain(AppDomain.CurrentDomain,
                                                                                            assemblyName, typeToCreate,
                                                                                            methodToInvoke, methodParams);

            Assert.IsNotNull(resultInCurrentAppDomain, "result");
            DI.log.debug("{0} = {1}", "resultIncurrentAppDomain", resultInCurrentAppDomain);

            // test creating new AppDomain
            var newAppDomain = new O2AppDomainFactory("newAppDomain", testAppDomainDirectory);

            Assert.IsNotNull(newAppDomain, "newAppDomain");
            newAppDomain.load(assemblyName);
            object resultInNewAppDomain = LoadTypes.loadTypeAndExecuteMethodInAppDomain(newAppDomain.appDomain,
                                                                                        assemblyName, typeToCreate,
                                                                                        methodToInvoke, methodParams);

            Assert.IsNotNull(resultInNewAppDomain, "result");
            DI.log.debug("{0} = {1}", "resultInNewAppDomain", resultInNewAppDomain);
            Assert.That(resultInCurrentAppDomain != resultInNewAppDomain,
                        "resultIncurrentAppDomain == resultInNewAppDomain");

            // test creating new AppDomain just using the O2AppDomainFactory
            var appDomainFactory = new O2AppDomainFactory("appDomainFactory", testAppDomainDirectory);

            appDomainFactory.load(assemblyName);
            List <string> loadedAssemblies = appDomainFactory.getAssemblies(false);

            Assert.That(loadedAssemblies.Count > 0 && loadedAssemblies.Contains(assemblyName),
                        "Loaded assembly was not there");
            object proxyObject = appDomainFactory.getProxyObject((typeToCreate));

            Assert.IsNotNull(proxyObject, "proxyObject was null");
            object resultInAppDomainFactory = appDomainFactory.invoke(proxyObject, methodToInvoke, methodParams);

            DI.log.debug("{0} = {1}", "resultInAppDomainFactory", resultInAppDomainFactory);
            Assert.That(
                (resultInCurrentAppDomain != resultInAppDomainFactory) &&
                (resultInNewAppDomain != resultInAppDomainFactory), "All results should be different");

            // test creating objects using the format {type} {assembly}
            var appDomainFactory2 = new O2AppDomainFactory("appDomainFactory2", testAppDomainDirectory);

            appDomainFactory.load(assemblyName);
            object proxyObject2 = appDomainFactory2.getProxyObject(typeToCreate + " " + assemblyName);

            Assert.IsNotNull(proxyObject2, "proxyObject2 was null");
            DI.log.debug("{0} = {1}", "appDomainFactory2", appDomainFactory.invoke(proxyObject2, methodToInvoke));

            // test if we can get a MethodInfo using using the format {method} {type} {assembly}
            var appDomainFactory3 = new O2AppDomainFactory("appDomainFactory3", testAppDomainDirectory);

            appDomainFactory.load(assemblyName);
            var methodInfoFromappDomainFactory3 =
                (MethodInfo)appDomainFactory3.getProxyMethod(methodToInvoke + " " + typeToCreate + " " + assemblyName);

            Assert.That(methodInfoFromappDomainFactory3 != null, "methodInfoFromappDomainFactory3 was null");
            DI.log.debug("{0} MethodInfo = {1}", "from appDomainFactory3", methodInfoFromappDomainFactory3.ToString());
            // we can't invoke this guy because we don't have the proxy

            // test if we can invoke a MethodInfo using using the format {method} {type} {assembly}
            var appDomainFactory4 = new O2AppDomainFactory("appDomainFactory4", testAppDomainDirectory);

            appDomainFactory.load(assemblyName);
            object invocationResult4 =
                appDomainFactory4.invokeMethod(methodToInvoke + " " + typeToCreate + " " + assemblyName);

            Assert.That(invocationResult4 != null, "invocationResult4 was null");
            DI.log.debug("[{0}] {1} {2} {3} = {4}", "from appDomainFactory4", assemblyName, typeToCreate, methodToInvoke,
                         invocationResult4); // we can't invoke this guy because we don't have the proxy
        }