public void AddPluginXml_WhenBaseDirectoryIsNull_Throws() { var loader = new PluginLoader(); Assert.Throws<ArgumentNullException>(() => loader.AddPluginXml("", null)); }
public void AddPluginXml_WhenPluginXmlIsNull_Throws() { var loader = new PluginLoader(); Assert.Throws<ArgumentNullException>(() => loader.AddPluginXml(null, new DirectoryInfo(@"C:\"))); }
public void PopulateCatalog_WhenPluginXmlIsInvalid_Throws() { string pluginContents = GenerateInvalidPluginXml(); var loader = new PluginLoader(); var catalog = MockRepository.GenerateMock<IPluginCatalog>(); loader.AddPluginXml(pluginContents, 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<ValidationException>(ex.InnerException); catalog.VerifyAllExpectations(); // no plugins added }
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.Action<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); }
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.Action<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()); }); }