public void OnAssemblyRemovedShouldRaisePluginLostForEachPluginInAssembly() { MockAssemblySource mockSource = new MockAssemblySource(); PluginExtractor tested = new PluginExtractor(mockSource); List<PluginDescriptor> plugins = new List<PluginDescriptor>(); tested.PluginAdded += (s, e) => plugins.Add(e.Plugin); tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin); using (AssemblyReflectionManager manager = new AssemblyReflectionManager()) { string assemblyPath = GetType().Assembly.Location; manager.LoadAssembly(assemblyPath); mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager)); AssemblyRemovedEventArgs args = new AssemblyRemovedEventArgs(assemblyPath); mockSource.RaiseAssemblyRemoved(args); } Assert.AreEqual(0, plugins.Count); }
public void PluginDescriptorShouldContainDefaultName() { MockAssemblySource mockSource = new MockAssemblySource(); PluginExtractor tested = new PluginExtractor(mockSource); List<PluginDescriptor> plugins = new List<PluginDescriptor>(); tested.PluginAdded += (s, e) => plugins.Add(e.Plugin); tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin); using (AssemblyReflectionManager manager = new AssemblyReflectionManager()) { string assemblyPath = GetType().Assembly.Location; manager.LoadAssembly(assemblyPath); mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager)); } var expected = typeof(MockPlugin1).FullName; PluginDescriptor plugin = plugins.First(x => x.QualifiedName == typeof(MockPlugin1)); Assert.AreEqual(expected, plugin.Name); }
public void PluginDescriptorShouldContainPluginSettings() { MockAssemblySource mockSource = new MockAssemblySource(); PluginExtractor tested = new PluginExtractor(mockSource); List<PluginDescriptor> plugins = new List<PluginDescriptor>(); tested.PluginAdded += (s, e) => plugins.Add(e.Plugin); tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin); using (AssemblyReflectionManager manager = new AssemblyReflectionManager()) { string assemblyPath = GetType().Assembly.Location; manager.LoadAssembly(assemblyPath); mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager)); } PluginDescriptor plugin = plugins.First(x => x.QualifiedName == typeof(MockPlugin1)); Assert.AreEqual(2, plugin.Settings.Count); Assert.IsTrue(plugin.Settings.Any(x => x.Name == "Setting" && x.SettingType == typeof(int))); Assert.IsTrue(plugin.Settings.Any(x => x.Name == "AnotherSetting" && x.SettingType == typeof(string))); }
public void PluginDescriptorShouldContainDerivedClasses() { MockAssemblySource mockSource = new MockAssemblySource(); PluginExtractor tested = new PluginExtractor(mockSource); List<PluginDescriptor> plugins = new List<PluginDescriptor>(); tested.PluginAdded += (s, e) => plugins.Add(e.Plugin); tested.PluginRemoved += (s, e) => plugins.Remove(e.Plugin); using (AssemblyReflectionManager manager = new AssemblyReflectionManager()) { string assemblyPath = GetType().Assembly.Location; manager.LoadAssembly(assemblyPath); mockSource.RaiseAssemblyAdded(new AssemblyAddedEventArgs(assemblyPath, manager)); } PluginDescriptor plugin = plugins.First(x => x.QualifiedName == typeof(MockPlugin1)); Assert.AreEqual(3, plugin.Derives.Count); Assert.IsTrue(plugin.Derives.Any(x => x == typeof(MockPluginBase))); Assert.IsTrue(plugin.Derives.Any(x => x == typeof(MarshalByRefObject))); Assert.IsTrue(plugin.Derives.Any(x => x == typeof(object))); }