[Test] public void ResolveAssembly() { // // In this test, we're going to check the CorePluginManager's ability // to load requested editor plugins on-demand (to satisfy inter-plugin dependencies) // as well as to reject non-editor and non-plugins in those requests. // using (MockAssemblyLoader assemblyLoader = new MockAssemblyLoader()) { MockAssembly[] mockAssemblies = new MockAssembly[] { new MockAssembly("MockDir/MockPluginA.editor.dll", typeof(MockEditorPlugin)), new MockAssembly("MockDir/MockPluginB.editor.dll", typeof(MockEditorPlugin)), new MockAssembly("MockDir/MockPluginC.editor.dll", typeof(MockEditorPlugin)) }; MockAssembly mockCoreAssembly = new MockAssembly("MockDir/MockPluginD.core.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(mockCoreAssembly); // Set up a plugin manager using the mock loader EditorPluginManager pluginManager = new EditorPluginManager(); 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 core plugin Assembly resolvedAssembly = assemblyLoader.InvokeResolveAssembly(mockCoreAssembly.FullName); // Assert that we did not resolve this, nor load any assemblies. // Leave this to the CorePluginManager, 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 still the same count of plugins Assert.AreEqual(3, pluginManager.LoadedPlugins.Count()); // 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 do not have any duplicates and still the same count of plugins Assert.AreEqual(3, pluginManager.LoadedPlugins.Count()); pluginManager.Terminate(); } }