diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs
index 87a80b0519..d8b3dddd21 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.
///
@@ -111,8 +113,20 @@ 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
+ {
+ get
+ {
+ return this.isVersionCheckRequired;
+ }
+
+ private set
+ {
+ this.isVersionCheckRequired = value;
+ }
+ }
///
/// Gets a value indicating whether the test host supports protocol version check
@@ -203,14 +217,46 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(
EqtTrace.Verbose("DotnetTestHostmanager: File {0}, doesnot exist", depsFilePath);
}
- // 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))
+ var runtimeConfigDevPath = Path.Combine(sourceDirectory, string.Concat(sourceFile, ".runtimeconfig.dev.json"));
+ string testHostPath = string.Empty;
+
+ // If testhost.exe is available use it
+ 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 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.
+ 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
+ // 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 testHostNugetRoot = new DirectoryInfo(testHostPath).Parent.Parent.Parent;
+ var testHostExeNugetPath = Path.Combine(testHostNugetRoot.FullName, "build", "netcoreapp2.1", folderName, exeName);
+
+ if (this.fileHelper.Exists(testHostExeNugetPath))
+ {
+ EqtTrace.Verbose("DotnetTestHostManager: Testhost.exe/testhost.x86.exe found at path: " + testHostExeNugetPath);
+ startInfo.FileName = testHostExeNugetPath;
+ testHostExeFound = true;
+ }
+ }
+ }
}
- else
+
+ if (!testHostExeFound)
{
var currentProcessPath = this.processHelper.GetCurrentProcessFileName();
@@ -227,9 +273,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();
@@ -394,6 +437,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
index a33990d7a3..aae9c3ac41 100644
--- a/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props
+++ b/src/package/nuspec/Microsoft.TestPlatform.TestHost.NetCore.props
@@ -1,26 +1,26 @@
-
+
testhost.x86.exe
- PreserveNewest
+ PreserveNewest
False
testhost.x86.dll
- PreserveNewest
+ PreserveNewest
False
-
+
testhost.exe
- PreserveNewest
+ PreserveNewest
False
testhost.dll
- PreserveNewest
+ PreserveNewest
False
diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
index 05a81fbaf9..65e00437f6 100644
--- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
+++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
@@ -29,6 +29,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 +48,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,11 +71,12 @@ public TestRequestManager()
TestRunResultAggregator.Instance,
TestPlatformEventSource.Instance,
new InferHelper(AssemblyMetadataProvider.Instance),
- MetricsPublisherFactory.GetMetricsPublisher(IsTelemetryOptedIn(), CommandLineOptions.Instance.IsDesignMode))
+ MetricsPublisherFactory.GetMetricsPublisher(IsTelemetryOptedIn(), CommandLineOptions.Instance.IsDesignMode),
+ new ProcessHelper())
{
}
- internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform testPlatform, TestRunResultAggregator testRunResultAggregator, ITestPlatformEventSource testPlatformEventSource, InferHelper inferHelper, Task metricsPublisher)
+ internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform testPlatform, TestRunResultAggregator testRunResultAggregator, ITestPlatformEventSource testPlatformEventSource, InferHelper inferHelper, Task metricsPublisher, IProcessHelper processHelper)
{
this.testPlatform = testPlatform;
this.commandLineOptions = commandLineOptions;
@@ -81,6 +84,7 @@ internal TestRequestManager(CommandLineOptions commandLineOptions, ITestPlatform
this.testPlatformEventSource = testPlatformEventSource;
this.inferHelper = inferHelper;
this.metricsPublisher = metricsPublisher;
+ this.processHelper = processHelper;
}
#endregion
@@ -381,9 +385,15 @@ 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.
- var defaultArchitecture = chosenFramework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0
- || chosenFramework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0 ? Architecture.X64 : Architecture.X86;
+ // For .NET core, the default platform architecture should be based on the process.
+ // For a 64 bit process,
+ 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("dotnet", StringComparison.OrdinalIgnoreCase) && !Environment.Is64BitProcess) ? Architecture.X86: Architecture.X64;
+ }
settingsUpdated |= this.UpdatePlatform(document, navigator, sources, sourcePlatforms, defaultArchitecture, out Architecture chosenPlatform);
this.CheckSourcesForCompatibility(chosenFramework, chosenPlatform, sourcePlatforms, sourceFrameworks, registrar);
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,9 @@ public RunSpecificTestsArgumentProcessorTests()
this.mockMetricsPublisher = new Mock();
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]
@@ -105,7 +110,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 +121,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 +132,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 +143,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 +154,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 +165,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 +175,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 +193,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 +211,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 +229,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 +252,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 +277,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 +303,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 +324,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 +345,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 +372,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 +398,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 +425,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 +451,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 +478,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 +508,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 +537,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..2486b81164 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);
@@ -94,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]
@@ -115,7 +121,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 +203,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 +252,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 +299,8 @@ public void DiscoverTestsShouldCollectMetrics()
TestRunResultAggregator.Instance,
this.mockTestPlatformEventSource.Object,
this.inferHelper,
- this.mockMetricsPublisherTask);
+ this.mockMetricsPublisherTask,
+ this.mockProcessHelper.Object);
// Act
@@ -338,7 +348,8 @@ public void DiscoverTestsShouldCollectTargetDeviceLocalMachineIfTargetDeviceStri
TestRunResultAggregator.Instance,
this.mockTestPlatformEventSource.Object,
this.inferHelper,
- this.mockMetricsPublisherTask);
+ this.mockMetricsPublisherTask,
+ this.mockProcessHelper.Object);
// Act
@@ -380,7 +391,8 @@ public void DiscoverTestsShouldCollectTargetDeviceIfTargetDeviceIsDevice()
TestRunResultAggregator.Instance,
this.mockTestPlatformEventSource.Object,
this.inferHelper,
- this.mockMetricsPublisherTask);
+ this.mockMetricsPublisherTask,
+ this.mockProcessHelper.Object);
// Act
@@ -422,7 +434,8 @@ public void DiscoverTestsShouldCollectTargetDeviceIfTargetDeviceIsEmulator()
TestRunResultAggregator.Instance,
this.mockTestPlatformEventSource.Object,
this.inferHelper,
- this.mockMetricsPublisherTask);
+ this.mockMetricsPublisherTask,
+ this.mockProcessHelper.Object);
// Act
@@ -464,7 +477,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 +532,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 +579,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 +626,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 +948,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 +1015,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 +1064,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 +1111,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);
@@ -1137,7 +1158,8 @@ public void RunTestsWithSourcesShouldCallTestPlatformAndSucceed()
TestRunResultAggregator.Instance,
this.mockTestPlatformEventSource.Object,
this.inferHelper,
- this.mockMetricsPublisherTask);
+ this.mockMetricsPublisherTask,
+ this.mockProcessHelper.Object);
this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig);