Ejemplo n.º 1
0
        public void PopulateCatalog_WhenPluginXmlContainsPreprocessorInstructions_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>";

            var loader  = new PluginLoader();
            var catalog = MockRepository.GenerateMock <IPluginCatalog>();

            loader.AddPluginXml(pluginContents, new DirectoryInfo(@"C:\"));
            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);
        }
Ejemplo n.º 2
0
        public void PopulateCatalog_WhenPluginXmlIsValid_LoadsIt()
        {
            string pluginContents = GenerateValidPluginXml();

            var loader  = new PluginLoader();
            var catalog = MockRepository.GenerateMock <IPluginCatalog>();

            loader.AddPluginXml(pluginContents, new DirectoryInfo(@"C:\"));

            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(@"C:\", baseDirectory.ToString());
            });
        }
Ejemplo n.º 3
0
        public void PopulateCatalog_WhenPluginXmlCannotBeParsed_Throws()
        {
            var loader  = new PluginLoader();
            var catalog = MockRepository.GenerateMock <IPluginCatalog>();

            loader.AddPluginXml("<badxml />", new DirectoryInfo(@"C:\"));

            var ex = Assert.Throws <RuntimeException>(() => loader.PopulateCatalog(catalog, NullProgressMonitor.CreateInstance()));

            Assert.AreEqual("Failed to read and parse plugin metadata from Xml configuration.", ex.Message);
            Assert.IsInstanceOfType <InvalidOperationException>(ex.InnerException);

            catalog.VerifyAllExpectations(); // no plugins added
        }
Ejemplo n.º 4
0
        public void AddPluginXml_WhenBaseDirectoryIsNull_Throws()
        {
            var loader = new PluginLoader();

            Assert.Throws <ArgumentNullException>(() => loader.AddPluginXml("", null));
        }
Ejemplo n.º 5
0
        public void AddPluginXml_WhenPluginXmlIsNull_Throws()
        {
            var loader = new PluginLoader();

            Assert.Throws <ArgumentNullException>(() => loader.AddPluginXml(null, new DirectoryInfo(@"C:\")));
        }