/// <summary> /// Combine the settings in an other instance with the settings in this one. /// The settings in other overwrite settings in this. /// </summary> /// <param name="other"></param> public void MergeFrom(CatchAdapterSettings other) { // Combine the xclusion lists. this.TestExeInclude.AddRange(other.TestExeInclude); this.TestExeExclude.AddRange(other.TestExeExclude); // Combine the roots this.TestSourcePathRoots.AddRange(other.TestSourcePathRoots); }
/// <summary> /// Load the settings from xml. /// </summary> /// <param name="reader">Reader pointed at the root node of the adapter settings node.</param> public void Load(XmlReader reader) { // Check that the node is correct. if (reader.Read() && reader.Name == CatchAdapterSettings.XmlRoot) { // Deserialize the settings. var deserializer = new XmlSerializer(typeof(CatchAdapterSettings)); this.Settings = deserializer.Deserialize(reader) as CatchAdapterSettings; } }
/// <summary> /// Loads settings from the runsettings in the discovery context. /// Returns default settings otherwise. /// </summary> /// <param name="context"></param> /// <returns></returns> public static CatchAdapterSettings LoadSettings(IRunSettings runSettings) { CatchAdapterSettings settings = new CatchAdapterSettings(); if (runSettings != null) { var provider = runSettings.GetSettings(CatchAdapterSettings.XmlRoot) as CatchSettingsProvider; if (provider != null && provider.Settings != null) { settings = provider.Settings; } } return(settings); }
/// <summary> /// Visual studio calls this method on the IRunSettingsService to collect /// run settings for tests adapters. /// /// The settings are serialized as XML, because they need to be passed to the /// test host service across a process boundary. /// </summary> /// <param name="inputRunSettingDocument">Pre-existing run settings. Defaults or from a manually specified runsettings file.</param> /// <param name="configurationInfo">Contextual information on the test run.</param> /// <param name="log">Logger.</param> /// <returns>The entire settings document, as it should be after our modifications.</returns> public IXPathNavigable AddRunSettings( IXPathNavigable inputRunSettingDocument, IRunSettingsConfigurationInfo configurationInfo, ILogger log) { // This shall contain the merged settings. CatchAdapterSettings settings = new CatchAdapterSettings(); // Try to find an existing catch configuration node. var settingsFromContext = MaybeReadSettingsFromXml(inputRunSettingDocument); XPathNavigator navigator = inputRunSettingDocument.CreateNavigator(); if (settingsFromContext == null) { // Note that explicit runsettings for catch were not provided. log.Log(MessageLevel.Informational, $"No '{CatchAdapterSettings.XmlRoot}' node in explicit runsettings (or no explicit runsettins at all). " + "Searching for runsettings in solution directory and above."); // Read settings from files. foreach (var file in FindSettingsInFoldersAbove(Path.GetDirectoryName(dte.Solution.FullName), log)) { try { // Try to find settings from the file. var settingsFromFile = MaybeReadSettingsFromFile(file); if (settingsFromFile != null) { log.Log(MessageLevel.Informational, $"Reading test run settings from {file}."); settings.MergeFrom(settingsFromFile); } } catch (IOException ex) { log.Log(MessageLevel.Warning, $"Failed to read test run settings from file '{file}'. Exception: {ex.ToString()}"); } } } else { // Merge the settings from the context. settings.MergeFrom(settingsFromContext); // Erase the original. if (navigator.MoveToFollowing(CatchAdapterSettings.XmlRoot, "")) { navigator.DeleteSelf(); } } // Write the resolved settings to the xml. XPathNavigator settingsAsXml = settings.ToXml().CreateNavigator(); navigator.MoveToRoot(); navigator.MoveToFirstChild(); navigator.AppendChild(settingsAsXml); // Clean up the navigator. navigator.MoveToRoot(); return(navigator); }