コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
        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)));
        }