diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 26bbe02b7f..502f443153 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -61,8 +61,8 @@ $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1 # Dotnet build doesn't support --packages yet. See https://github.com/dotnet/cli/issues/2712 $env:NUGET_PACKAGES = $env:TP_PACKAGES_DIR $env:NUGET_EXE_Version = "3.4.3" -$env:DOTNET_CLI_VERSION = "2.1.0-preview1-007372" -# $env:DOTNET_RUNTIME_VERSION = "LATEST" +$env:DOTNET_CLI_VERSION = "LATEST" +$env:DOTNET_RUNTIME_VERSION = "LATEST" $env:VSWHERE_VERSION = "2.0.2" $env:MSBUILD_VERSION = "15.0" diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs index 395f937052..d933f3aefe 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs @@ -537,9 +537,9 @@ private Dictionary GetEnvironmentVari var dataCollectorEnvironmentVariable = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (var dataCollectorInfo in this.RunDataCollectors.Values) { + dataCollectorInfo.SetTestExecutionEnvironmentVariables(); try { - dataCollectorInfo.SetTestExecutionEnvironmentVariables(); this.AddCollectorEnvironmentVariables(dataCollectorInfo, dataCollectorEnvironmentVariable); } catch (Exception ex) diff --git a/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsProviderExtensions.cs b/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsProviderExtensions.cs index e2cf3529b8..d97856db80 100644 --- a/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsProviderExtensions.cs +++ b/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsProviderExtensions.cs @@ -109,8 +109,10 @@ private static string AddDefaultRunSettings(string runSettings) var document = new XmlDocument(); document.Load(reader); - InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(document, architecture, framework, defaultResultsDirectory); - return document.OuterXml; + var navigator = document.CreateNavigator(); + + InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, architecture, framework, defaultResultsDirectory); + return navigator.OuterXml; } } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs index e4b5d7186a..baac2470d5 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs @@ -26,7 +26,7 @@ internal class ProxyExecutionManagerWithDataCollection : ProxyExecutionManager /// /// Initializes a new instance of the class. /// - /// + /// /// Test request sender instance. /// /// @@ -44,7 +44,6 @@ public ProxyExecutionManagerWithDataCollection(IRequestData requestData, ITestRe this.ProxyDataCollectionManager = proxyDataCollectionManager; this.DataCollectionRunEventsHandler = new DataCollectionRunEventsHandler(); this.requestData = requestData; - this.dataCollectionEnvironmentVariables = new Dictionary(); } /// diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs index 687066c8ce..9fc0ac15c0 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs @@ -149,7 +149,7 @@ public DataCollectionParameters BeforeTestRunStart( ITestMessageEventHandler runEventsHandler) { var areTestCaseLevelEventsRequired = false; - IDictionary environmentVariables = new Dictionary(); + IDictionary environmentVariables = null; var dataCollectionEventsPort = 0; this.InvokeDataCollectionServiceAction( diff --git a/src/Microsoft.TestPlatform.ObjectModel/Navigation/NativeMethods.cs b/src/Microsoft.TestPlatform.ObjectModel/Navigation/NativeMethods.cs index 54f176beac..d207641584 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Navigation/NativeMethods.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Navigation/NativeMethods.cs @@ -556,11 +556,19 @@ internal static class DiaSourceObject public static IDiaDataSource GetDiaSourceObject() { - var nativeDllDirectory = new ProcessHelper().GetNativeDllDirectory(); + var currentDirectory = new ProcessHelper().GetCurrentProcessLocation(); - IntPtr modHandle = LoadLibraryEx(Path.Combine(nativeDllDirectory, "msdia140.dll"), IntPtr.Zero, 0); + IntPtr modHandle = IntPtr.Zero; + if (IntPtr.Size == 8) + { + modHandle = LoadLibraryEx(Path.Combine(currentDirectory, "x64\\msdia140.dll"), IntPtr.Zero, 0); + } + else + { + modHandle = LoadLibraryEx(Path.Combine(currentDirectory, "x86\\msdia140.dll"), IntPtr.Zero, 0); + } - if (modHandle == IntPtr.Zero) + if(modHandle == IntPtr.Zero) { throw new COMException(string.Format(Resources.Resources.FailedToLoadMsDia)); } diff --git a/src/Microsoft.TestPlatform.ObjectModel/TestCase.cs b/src/Microsoft.TestPlatform.ObjectModel/TestCase.cs index 786af5c29a..55c631c32e 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/TestCase.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/TestCase.cs @@ -18,12 +18,13 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel [DataContract] public sealed class TestCase : TestObject { +#if TODO /// /// LocalExtensionData which can be used by Adapter developers for local transfer of extended properties. /// Note that this data is available only for in-Proc execution, and may not be available for OutProc executors /// - private Object localExtensionData; - + private Object m_localExtensionData; +#endif private Guid defaultId = Guid.Empty; private Guid id; private string displayName; @@ -69,15 +70,17 @@ public TestCase(string fullyQualifiedName, Uri executorUri, string source) #region Properties +#if TODO /// /// LocalExtensionData which can be used by Adapter developers for local transfer of extended properties. /// Note that this data is available only for in-Proc execution, and may not be available for OutProc executors /// public Object LocalExtensionData { - get { return localExtensionData; } - set { localExtensionData = value; } + get { return m_localExtensionData; } + set { m_localExtensionData = value; } } +#endif /// /// Gets or sets the id of the test case. diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs b/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs index dd1c79dd5d..d45c31f47b 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs @@ -212,14 +212,7 @@ public static IXPathNavigable CreateDefaultRunSettings() #if NET451 return doc; #else - // Xmldocument doesn't inherit from XmlDocument for netcoreapp2.0 - var ret = doc as IXPathNavigable; - if (ret == null) - { - return doc.ToXPathNavigable(); - } - - return ret; + return doc.ToXPathNavigable(); #endif } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs index eca17c7099..e463046c8e 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs @@ -41,18 +41,6 @@ public interface IProcessHelper /// Location of test engine. string GetTestEngineDirectory(); - /// - /// Gets the location of native dll's, depending on current process architecture.. - /// - /// Location of native dll's - string GetNativeDllDirectory(); - - /// - /// Gets current process architecture - /// - /// Process Architecture - PlatformArchitecture GetCurrentProcessArchitecture(); - /// /// Gets the process id of test engine. /// diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs index ec924ed47b..aa147a1aad 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs @@ -16,8 +16,6 @@ namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions /// public partial class ProcessHelper : IProcessHelper { - private static readonly string ARM = "arm"; - /// public object LaunchProcess(string processPath, string arguments, string workingDirectory, IDictionary envVariables, Action errorCallback, Action exitCallBack) { @@ -164,28 +162,5 @@ public int GetProcessId(object process) var proc = process as Process; return proc?.Id ?? -1; } - - /// - public PlatformArchitecture GetCurrentProcessArchitecture() - { - if (IntPtr.Size == 8) - { - return PlatformArchitecture.X64; - } - - return PlatformArchitecture.X86; - } - - /// - public string GetNativeDllDirectory() - { - var osArchitecture = new PlatformEnvironment().Architecture; - if (osArchitecture == PlatformArchitecture.ARM || osArchitecture == PlatformArchitecture.ARM64) - { - return Path.Combine(this.GetCurrentProcessLocation(), this.GetCurrentProcessArchitecture().ToString().ToLower(), ARM); - } - - return Path.Combine(this.GetCurrentProcessLocation(), this.GetCurrentProcessArchitecture().ToString().ToLower()); - } } } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/ProcessHelper.cs index 7cd2ca470c..6cd58c1706 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/ProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/ProcessHelper.cs @@ -78,17 +78,5 @@ public int GetProcessId(object process) { throw new NotImplementedException(); } - - /// - public string GetNativeDllDirectory() - { - throw new NotImplementedException(); - } - - /// - public PlatformArchitecture GetCurrentProcessArchitecture() - { - throw new NotImplementedException(); - } } } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/System/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/System/ProcessHelper.cs index 69525fa74a..1661246052 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/System/ProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/System/ProcessHelper.cs @@ -77,23 +77,5 @@ public int GetProcessId(object process) { return -1; } - - /// - public PlatformArchitecture GetCurrentProcessArchitecture() - { - if (IntPtr.Size == 8) - { - return PlatformArchitecture.X64; - } - - return PlatformArchitecture.X86; - } - - /// - public string GetNativeDllDirectory() - { - // For UWP the native dll's are to be kept in same directory - return this.GetCurrentProcessLocation(); - } } } diff --git a/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs b/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs index 9b0032b3a1..5b94893702 100644 --- a/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs +++ b/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs @@ -69,7 +69,7 @@ public static string MakeRunsettingsCompatible(string runsettingsXml) { EqtTrace.Error("InferRunSettingsHelper.MakeRunsettingsCompatible: Unable to navigate to RunConfiguration. Current node: " + runSettingsNavigator.LocalName); } - else if (runSettingsNavigator.HasChildren) + else if(runSettingsNavigator.HasChildren) { var listOfInValidRunConfigurationSettings = new List(); @@ -90,7 +90,7 @@ public static string MakeRunsettingsCompatible(string runsettingsXml) runSettingsNavigator.MoveToFirstChild(); do { - if (!listOfValidRunConfigurationSettings.Contains(runSettingsNavigator.LocalName)) + if(!listOfValidRunConfigurationSettings.Contains(runSettingsNavigator.LocalName)) { listOfInValidRunConfigurationSettings.Add(runSettingsNavigator.LocalName); } @@ -100,7 +100,7 @@ public static string MakeRunsettingsCompatible(string runsettingsXml) // Delete all invalid RunConfiguration Settings if (listOfInValidRunConfigurationSettings.Count > 0) { - if (EqtTrace.IsWarningEnabled) + if(EqtTrace.IsWarningEnabled) { string settingsName = string.Join(", ", listOfInValidRunConfigurationSettings); EqtTrace.Warning(string.Format("InferRunSettingsHelper.MakeRunsettingsCompatible: Removing the following settings: {0} from RunSettings file. To use those settings please move to latest version of Microsoft.NET.Test.Sdk", settingsName)); @@ -109,7 +109,7 @@ public static string MakeRunsettingsCompatible(string runsettingsXml) // move navigator to RunConfiguration node runSettingsNavigator.MoveToParent(); - foreach (var s in listOfInValidRunConfigurationSettings) + foreach(var s in listOfInValidRunConfigurationSettings) { var nodePath = RunConfigurationNodePath + "/" + s; XmlUtilities.RemoveChildNode(runSettingsNavigator, nodePath, s); @@ -129,14 +129,12 @@ public static string MakeRunsettingsCompatible(string runsettingsXml) /// /// Updates the run settings XML with the specified values. /// - /// The XmlDocument of the XML. + /// The navigator of the XML. /// The architecture. /// The framework. /// The results directory. - public static void UpdateRunSettingsWithUserProvidedSwitches(XmlDocument runSettingsDocument, Architecture architecture, Framework framework, string resultsDirectory) + public static void UpdateRunSettingsWithUserProvidedSwitches(XPathNavigator runSettingsNavigator, Architecture architecture, Framework framework, string resultsDirectory) { - var runSettingsNavigator = runSettingsDocument.CreateNavigator(); - ValidateRunConfiguration(runSettingsNavigator); // when runsettings specifies platform, that takes precedence over the user specified platform via command line arguments. @@ -166,65 +164,67 @@ public static void UpdateRunSettingsWithUserProvidedSwitches(XmlDocument runSett VerifyCompatibilityWithOSArchitecture(architecture); // Check if inputRunSettings has results directory configured. - var hasResultsDirectory = runSettingsDocument.SelectSingleNode(ResultsDirectoryNodePath) != null; + var hasResultsDirectory = runSettingsNavigator.SelectSingleNode(ResultsDirectoryNodePath) != null; // Regenerate the effective settings. if (shouldUpdatePlatform || shouldUpdateFramework || !hasResultsDirectory) { - UpdateRunConfiguration(runSettingsDocument, architecture, framework, resultsDirectory); + UpdateRunConfiguration(runSettingsNavigator, architecture, framework, resultsDirectory); } + + runSettingsNavigator.MoveToRoot(); } /// /// Updates the RunConfiguration.DesignMode value for a run settings. Doesn't do anything if the value is already set. /// - /// Document for runsettings xml + /// Navigator for runsettings xml /// Value to set - public static void UpdateDesignMode(XmlDocument runSettingsDocument, bool designModeValue) + public static void UpdateDesignMode(XPathNavigator runSettingsNavigator, bool designModeValue) { - AddNodeIfNotPresent(runSettingsDocument, DesignModeNodePath, DesignModeNodeName, designModeValue); + AddNodeIfNotPresent(runSettingsNavigator, DesignModeNodePath, DesignModeNodeName, designModeValue); } /// /// Updates the RunConfiguration.CollectSourceInformation value for a run settings. Doesn't do anything if the value is already set. /// - /// Navigator for runsettings xml + /// Navigator for runsettings xml /// Value to set - public static void UpdateCollectSourceInformation(XmlDocument runSettingsDocument, bool collectSourceInformationValue) + public static void UpdateCollectSourceInformation(XPathNavigator runSettingsNavigator, bool collectSourceInformationValue) { - AddNodeIfNotPresent(runSettingsDocument, CollectSourceInformationNodePath, CollectSourceInformationNodeName, collectSourceInformationValue); + AddNodeIfNotPresent(runSettingsNavigator, CollectSourceInformationNodePath, CollectSourceInformationNodeName, collectSourceInformationValue); } /// /// Updates the RunConfiguration.TargetDevice value for a run settings. Doesn't do anything if the value is already set. /// - /// XmlDocument for runsettings xml + /// Navigator for runsettings xml /// Value to set - public static void UpdateTargetDevice(XmlDocument runSettingsDocument, string targetDevice) + public static void UpdateTargetDevice(XPathNavigator runSettingsNavigator, string targetDevice) { - AddNodeIfNotPresent(runSettingsDocument, TargetDeviceNodePath, TargetDevice, targetDevice); + AddNodeIfNotPresent(runSettingsNavigator, TargetDeviceNodePath, TargetDevice, targetDevice); } /// /// Updates the RunConfiguration.TargetFrameworkVersion value for a run settings. if the value is already set, behavior depends on overwrite. /// - /// XmlDocument for runsettings xml + /// Navigator for runsettings xml /// Value to set /// Overwrite option. - public static void UpdateTargetFramework(XmlDocument runSettingsDocument, string framework, bool overwrite = false) + public static void UpdateTargetFramework(XPathNavigator runSettingsNavigator, string framework, bool overwrite=false) { - AddNodeIfNotPresent(runSettingsDocument, TargetFrameworkNodePath, TargetFrameworkNodeName, framework, overwrite); + AddNodeIfNotPresent(runSettingsNavigator, TargetFrameworkNodePath, TargetFrameworkNodeName, framework, overwrite); } /// /// Updates the RunConfiguration.TargetPlatform value for a run settings. if the value is already set, behavior depends on overwrite. /// - /// Navigator for runsettings xml + /// Navigator for runsettings xml /// Value to set /// Overwrite option. - public static void UpdateTargetPlatform(XmlDocument runSettingsDocument, string platform, bool overwrite = false) + public static void UpdateTargetPlatform(XPathNavigator runSettingsNavigator, string platform, bool overwrite = false) { - AddNodeIfNotPresent(runSettingsDocument, TargetPlatformNodePath, TargetPlatformNodeName, platform, overwrite); + AddNodeIfNotPresent(runSettingsNavigator, TargetPlatformNodePath, TargetPlatformNodeName, platform, overwrite); } public static bool TryGetDeviceXml(XPathNavigator runSettingsNavigator, out String deviceXml) @@ -267,7 +267,7 @@ public static bool IsTestSettingsEnabled(string runsettingsXml) } var node = runSettingsNavigator.SelectSingleNode(@"/RunSettings/MSTest/SettingsFile"); - if (node != null && !string.IsNullOrEmpty(node.InnerXml)) + if(node != null && !string.IsNullOrEmpty(node.InnerXml)) { return true; } @@ -280,21 +280,21 @@ public static bool IsTestSettingsEnabled(string runsettingsXml) /// /// Adds node under RunConfiguration setting. Noop if node is already present. /// - private static void AddNodeIfNotPresent(XmlDocument xmlDocument, string nodePath, string nodeName, T nodeValue, bool overwrite = false) + private static void AddNodeIfNotPresent(XPathNavigator runSettingsNavigator, string nodePath, string nodeName, T nodeValue, bool overwrite = false) { // Navigator should be at Root of runsettings xml, attempt to move to /RunSettings/RunConfiguration - var root = xmlDocument.DocumentElement; - - if (root.SelectSingleNode(RunConfigurationNodePath) == null) + if (!runSettingsNavigator.MoveToChild(RunSettingsNodeName, string.Empty) || + !runSettingsNavigator.MoveToChild(RunConfigurationNodeName, string.Empty)) { - EqtTrace.Error("InferRunSettingsHelper.UpdateNodeIfNotPresent: Unable to navigate to RunConfiguration. Current node: " + xmlDocument.LocalName); + EqtTrace.Error("InferRunSettingsHelper.UpdateNodeIfNotPresent: Unable to navigate to RunConfiguration. Current node: " + runSettingsNavigator.LocalName); return; } - var node = xmlDocument.SelectSingleNode(nodePath); + var node = runSettingsNavigator.SelectSingleNode(nodePath); if (node == null || overwrite) { - XmlUtilities.AppendOrModifyChild(xmlDocument, nodePath, nodeName, nodeValue.ToString()); + XmlUtilities.AppendOrModifyChild(runSettingsNavigator, nodePath, nodeName, nodeValue.ToString()); + runSettingsNavigator.MoveToRoot(); } } @@ -370,22 +370,26 @@ private static void VerifyCompatibilityWithOSArchitecture(Architecture architect /// Regenerates the RunConfiguration node with new values under runsettings. /// private static void UpdateRunConfiguration( - XmlDocument xmlDocument, + XPathNavigator navigator, Architecture effectivePlatform, Framework effectiveFramework, string resultsDirectory) { - var childNode = xmlDocument.SelectSingleNode(ResultsDirectoryNodePath); - if (null != childNode) + var resultsDirectoryNavigator = navigator.SelectSingleNode(ResultsDirectoryNodePath); + if (null != resultsDirectoryNavigator) { - resultsDirectory = childNode.InnerXml; + resultsDirectory = resultsDirectoryNavigator.InnerXml; } - XmlUtilities.AppendOrModifyChild(xmlDocument, RunConfigurationNodePath, RunConfigurationNodeName, null); - XmlUtilities.AppendOrModifyChild(xmlDocument, ResultsDirectoryNodePath, ResultsDirectoryNodeName, resultsDirectory); + XmlUtilities.AppendOrModifyChild(navigator, RunConfigurationNodePath, RunConfigurationNodeName, null); + navigator.MoveToChild(RunConfigurationNodeName, string.Empty); + + XmlUtilities.AppendOrModifyChild(navigator, ResultsDirectoryNodePath, ResultsDirectoryNodeName, resultsDirectory); + + XmlUtilities.AppendOrModifyChild(navigator, TargetPlatformNodePath, TargetPlatformNodeName, effectivePlatform.ToString()); + XmlUtilities.AppendOrModifyChild(navigator, TargetFrameworkNodePath, TargetFrameworkNodeName, effectiveFramework.ToString()); - XmlUtilities.AppendOrModifyChild(xmlDocument, TargetPlatformNodePath, TargetPlatformNodeName, effectivePlatform.ToString()); - XmlUtilities.AppendOrModifyChild(xmlDocument, TargetFrameworkNodePath, TargetFrameworkNodeName, effectiveFramework.ToString()); + navigator.MoveToRoot(); } public static bool TryGetPlatformXml(XPathNavigator runSettingsNavigator, out string platformXml) diff --git a/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs b/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs index 3c5480e078..823f311072 100644 --- a/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs +++ b/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs @@ -51,12 +51,12 @@ internal static bool IsValidNodeXmlValue(string xmlNodeValue, Func [SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver", Justification = "XmlDocument.XmlResolver is not available in core. Suppress until fxcop issue is fixed.")] internal static void AppendOrModifyChild( - XmlDocument xmlDocument, + XPathNavigator parentNavigator, string nodeXPath, string nodeName, string innerXml) { - var childNode = xmlDocument.SelectSingleNode(nodeXPath); + var childNodeNavigator = parentNavigator.SelectSingleNode(nodeXPath); // Todo: There isn't an equivalent API to SecurityElement.Escape in Core yet. // So trusting that the XML is always valid for now. @@ -65,21 +65,37 @@ internal static void AppendOrModifyChild( #else var secureInnerXml = innerXml; #endif - if (childNode == null) + if (childNodeNavigator == null) { - var childElement = xmlDocument.CreateElement(nodeName); + var doc = new XmlDocument(); + var childElement = doc.CreateElement(nodeName); if (!string.IsNullOrEmpty(innerXml)) { childElement.InnerXml = secureInnerXml; } - var parentNode = xmlDocument.SelectSingleNode(nodeXPath.Substring(0, nodeXPath.LastIndexOf('/'))); - parentNode?.AppendChild(childElement); + childNodeNavigator = childElement.CreateNavigator(); + parentNavigator.AppendChild(childNodeNavigator); } else if (!string.IsNullOrEmpty(innerXml)) { - childNode.InnerXml = secureInnerXml; +#if NET451 + childNodeNavigator.InnerXml = secureInnerXml; +#else + // .Net Core has a bug where calling childNodeNavigator.InnerXml throws an XmlException with "Data at the root level is invalid". + // So doing the below instead. + var doc = new XmlDocument(); + + var childElement = doc.CreateElement(nodeName); + + if (!string.IsNullOrEmpty(innerXml)) + { + childElement.InnerXml = secureInnerXml; + } + + childNodeNavigator.ReplaceSelf(childElement.CreateNavigator().OuterXml); +#endif } } diff --git a/src/package/VSIXProject/testplatform.config b/src/package/VSIXProject/testplatform.config index 4d391b6d12..0ab8787965 100644 --- a/src/package/VSIXProject/testplatform.config +++ b/src/package/VSIXProject/testplatform.config @@ -3,7 +3,7 @@ - + diff --git a/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs b/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs index 9b337fcc9e..60ca7328ad 100644 --- a/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs +++ b/src/vstest.console/Processors/EnableCodeCoverageArgumentProcessor.cs @@ -160,12 +160,11 @@ private void UpdateWithCodeCoverageSettingsIfNotConfigured() { var document = new XmlDocument(); document.Load(reader); - -#if !NETCOREAPP1_0 +#if NET451 runSettingsDocument = document; #else runSettingsDocument = document.ToXPathNavigable(); -#endif +#endif } var runSettingsNavigator = runSettingsDocument.CreateNavigator(); diff --git a/src/vstest.console/Processors/RunSettingsArgumentProcessor.cs b/src/vstest.console/Processors/RunSettingsArgumentProcessor.cs index 6c95c980e3..9098f2dc20 100644 --- a/src/vstest.console/Processors/RunSettingsArgumentProcessor.cs +++ b/src/vstest.console/Processors/RunSettingsArgumentProcessor.cs @@ -182,12 +182,11 @@ private IXPathNavigable GetRunSettingsDocument(string runSettingsFile) var settingsDocument = new XmlDocument(); settingsDocument.Load(reader); ClientUtilities.FixRelativePathsInRunSettings(settingsDocument, runSettingsFile); - -#if !NETCOREAPP1_0 +#if NET451 runSettingsDocument = settingsDocument; #else runSettingsDocument = settingsDocument.ToXPathNavigable(); -#endif +#endif } } else diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 8c73862869..0bb64d72ec 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -410,14 +410,14 @@ private bool UpdateRunSettingsIfRequired(string runsettingsXml, List sou if (updateFramework) { - InferRunSettingsHelper.UpdateTargetFramework(document, inferedFramework?.ToString(), overwrite: true); + InferRunSettingsHelper.UpdateTargetFramework(navigator, inferedFramework?.ToString(), overwrite: true); chosenFramework = inferedFramework; settingsUpdated = true; } if (updatePlatform) { - InferRunSettingsHelper.UpdateTargetPlatform(document, inferedPlatform.ToString(), overwrite: true); + InferRunSettingsHelper.UpdateTargetPlatform(navigator, inferedPlatform.ToString(), overwrite: true); chosenPlatform = inferedPlatform; settingsUpdated = true; } @@ -441,19 +441,19 @@ private bool UpdateRunSettingsIfRequired(string runsettingsXml, List sou if (!runConfiguration.DesignModeSet) { - InferRunSettingsHelper.UpdateDesignMode(document, this.commandLineOptions.IsDesignMode); + InferRunSettingsHelper.UpdateDesignMode(navigator, this.commandLineOptions.IsDesignMode); settingsUpdated = true; } if (!runConfiguration.CollectSourceInformationSet) { - InferRunSettingsHelper.UpdateCollectSourceInformation(document, this.commandLineOptions.ShouldCollectSourceInformation); + InferRunSettingsHelper.UpdateCollectSourceInformation(navigator, this.commandLineOptions.ShouldCollectSourceInformation); settingsUpdated = true; } if (InferRunSettingsHelper.TryGetDeviceXml(navigator, out string deviceXml)) { - InferRunSettingsHelper.UpdateTargetDevice(document, deviceXml); + InferRunSettingsHelper.UpdateTargetDevice(navigator, deviceXml); settingsUpdated = true; } diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs index ba778d8021..a2526df5ca 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs @@ -136,9 +136,9 @@ public void BeforeTestRunStartsShouldInvokeRunEventsHandlerIfExceptionIsThrown() var result = this.proxyDataCollectionManager.BeforeTestRunStart(true, true, mockRunEventsHandler.Object); mockRunEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, "Exception of type 'System.Exception' was thrown."), Times.Once); - Assert.AreEqual(0, result.EnvironmentVariables.Count); - Assert.AreEqual(false, result.AreTestCaseLevelEventsRequired); - Assert.AreEqual(0, result.DataCollectionEventsPort); + Assert.AreEqual(result.EnvironmentVariables, null); + Assert.AreEqual(result.AreTestCaseLevelEventsRequired, false); + Assert.AreEqual(result.DataCollectionEventsPort, 0); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestCaseTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestCaseTests.cs index 4923d4898a..70630bf9af 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestCaseTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestCaseTests.cs @@ -53,14 +53,6 @@ public void TestCaseIdShouldReturnIdSetExplicitlyEvenIfNameOrSourceInfoChanges() Assert.AreEqual(testGuid, testCase.Id); } - [TestMethod] - public void TestCaseLocalExtensionDataIsPubliclySettableGettableProperty() - { - var dummyData = "foo"; - this.testCase.LocalExtensionData = dummyData; - Assert.AreEqual("foo", this.testCase.LocalExtensionData); - } - #region GetSetPropertyValue Tests [TestMethod] diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/InferRunSettingsHelperTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/InferRunSettingsHelperTests.cs index b8fab24f6a..b3206616e4 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/InferRunSettingsHelperTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/InferRunSettingsHelperTests.cs @@ -40,9 +40,9 @@ public InferRunSettingsHelperTests() public void UpdateRunSettingsShouldThrowIfRunSettingsNodeDoesNotExist() { var settings = @""; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - Action action = () => InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X86, Framework.DefaultFramework, "temp"); + Action action = () => InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X86, Framework.DefaultFramework, "temp"); Assert.That.Throws(action) .WithMessage(string.Format("An error occurred while loading the settings. Error: {0}.", @@ -53,9 +53,9 @@ public void UpdateRunSettingsShouldThrowIfRunSettingsNodeDoesNotExist() public void UpdateRunSettingsShouldThrowIfPlatformNodeIsInvalid() { var settings = @"foo"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - Action action = () => InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X86, Framework.DefaultFramework, "temp"); + Action action = () => InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X86, Framework.DefaultFramework, "temp"); Assert.That.Throws(action) .WithMessage(string.Format("An error occurred while loading the settings. Error: {0}.", @@ -69,9 +69,9 @@ public void UpdateRunSettingsShouldThrowIfPlatformNodeIsInvalid() public void UpdateRunSettingsShouldThrowIfFrameworkNodeIsInvalid() { var settings = @"foo"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - Action action = () => InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X86, Framework.DefaultFramework, "temp"); + Action action = () => InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X86, Framework.DefaultFramework, "temp"); Assert.That.Throws(action) .WithMessage(string.Format("An error occurred while loading the settings. Error: {0}.", @@ -85,11 +85,11 @@ public void UpdateRunSettingsShouldThrowIfFrameworkNodeIsInvalid() public void UpdateRunSettingsShouldUpdateWithPlatformSettings() { var settings = @""; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X86, Framework.DefaultFramework, "temp"); + InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X86, Framework.DefaultFramework, "temp"); - var xml = xmlDocument.OuterXml; + var xml = navigator.OuterXml; StringAssert.Contains(xml, "X86"); } @@ -98,11 +98,11 @@ public void UpdateRunSettingsShouldUpdateWithPlatformSettings() public void UpdateRunSettingsShouldUpdateWithFrameworkSettings() { var settings = @""; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X86, Framework.DefaultFramework, "temp"); + InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X86, Framework.DefaultFramework, "temp"); - var xml = xmlDocument.OuterXml; + var xml = navigator.OuterXml; StringAssert.Contains(xml, $"{Framework.DefaultFramework.Name}"); } @@ -111,11 +111,11 @@ public void UpdateRunSettingsShouldUpdateWithFrameworkSettings() public void UpdateRunSettingsShouldUpdateWithResultsDirectorySettings() { var settings = @""; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X86, Framework.DefaultFramework, "temp"); + InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X86, Framework.DefaultFramework, "temp"); - var xml = xmlDocument.OuterXml; + var xml = navigator.OuterXml; StringAssert.Contains(xml, "temp"); } @@ -124,11 +124,11 @@ public void UpdateRunSettingsShouldUpdateWithResultsDirectorySettings() public void UpdateRunSettingsShouldNotUpdatePlatformIfRunSettingsAlreadyHasIt() { var settings = @"X86"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X64, Framework.DefaultFramework, "temp"); + InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X64, Framework.DefaultFramework, "temp"); - var xml = xmlDocument.OuterXml; + var xml = navigator.OuterXml; StringAssert.Contains(xml, "X86"); } @@ -137,11 +137,11 @@ public void UpdateRunSettingsShouldNotUpdatePlatformIfRunSettingsAlreadyHasIt() public void UpdateRunSettingsShouldNotUpdateFrameworkIfRunSettingsAlreadyHasIt() { var settings = @"Framework40"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X64, Framework.DefaultFramework, "temp"); + InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X64, Framework.DefaultFramework, "temp"); - var xml = xmlDocument.OuterXml; + var xml = navigator.OuterXml; StringAssert.Contains(xml, ".NETFramework,Version=v4.0"); } @@ -152,11 +152,11 @@ public void UpdateRunSettingsShouldAllowTargetFrameworkMonikerValue() { var settings = @".NETFramework,Version=v4.0"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X64, Framework.DefaultFramework, "temp"); + InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X64, Framework.DefaultFramework, "temp"); - var xml = xmlDocument.OuterXml; + var xml = navigator.OuterXml; StringAssert.Contains(xml, ".NETFramework,Version=v4.0"); } @@ -165,11 +165,11 @@ public void UpdateRunSettingsShouldAllowTargetFrameworkMonikerValue() public void UpdateRunSettingsShouldNotUpdateResultsDirectoryIfRunSettingsAlreadyHasIt() { var settings = @"someplace"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X64, Framework.DefaultFramework, "temp"); + InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X64, Framework.DefaultFramework, "temp"); - var xml = xmlDocument.OuterXml; + var xml = navigator.OuterXml; StringAssert.Contains(xml, "someplace"); } @@ -178,11 +178,11 @@ public void UpdateRunSettingsShouldNotUpdateResultsDirectoryIfRunSettingsAlready public void UpdateRunSettingsShouldNotUpdatePlatformOrFrameworkOrResultsDirectoryIfRunSettingsAlreadyHasIt() { var settings = @"X86Framework40someplace"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X64, Framework.DefaultFramework, "temp"); + InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X64, Framework.DefaultFramework, "temp"); - var xml = xmlDocument.OuterXml; + var xml = navigator.OuterXml; StringAssert.Contains(xml, "X86"); StringAssert.Contains(xml, "Framework40"); @@ -193,11 +193,11 @@ public void UpdateRunSettingsShouldNotUpdatePlatformOrFrameworkOrResultsDirector public void UpdateRunSettingsWithAnEmptyRunSettingsShouldAddValuesSpecifiedInRunConfiguration() { var settings = @""; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X64, Framework.DefaultFramework, "temp"); + InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X64, Framework.DefaultFramework, "temp"); - var xml = xmlDocument.OuterXml; + var xml = navigator.OuterXml; StringAssert.Contains(xml, "X64"); StringAssert.Contains(xml, $"{Framework.DefaultFramework.Name}"); @@ -208,12 +208,12 @@ public void UpdateRunSettingsWithAnEmptyRunSettingsShouldAddValuesSpecifiedInRun public void UpdateRunSettingsShouldReturnBackACompleteRunSettings() { var settings = @""; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.X64, Framework.DefaultFramework, "temp"); + InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.X64, Framework.DefaultFramework, "temp"); - var xml = xmlDocument.OuterXml; - var expectedRunSettings = string.Format("tempX64{0}", Framework.DefaultFramework.Name); + var xml = navigator.OuterXml; + var expectedRunSettings = string.Format("\r\n \r\n temp\r\n X64\r\n {0}\r\n \r\n", Framework.DefaultFramework.Name); Assert.AreEqual(expectedRunSettings, xml); } @@ -222,9 +222,9 @@ public void UpdateRunSettingsShouldReturnBackACompleteRunSettings() public void UpdateRunSettingsShouldThrowIfArchitectureSetIsIncompatibleWithCurrentSystemArchitecture() { var settings = @""; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - Action action = () => InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(xmlDocument, Architecture.ARM, Framework.DefaultFramework, "temp"); + Action action = () => InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(navigator, Architecture.ARM, Framework.DefaultFramework, "temp"); Assert.That.Throws(action) .WithMessage(string.Format( @@ -233,17 +233,41 @@ public void UpdateRunSettingsShouldThrowIfArchitectureSetIsIncompatibleWithCurre XmlRunSettingsUtilities.OSArchitecture.ToString())); } + [DataTestMethod] + [DataRow("DesignMode")] + [DataRow("CollectSourceInformation")] + public void UpdateRunSettingsShouldNotModifyXmlIfNavigatorIsNotAtRootNode(string settingName) + { + var settings = @""; + var navigator = this.GetNavigator(settings); + navigator.MoveToFirstChild(); + + switch (settingName.ToUpperInvariant()) + { + case "DESIGNMODE": + InferRunSettingsHelper.UpdateDesignMode(navigator, true); + break; + + case "COLLECTSOURCEINFORMATION": + InferRunSettingsHelper.UpdateCollectSourceInformation(navigator, true); + break; + }; + + navigator.MoveToRoot(); + Assert.IsTrue(navigator.InnerXml.IndexOf(settingName, StringComparison.OrdinalIgnoreCase) < 0); + } + [TestMethod] public void UpdateDesignModeOrCsiShouldNotModifyXmlIfNodeIsAlreadyPresent() { var settings = @"FalseFalse"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateDesignMode(xmlDocument, true); - InferRunSettingsHelper.UpdateCollectSourceInformation(xmlDocument, true); + InferRunSettingsHelper.UpdateDesignMode(navigator, true); + InferRunSettingsHelper.UpdateCollectSourceInformation(navigator, true); - Assert.AreEqual("False", this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/DesignMode")); - Assert.AreEqual("False", this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/CollectSourceInformation")); + Assert.AreEqual("False", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/DesignMode")); + Assert.AreEqual("False", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/CollectSourceInformation")); } [DataTestMethod] @@ -252,13 +276,13 @@ public void UpdateDesignModeOrCsiShouldNotModifyXmlIfNodeIsAlreadyPresent() public void UpdateDesignModeOrCsiShouldModifyXmlToValueProvided(bool val) { var settings = @""; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateDesignMode(xmlDocument, val); - InferRunSettingsHelper.UpdateCollectSourceInformation(xmlDocument, val); + InferRunSettingsHelper.UpdateDesignMode(navigator, val); + InferRunSettingsHelper.UpdateCollectSourceInformation(navigator, val); - Assert.AreEqual(val.ToString(), this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/DesignMode")); - Assert.AreEqual(val.ToString(), this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/CollectSourceInformation")); + Assert.AreEqual(val.ToString(), this.GetValueOf(navigator, "/RunSettings/RunConfiguration/DesignMode")); + Assert.AreEqual(val.ToString(), this.GetValueOf(navigator, "/RunSettings/RunConfiguration/CollectSourceInformation")); } [TestMethod] @@ -315,79 +339,79 @@ public void UpdateTargetDeviceValueFromOldMsTestSettings() "; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - var result = InferRunSettingsHelper.TryGetDeviceXml(xmlDocument.CreateNavigator(), out string deviceXml); + var result = InferRunSettingsHelper.TryGetDeviceXml(navigator, out string deviceXml); Assert.IsTrue(result); - InferRunSettingsHelper.UpdateTargetDevice(xmlDocument, deviceXml); - Assert.AreEqual(deviceXml.ToString(), this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/TargetDevice")); + InferRunSettingsHelper.UpdateTargetDevice(navigator, deviceXml); + Assert.AreEqual(deviceXml.ToString(), this.GetValueOf(navigator, "/RunSettings/RunConfiguration/TargetDevice")); } [TestMethod] public void UpdateTargetPlatformShouldNotModifyXmlIfNodeIsAlreadyPresentForOverwriteFalse() { var settings = @"x86"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateTargetPlatform(xmlDocument, "X64", overwrite: false); + InferRunSettingsHelper.UpdateTargetPlatform(navigator, "X64", overwrite: false); - Assert.AreEqual("x86", this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/TargetPlatform")); + Assert.AreEqual("x86", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/TargetPlatform")); } [TestMethod] public void UpdateTargetPlatformShouldModifyXmlIfNodeIsAlreadyPresentForOverwriteTrue() { var settings = @"x86"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateTargetPlatform(xmlDocument, "X64", overwrite: true); + InferRunSettingsHelper.UpdateTargetPlatform(navigator, "X64", overwrite: true); - Assert.AreEqual("X64", this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/TargetPlatform")); + Assert.AreEqual("X64", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/TargetPlatform")); } [TestMethod] public void UpdateTargetPlatformShouldAddPlatformXmlNodeIfNotPresent() { var settings = @""; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateTargetPlatform(xmlDocument, "X64"); + InferRunSettingsHelper.UpdateTargetPlatform(navigator, "X64"); - Assert.AreEqual("X64", this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/TargetPlatform")); + Assert.AreEqual("X64", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/TargetPlatform")); } [TestMethod] public void UpdateTargetFrameworkShouldNotModifyXmlIfNodeIsAlreadyPresentForOverwriteFalse() { var settings = @".NETFramework,Version=v4.5"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateTargetFramework(xmlDocument, ".NETCoreApp,Version=v1.0", overwrite: false); + InferRunSettingsHelper.UpdateTargetFramework(navigator, ".NETCoreApp,Version=v1.0", overwrite: false); - Assert.AreEqual(".NETFramework,Version=v4.5", this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/TargetFrameworkVersion")); + Assert.AreEqual(".NETFramework,Version=v4.5", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/TargetFrameworkVersion")); } [TestMethod] public void UpdateTargetFrameworkShouldModifyXmlIfNodeIsAlreadyPresentForOverwriteTrue() { var settings = @".NETFramework,Version=v4.5"; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateTargetFramework(xmlDocument, ".NETCoreApp,Version=v1.0", overwrite: true); + InferRunSettingsHelper.UpdateTargetFramework(navigator, ".NETCoreApp,Version=v1.0", overwrite: true); - Assert.AreEqual(".NETCoreApp,Version=v1.0", this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/TargetFrameworkVersion")); + Assert.AreEqual(".NETCoreApp,Version=v1.0", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/TargetFrameworkVersion")); } [TestMethod] public void UpdateTargetFrameworkShouldAddFrameworkXmlNodeIfNotPresent() { var settings = @""; - var xmlDocument = this.GetXmlDocument(settings); + var navigator = this.GetNavigator(settings); - InferRunSettingsHelper.UpdateTargetFramework(xmlDocument, ".NETCoreApp,Version=v1.0"); + InferRunSettingsHelper.UpdateTargetFramework(navigator, ".NETCoreApp,Version=v1.0"); - Assert.AreEqual(".NETCoreApp,Version=v1.0", this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/TargetFrameworkVersion")); + Assert.AreEqual(".NETCoreApp,Version=v1.0", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/TargetFrameworkVersion")); } [TestMethod] @@ -500,17 +524,18 @@ private string GetSourceIncompatibleMessage(string source) return string.Format(CultureInfo.CurrentCulture, OMResources.SourceIncompatible, source, sourceFrameworks[source].Version, sourceArchitectures[source]); } - private XmlDocument GetXmlDocument(string settingsXml) + private XPathNavigator GetNavigator(string settingsXml) { var doc = new XmlDocument(); doc.LoadXml(settingsXml); - return doc; + return doc.CreateNavigator(); } - private string GetValueOf(XmlDocument xmlDocument, string xpath) + private string GetValueOf(XPathNavigator navigator, string xpath) { - return xmlDocument.SelectSingleNode(xpath).InnerText; + navigator.MoveToRoot(); + return navigator.SelectSingleNode(xpath).Value; } #endregion } diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/XmlUtilitiesTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/XmlUtilitiesTests.cs index 5c99e77d20..b35d1a4fbd 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/XmlUtilitiesTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/XmlUtilitiesTests.cs @@ -17,7 +17,7 @@ public class XmlUtilitiesTests #region GetNodeXml tests [TestMethod] - public void GetNodeXmlShouldThrowIfxmlDocumentIsNull() + public void GetNodeXmlShouldThrowIfNavigatorIsNull() { Assert.ThrowsException(() => XmlUtilities.GetNodeXml(null, @"/RunSettings/RunConfiguration")); } @@ -26,36 +26,36 @@ public void GetNodeXmlShouldThrowIfxmlDocumentIsNull() public void GetNodeXmlShouldThrowIfXPathIsNull() { var settingsXml = @""; - var xmlDocument = this.GetXmlDocument(settingsXml); + var navigator = this.GetNavigator(settingsXml); - Assert.ThrowsException(() => XmlUtilities.GetNodeXml(xmlDocument.CreateNavigator(), null)); + Assert.ThrowsException(() => XmlUtilities.GetNodeXml(navigator, null)); } [TestMethod] public void GetNodeXmlShouldThrowIfXPathIsInvalid() { var settingsXml = @""; - var xmlDocument = this.GetXmlDocument(settingsXml); + var navigator = this.GetNavigator(settingsXml); - Assert.ThrowsException(() => XmlUtilities.GetNodeXml(xmlDocument.CreateNavigator(), @"Rs\r")); + Assert.ThrowsException(() => XmlUtilities.GetNodeXml(navigator, @"Rs\r")); } [TestMethod] public void GetNodeXmlShouldReturnNullIfNodeDoesNotExist() { var settingsXml = @""; - var xmlDocument = this.GetXmlDocument(settingsXml); + var navigator = this.GetNavigator(settingsXml); - Assert.IsNull(XmlUtilities.GetNodeXml(xmlDocument.CreateNavigator(), @"/RunSettings/RunConfiguration")); + Assert.IsNull(XmlUtilities.GetNodeXml(navigator, @"/RunSettings/RunConfiguration")); } [TestMethod] public void GetNodeXmlShouldReturnNodeValue() { var settingsXml = @"abc"; - var xmlDocument = this.GetXmlDocument(settingsXml); + var navigator = this.GetNavigator(settingsXml); - Assert.AreEqual("abc", XmlUtilities.GetNodeXml(xmlDocument.CreateNavigator(), @"/RunSettings/RC")); + Assert.AreEqual("abc", XmlUtilities.GetNodeXml(navigator, @"/RunSettings/RC")); } #endregion @@ -99,57 +99,65 @@ public void IsValidNodeXmlValueShouldReturnTrueIfValidatorReturnsTrue() #endregion #region AppendOrModifyChild tests - + [TestMethod] public void AppendOrModifyChildShouldModifyExistingNode() { var settingsXml = @"abc"; - var xmlDocument = this.GetXmlDocument(settingsXml); + var navigator = this.GetNavigator(settingsXml); + + navigator.MoveToChild("RunSettings", string.Empty); - XmlUtilities.AppendOrModifyChild(xmlDocument, @"/RunSettings/RC", "RC", "ab"); + XmlUtilities.AppendOrModifyChild(navigator, @"/RunSettings/RC", "RC", "ab"); - var rcxmlDocument = xmlDocument.SelectSingleNode(@"/RunSettings/RC"); - Assert.IsNotNull(rcxmlDocument); - Assert.AreEqual("ab", rcxmlDocument.InnerXml); + var rcNavigator = navigator.SelectSingleNode(@"/RunSettings/RC"); + Assert.IsNotNull(rcNavigator); + Assert.AreEqual("ab", rcNavigator.InnerXml); } [TestMethod] public void AppendOrModifyChildShouldAppendANewNode() { var settingsXml = @""; - var xmlDocument = this.GetXmlDocument(settingsXml); + var navigator = this.GetNavigator(settingsXml); - XmlUtilities.AppendOrModifyChild(xmlDocument, @"/RunSettings/RC", "RC", "abc"); + navigator.MoveToChild("RunSettings", string.Empty); - var rcxmlDocument = xmlDocument.SelectSingleNode(@"/RunSettings/RC"); - Assert.IsNotNull(rcxmlDocument); - Assert.AreEqual("abc", rcxmlDocument.InnerXml); + XmlUtilities.AppendOrModifyChild(navigator, @"/RunSettings/RC", "RC", "abc"); + + var rcNavigator = navigator.SelectSingleNode(@"/RunSettings/RC"); + Assert.IsNotNull(rcNavigator); + Assert.AreEqual("abc", rcNavigator.InnerXml); } [TestMethod] public void AppendOrModifyChildShouldNotModifyExistingXmlIfInnerXmlPassedInIsNull() { var settingsXml = @"abc"; - var xmlDocument = this.GetXmlDocument(settingsXml); + var navigator = this.GetNavigator(settingsXml); + + navigator.MoveToChild("RunSettings", string.Empty); - XmlUtilities.AppendOrModifyChild(xmlDocument, @"/RunSettings/RC", "RC", null); + XmlUtilities.AppendOrModifyChild(navigator, @"/RunSettings/RC", "RC", null); - var rcxmlDocument = xmlDocument.SelectSingleNode(@"/RunSettings/RC"); - Assert.IsNotNull(rcxmlDocument); - Assert.AreEqual("abc", rcxmlDocument.InnerXml); + var rcNavigator = navigator.SelectSingleNode(@"/RunSettings/RC"); + Assert.IsNotNull(rcNavigator); + Assert.AreEqual("abc", rcNavigator.InnerXml); } [TestMethod] public void AppendOrModifyChildShouldCreateAnEmptyNewNodeIfInnerXmlPassedInIsNull() { var settingsXml = @""; - var xmlDocument = this.GetXmlDocument(settingsXml); + var navigator = this.GetNavigator(settingsXml); - XmlUtilities.AppendOrModifyChild(xmlDocument, @"/RunSettings/RC", "RC", null); + navigator.MoveToChild("RunSettings", string.Empty); + + XmlUtilities.AppendOrModifyChild(navigator, @"/RunSettings/RC", "RC", null); - var rcxmlDocument = xmlDocument.SelectSingleNode(@"/RunSettings/RC"); - Assert.IsNotNull(rcxmlDocument); - Assert.AreEqual(string.Empty, rcxmlDocument.InnerXml); + var rcNavigator = navigator.SelectSingleNode(@"/RunSettings/RC"); + Assert.IsNotNull(rcNavigator); + Assert.AreEqual(string.Empty, rcNavigator.InnerXml); } #endregion @@ -160,35 +168,38 @@ public void AppendOrModifyChildShouldCreateAnEmptyNewNodeIfInnerXmlPassedInIsNul public void RemoveChildNodeShouldNotModifyExistingXmlIfNodeDoesnotExist() { var settingsXml = @""; - var xmlDocument = this.GetXmlDocument(settingsXml); + var navigator = this.GetNavigator(settingsXml); - XmlUtilities.RemoveChildNode(xmlDocument.CreateNavigator(), @"/RunSettings/RC", "RC"); + navigator.MoveToChild("RunSettings", string.Empty); - Assert.AreEqual(settingsXml, xmlDocument.OuterXml); + XmlUtilities.RemoveChildNode(navigator, @"/RunSettings/RC", "RC"); + + Assert.AreEqual(settingsXml, navigator.OuterXml); } [TestMethod] public void RemoveChildNodeShouldRemoveXmlIfExist() { var settingsXml = @"abc"; - var xmlDocument = this.GetXmlDocument(settingsXml); - var navigator = xmlDocument.CreateNavigator(); + var navigator = this.GetNavigator(settingsXml); + navigator.MoveToChild("RunSettings", string.Empty); + XmlUtilities.RemoveChildNode(navigator, @"/RunSettings/RC", "RC"); - Assert.AreEqual(@"", xmlDocument.OuterXml); + Assert.AreEqual(@"", navigator.OuterXml); } #endregion #region private methods - private XmlDocument GetXmlDocument(string settingsXml) + private XPathNavigator GetNavigator(string settingsXml) { var doc = new XmlDocument(); doc.LoadXml(settingsXml); - return doc; + return doc.CreateNavigator(); } #endregion diff --git a/test/datacollector.UnitTests/DataCollectionManagerTests.cs b/test/datacollector.UnitTests/DataCollectionManagerTests.cs index 94d5bf01ee..9c9963323f 100644 --- a/test/datacollector.UnitTests/DataCollectionManagerTests.cs +++ b/test/datacollector.UnitTests/DataCollectionManagerTests.cs @@ -157,17 +157,6 @@ public void InitializeDataCollectorsShouldLogExceptionToMessageSinkIfInitializat this.mockMessageSink.Verify(x => x.SendMessage(It.IsAny()), Times.Once); } - [TestMethod] - public void InitializeDataCollectorsShouldLogExceptionToMessageSinkIfSetEnvironmentVariableFails() - { - this.mockDataCollector.As().Setup(x => x.GetTestExecutionEnvironmentVariables()).Throws(); - - this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettings); - - Assert.AreEqual(0, this.dataCollectionManager.RunDataCollectors.Count); - this.mockMessageSink.Verify(x => x.SendMessage(It.IsAny()), Times.Once); - } - [TestMethod] public void InitializeDataCollectorsShouldReturnFirstEnvironmentVariableIfMoreThanOneVariablesWithSameKeyIsSpecified() { diff --git a/test/vstest.console.UnitTests/Processors/RunSettingsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunSettingsArgumentProcessorTests.cs index 57753e5192..254354bafd 100644 --- a/test/vstest.console.UnitTests/Processors/RunSettingsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunSettingsArgumentProcessorTests.cs @@ -235,7 +235,7 @@ public void InitializeShouldSetActiveRunSettingsForTestSettingsFiles() // Assert. Assert.IsNotNull(this.settingsProvider.ActiveRunSettings); - StringAssert.Contains(this.settingsProvider.ActiveRunSettings.SettingsXml, $"\r\n\r\n \r\n {Constants.DefaultPlatform}\r\n {Framework.FromString(FrameworkVersion.Framework45.ToString()).Name}\r\n {Constants.DefaultResultsDirectory}\r\n \r\n \r\n C:\\temp\\r.testsettings\r\n true\r\n \r\n \r\n \r\n \r\n"); + StringAssert.Contains(this.settingsProvider.ActiveRunSettings.SettingsXml, $"\r\n \r\n {Constants.DefaultPlatform}\r\n {Framework.FromString(FrameworkVersion.Framework45.ToString()).Name}\r\n {Constants.DefaultResultsDirectory}\r\n \r\n \r\n C:\\temp\\r.testsettings\r\n true\r\n \r\n \r\n \r\n \r\n"); }