From 85f3219be88dca54b3439e83a3ca5ea4981a4094 Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Tue, 1 Oct 2019 16:58:06 +0530 Subject: [PATCH 1/7] [Draft] AnyCPU tests to choose default architecture based on process --- .../Hosting/DotnetTestHostManager.cs | 41 +++++++++++++++---- ...rosoft.TestPlatform.TestHost.NetCore.props | 4 +- .../TestPlatformHelpers/TestRequestManager.cs | 41 +++++++++++++++++-- 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 87a80b0519..5a29977d02 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -203,14 +203,42 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( EqtTrace.Verbose("DotnetTestHostmanager: File {0}, doesnot exist", depsFilePath); } + var runtimeConfigDevPath = Path.Combine(sourceDirectory, string.Concat(sourceFile, ".runtimeconfig.dev.json")); + var testHostPath = this.GetTestHostPath(runtimeConfigDevPath, depsFilePath, sourceDirectory); + // If Testhost.exe is available use it - var exeName = this.architecture == Architecture.X86 ? "testhost.x86.exe" : "testhost.exe"; - var fullExePath = Path.Combine(sourceDirectory, exeName); - if (this.platformEnvironment.OperatingSystem.Equals(PlatformOperatingSystem.Windows) && this.fileHelper.Exists(fullExePath)) + bool testHostExeFound = false; + if (this.platformEnvironment.OperatingSystem.Equals(PlatformOperatingSystem.Windows)) { - startInfo.FileName = fullExePath; + var exeName = this.architecture == Architecture.X86 ? "testhost.x86.exe" : "testhost.exe"; + var fullExePath = Path.Combine(sourceDirectory, exeName); + + // check for testhost.exe in sourceDirectory. If not found, check this in nuget folder. + if (this.fileHelper.Exists(fullExePath)) + { + startInfo.FileName = fullExePath; + testHostExeFound = true; + } + else + { + // Check if testhost.dll is found in nuget folder. + if (testHostPath.Contains("microsoft.testplatform.testhost")) + { + var folderName = this.architecture == Architecture.X86 ? "x86" : "x64"; + var testHostNugetPath = Directory.GetParent(Directory.GetParent(Directory.GetParent(testHostPath).FullName).FullName); + + var testHostExePath = Path.Combine(testHostNugetPath.FullName, "build", "netcoreapp2.1", folderName, exeName); + + if (this.fileHelper.Exists(testHostExePath)) + { + EqtTrace.Verbose("DotnetTestHostManager: testhost.exe/testhost.x86.exe found at path: " + testHostExePath); + startInfo.FileName = testHostExePath; + testHostExeFound = true; + } + } + } } - else + else if (!testHostExeFound) { var currentProcessPath = this.processHelper.GetCurrentProcessFileName(); @@ -227,9 +255,6 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( startInfo.FileName = this.dotnetHostHelper.GetDotnetPath(); } - var runtimeConfigDevPath = Path.Combine(sourceDirectory, string.Concat(sourceFile, ".runtimeconfig.dev.json")); - var testHostPath = this.GetTestHostPath(runtimeConfigDevPath, depsFilePath, sourceDirectory); - EqtTrace.Verbose("DotnetTestHostmanager: Full path of testhost.dll is {0}", testHostPath); args = "exec" + args; args += " " + testHostPath.AddDoubleQuote(); diff --git a/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props b/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props index a33990d7a3..a13eb787a7 100644 --- a/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props +++ b/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props @@ -1,6 +1,6 @@ - + testhost.x86.exe PreserveNewest @@ -12,7 +12,7 @@ False - + testhost.exe PreserveNewest diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 05a81fbaf9..fab20235c2 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers { using System; using System.Collections.Generic; + using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -29,6 +30,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities; /// @@ -47,6 +49,7 @@ internal class TestRequestManager : ITestRequestManager private readonly object syncObject = new object(); private readonly Task metricsPublisher; private bool isDisposed; + private IProcessHelper processHelper; /// /// Maintains the current active execution request @@ -69,7 +72,8 @@ public TestRequestManager() TestRunResultAggregator.Instance, TestPlatformEventSource.Instance, new InferHelper(AssemblyMetadataProvider.Instance), - MetricsPublisherFactory.GetMetricsPublisher(IsTelemetryOptedIn(), CommandLineOptions.Instance.IsDesignMode)) + MetricsPublisherFactory.GetMetricsPublisher(IsTelemetryOptedIn(), CommandLineOptions.Instance.IsDesignMode), + new ProcessHelper()) { } @@ -81,6 +85,18 @@ internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform this.testPlatformEventSource = testPlatformEventSource; this.inferHelper = inferHelper; this.metricsPublisher = metricsPublisher; + this.processHelper = new ProcessHelper(); + } + + internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform testPlatform, TestRunResultAggregator testRunResultAggregator, ITestPlatformEventSource testPlatformEventSource, InferHelper inferHelper, Task metricsPublisher, IProcessHelper processHelper) + { + this.testPlatform = testPlatform; + this.commandLineOptions = commandLineOptions; + this.testRunResultAggregator = testRunResultAggregator; + this.testPlatformEventSource = testPlatformEventSource; + this.inferHelper = inferHelper; + this.metricsPublisher = metricsPublisher; + this.processHelper = processHelper; } #endregion @@ -382,8 +398,27 @@ private bool UpdateRunSettingsIfRequired(string runsettingsXml, List sou // Choose default architecture based on the framework // For .NET core, the default platform architecture should be x64. - var defaultArchitecture = chosenFramework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0 - || chosenFramework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0 ? Architecture.X64 : Architecture.X86; + Architecture defaultArchitecture = Architecture.X64; + if (chosenFramework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0 + || chosenFramework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0) + { + string currentProcess = this.processHelper.GetProcessName(this.processHelper.GetCurrentProcessId()); + if (currentProcess.StartsWith("vstest.console")) + { + defaultArchitecture = Architecture.X64; + } + else + { + if (Environment.Is64BitProcess) + { + defaultArchitecture = Architecture.X64; + } + else + { + defaultArchitecture = Architecture.X86; + } + } + } settingsUpdated |= this.UpdatePlatform(document, navigator, sources, sourcePlatforms, defaultArchitecture, out Architecture chosenPlatform); this.CheckSourcesForCompatibility(chosenFramework, chosenPlatform, sourcePlatforms, sourceFrameworks, registrar); From 29ca15082b607a59a6aa2c6e707f88e4d88b69c8 Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Thu, 3 Oct 2019 17:20:41 +0530 Subject: [PATCH 2/7] Cleaning and Addidng Tests --- .../Hosting/DotnetTestHostManager.cs | 16 +- .../TestPlatformHelpers/TestRequestManager.cs | 37 +---- .../Hosting/DotnetTestHostManagerTests.cs | 142 +++++++++++++++++- ...llyQualifiedTestsArgumentProcessorTests.cs | 19 ++- .../ListTestsArgumentProcessorTests.cs | 17 ++- .../RunSpecificTestsArgumentProcessorTests.cs | 47 +++--- .../RunTestsArgumentProcessorTests.cs | 17 ++- .../TestRequestManagerTests.cs | 55 ++++--- 8 files changed, 252 insertions(+), 98 deletions(-) diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 5a29977d02..2a926d444a 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -206,14 +206,15 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( var runtimeConfigDevPath = Path.Combine(sourceDirectory, string.Concat(sourceFile, ".runtimeconfig.dev.json")); var testHostPath = this.GetTestHostPath(runtimeConfigDevPath, depsFilePath, sourceDirectory); - // If Testhost.exe is available use it + // If testhost.exe is available use it bool testHostExeFound = false; if (this.platformEnvironment.OperatingSystem.Equals(PlatformOperatingSystem.Windows)) { var exeName = this.architecture == Architecture.X86 ? "testhost.x86.exe" : "testhost.exe"; var fullExePath = Path.Combine(sourceDirectory, exeName); + EqtTrace.Verbose("DotnetTestHostManager: test host exe path : " + fullExePath); - // check for testhost.exe in sourceDirectory. If not found, check this in nuget folder. + // check for testhost.exe in sourceDirectory. If not found, check in nuget folder. if (this.fileHelper.Exists(fullExePath)) { startInfo.FileName = fullExePath; @@ -227,18 +228,19 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( var folderName = this.architecture == Architecture.X86 ? "x86" : "x64"; var testHostNugetPath = Directory.GetParent(Directory.GetParent(Directory.GetParent(testHostPath).FullName).FullName); - var testHostExePath = Path.Combine(testHostNugetPath.FullName, "build", "netcoreapp2.1", folderName, exeName); + var testHostExeNugetPath = Path.Combine(testHostNugetPath.FullName, "build", "netcoreapp2.1", folderName, exeName); - if (this.fileHelper.Exists(testHostExePath)) + if (this.fileHelper.Exists(testHostExeNugetPath)) { - EqtTrace.Verbose("DotnetTestHostManager: testhost.exe/testhost.x86.exe found at path: " + testHostExePath); - startInfo.FileName = testHostExePath; + EqtTrace.Verbose("DotnetTestHostManager: Testhost.exe/testhost.x86.exe found at path: " + testHostExeNugetPath); + startInfo.FileName = testHostExeNugetPath; testHostExeFound = true; } } } } - else if (!testHostExeFound) + + if (!testHostExeFound) { var currentProcessPath = this.processHelper.GetCurrentProcessFileName(); diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index fab20235c2..6e1d4284e6 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -5,7 +5,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers { using System; using System.Collections.Generic; - using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -77,17 +76,6 @@ public TestRequestManager() { } - internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform testPlatform, TestRunResultAggregator testRunResultAggregator, ITestPlatformEventSource testPlatformEventSource, InferHelper inferHelper, Task metricsPublisher) - { - this.testPlatform = testPlatform; - this.commandLineOptions = commandLineOptions; - this.testRunResultAggregator = testRunResultAggregator; - this.testPlatformEventSource = testPlatformEventSource; - this.inferHelper = inferHelper; - this.metricsPublisher = metricsPublisher; - this.processHelper = new ProcessHelper(); - } - internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform testPlatform, TestRunResultAggregator testRunResultAggregator, ITestPlatformEventSource testPlatformEventSource, InferHelper inferHelper, Task metricsPublisher, IProcessHelper processHelper) { this.testPlatform = testPlatform; @@ -397,27 +385,18 @@ private bool UpdateRunSettingsIfRequired(string runsettingsXml, List sou settingsUpdated |= this.UpdateFramework(document, navigator, sources, sourceFrameworks, registrar, out Framework chosenFramework); // Choose default architecture based on the framework - // For .NET core, the default platform architecture should be x64. + // For .NET core, the default platform architecture should be based on the process. + // For a 64 bit process, Architecture defaultArchitecture = Architecture.X64; if (chosenFramework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0 || chosenFramework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0) { - string currentProcess = this.processHelper.GetProcessName(this.processHelper.GetCurrentProcessId()); - if (currentProcess.StartsWith("vstest.console")) - { - defaultArchitecture = Architecture.X64; - } - else - { - if (Environment.Is64BitProcess) - { - defaultArchitecture = Architecture.X64; - } - else - { - defaultArchitecture = Architecture.X86; - } - } + var currentProcessName = this.processHelper.GetProcessName(this.processHelper.GetCurrentProcessId()); + defaultArchitecture = (currentProcessName.StartsWith("vstest.console") || Environment.Is64BitProcess) ? Architecture.X64 : Architecture.X86; + } + else + { + defaultArchitecture = Architecture.X86; } settingsUpdated |= this.UpdatePlatform(document, navigator, sources, sourcePlatforms, defaultArchitecture, out Architecture chosenPlatform); diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs index fed8ecaf98..888fbf7cfc 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs @@ -244,6 +244,7 @@ public void GetTestHostProcessStartInfoShouldUseTestHostX86ExePresentOnWindows() { var testhostExePath = "testhost.x86.exe"; this.mockFileHelper.Setup(ph => ph.Exists(testhostExePath)).Returns(true); + this.mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); this.mockEnvironment.Setup(ev => ev.OperatingSystem).Returns(PlatformOperatingSystem.Windows); var startInfo = this.GetDefaultStartInfo(); @@ -264,10 +265,11 @@ public void GetTestHostProcessStartInfoShouldUseDotnetExeOnUnix() } [TestMethod] - public void GetTestHostProcessStartInfoShouldUseTestHostExeIsPresentOnWindows() + public void GetTestHostProcessStartInfoShouldUseTestHostExeIfPresentOnWindows() { var testhostExePath = "testhost.exe"; this.mockFileHelper.Setup(ph => ph.Exists(testhostExePath)).Returns(true); + this.mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); this.mockEnvironment.Setup(ev => ev.OperatingSystem).Returns(PlatformOperatingSystem.Windows); this.dotnetHostManager.Initialize(this.mockMessageLogger.Object, "x64"); @@ -276,6 +278,144 @@ public void GetTestHostProcessStartInfoShouldUseTestHostExeIsPresentOnWindows() StringAssert.Contains(startInfo.FileName, testhostExePath); } + [TestMethod] + public void GetTestHostProcessStartInfoShouldUseTestHostExeFromNugetIfNotFoundInSourceLocation() + { + var testhostExePath = "testhost.exe"; + this.dotnetHostManager.Initialize(this.mockMessageLogger.Object, "x64"); + this.mockFileHelper.Setup(ph => ph.Exists(testhostExePath)).Returns(false); + this.mockFileHelper.Setup(ph => ph.Exists("C:\\packages\\microsoft.testplatform.testhost\\15.0.0-Dev\\build\\netcoreapp2.1\\x64\\testhost.exe")).Returns(true); + this.mockEnvironment.Setup(ev => ev.OperatingSystem).Returns(PlatformOperatingSystem.Windows); + var sourcePath = Path.Combine($"{Path.DirectorySeparatorChar}tmp", "test.dll"); + + string runtimeConfigFileContent = +@"{ + ""runtimeOptions"": { + ""additionalProbingPaths"": [ + ""C:\\packages"" + ] + } +}"; + + string depsFileContent = +@"{ + ""runtimeTarget"": { + ""name"": "".NETCoreApp,Version=v1.0"", + ""signature"": ""8f25843f8e35a3e80ef4ae98b95117ea5c468b3f"" + }, + ""compilationOptions"": {}, + ""targets"": { + "".NETCoreApp,Version=v1.0"": { + ""microsoft.testplatform.testhost/15.0.0-Dev"": { + ""dependencies"": { + ""Microsoft.TestPlatform.ObjectModel"": ""15.0.0-Dev"", + ""Newtonsoft.Json"": ""9.0.1"" + }, + ""runtime"": { + ""lib/netstandard1.5/Microsoft.TestPlatform.CommunicationUtilities.dll"": { }, + ""lib/netstandard1.5/Microsoft.TestPlatform.CrossPlatEngine.dll"": { }, + ""lib/netstandard1.5/Microsoft.VisualStudio.TestPlatform.Common.dll"": { }, + ""lib/netstandard1.5/testhost.dll"": { } + } + } + } + }, + ""libraries"": { + ""microsoft.testplatform.testhost/15.0.0-Dev"": { + ""type"": ""package"", + ""serviceable"": true, + ""sha512"": ""sha512-enO8sZmjbhXOfiZ6hV2ncaknaHnQbrGVsHUJzzu2Dmoh4fHFro4BF1Y4+sb4LOQhu4b3DFYPRj1ncd1RQK6HmQ=="", + ""path"": ""microsoft.testplatform.testhost/15.0.0-Dev"", + ""hashPath"": ""microsoft.testplatform.testhost.15.0.0-Dev"" + } + } +}"; + + MemoryStream runtimeConfigStream = new MemoryStream(Encoding.UTF8.GetBytes(runtimeConfigFileContent)); + this.mockFileHelper.Setup(ph => ph.GetStream("\\tmp\\test.runtimeconfig.dev.json", FileMode.Open, FileAccess.Read)).Returns(runtimeConfigStream); + this.mockFileHelper.Setup(ph => ph.Exists("\\tmp\\test.runtimeconfig.dev.json")).Returns(true); + + MemoryStream depsFileStream = new MemoryStream(Encoding.UTF8.GetBytes(depsFileContent)); + this.mockFileHelper.Setup(ph => ph.GetStream("\\tmp\\test.deps.json", FileMode.Open, FileAccess.Read)).Returns(depsFileStream); + this.mockFileHelper.Setup(ph => ph.Exists("\\tmp\\test.deps.json")).Returns(true); + + string testHostFullPath = @"C:\packages\microsoft.testplatform.testhost/15.0.0-Dev\lib/netstandard1.5/testhost.dll"; + this.mockFileHelper.Setup(ph => ph.Exists(testHostFullPath)).Returns(true); + + var startInfo = this.dotnetHostManager.GetTestHostProcessStartInfo(new[] { sourcePath }, null, this.defaultConnectionInfo); + + StringAssert.Contains(startInfo.FileName, "C:\\packages\\microsoft.testplatform.testhost\\15.0.0-Dev\\build\\netcoreapp2.1\\x64\\testhost.exe"); + } + + [TestMethod] + public void GetTestHostProcessStartInfoShouldUseTestHostX86ExeFromNugetIfNotFoundInSourceLocation() + { + var testhostExePath = "testhost.x86.exe"; + this.dotnetHostManager.Initialize(this.mockMessageLogger.Object, "x86"); + this.mockFileHelper.Setup(ph => ph.Exists(testhostExePath)).Returns(false); + this.mockFileHelper.Setup(ph => ph.Exists("C:\\packages\\microsoft.testplatform.testhost\\15.0.0-Dev\\build\\netcoreapp2.1\\x86\\testhost.x86.exe")).Returns(true); + this.mockEnvironment.Setup(ev => ev.OperatingSystem).Returns(PlatformOperatingSystem.Windows); + var sourcePath = Path.Combine($"{Path.DirectorySeparatorChar}tmp", "test.dll"); + + string runtimeConfigFileContent = +@"{ + ""runtimeOptions"": { + ""additionalProbingPaths"": [ + ""C:\\packages"" + ] + } +}"; + + string depsFileContent = +@"{ + ""runtimeTarget"": { + ""name"": "".NETCoreApp,Version=v1.0"", + ""signature"": ""8f25843f8e35a3e80ef4ae98b95117ea5c468b3f"" + }, + ""compilationOptions"": {}, + ""targets"": { + "".NETCoreApp,Version=v1.0"": { + ""microsoft.testplatform.testhost/15.0.0-Dev"": { + ""dependencies"": { + ""Microsoft.TestPlatform.ObjectModel"": ""15.0.0-Dev"", + ""Newtonsoft.Json"": ""9.0.1"" + }, + ""runtime"": { + ""lib/netstandard1.5/Microsoft.TestPlatform.CommunicationUtilities.dll"": { }, + ""lib/netstandard1.5/Microsoft.TestPlatform.CrossPlatEngine.dll"": { }, + ""lib/netstandard1.5/Microsoft.VisualStudio.TestPlatform.Common.dll"": { }, + ""lib/netstandard1.5/testhost.dll"": { } + } + } + } + }, + ""libraries"": { + ""microsoft.testplatform.testhost/15.0.0-Dev"": { + ""type"": ""package"", + ""serviceable"": true, + ""sha512"": ""sha512-enO8sZmjbhXOfiZ6hV2ncaknaHnQbrGVsHUJzzu2Dmoh4fHFro4BF1Y4+sb4LOQhu4b3DFYPRj1ncd1RQK6HmQ=="", + ""path"": ""microsoft.testplatform.testhost/15.0.0-Dev"", + ""hashPath"": ""microsoft.testplatform.testhost.15.0.0-Dev"" + } + } +}"; + + MemoryStream runtimeConfigStream = new MemoryStream(Encoding.UTF8.GetBytes(runtimeConfigFileContent)); + this.mockFileHelper.Setup(ph => ph.GetStream("\\tmp\\test.runtimeconfig.dev.json", FileMode.Open, FileAccess.Read)).Returns(runtimeConfigStream); + this.mockFileHelper.Setup(ph => ph.Exists("\\tmp\\test.runtimeconfig.dev.json")).Returns(true); + + MemoryStream depsFileStream = new MemoryStream(Encoding.UTF8.GetBytes(depsFileContent)); + this.mockFileHelper.Setup(ph => ph.GetStream("\\tmp\\test.deps.json", FileMode.Open, FileAccess.Read)).Returns(depsFileStream); + this.mockFileHelper.Setup(ph => ph.Exists("\\tmp\\test.deps.json")).Returns(true); + + string testHostFullPath = @"C:\packages\microsoft.testplatform.testhost/15.0.0-Dev\lib/netstandard1.5/testhost.dll"; + this.mockFileHelper.Setup(ph => ph.Exists(testHostFullPath)).Returns(true); + + var startInfo = this.dotnetHostManager.GetTestHostProcessStartInfo(new[] { sourcePath }, null, this.defaultConnectionInfo); + + StringAssert.Contains(startInfo.FileName, "C:\\packages\\microsoft.testplatform.testhost\\15.0.0-Dev\\build\\netcoreapp2.1\\x86\\testhost.x86.exe"); + } + [TestMethod] public void LaunchTestHostShouldLaunchProcessWithNullEnvironmentVariablesOrArgs() { diff --git a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs index 56e617f45e..66f6db2d3d 100644 --- a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs @@ -18,6 +18,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using Microsoft.VisualStudio.TestPlatform.CommandLine.Publisher; using Microsoft.VisualStudio.TestPlatform.CommandLineUtilities; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -42,6 +43,7 @@ public class ListFullyQualifiedTestsArgumentProcessorTests private readonly Mock mockTestPlatformEventSource; private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; + private Mock mockProcessHelper; private static ListFullyQualifiedTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager, IOutput output) { @@ -75,6 +77,7 @@ public ListFullyQualifiedTestsArgumentProcessorTests() this.mockAssemblyMetadataProvider.Setup(x => x.GetArchitecture(It.IsAny())).Returns(Architecture.X64); this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); this.inferHelper = new InferHelper(this.mockAssemblyMetadataProvider.Object); + this.mockProcessHelper = new Mock(); } /// @@ -121,7 +124,7 @@ public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() { CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager, null); executor.Initialize(this.dummyTestFilePath); @@ -133,7 +136,7 @@ public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() public void ExecutorExecuteForNoSourcesShouldReturnFail() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -150,7 +153,7 @@ public void ExecutorExecuteShouldThrowTestPlatformException() this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager, null); @@ -167,7 +170,7 @@ public void ExecutorExecuteShouldThrowSettingsException() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); @@ -186,7 +189,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationException() this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); @@ -204,7 +207,7 @@ public void ExecutorExecuteShouldThrowOtherExceptions() this.ResetAndAddSourceToCommandLineOptions(true); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager, null); @@ -296,7 +299,7 @@ private void RunListFullyQualifiedTestArgumentProcessorWithTraits(Mock mockTestPlatformEventSource; private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; + private Mock mockProcessHelper; private static ListTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager, IOutput output) { @@ -73,6 +75,7 @@ public ListTestsArgumentProcessorTests() this.mockAssemblyMetadataProvider.Setup(x => x.GetArchitecture(It.IsAny())).Returns(Architecture.X64); this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); this.inferHelper = new InferHelper(this.mockAssemblyMetadataProvider.Object); + this.mockProcessHelper = new Mock(); } /// @@ -122,7 +125,7 @@ public void ExecutorInitializeWithValidSourceShouldAddItToTestSources() { CommandLineOptions.Instance.FileHelper = this.mockFileHelper.Object; CommandLineOptions.Instance.FilePatternParser = new FilePatternParser(new Mock().Object, this.mockFileHelper.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager, null); executor.Initialize(this.dummyTestFilePath); @@ -135,7 +138,7 @@ public void ExecutorExecuteForNoSourcesShouldReturnFail() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -152,7 +155,7 @@ public void ExecutorExecuteShouldThrowTestPlatformException() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -169,7 +172,7 @@ public void ExecutorExecuteShouldThrowSettingsException() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => listTestsArgumentExecutor.Execute()); @@ -186,7 +189,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationException() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => listTestsArgumentExecutor.Execute()); @@ -203,7 +206,7 @@ public void ExecutorExecuteShouldThrowOtherExceptions() this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager, null); Assert.ThrowsException(() => executor.Execute()); @@ -260,7 +263,7 @@ private void RunListTestArgumentProcessorExecuteWithMockSetup(Mock mockAssemblyMetadataProvider; private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; + private Mock mockProcessHelper; private RunSpecificTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestManager) { @@ -61,6 +63,7 @@ public RunSpecificTestsArgumentProcessorTests() this.mockMetricsPublisher = new Mock(); this.mockMetricsPublisherTask = Task.FromResult(this.mockMetricsPublisher.Object); this.mockTestPlatformEventSource = new Mock(); + this.mockProcessHelper = new Mock(); } [TestMethod] @@ -105,7 +108,7 @@ public void InitializeShouldThrowIfArgumentIsNull() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(null); }); @@ -116,7 +119,7 @@ public void InitializeShouldThrowIfArgumentIsEmpty() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(String.Empty); }); @@ -127,7 +130,7 @@ public void InitializeShouldThrowIfArgumentIsWhiteSpace() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(" "); }); @@ -138,7 +141,7 @@ public void InitializeShouldThrowIfArgumentsAreEmpty() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => { executor.Initialize(" , "); }); @@ -149,7 +152,7 @@ public void ExecutorShouldSplitTestsSeparatedByComma() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -160,7 +163,7 @@ public void ExecutorExecuteForNoSourcesShouldThrowCommandLineException() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -170,7 +173,7 @@ public void ExecutorExecuteForNoSourcesShouldThrowCommandLineException() public void ExecutorExecuteForValidSourceWithTestCaseFilterShouldThrowCommandLineException() { this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); CommandLineOptions.Instance.TestCaseFilterValue = "Filter"; Assert.ThrowsException(() => executor.Execute()); @@ -188,7 +191,7 @@ public void ExecutorExecuteShouldThrowTestPlatformExceptionThrownDuringDiscovery mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -206,7 +209,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationExceptionThrownDuringDisco mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -224,7 +227,7 @@ public void ExecutorExecuteShouldThrowSettingsExceptionThrownDuringDiscovery() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -247,7 +250,7 @@ public void ExecutorExecuteShouldThrowTestPlatformExceptionThrownDuringExecution mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -272,7 +275,7 @@ public void ExecutorExecuteShouldThrowSettingsExceptionThrownDuringExecution() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -298,7 +301,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationExceptionThrownDuringExecu this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -319,7 +322,7 @@ public void ExecutorExecuteShouldForValidSourcesAndNoTestsDiscoveredShouldLogWar mockDiscoveryRequest.Setup(dr => dr.DiscoverAsync()).Raises(dr => dr.OnDiscoveredTests += null, new DiscoveredTestsEventArgs(new List())); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -340,7 +343,7 @@ public void ExecutorExecuteShouldForValidSourcesAndNoTestsDiscoveredShouldLogApp mockDiscoveryRequest.Setup(dr => dr.DiscoverAsync()).Raises(dr => dr.OnDiscoveredTests += null, new DiscoveredTestsEventArgs(new List())); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -367,7 +370,7 @@ public void ExecutorExecuteShouldForValidSourcesAndValidSelectedTestsRunsTestsAn mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -393,7 +396,7 @@ public void ExecutorShouldRunTestsWhenTestsAreCommaSeparated() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1, Test2"); @@ -420,7 +423,7 @@ public void ExecutorShouldRunTestsWhenTestsAreFiltered() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -446,7 +449,7 @@ public void ExecutorShouldWarnWhenTestsAreNotAvailable() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1, Test2"); @@ -473,7 +476,7 @@ public void ExecutorShouldRunTestsWhenTestsAreCommaSeparatedWithEscape() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1(a\\,b), Test2(c\\,d)"); @@ -503,7 +506,7 @@ public void ExecutorShouldDisplayWarningIfNoTestsAreExecuted() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); @@ -532,7 +535,7 @@ public void ExecutorShouldNotDisplayWarningIfTestsAreExecuted() mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); executor.Initialize("Test1"); diff --git a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs index 7aea9780e9..a44c555364 100644 --- a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs @@ -24,6 +24,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -45,6 +46,7 @@ public class RunTestsArgumentProcessorTests private Mock mockTestPlatformEventSource; private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; + private Mock mockProcessHelper; public RunTestsArgumentProcessorTests() { @@ -61,6 +63,7 @@ public RunTestsArgumentProcessorTests() this.mockAssemblyMetadataProvider.Setup(a => a.GetArchitecture(It.IsAny())) .Returns(Architecture.X86); this.mockAssemblyMetadataProvider.Setup(x => x.GetFrameWork(It.IsAny())).Returns(new FrameworkName(Constants.DotNetFramework40)); + this.mockProcessHelper = new Mock(); } [TestMethod] @@ -106,7 +109,7 @@ public void ExecutorExecuteShouldReturnSuccessWithoutExecutionInDesignMode() CommandLineOptions.Instance.Reset(); CommandLineOptions.Instance.IsDesignMode = true; - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = new RunTestsArgumentExecutor(CommandLineOptions.Instance, runSettingsProvider, testRequestManager, this.mockOutput.Object); Assert.AreEqual(ArgumentProcessorResult.Success, executor.Execute()); @@ -116,7 +119,7 @@ public void ExecutorExecuteShouldReturnSuccessWithoutExecutionInDesignMode() public void ExecutorExecuteForNoSourcesShouldThrowCommandLineException() { CommandLineOptions.Instance.Reset(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, TestPlatformFactory.GetTestPlatform(), TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -145,7 +148,7 @@ public void ExecutorExecuteShouldThrowTestPlatformException() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -161,7 +164,7 @@ public void ExecutorExecuteShouldThrowSettingsException() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -177,7 +180,7 @@ public void ExecutorExecuteShouldThrowInvalidOperationException() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -193,7 +196,7 @@ public void ExecutorExecuteShouldThrowOtherExceptions() mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); Assert.ThrowsException(() => executor.Execute()); @@ -248,7 +251,7 @@ private ArgumentProcessorResult RunRunArgumentProcessorExecuteWithMockSetup(ITes this.ResetAndAddSourceToCommandLineOptions(); - var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); + var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, this.mockProcessHelper.Object); var executor = GetExecutor(testRequestManager); return executor.Execute(); diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index 968d0516da..6e8acbdcae 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -34,6 +34,7 @@ namespace vstest.console.UnitTests.TestPlatformHelpers using vstest.console.UnitTests.TestDoubles; using Microsoft.VisualStudio.TestPlatform.Utilities; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; [TestClass] public class TestRequestManagerTests @@ -53,6 +54,7 @@ public class TestRequestManagerTests private ProtocolConfig protocolConfig; private Task mockMetricsPublisherTask; private Mock mockMetricsPublisher; + private Mock mockProcessHelper; private const string DefaultRunsettings = @" @@ -73,6 +75,7 @@ public TestRequestManagerTests() this.mockAssemblyMetadataProvider = new Mock(); this.inferHelper = new InferHelper(this.mockAssemblyMetadataProvider.Object); var testRunResultAggregator = new DummyTestRunResultAggregator(); + this.mockProcessHelper = new Mock(); this.mockMetricsPublisher = new Mock(); this.mockMetricsPublisherTask = Task.FromResult(this.mockMetricsPublisher.Object); @@ -82,7 +85,8 @@ public TestRequestManagerTests() testRunResultAggregator, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); this.mockMetricsCollection = new Mock(); this.mockRequestData = new Mock(); this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(this.mockMetricsCollection.Object); @@ -115,7 +119,8 @@ public void TestRequestManagerShouldNotInitializeConsoleLoggerIfDesignModeIsSet( TestRunResultAggregator.Instance, new Mock().Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); Assert.IsFalse(this.mockLoggerEvents.EventsSubscribed()); } @@ -196,7 +201,8 @@ public void DiscoverTestsShouldCallTestPlatformAndSucceed() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); this.testRequestManager.DiscoverTests(payload, mockDiscoveryRegistrar.Object, this.protocolConfig); @@ -244,7 +250,8 @@ public void DiscoverTestsShouldPassSameProtocolConfigInRequestData() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); // Act this.testRequestManager.DiscoverTests(payload, mockDiscoveryRegistrar.Object, mockProtocolConfig); @@ -290,7 +297,8 @@ public void DiscoverTestsShouldCollectMetrics() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); // Act @@ -338,7 +346,8 @@ public void DiscoverTestsShouldCollectTargetDeviceLocalMachineIfTargetDeviceStri TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); // Act @@ -380,7 +389,8 @@ public void DiscoverTestsShouldCollectTargetDeviceIfTargetDeviceIsDevice() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); // Act @@ -422,7 +432,8 @@ public void DiscoverTestsShouldCollectTargetDeviceIfTargetDeviceIsEmulator() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); // Act @@ -464,7 +475,8 @@ public void DiscoverTestsShouldCollectCommands() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); CommandLineOptions.Instance.Parallel = true; CommandLineOptions.Instance.EnableCodeCoverage = true; @@ -518,7 +530,8 @@ public void DiscoverTestsShouldCollectTestSettings() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); CommandLineOptions.Instance.SettingsFile = @"c://temp/.testsettings"; @@ -564,7 +577,8 @@ public void DiscoverTestsShouldCollectVsmdiFile() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); CommandLineOptions.Instance.SettingsFile = @"c://temp/.vsmdi"; @@ -610,7 +624,8 @@ public void DiscoverTestsShouldCollectTestRunConfigFile() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); CommandLineOptions.Instance.SettingsFile = @"c://temp/.testrunConfig"; @@ -931,7 +946,8 @@ public void RunTestsShouldCollectCommands() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); CommandLineOptions.Instance.Parallel = true; CommandLineOptions.Instance.EnableCodeCoverage = true; @@ -997,7 +1013,8 @@ public void RunTestsShouldCollectTelemetryForLegacySettings() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); // Act. this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, mockProtocolConfig); @@ -1045,7 +1062,8 @@ public void RunTestsShouldCollectTelemetryForTestSettingsEmbeddedInsideRunSettin TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); // Act. this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, mockProtocolConfig); @@ -1091,7 +1109,8 @@ public void RunTestsShouldCollectMetrics() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + this.mockProcessHelper.Object); // Act. this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, mockProtocolConfig); @@ -1129,6 +1148,7 @@ public void RunTestsWithSourcesShouldCallTestPlatformAndSucceed() var mockRunEventsRegistrar = new Mock(); var mockCustomlauncher = new Mock(); + var mockProcessHelper = new Mock(); string testCaseFilterValue = "TestFilter"; payload.TestPlatformOptions = new TestPlatformOptions { TestCaseFilter = testCaseFilterValue }; @@ -1137,7 +1157,8 @@ public void RunTestsWithSourcesShouldCallTestPlatformAndSucceed() TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, - this.mockMetricsPublisherTask); + this.mockMetricsPublisherTask, + mockProcessHelper.Object); this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); From b523963590d1e7c5b3823041a56c10681b6e5035 Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Fri, 4 Oct 2019 15:11:16 +0530 Subject: [PATCH 3/7] Addressing review comments --- .../Hosting/DotnetTestHostManager.cs | 11 ++++++----- .../TestPlatformHelpers/TestRequestManager.cs | 8 ++------ .../RunSpecificTestsArgumentProcessorTests.cs | 2 ++ .../TestPlatformHelpers/TestRequestManagerTests.cs | 5 +++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 2a926d444a..56d0ad840e 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -212,23 +212,24 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( { var exeName = this.architecture == Architecture.X86 ? "testhost.x86.exe" : "testhost.exe"; var fullExePath = Path.Combine(sourceDirectory, exeName); - EqtTrace.Verbose("DotnetTestHostManager: test host exe path : " + fullExePath); // check for testhost.exe in sourceDirectory. If not found, check in nuget folder. if (this.fileHelper.Exists(fullExePath)) { + EqtTrace.Verbose("DotnetTestHostManager: Testhost.exe/testhost.x86.exe found at path: " + fullExePath); startInfo.FileName = fullExePath; testHostExeFound = true; } else { // Check if testhost.dll is found in nuget folder. - if (testHostPath.Contains("microsoft.testplatform.testhost")) + if (testHostPath.IndexOf("microsoft.testplatform.testhost", StringComparison.OrdinalIgnoreCase) >= 0) { + // testhost.dll is present in path {testHostNugetRoot}\lib\netcoreapp2.1\testhost.dll + // testhost.(x86).exe is present in location {testHostNugetRoot}\build\netcoreapp2.1\{x86/x64}\{testhost.x86.exe/testhost.exe} var folderName = this.architecture == Architecture.X86 ? "x86" : "x64"; - var testHostNugetPath = Directory.GetParent(Directory.GetParent(Directory.GetParent(testHostPath).FullName).FullName); - - var testHostExeNugetPath = Path.Combine(testHostNugetPath.FullName, "build", "netcoreapp2.1", folderName, exeName); + var testHostNugetRoot = new DirectoryInfo(testHostPath).Parent.Parent.Parent; + var testHostExeNugetPath = Path.Combine(testHostNugetRoot.FullName, "build", "netcoreapp2.1", folderName, exeName); if (this.fileHelper.Exists(testHostExeNugetPath)) { diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 6e1d4284e6..65e00437f6 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -387,16 +387,12 @@ private bool UpdateRunSettingsIfRequired(string runsettingsXml, List sou // Choose default architecture based on the framework // For .NET core, the default platform architecture should be based on the process. // For a 64 bit process, - Architecture defaultArchitecture = Architecture.X64; + Architecture defaultArchitecture = Architecture.X86; if (chosenFramework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0 || chosenFramework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0) { var currentProcessName = this.processHelper.GetProcessName(this.processHelper.GetCurrentProcessId()); - defaultArchitecture = (currentProcessName.StartsWith("vstest.console") || Environment.Is64BitProcess) ? Architecture.X64 : Architecture.X86; - } - else - { - defaultArchitecture = Architecture.X86; + defaultArchitecture = (currentProcessName.StartsWith("dotnet", StringComparison.OrdinalIgnoreCase) && !Environment.Is64BitProcess) ? Architecture.X86: Architecture.X64; } settingsUpdated |= this.UpdatePlatform(document, navigator, sources, sourcePlatforms, defaultArchitecture, out Architecture chosenPlatform); diff --git a/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs index 6da9410393..61ba0f3b42 100644 --- a/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs @@ -64,6 +64,8 @@ public RunSpecificTestsArgumentProcessorTests() this.mockMetricsPublisherTask = Task.FromResult(this.mockMetricsPublisher.Object); this.mockTestPlatformEventSource = new Mock(); this.mockProcessHelper = new Mock(); + this.mockProcessHelper.Setup(x => x.GetCurrentProcessId()).Returns(1234); + this.mockProcessHelper.Setup(x => x.GetProcessName(It.IsAny())).Returns("dotnet.exe"); } [TestMethod] diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index 6e8acbdcae..2486b81164 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -98,6 +98,8 @@ public TestRequestManagerTests() .Returns(Architecture.X86); this.mockAssemblyMetadataProvider.Setup(a => a.GetFrameWork(It.IsAny())) .Returns(new FrameworkName(Constants.DotNetFramework40)); + this.mockProcessHelper.Setup(x => x.GetCurrentProcessId()).Returns(1234); + this.mockProcessHelper.Setup(x => x.GetProcessName(It.IsAny())).Returns("dotnet.exe"); } [TestCleanup] @@ -1148,7 +1150,6 @@ public void RunTestsWithSourcesShouldCallTestPlatformAndSucceed() var mockRunEventsRegistrar = new Mock(); var mockCustomlauncher = new Mock(); - var mockProcessHelper = new Mock(); string testCaseFilterValue = "TestFilter"; payload.TestPlatformOptions = new TestPlatformOptions { TestCaseFilter = testCaseFilterValue }; @@ -1158,7 +1159,7 @@ public void RunTestsWithSourcesShouldCallTestPlatformAndSucceed() this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask, - mockProcessHelper.Object); + this.mockProcessHelper.Object); this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); From 3b2837ae90ce07fd674cce1944882ec7b3df0923 Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Mon, 14 Oct 2019 13:24:35 +0530 Subject: [PATCH 4/7] Removing props file and changed protocol version check --- scripts/build.ps1 | 2 +- .../Hosting/DotnetTestHostManager.cs | 4 ++- ...rosoft.TestPlatform.TestHost.NetCore.props | 27 ------------------- ...soft.TestPlatform.TestHost.NetCore.targets | 9 +++++++ .../nuspec/TestPlatform.TestHost.nuspec | 2 +- 5 files changed, 14 insertions(+), 30 deletions(-) delete mode 100644 src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props create mode 100644 src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.targets diff --git a/scripts/build.ps1 b/scripts/build.ps1 index f71b0da3ac..85979cd34d 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -608,7 +608,7 @@ function Create-NugetPackages Copy-Item $tpNuspecDir\uap\"Microsoft.TestPlatform.TestHost.Uap.targets" $testhostUapPackageDir\Microsoft.TestPlatform.TestHost.targets -Force $testhostCorePackageDir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore20") - Copy-Item $tpNuspecDir\"Microsoft.TestPlatform.TestHost.NetCore.props" $testhostCorePackageDir\Microsoft.TestPlatform.TestHost.props -Force + Copy-Item $tpNuspecDir\"Microsoft.TestPlatform.TestHost.NetCore.targets" $testhostCorePackageDir\Microsoft.TestPlatform.TestHost.targets -Force # Call nuget pack on these components. $nugetExe = Join-Path $env:TP_PACKAGES_DIR -ChildPath "Nuget.CommandLine" | Join-Path -ChildPath $env:NUGET_EXE_Version | Join-Path -ChildPath "tools\NuGet.exe" diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 56d0ad840e..3b49aa59d5 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -111,8 +111,9 @@ internal DotnetTestHostManager( /// /// Gets a value indicating whether the test host supports protocol version check + /// By default this is set to true. For host package version 15.0.0, this will be set to false; /// - internal virtual bool IsVersionCheckRequired => !this.hostPackageVersion.StartsWith("15.0.0"); + internal virtual bool IsVersionCheckRequired => true; /// /// Gets a value indicating whether the test host supports protocol version check @@ -422,6 +423,7 @@ private string GetTestHostPath(string runtimeConfigDevPath, string depsFilePath, testHostPath = Path.Combine(testhostPackage.Path, testHostPath); this.hostPackageVersion = testhostPackage.Version; + this.IsVersionCheckRequired = !(this.hostPackageVersion.StartsWith("15.0.0")); EqtTrace.Verbose("DotnetTestHostmanager: Relative path of testhost.dll with respect to package folder is {0}", testHostPath); } } diff --git a/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props b/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props deleted file mode 100644 index a13eb787a7..0000000000 --- a/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props +++ /dev/null @@ -1,27 +0,0 @@ - - - - - testhost.x86.exe - PreserveNewest - False - - - testhost.x86.dll - PreserveNewest - False - - - - - testhost.exe - PreserveNewest - False - - - testhost.dll - PreserveNewest - False - - - \ No newline at end of file diff --git a/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.targets b/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.targets new file mode 100644 index 0000000000..d7deb6bca0 --- /dev/null +++ b/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.targets @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/package/nuspec/TestPlatform.TestHost.nuspec b/src/package/nuspec/TestPlatform.TestHost.nuspec index d2f1343ff5..43ba875dc9 100644 --- a/src/package/nuspec/TestPlatform.TestHost.nuspec +++ b/src/package/nuspec/TestPlatform.TestHost.nuspec @@ -47,7 +47,7 @@ - + From 81aa8ef6c361bfd731c71468145fc14a1eea469b Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Mon, 14 Oct 2019 14:39:18 +0530 Subject: [PATCH 5/7] Fixing build failure --- .../Hosting/DotnetTestHostManager.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 3b49aa59d5..bbb004d84b 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -67,6 +67,8 @@ public class DotnetTestHostManager : ITestRuntimeProvider private Architecture architecture; + private bool isVersionCheckRequired = true; + /// /// Initializes a new instance of the class. /// @@ -113,7 +115,18 @@ internal DotnetTestHostManager( /// Gets a value indicating whether the test host supports protocol version check /// By default this is set to true. For host package version 15.0.0, this will be set to false; /// - internal virtual bool IsVersionCheckRequired => true; + internal virtual bool IsVersionCheckRequired + { + get + { + return this.isVersionCheckRequired; + } + + set + { + this.isVersionCheckRequired = value; + } + } /// /// Gets a value indicating whether the test host supports protocol version check @@ -423,7 +436,7 @@ private string GetTestHostPath(string runtimeConfigDevPath, string depsFilePath, testHostPath = Path.Combine(testhostPackage.Path, testHostPath); this.hostPackageVersion = testhostPackage.Version; - this.IsVersionCheckRequired = !(this.hostPackageVersion.StartsWith("15.0.0")); + this.IsVersionCheckRequired = !this.hostPackageVersion.StartsWith("15.0.0"); EqtTrace.Verbose("DotnetTestHostmanager: Relative path of testhost.dll with respect to package folder is {0}", testHostPath); } } From 0b6a6b34e6bea45e31bb58aeb8bee9c67406e91f Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Wed, 16 Oct 2019 11:19:48 +0530 Subject: [PATCH 6/7] Using CopyToPublishDIrectory in props file --- .../Hosting/DotnetTestHostManager.cs | 5 ++-- ...rosoft.TestPlatform.TestHost.NetCore.props | 27 +++++++++++++++++++ ...soft.TestPlatform.TestHost.NetCore.targets | 9 ------- 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props delete mode 100644 src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.targets diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index bbb004d84b..d8b3dddd21 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -122,7 +122,7 @@ internal virtual bool IsVersionCheckRequired return this.isVersionCheckRequired; } - set + private set { this.isVersionCheckRequired = value; } @@ -218,7 +218,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( } var runtimeConfigDevPath = Path.Combine(sourceDirectory, string.Concat(sourceFile, ".runtimeconfig.dev.json")); - var testHostPath = this.GetTestHostPath(runtimeConfigDevPath, depsFilePath, sourceDirectory); + string testHostPath = string.Empty; // If testhost.exe is available use it bool testHostExeFound = false; @@ -237,6 +237,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( else { // Check if testhost.dll is found in nuget folder. + testHostPath = this.GetTestHostPath(runtimeConfigDevPath, depsFilePath, sourceDirectory); if (testHostPath.IndexOf("microsoft.testplatform.testhost", StringComparison.OrdinalIgnoreCase) >= 0) { // testhost.dll is present in path {testHostNugetRoot}\lib\netcoreapp2.1\testhost.dll diff --git a/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props b/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props new file mode 100644 index 0000000000..aae9c3ac41 --- /dev/null +++ b/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props @@ -0,0 +1,27 @@ + + + + + testhost.x86.exe + PreserveNewest + False + + + testhost.x86.dll + PreserveNewest + False + + + + + testhost.exe + PreserveNewest + False + + + testhost.dll + PreserveNewest + False + + + \ No newline at end of file diff --git a/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.targets b/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.targets deleted file mode 100644 index d7deb6bca0..0000000000 --- a/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.targets +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file From 5157854b5d2756071320365c0ed05e65a97bb4ae Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Wed, 16 Oct 2019 11:50:25 +0530 Subject: [PATCH 7/7] Fixing build scripts --- scripts/build.ps1 | 2 +- src/package/nuspec/TestPlatform.TestHost.nuspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 85979cd34d..f71b0da3ac 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -608,7 +608,7 @@ function Create-NugetPackages Copy-Item $tpNuspecDir\uap\"Microsoft.TestPlatform.TestHost.Uap.targets" $testhostUapPackageDir\Microsoft.TestPlatform.TestHost.targets -Force $testhostCorePackageDir = $(Join-Path $env:TP_OUT_DIR "$TPB_Configuration\Microsoft.TestPlatform.TestHost\$TPB_TargetFrameworkCore20") - Copy-Item $tpNuspecDir\"Microsoft.TestPlatform.TestHost.NetCore.targets" $testhostCorePackageDir\Microsoft.TestPlatform.TestHost.targets -Force + Copy-Item $tpNuspecDir\"Microsoft.TestPlatform.TestHost.NetCore.props" $testhostCorePackageDir\Microsoft.TestPlatform.TestHost.props -Force # Call nuget pack on these components. $nugetExe = Join-Path $env:TP_PACKAGES_DIR -ChildPath "Nuget.CommandLine" | Join-Path -ChildPath $env:NUGET_EXE_Version | Join-Path -ChildPath "tools\NuGet.exe" diff --git a/src/package/nuspec/TestPlatform.TestHost.nuspec b/src/package/nuspec/TestPlatform.TestHost.nuspec index 43ba875dc9..d2f1343ff5 100644 --- a/src/package/nuspec/TestPlatform.TestHost.nuspec +++ b/src/package/nuspec/TestPlatform.TestHost.nuspec @@ -47,7 +47,7 @@ - +