예제 #1
0
        [Test] public void ResolveAssembly()
        {
            using (MockPluginLoader pluginLoader = new MockPluginLoader())
            {
                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
                pluginLoader.AddBaseDir("MockDir");
                for (int i = 0; i < mockAssemblies.Length; i++)
                {
                    pluginLoader.AddPlugin(mockAssemblies[i]);
                }

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

                // 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], pluginLoader.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
        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 (MockPluginLoader pluginLoader = new MockPluginLoader())
            {
                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
                pluginLoader.AddBaseDir("MockDir");
                for (int i = 0; i < mockAssemblies.Length; i++)
                {
                    pluginLoader.AddPlugin(mockAssemblies[i]);
                }
                pluginLoader.AddPlugin(mockEditorAssembly);

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

                {
                    // First, make sure the attempt to resolve a not-yet-loaded plugin
                    // will result in loading it immediately to satisfy dependency relations
                    Assembly resolvedAssembly = pluginLoader.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, pluginLoader.LoadedAssemblies.Count());
                    CollectionAssert.Contains(pluginLoader.LoadedAssemblies, mockAssemblies[0].Location);
                }

                {
                    // Attempt to resolve a not-yet-loaded editor plugin
                    Assembly resolvedAssembly = pluginLoader.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, pluginLoader.LoadedAssemblies.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], pluginLoader.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();
            }
        }
예제 #3
0
        public void ResolveAssembly()
        {
            using (MockPluginLoader pluginLoader = new MockPluginLoader())
            {
                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
                pluginLoader.AddBaseDir("MockDir");
                for (int i = 0; i < mockAssemblies.Length; i++)
                {
                    pluginLoader.AddPlugin(mockAssemblies[i]);
                }

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

                // 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], pluginLoader.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();
            }
        }
예제 #4
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 (MockPluginLoader pluginLoader = new MockPluginLoader())
            {
                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
                pluginLoader.AddBaseDir("MockDir");
                for (int i = 0; i < mockAssemblies.Length; i++)
                {
                    pluginLoader.AddPlugin(mockAssemblies[i]);
                }
                pluginLoader.AddPlugin(mockEditorAssembly);

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

                {
                    // First, make sure the attempt to resolve a not-yet-loaded plugin
                    // will result in loading it immediately to satisfy dependency relations
                    Assembly resolvedAssembly = pluginLoader.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, pluginLoader.LoadedAssemblyPaths.Count());
                    CollectionAssert.Contains(pluginLoader.LoadedAssemblyPaths, mockAssemblies[0].Location);
                }

                {
                    // Attempt to resolve a not-yet-loaded editor plugin
                    Assembly resolvedAssembly = pluginLoader.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, pluginLoader.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], pluginLoader.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();
            }
        }