コード例 #1
0
        public void ShouldResolvePartialAssemblyName()
        {
            string assemblyPath = CompilerHelper.GenerateDynamicModule("ModuleInLoadedFromContext2", "Module", ModulesDirectory1 + @"\ModuleInLoadedFromContext2.dll");
            var    uriBuilder   = new UriBuilder
            {
                Host   = String.Empty,
                Scheme = Uri.UriSchemeFile,
                Path   = Path.GetFullPath(assemblyPath)
            };
            var assemblyUri = uriBuilder.Uri;

            using (var resolver = new AssemblyResolver())
            {
                resolver.LoadAssemblyFrom(assemblyUri.ToString());

                Type resolvedType =
                    Type.GetType("TestModules.ModuleInLoadedFromContext2Class, ModuleInLoadedFromContext2");

                Assert.IsNotNull(resolvedType);

                resolvedType =
                    Type.GetType("TestModules.ModuleInLoadedFromContext2Class, ModuleInLoadedFromContext2, Version=0.0.0.0");

                Assert.IsNotNull(resolvedType);

                resolvedType =
                    Type.GetType("TestModules.ModuleInLoadedFromContext2Class, ModuleInLoadedFromContext2, Version=0.0.0.0, Culture=neutral");

                Assert.IsNotNull(resolvedType);
            }
        }
コード例 #2
0
        public void ShouldResolveTypeFromAbsoluteUriToAssembly()
        {
            string assemblyPath = CompilerHelper.GenerateDynamicModule("ModuleInLoadedFromContext1", "Module", ModulesDirectory1 + @"\ModuleInLoadedFromContext1.dll");
            var    uriBuilder   = new UriBuilder
            {
                Host   = String.Empty,
                Scheme = Uri.UriSchemeFile,
                Path   = Path.GetFullPath(assemblyPath)
            };
            var assemblyUri = uriBuilder.Uri;

            using (var resolver = new AssemblyResolver())
            {
                Type resolvedType =
                    Type.GetType(
                        "TestModules.ModuleInLoadedFromContext1Class, ModuleInLoadedFromContext1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
                Assert.Null(resolvedType);

                resolver.LoadAssemblyFrom(assemblyUri.ToString());

                resolvedType =
                    Type.GetType(
                        "TestModules.ModuleInLoadedFromContext1Class, ModuleInLoadedFromContext1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
                Assert.NotNull(resolvedType);
            }
        }
コード例 #3
0
ファイル: ModuleLoaderFixture.cs プロジェクト: eslahi/prism
        public void FailWhenDependingOnMissingModule()
        {
            string     assembly = CompilerHelper.GenerateDynamicModule("ModuleK", null, "ModuleL");
            ModuleInfo module   = new ModuleInfo(assembly, "ModuleK.TestsModules.ModuleKClass", "ModuleK", "ModuleL");

            ModuleLoader loader = new ModuleLoader(new MockContainerAdapter(), new MockLogger());

            loader.Initialize(new[] { module });
        }
コード例 #4
0
        public void CanRetrieveModule()
        {
            var    assemblyResolver = new MockAssemblyResolver();
            var    retriever        = new FileModuleTypeLoader(assemblyResolver);
            string assembly         = CompilerHelper.GenerateDynamicModule("FileModuleA", null);
            var    fileModuleInfo   = CreateModuleInfo(assembly, "TestModules.FileModuleAClass", "ModuleA", true, null);

            ManualResetEvent callbackEvent = new ManualResetEvent(false);

            retriever.BeginLoadModuleType(fileModuleInfo, delegate
            {
                callbackEvent.Set();
            });

            callbackEvent.WaitOne(500);

            Assert.AreEqual(assembly, assemblyResolver.LoadAssemblyFromArgument);
        }
コード例 #5
0
        public void CanRetrieveModule()
        {
            var    assemblyResolver = new MockAssemblyResolver();
            var    retriever        = new FileModuleTypeLoader(assemblyResolver);
            string assembly         = CompilerHelper.GenerateDynamicModule("FileModuleA", null);
            string assemblyRef      = "file://" + assembly;
            var    fileModuleInfo   = CreateModuleInfo(assemblyRef, "TestModules.FileModuleAClass", "ModuleA", true, null);

            bool loadCompleted = false;

            retriever.LoadModuleCompleted += delegate(object sender, LoadModuleCompletedEventArgs e)
            {
                loadCompleted = true;
            };

            retriever.LoadModuleType(fileModuleInfo);

            Assert.IsTrue(loadCompleted);
            Assert.AreEqual(assemblyRef, assemblyResolver.LoadAssemblyFromArgument);
        }
コード例 #6
0
ファイル: ModuleLoaderFixture.cs プロジェクト: eslahi/prism
        public void FailWhenLoadingModulesWithCyclicDependencies()
        {
            List <string> assemblies = new List <string>();

            // Create several modules with this dependency graph (X->Y meaning Y depends on X)
            // 1->2, 2->3, 3->4, 4->5, 4->2
            assemblies.Add(CompilerHelper.GenerateDynamicModule("Module1", "Module1"));
            assemblies.Add(CompilerHelper.GenerateDynamicModule("Module2", "Module2", "Module1", "Module4"));
            assemblies.Add(CompilerHelper.GenerateDynamicModule("Module3", "Module3", "Module2"));
            assemblies.Add(CompilerHelper.GenerateDynamicModule("Module4", "Module4", "Module3"));
            assemblies.Add(CompilerHelper.GenerateDynamicModule("Module5", "Module5", "Module4"));

            List <ModuleInfo> modules = new List <ModuleInfo>();

            modules.Add(new ModuleInfo(assemblies[0], "Module1.TestModules.Module1Class", "Module1"));
            modules.Add(new ModuleInfo(assemblies[1], "Module2.TestModules.Module2Class", "Module2", "Module1", "Module4"));
            modules.Add(new ModuleInfo(assemblies[2], "Module3.TestModules.Module3Class", "Module3", "Module2"));
            modules.Add(new ModuleInfo(assemblies[3], "Module4.TestModules.Module4Class", "Module4", "Module3"));
            modules.Add(new ModuleInfo(assemblies[4], "Module5.TestModules.Module5Class", "Module5", "Module4"));

            ModuleLoader loader = new ModuleLoader(new MockContainerAdapter(), new MockLogger());

            loader.Initialize(modules.ToArray());
        }