Пример #1
0
        [Test] public void LoadPlugins()
        {
            //
            // In this test, we're going to check overall LoadPlugins behavior,
            // as well as the specific case of selective loading, where non-editor
            // plugins and non-plugins are filtered out before loading.
            //
            using (MockPluginLoader pluginLoader = new MockPluginLoader())
            {
                // Set up some mock data for available assemblies
                MockAssembly[] mockPlugins = new MockAssembly[]
                {
                    new MockAssembly("MockDir/MockPluginA.editor.dll", typeof(MockEditorPlugin)),
                    new MockAssembly("MockDir/MockPluginB.editor.dll", typeof(MockEditorPlugin)),
                    new MockAssembly("MockDir2/MockPluginC.editor.dll", typeof(MockEditorPlugin))
                };
                MockAssembly[] mockNoise = new MockAssembly[]
                {
                    new MockAssembly("MockDir/MockAuxillaryA.dll"),
                    new MockAssembly("MockDir/MockPluginD.core.dll", typeof(MockEditorPlugin)),
                    new MockAssembly("MockDir/MockPluginE.editor.dll"),
                    new MockAssembly("MockDir2/MockAuxillaryB.dll", typeof(MockEditorPlugin)),
                    MockAssembly.CreateInvalid("MockDir2/MockPluginF.editor.dll"),
                    MockAssembly.CreateInvalid("MockDir2/MockAuxillaryC.dll")
                };
                string[] mockLoadedPaths = new string[] {
                    mockPlugins[0].Location, mockPlugins[1].Location, mockPlugins[2].Location,
                    mockNoise[2].Location, mockNoise[4].Location
                };

                pluginLoader.AddBaseDir("MockDir");
                pluginLoader.AddBaseDir("MockDir2");
                for (int i = 0; i < mockPlugins.Length; i++)
                {
                    pluginLoader.AddPlugin(mockPlugins[i]);
                }
                for (int i = 0; i < mockNoise.Length; i++)
                {
                    pluginLoader.AddPlugin(mockNoise[i]);
                }
                pluginLoader.AddIncompatibleDll("MockDir2/MockAuxillaryD.dll");

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

                // Load all plugins
                pluginManager.LoadPlugins();
                EditorPlugin[] loadedPlugins = pluginManager.LoadedPlugins.ToArray();

                // Assert that we loaded all expected plugins, but nothing more
                Assert.AreEqual(3, loadedPlugins.Length);
                CollectionAssert.AreEquivalent(mockPlugins, loadedPlugins.Select(plugin => plugin.PluginAssembly));

                // Assert that we properly assigned all plugin properties
                Assert.IsTrue(loadedPlugins.All(plugin => plugin.AssemblyName == plugin.PluginAssembly.GetShortAssemblyName()));

                // Assert that we loaded core plugin and auxilliary libraries, but not editor plugins
                CollectionAssert.AreEquivalent(
                    mockLoadedPaths,
                    pluginLoader.LoadedAssemblies);

                // Assert that we can access all assemblies and types from plugins
                foreach (MockAssembly mockAssembly in mockPlugins)
                {
                    CollectionAssert.Contains(pluginManager.GetAssemblies(), mockAssembly);
                }
                CollectionAssert.Contains(pluginManager.GetTypes(typeof(object)), typeof(MockEditorPlugin));
                Assert.AreEqual(3, pluginManager.GetTypes(typeof(MockEditorPlugin)).Count());

                pluginManager.Terminate();
            }
        }