예제 #1
0
        [Test] public void ResolveAssembly()
        {
            using (MockAssemblyLoader assemblyLoader = new MockAssemblyLoader())
            {
                MockAssembly[] mockAssemblies = new MockAssembly[]
                {
                    new MockAssembly("MockDir/MockPluginA.dll", typeof(MockPlugin)),
                    new MockAssembly("MockDir/MockPluginB.dll", typeof(MockPlugin)),
                    new MockAssembly("MockDir/MockPluginC.dll", typeof(MockPlugin))
                };

                // Set up some mock data for available assemblies
                assemblyLoader.AddBaseDir("MockDir");
                for (int i = 0; i < mockAssemblies.Length; i++)
                {
                    assemblyLoader.AddPlugin(mockAssemblies[i]);
                }

                // Set up a plugin manager using the mock loader
                MockPluginManager pluginManager = new MockPluginManager();
                pluginManager.Init(assemblyLoader);

                // Load and init all plugins
                pluginManager.LoadPlugins();
                pluginManager.InitPlugins();

                // Assert that other resolve calls will map to existing assemblies,
                // both for plugins and auxilliary libraries
                for (int i = 0; i < mockAssemblies.Length; i++)
                {
                    Assert.AreSame(mockAssemblies[i], assemblyLoader.InvokeResolveAssembly(mockAssemblies[i].FullName));
                }

                // Assert that we still have the expected amount of loaded and disposed plugins
                Assert.AreEqual(3, pluginManager.LoadedPlugins.Count());
                Assert.IsEmpty(pluginManager.DisposedPlugins);

                pluginManager.Terminate();
            }
        }
예제 #2
0
        [Test] public void ResolveAssembly()
        {
            //
            // In this test, we're going to check the CorePluginManager's ability
            // to load requested core plugins on-demand (to satisfy inter-plugin dependencies)
            // as well as to reject non-core and non-plugins in those requests.
            //
            using (MockAssemblyLoader assemblyLoader = new MockAssemblyLoader())
            {
                MockAssembly[] mockAssemblies = new MockAssembly[]
                {
                    new MockAssembly("MockDir/MockPluginA.core.dll", typeof(MockCorePlugin)),
                    new MockAssembly("MockDir/MockPluginB.core.dll", typeof(MockCorePlugin)),
                    new MockAssembly("MockDir/MockPluginC.core.dll", typeof(MockCorePlugin)),
                    new MockAssembly("MockDir/MockAuxilliaryA.dll"),
                    new MockAssembly("MockDir/MockAuxilliaryB.dll")
                };
                MockAssembly mockEditorAssembly = new MockAssembly("MockDir/MockPluginD.editor.dll");

                // Set up some mock data for available assemblies
                assemblyLoader.AddBaseDir("MockDir");
                for (int i = 0; i < mockAssemblies.Length; i++)
                {
                    assemblyLoader.AddPlugin(mockAssemblies[i]);
                }
                assemblyLoader.AddPlugin(mockEditorAssembly);

                // Set up a plugin manager using the mock loader
                CorePluginManager pluginManager = new CorePluginManager();
                pluginManager.Init(assemblyLoader);

                {
                    // First, make sure the attempt to resolve a not-yet-loaded plugin
                    // will result in loading it immediately to satisfy dependency relations
                    Assembly resolvedAssembly = assemblyLoader.InvokeResolveAssembly(mockAssemblies[0].FullName);

                    // Assert that we successfully resolved it with a plugin (not just an assembly)
                    Assert.IsNotNull(resolvedAssembly);
                    Assert.AreSame(mockAssemblies[0], resolvedAssembly);
                    Assert.AreEqual(1, pluginManager.LoadedPlugins.Count());
                    Assert.AreSame(mockAssemblies[0], pluginManager.LoadedPlugins.First().PluginAssembly);
                    Assert.AreEqual(1, assemblyLoader.LoadedAssemblyPaths.Count());
                    CollectionAssert.Contains(assemblyLoader.LoadedAssemblyPaths, mockAssemblies[0].Location);
                }

                {
                    // Attempt to resolve a not-yet-loaded editor plugin
                    Assembly resolvedAssembly = assemblyLoader.InvokeResolveAssembly(mockEditorAssembly.FullName);

                    // Assert that we did not resolve this, nor load any assemblies.
                    // Leave this to the EditorPluginManager, which can properly load them as a plugin.
                    Assert.IsNull(resolvedAssembly);
                    Assert.AreEqual(1, pluginManager.LoadedPlugins.Count());
                    Assert.AreEqual(1, assemblyLoader.LoadedAssemblyPaths.Count());
                }

                // Load and init all plugins
                pluginManager.LoadPlugins();
                pluginManager.InitPlugins();

                // Assert that we do not have any duplicates and no disposed plugins
                Assert.AreEqual(3, pluginManager.LoadedPlugins.Count());
                Assert.IsEmpty(pluginManager.DisposedPlugins);

                // Assert that other resolve calls will map to existing assemblies,
                // both for plugins and auxilliary libraries
                for (int i = 0; i < mockAssemblies.Length; i++)
                {
                    Assert.AreSame(mockAssemblies[i], assemblyLoader.InvokeResolveAssembly(mockAssemblies[i].FullName));
                }

                // Assert that we still have the expected amount of loaded and disposed plugins
                Assert.AreEqual(3, pluginManager.LoadedPlugins.Count());
                Assert.IsEmpty(pluginManager.DisposedPlugins);

                pluginManager.Terminate();
            }
        }