private bool UpdateRunSettingsIfRequired(string runsettingsXml, out string updatedRunSettingsXml) { bool settingsUpdated = false; updatedRunSettingsXml = runsettingsXml; if (!string.IsNullOrEmpty(runsettingsXml)) { // TargetFramework is full CLR. Set DesignMode based on current context. using (var stream = new StringReader(runsettingsXml)) using (var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings)) { var document = new XmlDocument(); document.Load(reader); var navigator = document.CreateNavigator(); // If user is already setting DesignMode via runsettings or CLI args; we skip. var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml); if (!runConfiguration.DesignModeSet) { InferRunSettingsHelper.UpdateDesignMode(navigator, this.commandLineOptions.IsDesignMode); settingsUpdated = true; } if (!runConfiguration.CollectSourceInformationSet) { InferRunSettingsHelper.UpdateCollectSourceInformation(navigator, this.commandLineOptions.ShouldCollectSourceInformation); settingsUpdated = true; } if (InferRunSettingsHelper.TryGetDeviceXml(navigator, out string deviceXml)) { InferRunSettingsHelper.UpdateTargetDeviceInformation(navigator, deviceXml); settingsUpdated = true; } updatedRunSettingsXml = navigator.OuterXml; } } return(settingsUpdated); }
public void UpdateTargetDeviceValueFromOldMsTestSettings() { var settings = @"<RunSettings> <RunConfiguration> <MaxCpuCount>2</MaxCpuCount> <DisableParallelization>False</DisableParallelization> <DisableAppDomain>False</DisableAppDomain> </RunConfiguration> <MSPhoneTest> <TargetDevice>169.254.193.190</TargetDevice> </MSPhoneTest> </RunSettings>"; var navigator = this.GetNavigator(settings); var result = InferRunSettingsHelper.TryGetDeviceXml(navigator, out string deviceXml); Assert.IsTrue(result); InferRunSettingsHelper.UpdateTargetDeviceInformation(navigator, deviceXml); Assert.AreEqual(deviceXml.ToString(), this.GetValueOf(navigator, "/RunSettings/RunConfiguration/TargetDevice")); }