public void AddBindingRedirect_WhenBindingRedirectIsNotNull_AddsTheRedirect() { var binding = new AssemblyBinding(new AssemblyName("Gallio")); binding.AddBindingRedirect(new AssemblyBinding.BindingRedirect("1.2.3.4")); Assert.AreElementsEqual(new[] { new AssemblyBinding.BindingRedirect("1.2.3.4") }, binding.BindingRedirects, (x, y) => x.OldVersion == y.OldVersion); }
private static IList <IPluginDescriptor> RegisterPlugins(IRegistry registry, IList <PluginData> topologicallySortedPlugins) { IPluginDescriptor[] pluginDescriptors = new IPluginDescriptor[topologicallySortedPlugins.Count]; for (int i = 0; i < topologicallySortedPlugins.Count; i++) { Plugin plugin = topologicallySortedPlugins[i].Plugin; DirectoryInfo baseDirectory = topologicallySortedPlugins[i].BaseDirectory; try { var pluginType = plugin.PluginType != null ? new TypeName(plugin.PluginType) : new TypeName(typeof(DefaultPlugin)); List <string> disabledReasons = new List <string>(); var pluginRegistration = new PluginRegistration(plugin.PluginId, pluginType, baseDirectory); if (plugin.Parameters != null) { pluginRegistration.PluginProperties = plugin.Parameters.PropertySet; } if (plugin.Traits != null) { pluginRegistration.TraitsProperties = plugin.Traits.PropertySet; } pluginRegistration.ProbingPaths = plugin.ProbingPaths; pluginRegistration.RecommendedInstallationPath = plugin.RecommendedInstallationPath; if (plugin.EnableCondition != null) { pluginRegistration.EnableCondition = Condition.Parse(plugin.EnableCondition); } foreach (var file in plugin.Files) { pluginRegistration.FilePaths.Add(file.Path); } foreach (var dependency in plugin.Dependencies) { string pluginDependencyId = dependency.PluginId; IPluginDescriptor pluginDependency = registry.Plugins[pluginDependencyId]; if (pluginDependency == null) { disabledReasons.Add(string.Format("Could not find plugin '{0}' upon which this plugin depends.", pluginDependencyId)); } else { pluginRegistration.PluginDependencies.Add(pluginDependency); } } foreach (var assembly in plugin.Assemblies) { Uri absoluteCodeBase; if (assembly.CodeBase != null) { List <string> attemptedPaths = new List <string>(); string foundCodeBasePath = ProbeForCodeBase(baseDirectory, plugin.ProbingPaths, assembly.CodeBase, attemptedPaths); if (foundCodeBasePath == null) { StringBuilder formattedPaths = new StringBuilder(); foreach (string path in attemptedPaths) { if (formattedPaths.Length != 0) { formattedPaths.Append(", "); } formattedPaths.Append("'").Append(path).Append("'"); } disabledReasons.Add(string.Format("Could not find assembly '{0}' after probing for its code base in {1}.", assembly.FullName, formattedPaths)); absoluteCodeBase = null; } else { absoluteCodeBase = new Uri(foundCodeBasePath); } } else { #if STRICT_GAC_CHECKS if (!IsAssemblyRegisteredInGAC(assembly.FullName)) { disabledReasons.Add( string.Format("Could not find assembly '{0}' in the global assembly cache.", assembly.FullName)); } #endif absoluteCodeBase = null; } var assemblyBinding = new AssemblyBinding(new AssemblyName(assembly.FullName)) { CodeBase = absoluteCodeBase, QualifyPartialName = assembly.QualifyPartialName, ApplyPublisherPolicy = assembly.ApplyPublisherPolicy }; foreach (BindingRedirect redirect in assembly.BindingRedirects) { assemblyBinding.AddBindingRedirect(new AssemblyBinding.BindingRedirect(redirect.OldVersion)); } pluginRegistration.AssemblyBindings.Add(assemblyBinding); } IPluginDescriptor pluginDescriptor = registry.RegisterPlugin(pluginRegistration); pluginDescriptors[i] = pluginDescriptor; if (disabledReasons.Count != 0) { pluginDescriptor.Disable(disabledReasons[0]); } } catch (Exception ex) { throw new RuntimeException(string.Format("Could not register plugin '{0}'.", plugin.PluginId), ex); } } return(pluginDescriptors); }
public void AddBindingRedirect_WhenBindingRedirectIsNull_Throws() { var binding = new AssemblyBinding(new AssemblyName("Gallio")); Assert.Throws <ArgumentNullException>(() => binding.AddBindingRedirect(null)); }