Esempio n. 1
0
        public void PopulateCatalog_WhenPluginFileContainsPreprocessorInstructions_AppliesThem()
        {
            string pluginContents = "<plugin pluginId=\"pluginId\" xmlns=\"http://www.gallio.org/\"><traits><?ifdef A?><name>A</name><?endif?><?ifdef B?><property>B</property><?endif?></traits></plugin>";

            RunWithTemporaryPluginFile((pluginDir, pluginFile) =>
            {
                var loader  = new PluginLoader();
                var catalog = MockRepository.GenerateMock <IPluginCatalog>();
                loader.AddPluginPath(pluginFile);
                loader.DefinePreprocessorConstant("A");

                Plugin plugin = null;
                catalog.Expect(x => x.AddPlugin(null, null)).IgnoreArguments()
                .Do((Gallio.Common.GallioAction <Plugin, DirectoryInfo>) delegate(Plugin pluginArg, DirectoryInfo baseDirectoryArg)
                {
                    plugin = pluginArg;
                });

                loader.PopulateCatalog(catalog, NullProgressMonitor.CreateInstance());

                catalog.VerifyAllExpectations(); // added one plugin

                Assert.AreEqual(new PropertySet()
                {
                    { "name", "A" }
                }, plugin.Traits.PropertySet);
            }, pluginContents);
        }
Esempio n. 2
0
        public void PopulateCatalog_WhenPluginPathContainsInvalidDirectory_IgnoresIt()
        {
            var loader  = new PluginLoader();
            var catalog = MockRepository.GenerateMock <IPluginCatalog>();

            loader.AddPluginPath(@"C:\This\Directory\Does\Not\Exist");

            loader.PopulateCatalog(catalog, NullProgressMonitor.CreateInstance());

            catalog.VerifyAllExpectations(); // nothing added to catalog
        }
        private PluginLoader SetupPluginLoader(IProgressMonitor progressMonitor)
        {
            var pluginLoader = new PluginLoader();

            using (var subProgressMonitor = progressMonitor.CreateSubProgressMonitor(10))
            {
                subProgressMonitor.BeginTask(Resources.UpdatePluginFolderCommand_Adding_plugin_path, 100);
                pluginLoader.AddPluginPath(PluginFolder);
            }

            return(pluginLoader);
        }
Esempio n. 4
0
        public void PopulateCatalog_WhenPluginPathContainsUnparsablePluginFile_Throws()
        {
            RunWithTemporaryPluginFile((pluginDir, pluginFile) =>
            {
                var loader  = new PluginLoader();
                var catalog = MockRepository.GenerateMock <IPluginCatalog>();
                loader.AddPluginPath(pluginFile);

                var ex = Assert.Throws <RuntimeException>(() => loader.PopulateCatalog(catalog, NullProgressMonitor.CreateInstance()));
                Assert.AreEqual(string.Format("Failed to read and parse plugin metadata file '{0}'.", pluginFile), ex.Message);
                Assert.IsInstanceOfType <InvalidOperationException>(ex.InnerException);

                catalog.VerifyAllExpectations(); // no plugins added
            }, "<badxml />");
        }
Esempio n. 5
0
        public void PopulateCatalog_WhenPluginPathRefersToDirectoryWithAtLeastOnePluginFile_LoadsIt()
        {
            string pluginContents = GenerateValidPluginXml();

            RunWithTemporaryPluginFile((pluginDir, pluginFile) =>
            {
                var loader  = new PluginLoader();
                var catalog = MockRepository.GenerateMock <IPluginCatalog>();
                loader.AddPluginPath(pluginDir);

                Plugin plugin = null;
                DirectoryInfo baseDirectory = null;
                catalog.Expect(x => x.AddPlugin(null, null)).IgnoreArguments()
                .Do((Gallio.Common.GallioAction <Plugin, DirectoryInfo>) delegate(Plugin pluginArg, DirectoryInfo baseDirectoryArg)
                {
                    plugin        = pluginArg;
                    baseDirectory = baseDirectoryArg;
                });

                loader.PopulateCatalog(catalog, NullProgressMonitor.CreateInstance());

                catalog.VerifyAllExpectations(); // added one plugin

                Assert.Multiple(() =>
                {
                    Assert.AreEqual("pluginId", plugin.PluginId);
                    Assert.AreEqual("serviceId", plugin.Services[0].ServiceId);
                    Assert.AreEqual("componentId", plugin.Components[0].ComponentId);
                    Assert.AreEqual("Assembly1", plugin.Assemblies[0].FullName);
                    Assert.AreEqual("CodeBase.dll", plugin.Assemblies[0].CodeBase);
                    Assert.AreEqual("Assembly2", plugin.Assemblies[1].FullName);

                    Assert.AreEqual(pluginDir, baseDirectory.ToString());
                });
            }, pluginContents);
        }
Esempio n. 6
0
        public void AddPluginPath_WhenPluginPathIsNull_Throws()
        {
            var loader = new PluginLoader();

            Assert.Throws <ArgumentNullException>(() => loader.AddPluginPath(null));
        }