diff --git a/TestPlatform.sln b/TestPlatform.sln index 0496fd0ded..0ff32b6a25 100644 --- a/TestPlatform.sln +++ b/TestPlatform.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26228.4 +VisualStudioVersion = 15.0.26326.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED0C35EB-7F31-4841-A24F-8EB708FFA959}" EndProject @@ -147,6 +147,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Platform", "Platform", "{37 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.CommunicationUtilities.PlatformTests", "test\Microsoft.TestPlatform.CommunicationUtilities.PlatformTests\Microsoft.TestPlatform.CommunicationUtilities.PlatformTests.csproj", "{3E698655-0701-482E-9AA7-F956F6337FC7}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.TestHostProvider", "src\Microsoft.TestPlatform.TestHostProvider\Microsoft.TestPlatform.TestHostProvider.csproj", "{F6624DEC-C1F7-4076-8488-93EE30C163C4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.TestHostProvider.UnitTests", "test\Microsoft.TestPlatform.TestHostProvider.UnitTests\Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj", "{FBF74C8F-695C-4967-84AC-358EEFB1376D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -757,6 +761,30 @@ Global {3E698655-0701-482E-9AA7-F956F6337FC7}.Release|x64.Build.0 = Release|Any CPU {3E698655-0701-482E-9AA7-F956F6337FC7}.Release|x86.ActiveCfg = Release|Any CPU {3E698655-0701-482E-9AA7-F956F6337FC7}.Release|x86.Build.0 = Release|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Debug|x64.ActiveCfg = Debug|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Debug|x64.Build.0 = Debug|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Debug|x86.ActiveCfg = Debug|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Debug|x86.Build.0 = Debug|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Release|Any CPU.Build.0 = Release|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Release|x64.ActiveCfg = Release|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Release|x64.Build.0 = Release|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Release|x86.ActiveCfg = Release|Any CPU + {F6624DEC-C1F7-4076-8488-93EE30C163C4}.Release|x86.Build.0 = Release|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Debug|x64.ActiveCfg = Debug|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Debug|x64.Build.0 = Debug|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Debug|x86.ActiveCfg = Debug|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Debug|x86.Build.0 = Debug|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Release|Any CPU.Build.0 = Release|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Release|x64.ActiveCfg = Release|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Release|x64.Build.0 = Release|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Release|x86.ActiveCfg = Release|Any CPU + {FBF74C8F-695C-4967-84AC-358EEFB1376D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -821,5 +849,7 @@ Global {E141A226-CC0A-4F26-BD17-4AE427D81C3B} = {D27E1CB4-C641-4C6C-A140-EF5F6215AE29} {376C19DE-31E2-4FF6-88FC-0D0D6233C999} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} {3E698655-0701-482E-9AA7-F956F6337FC7} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999} + {F6624DEC-C1F7-4076-8488-93EE30C163C4} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} + {FBF74C8F-695C-4967-84AC-358EEFB1376D} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} EndGlobalSection EndGlobal diff --git a/scripts/build.ps1 b/scripts/build.ps1 index b2de3308a1..94b4854fee 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -257,6 +257,16 @@ function Publish-Package Write-Verbose "Move-Item $coreCLR20PackageDir\$file $coreCLRExtensionsDir -Force" Move-Item $coreCLR20PackageDir\$file $coreCLRExtensionsDir -Force } + + # Note Note: If there are some dependencies for the TestHostProvider assemblies, those need to be moved too. + $runtimeproviders = @("Microsoft.TestPlatform.TestHostProvider.dll", "Microsoft.TestPlatform.TestHostProvider.pdb") + foreach($file in $runtimeproviders) { + Write-Verbose "Move-Item $fullCLRPackageDir\$file $fullCLRExtensionsDir -Force" + Move-Item $fullCLRPackageDir\$file $fullCLRExtensionsDir -Force + + Write-Verbose "Move-Item $coreCLR20PackageDir\$file $coreCLRExtensionsDir -Force" + Move-Item $coreCLR20PackageDir\$file $coreCLRExtensionsDir -Force + } # For libraries that are externally published, copy the output into artifacts. These will be signed and packaged independently. Copy-PackageItems "Microsoft.TestPlatform.Build" diff --git a/src/Microsoft.TestPlatform.Client/TestPlatform.cs b/src/Microsoft.TestPlatform.Client/TestPlatform.cs index 2f2d4f1552..98a6b80bc9 100644 --- a/src/Microsoft.TestPlatform.Client/TestPlatform.cs +++ b/src/Microsoft.TestPlatform.Client/TestPlatform.cs @@ -4,13 +4,14 @@ namespace Microsoft.VisualStudio.TestPlatform.Client { using System; - using System.IO; using System.Collections.Generic; + using System.IO; using System.Linq; using Microsoft.VisualStudio.TestPlatform.Client.Discovery; using Microsoft.VisualStudio.TestPlatform.Client.Execution; using Microsoft.VisualStudio.TestPlatform.Common; + using Microsoft.VisualStudio.TestPlatform.Common.Hosting; using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine; @@ -20,21 +21,21 @@ namespace Microsoft.VisualStudio.TestPlatform.Client using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; - using Microsoft.VisualStudio.TestPlatform.Common.Hosting; /// /// Implementation for TestPlatform /// public class TestPlatform : ITestPlatform { - private IFileHelper fileHelper; + private readonly TestRuntimeProviderManager testHostProviderManager; + + private readonly IFileHelper fileHelper; + /// /// Initializes a new instance of the class. /// - public TestPlatform() : this(new TestEngine(), new FileHelper()) + public TestPlatform() : this(new TestEngine(), new FileHelper(), TestRuntimeProviderManager.Instance) { - this.testHostProviderManager = TestRuntimeProviderManager.Instance; } /// @@ -43,10 +44,17 @@ public class TestPlatform : ITestPlatform /// /// The test engine. /// - protected TestPlatform(ITestEngine testEngine, IFileHelper filehelper) + /// + /// The filehelper. + /// + /// + /// The data. + /// + protected TestPlatform(ITestEngine testEngine, IFileHelper filehelper, TestRuntimeProviderManager testHostProviderManager) { this.TestEngine = testEngine; this.fileHelper = filehelper; + this.testHostProviderManager = testHostProviderManager; } /// @@ -54,8 +62,6 @@ protected TestPlatform(ITestEngine testEngine, IFileHelper filehelper) /// private ITestEngine TestEngine { get; set; } - private TestRuntimeProviderManager testHostProviderManager; - /// /// The create discovery request. /// @@ -66,16 +72,13 @@ public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCrite { if (discoveryCriteria == null) { - throw new ArgumentNullException("discoveryCriteria"); + throw new ArgumentNullException(nameof(discoveryCriteria)); } - UpdateTestAdapterPaths(discoveryCriteria.RunSettings); + this.UpdateTestAdapterPaths(discoveryCriteria.RunSettings); - var runconfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(discoveryCriteria.RunSettings); - //var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(runconfiguration); + var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings); - var testHostManager = this.TestEngine.GetDefaultTestHostManager(runconfiguration); - var discoveryManager = this.TestEngine.GetDiscoveryManager(testHostManager, discoveryCriteria); discoveryManager.Initialize(); @@ -92,26 +95,24 @@ public ITestRunRequest CreateTestRunRequest(TestRunCriteria testRunCriteria) { if (testRunCriteria == null) { - throw new ArgumentNullException("testRunCriteria"); + throw new ArgumentNullException(nameof(testRunCriteria)); } - UpdateTestAdapterPaths(testRunCriteria.TestRunSettings); + this.UpdateTestAdapterPaths(testRunCriteria.TestRunSettings); var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings); - //var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(runConfiguration); - // Update and initialize loggers only when DesignMode is false if (runConfiguration.DesignMode == false) { - UpdateTestLoggerPath(testRunCriteria); + this.UpdateTestLoggerPath(testRunCriteria); // Initialize loggers TestLoggerManager.Instance.InitializeLoggers(); } - var testHostManager = this.TestEngine.GetDefaultTestHostManager(runConfiguration); - testHostManager.Initialize(TestSessionMessageLogger.Instance); + var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(testRunCriteria.TestRunSettings); + testHostManager.Initialize(TestSessionMessageLogger.Instance, testRunCriteria.TestRunSettings); if (testRunCriteria.TestHostLauncher != null) { @@ -159,6 +160,9 @@ public void UpdateExtensions(IEnumerable pathToAdditionalExtensions, boo /// /// Update the test adapter paths provided through run settings to be used by the test service /// + /// + /// The run Settings. + /// private void UpdateTestAdapterPaths(string runSettings) { IEnumerable customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(runSettings); @@ -175,8 +179,10 @@ private void UpdateTestAdapterPaths(string runSettings) } List adapterFiles = new List( - this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.TestAdapterRegexPattern, SearchOption.AllDirectories) - ); + this.fileHelper.EnumerateFiles( + adapterPath, + TestPlatformConstants.TestAdapterRegexPattern, + SearchOption.AllDirectories)); if (adapterFiles.Count > 0) { this.UpdateExtensions(adapterFiles, true); @@ -188,6 +194,9 @@ private void UpdateTestAdapterPaths(string runSettings) /// /// Update the test logger paths from source directory /// + /// + /// The test Run Criteria. + /// private void UpdateTestLoggerPath(TestRunCriteria testRunCriteria) { IEnumerable sources = testRunCriteria.Sources; diff --git a/src/Microsoft.TestPlatform.Common/Friends.cs b/src/Microsoft.TestPlatform.Common/Friends.cs index 7cb1d1036d..1655273bda 100644 --- a/src/Microsoft.TestPlatform.Common/Friends.cs +++ b/src/Microsoft.TestPlatform.Common/Friends.cs @@ -21,6 +21,6 @@ [assembly: InternalsVisibleTo("datacollector.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] [assembly: InternalsVisibleTo("Microsoft.TestPlatform.CommunicationUtilities.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] - +[assembly: InternalsVisibleTo("Microsoft.TestPlatform.Client.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] #endregion \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Hosting/TestRunTimeExtensionManager.cs b/src/Microsoft.TestPlatform.Common/Hosting/TestRunTimeExtensionManager.cs index 0becb1f58c..f2089686a8 100644 --- a/src/Microsoft.TestPlatform.Common/Hosting/TestRunTimeExtensionManager.cs +++ b/src/Microsoft.TestPlatform.Common/Hosting/TestRunTimeExtensionManager.cs @@ -3,12 +3,13 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Hosting { + using System.Collections.Generic; + using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework; using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities; using Microsoft.VisualStudio.TestPlatform.Common.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; - using System.Collections.Generic; /// /// Manages loading and provides access to testhost extensions implementing the @@ -17,6 +18,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Hosting internal class TestRuntimeExtensionManager : TestExtensionManager { /// + /// Initializes a new instance of the class. /// Default constructor. /// /// @@ -60,5 +62,4 @@ public static TestRuntimeExtensionManager Create(IMessageLogger messageLogger) return new TestRuntimeExtensionManager(unfilteredTestExtensions, filteredTestExtensions, messageLogger); } } - } diff --git a/src/Microsoft.TestPlatform.Common/Hosting/TestRunTimeProviderManager.cs b/src/Microsoft.TestPlatform.Common/Hosting/TestRunTimeProviderManager.cs index 50b02be604..0e9f670a5f 100644 --- a/src/Microsoft.TestPlatform.Common/Hosting/TestRunTimeProviderManager.cs +++ b/src/Microsoft.TestPlatform.Common/Hosting/TestRunTimeProviderManager.cs @@ -4,59 +4,43 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Hosting { using System; + + using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; - using Microsoft.VisualStudio.TestPlatform.Common.Logging; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; /// /// Responsible for managing TestRuntimeProviderManager extensions /// - internal class TestRuntimeProviderManager + public class TestRuntimeProviderManager { #region Fields private static TestRuntimeProviderManager testHostManager; - /// - /// Gets an instance of the logger. - /// - private IMessageLogger messageLogger; + private readonly TestRuntimeExtensionManager testHostExtensionManager; - private TestRuntimeExtensionManager testHostExtensionManager; - #endregion #region Constructor /// + /// Initializes a new instance of the class. /// Default constructor. /// - protected TestRuntimeProviderManager(TestSessionMessageLogger sessionLogger) + /// + /// The session Logger. + /// + protected TestRuntimeProviderManager(IMessageLogger sessionLogger) { - this.messageLogger = sessionLogger; this.testHostExtensionManager = TestRuntimeExtensionManager.Create(sessionLogger); } /// - /// Gets the instance. + /// Gets the instance of TestRuntimeProviderManager /// - public static TestRuntimeProviderManager Instance - { - get - { - if (testHostManager == null) - { - testHostManager = new TestRuntimeProviderManager(TestSessionMessageLogger.Instance); - } - return testHostManager; - } - - protected set - { - testHostManager = value; - } - } + public static TestRuntimeProviderManager Instance => testHostManager + ?? (testHostManager = new TestRuntimeProviderManager(TestSessionMessageLogger.Instance)); #endregion @@ -65,21 +49,17 @@ protected set public ITestRuntimeProvider GetTestHostManagerByUri(string hostUri) { var host = this.testHostExtensionManager.TryGetTestExtension(hostUri); - if (host != null) - { - return host.Value; - } - - return null; + return host?.Value; } - public ITestRuntimeProvider GetTestHostManagerByRunConfiguration(string runConfiguration) + public virtual ITestRuntimeProvider GetTestHostManagerByRunConfiguration(string runConfiguration) { foreach (var testExtension in this.testHostExtensionManager.TestExtensions) { if (testExtension.Value.CanExecuteCurrentRunConfiguration(runConfiguration)) { - return testExtension.Value; + // we are creating a new Instance of ITestRuntimeProvider so that each POM gets it's own object of ITestRuntimeProvider + return (ITestRuntimeProvider)Activator.CreateInstance(testExtension.Value.GetType()); } } diff --git a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/ClientProtocol/ITestEngine.cs b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/ClientProtocol/ITestEngine.cs index e429dcdedf..c1c68701cf 100644 --- a/src/Microsoft.TestPlatform.Common/Interfaces/Engine/ClientProtocol/ITestEngine.cs +++ b/src/Microsoft.TestPlatform.Common/Interfaces/Engine/ClientProtocol/ITestEngine.cs @@ -14,8 +14,15 @@ public interface ITestEngine /// /// Fetches the DiscoveryManager for this engine. This manager would provide all functionality required for discovery. /// - /// Test host manager for the current test discovery. - /// ITestDiscoveryManager object that can do discovery + /// + /// Test host manager for the current test discovery. + /// + /// + /// The discovery Criteria. + /// + /// + /// ITestDiscoveryManager object that can do discovery + /// IProxyDiscoveryManager GetDiscoveryManager(ITestRuntimeProvider testHostManager, DiscoveryCriteria discoveryCriteria); /// @@ -32,13 +39,5 @@ public interface ITestEngine /// /// ITestExtensionManager object that helps with extensibility ITestExtensionManager GetExtensionManager(); - - /// - /// Fetches the Test Host manager for this engine. This manager would provide extensibility - /// features that this engine supports. - /// - /// RunConfiguration information which contains info like Architecture, Framework for the test run. - /// Launcher for the test host process - ITestRuntimeProvider GetDefaultTestHostManager(RunConfiguration runConfiguration); } } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/DotnetHostHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs similarity index 91% rename from src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/DotnetHostHelper.cs rename to src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs index a16828ba8e..4bf0dfdd16 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/DotnetHostHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs @@ -3,16 +3,17 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers { - using Microsoft.VisualStudio.TestPlatform.ObjectModel; using System; using System.IO; using System.Runtime.InteropServices; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Resources; - using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; - using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; + + using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Resources; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; + using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; - internal class DotnetHostHelper : IDotnetHostHelper + public class DotnetHostHelper : IDotnetHostHelper { private readonly IFileHelper fileHelper; @@ -58,7 +59,8 @@ public string GetDotnetHostFullPath() } } - string errorMessage = String.Format(Resources.NoDotnetExeFound, dotnetExeName); + string errorMessage = string.Format(Resources.NoDotnetExeFound, dotnetExeName); + EqtTrace.Error(errorMessage); throw new FileNotFoundException(errorMessage); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/Interfaces/IDotnetHostHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs similarity index 94% rename from src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/Interfaces/IDotnetHostHelper.cs rename to src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs index b70dfb9c7c..05cb904c39 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/Interfaces/IDotnetHostHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IDotnetHostHelper.cs @@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces /// /// Helper class for getting info about dotnet host. /// - internal interface IDotnetHostHelper + public interface IDotnetHostHelper { /// /// Get full path for the .net host diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.Designer.cs index ffb72db0f4..6a615e84d7 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.Designer.cs @@ -195,5 +195,16 @@ internal static string Utility_ProcessNameWhenCannotGetIt { return ResourceManager.GetString("Utility_ProcessNameWhenCannotGetIt", resourceCulture); } } + + /// + /// Looks up a localized string similar to Could not find {0}. Make sure that the dotnet is installed on the machine.. + /// + internal static string NoDotnetExeFound + { + get + { + return ResourceManager.GetString("NoDotnetExeFound", resourceCulture); + } + } } } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.resx b/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.resx index 9b872db0c2..a57060159f 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/Resources.resx @@ -153,6 +153,9 @@ Unhandled exception occurred while processing a job from the '{0}' queue: {1} + + Could not find {0}. Make sure that the dotnet is installed on the machine. + The {0} queue has already been disposed. diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.cs.xlf index 19b6a0cd9f..d8e4728fd5 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.cs.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.de.xlf index 4534555131..d05cb072e4 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.de.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.es.xlf index f1e914b128..945121b586 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.es.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.fr.xlf index 8d1405df4b..4c9c0f1caf 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.fr.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.it.xlf index 7edebd682b..38cebd789c 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.it.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ja.xlf index 2333bcb162..106111a4a1 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ja.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ko.xlf index 5f576717a7..cc9b267cdb 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ko.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pl.xlf index 0202bd5264..a445e3188e 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pl.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pt-BR.xlf index 3503935815..d99c1dc56c 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.pt-BR.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ru.xlf index 4b509377bf..be5b878810 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.ru.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.tr.xlf index 850b4b1262..6023b77960 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.tr.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.xlf index 2e67511ef2..0c91d32024 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.xlf @@ -62,6 +62,11 @@ Error getting process name. + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hans.xlf index e19c80f4da..6648642650 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hans.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hant.xlf index 9df876ea10..2ff6ccaaf3 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.CoreUtilities/Resources/xlf/Resources.zh-Hant.xlf @@ -155,6 +155,11 @@ fuzzyMatch="15" wordcount="4" adjWordcount="3.4" curWordcount="3.4" + + Could not find {0}. Make sure that the dotnet is installed on the machine. + Could not find {0}. Make sure that the dotnet is installed on the machine. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index f323a470a9..962bc6e432 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -11,10 +11,10 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities; using CrossPlatEngineResources = Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Resources.Resources; diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionLauncherFactory.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionLauncherFactory.cs index 6f3d4d3aba..8e5688e8dd 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionLauncherFactory.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionLauncherFactory.cs @@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection using System; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; /// /// Factory for creating DataCollectionLauncher diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DefaultDataCollectionLauncher.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DefaultDataCollectionLauncher.cs index 31b7d15d31..452e9c33b2 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DefaultDataCollectionLauncher.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DefaultDataCollectionLauncher.cs @@ -10,8 +10,8 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection using System.Reflection; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; /// /// The datacollection launcher. @@ -66,8 +66,8 @@ public virtual int LaunchDataCollector(IDictionary environmentVa var argumentsString = string.Join(" ", commandLineArguments); - this.DataCollectorProcess = this.processHelper.LaunchProcess(dataCollectorProcessPath, argumentsString, processWorkingDirectory, environmentVariables, null, null); - return this.DataCollectorProcess.Id; + this.DataCollectorProcess = this.processHelper.LaunchProcess(dataCollectorProcessPath, argumentsString, processWorkingDirectory, environmentVariables, null, null) as Process; + return this.DataCollectorProcess?.Id ?? 0; } } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DotnetDataCollectionLauncher.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DotnetDataCollectionLauncher.cs index 7ffd356b72..62899babdf 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DotnetDataCollectionLauncher.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DotnetDataCollectionLauncher.cs @@ -3,18 +3,17 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection { - using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; - using System.Runtime.InteropServices; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Resources; using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; @@ -129,8 +128,8 @@ public virtual int LaunchDataCollector(IDictionary environmentVa var cliArgs = string.Join(" ", commandLineArguments); var argumentsString = string.Format("{0} {1} {2} ", args, dataCollectorAssemblyPath, cliArgs); - this.DataCollectorProcess = this.processHelper.LaunchProcess(currentProcessFileName, argumentsString, currentWorkingDirectory, environmentVariables, null, null); - return this.DataCollectorProcess.Id; + this.DataCollectorProcess = this.processHelper.LaunchProcess(currentProcessFileName, argumentsString, currentWorkingDirectory, environmentVariables, null, null) as Process; + return this.DataCollectorProcess != null ? this.DataCollectorProcess.Id : 0; } } } \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs index 85be2daf5d..c9fcd5f6f0 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs @@ -12,10 +12,10 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities; using CrossPlatEngineResources = Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Resources.Resources; diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs index 3ae1c613f2..bfdddaf498 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs @@ -6,12 +6,12 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine using System; using System.Linq; + using Microsoft.VisualStudio.TestPlatform.Common.Hosting; using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; @@ -25,10 +25,20 @@ public class TestEngine : ITestEngine { #region Private Fields + private readonly TestRuntimeProviderManager testHostProviderManager; private ITestExtensionManager testExtensionManager; #endregion + public TestEngine() : this(TestRuntimeProviderManager.Instance) + { + } + + protected TestEngine(TestRuntimeProviderManager testHostProviderManager) + { + this.testHostProviderManager = testHostProviderManager; + } + #region ITestEngine implementation /// @@ -49,12 +59,12 @@ public IProxyDiscoveryManager GetDiscoveryManager(ITestRuntimeProvider testHostM Func proxyDiscoveryManagerCreator = delegate { - // Create a new HostProvider, to be associated with individual ProxyDiscoveryManager(&POM) - var hostManager = this.GetDefaultTestHostManager(XmlRunSettingsUtilities.GetRunConfigurationNode(discoveryCriteria.RunSettings)); - hostManager.Initialize(TestSessionMessageLogger.Instance); + var hostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings); + hostManager?.Initialize(TestSessionMessageLogger.Instance, discoveryCriteria.RunSettings); return new ProxyDiscoveryManager(hostManager); }; + return !testHostManager.Shared ? new ParallelProxyDiscoveryManager(proxyDiscoveryManagerCreator, parallelLevel, sharedHosts: testHostManager.Shared) : proxyDiscoveryManagerCreator(); } @@ -77,8 +87,8 @@ public IProxyExecutionManager GetExecutionManager(ITestRuntimeProvider testHostM Func proxyExecutionManagerCreator = delegate { // Create a new HostManager, to be associated with individual ProxyExecutionManager(&POM) - var hostManager = this.GetDefaultTestHostManager(XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings)); - hostManager.Initialize(TestSessionMessageLogger.Instance); + var hostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(testRunCriteria.TestRunSettings); + hostManager?.Initialize(TestSessionMessageLogger.Instance, testRunCriteria.TestRunSettings); if (testRunCriteria.TestHostLauncher != null) { @@ -109,31 +119,6 @@ public ITestExtensionManager GetExtensionManager() return this.testExtensionManager ?? (this.testExtensionManager = new TestExtensionManager()); } - /// - /// Retrieves the default test host manager for this engine. - /// - /// - /// The run Configuration. - /// - /// - /// An instance of the test host manager. - /// - public ITestRuntimeProvider GetDefaultTestHostManager(RunConfiguration runConfiguration) - { - var framework = runConfiguration.TargetFrameworkVersion; - - // This is expected to be called once every run so returning a new instance every time. - if (framework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0 - || framework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0) - { - return new DotnetTestHostManager(); - } - - // Only share the manager if DisableAppDomain is "false" - // meaning AppDomain is enabled and we can reuse the host for multiple sources - return new DefaultTestHostManager(runConfiguration.TargetPlatform, framework, shared: !runConfiguration.DisableAppDomain); - } - #endregion private static int GetDistinctNumberOfSources(TestRunCriteria testRunCriteria) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/TestExtensionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/TestExtensionManager.cs index a381b2970e..9b0022cb27 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/TestExtensionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/TestExtensionManager.cs @@ -6,9 +6,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine using System.Collections.Generic; using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; /// diff --git a/src/Microsoft.TestPlatform.ObjectModel/Host/ITestRunTimeProvider.cs b/src/Microsoft.TestPlatform.ObjectModel/Host/ITestRunTimeProvider.cs index 3382572a8f..c018109090 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Host/ITestRunTimeProvider.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Host/ITestRunTimeProvider.cs @@ -39,19 +39,20 @@ public interface ITestRuntimeProvider /// Sets a Message Logger /// /// provide logger to runtimes - void Initialize(IMessageLogger logger); + /// provide runsettings to runtimes for initialization + void Initialize(IMessageLogger logger, string runsettingsXml); /// /// Gets a value indicating whether the test host is specific to a test source. If yes, each test source /// is launched in a separate host process. /// - /// + /// /// The run Configuration. /// /// /// The . /// - bool CanExecuteCurrentRunConfiguration(string runConfiguration); + bool CanExecuteCurrentRunConfiguration(string runsettingsXml); /// /// Sets a custom launcher diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/Interfaces/IProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/Process/IProcessHelper.cs similarity index 84% rename from src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/Interfaces/IProcessHelper.cs rename to src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/Process/IProcessHelper.cs index f6d9857b10..4f1a95476b 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/Interfaces/IProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/Process/IProcessHelper.cs @@ -1,17 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces +namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces { using System; using System.Collections.Generic; - using System.Diagnostics; - using System.Threading.Tasks; /// /// Interface for any process related functionality. This is needed for clean unit-testing. /// - internal interface IProcessHelper + public interface IProcessHelper { /// /// Launches the process with the given arguments. @@ -23,7 +21,7 @@ internal interface IProcessHelper /// Call back for to read error stream data /// Call back for on process exit /// The process created. - Process LaunchProcess(string processPath, string arguments, string workingDirectory, IDictionary environmentVariables, Action errorCallback, Action exitCallBack); + object LaunchProcess(string processPath, string arguments, string workingDirectory, IDictionary environmentVariables, Action errorCallback, Action exitCallBack); /// /// Gets the current process file path. @@ -56,7 +54,7 @@ internal interface IProcessHelper /// process parameter /// return value of exitCode /// False if process has not exited, True otherwise - bool TryGetExitCode(Process process, out int exitCode); + bool TryGetExitCode(object process, out int exitCode); /// /// The wait for parent process exit async. diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/common/Process/ProcessHelper.cs similarity index 69% rename from src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/ProcessHelper.cs rename to src/Microsoft.TestPlatform.PlatformAbstractions/common/Process/ProcessHelper.cs index 18fb400c42..57e2e9b15f 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Helpers/ProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/common/Process/ProcessHelper.cs @@ -1,26 +1,23 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers +namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions { using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; - using System.Threading; - using System.Threading.Tasks; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; /// /// Helper class to deal with process related functionality. /// - internal class ProcessHelper : IProcessHelper + public class ProcessHelper : IProcessHelper { /// - public Process LaunchProcess(string processPath, string arguments, string workingDirectory, IDictionary envVariables, Action errorCallback, Action exitCallBack) + public object LaunchProcess(string processPath, string arguments, string workingDirectory, IDictionary envVariables, Action errorCallback, Action exitCallBack) { var process = new Process(); try @@ -50,15 +47,15 @@ public Process LaunchProcess(string processPath, string arguments, string workin if (exitCallBack != null) { process.Exited += (sender, args) => - { - // Call WaitForExit again to ensure all streams are flushed - var p = sender as Process; - p.WaitForExit(); - exitCallBack(p); - }; + { + // Call WaitForExit again to ensure all streams are flushed + var p = sender as Process; + p.WaitForExit(); + exitCallBack(p); + }; } - EqtTrace.Verbose("ProcessHelper: Starting process '{0}' with command line '{1}'", processPath, arguments); + // EqtTrace.Verbose("ProcessHelper: Starting process '{0}' with command line '{1}'", processPath, arguments); process.Start(); if (errorCallback != null) @@ -66,17 +63,17 @@ public Process LaunchProcess(string processPath, string arguments, string workin process.BeginErrorReadLine(); } } - catch (Exception exception) + catch (Exception) { process.Dispose(); process = null; - EqtTrace.Error("TestHost Process {0} failed to launch with the following exception: {1}", processPath, exception.Message); + // EqtTrace.Error("TestHost Object {0} failed to launch with the following exception: {1}", processPath, exception.Message); throw; } - return process; + return process as object; } /// @@ -104,11 +101,12 @@ public string GetProcessName(int processId) } /// - public bool TryGetExitCode(Process process, out int exitCode) + public bool TryGetExitCode(object process, out int exitCode) { - if (process.HasExited) + var proc = process as Process; + if (proc != null && proc.HasExited) { - exitCode = process.ExitCode; + exitCode = proc.ExitCode; return true; } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/Process/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/Process/ProcessHelper.cs new file mode 100644 index 0000000000..5b39e4ff66 --- /dev/null +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/Process/ProcessHelper.cs @@ -0,0 +1,64 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions +{ + using System; + using System.Collections.Generic; + + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; + + /// + /// Helper class to deal with process related functionality. + /// + public class ProcessHelper : IProcessHelper + { + /// + public object LaunchProcess( + string processPath, + string arguments, + string workingDirectory, + IDictionary environmentVariables, + Action errorCallback, + Action exitCallBack) + { + throw new NotImplementedException(); + } + + /// + public string GetCurrentProcessFileName() + { + throw new NotImplementedException(); + } + + /// + public string GetTestEngineDirectory() + { + throw new NotImplementedException(); + } + + /// + public int GetCurrentProcessId() + { + throw new NotImplementedException(); + } + + /// + public string GetProcessName(int processId) + { + throw new NotImplementedException(); + } + + /// + public bool TryGetExitCode(object process, out int exitCode) + { + throw new NotImplementedException(); + } + + /// + public void SetExitCallback(int parentProcessId, Action callbackAction) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Friends.cs b/src/Microsoft.TestPlatform.TestHostProvider/Friends.cs new file mode 100644 index 0000000000..a52ba53674 --- /dev/null +++ b/src/Microsoft.TestPlatform.TestHostProvider/Friends.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CrossPlatEngine.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CrossPlatEngine, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("vstest.console.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("datacollector, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.DataCollector.PlatformTests, PublicKey = 002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("Microsoft.TestPlatform.TestHostProvider.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs similarity index 79% rename from src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DefaultTestHostManager.cs rename to src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index 4bbab1f86b..9675e2ad17 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -13,27 +13,32 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting using System.Threading; using System.Threading.Tasks; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities; /// /// The default test host launcher for the engine. /// This works for Desktop local scenarios /// + [ExtensionUri(DefaultTestHostUri)] + [FriendlyName(DefaultTestHostFriendltName)] public class DefaultTestHostManager : ITestRuntimeProvider { private const string X64TestHostProcessName = "testhost.exe"; private const string X86TestHostProcessName = "testhost.x86.exe"; - private readonly Architecture architecture; - private readonly Framework framework; - private readonly IProcessHelper processHelper; + private const string DefaultTestHostUri = "HostProvider://DefaultTestHost"; + private const string DefaultTestHostFriendltName = "DefaultTestHost"; + + private Architecture architecture; + + private IProcessHelper processHelper; private ITestHostLauncher customTestHostLauncher; private Process testHostProcess; @@ -45,11 +50,7 @@ public class DefaultTestHostManager : ITestRuntimeProvider /// /// Initializes a new instance of the class. /// - /// Platform architecture of the host process. - /// Runtime framework for the host process. - /// can host process be shared for multiple sources. - public DefaultTestHostManager(Architecture architecture, Framework framework, bool shared) - : this(architecture, framework, new ProcessHelper(), shared) + public DefaultTestHostManager() { } @@ -63,7 +64,6 @@ public DefaultTestHostManager(Architecture architecture, Framework framework, bo internal DefaultTestHostManager(Architecture architecture, Framework framework, IProcessHelper processHelper, bool shared) { this.architecture = architecture; - this.framework = framework; this.processHelper = processHelper; this.testHostProcess = null; @@ -71,8 +71,10 @@ internal DefaultTestHostManager(Architecture architecture, Framework framework, this.hostExitedEventRaised = false; } + /// public event EventHandler HostLaunched; + /// public event EventHandler HostExited; /// @@ -83,25 +85,31 @@ internal DefaultTestHostManager(Architecture architecture, Framework framework, /// public IDictionary Properties => new Dictionary(); + /// + /// Gets or sets the error length for runtime error stream. + /// protected int ErrorLength { get; set; } = 1000; + /// + /// Gets or sets the Timeout for runtime to initialize. + /// protected int TimeOut { get; set; } = 10000; /// - /// Callback on process exit + /// Gets callback on process exit /// - private Action ExitCallBack => ((process) => + private Action ExitCallBack => (process) => { var exitCode = 0; this.processHelper.TryGetExitCode(process, out exitCode); - this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, process.Id)); - }); + this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, (process as Process).Id)); + }; /// - /// Callback to read from process error stream + /// Gets callback to read from process error stream /// - private Action ErrorReceivedCallback => ((process, data) => + private Action ErrorReceivedCallback => (process, data) => { var exitCode = 0; if (!string.IsNullOrEmpty(data)) @@ -129,10 +137,9 @@ internal DefaultTestHostManager(Architecture architecture, Framework framework, if (this.processHelper.TryGetExitCode(process, out exitCode)) { EqtTrace.Error("Test host exited with error: {0}", this.testHostProcessStdError); - this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, process.Id)); + this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, (process as Process).Id)); } - }); - + }; /// public void SetCustomLauncher(ITestHostLauncher customLauncher) @@ -154,7 +161,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( { // Default test host manager supports shared test sources var testHostProcessName = (this.architecture == Architecture.X86) ? X86TestHostProcessName : X64TestHostProcessName; - var currentWorkingDirectory = Path.GetDirectoryName(typeof(DefaultTestHostManager).GetTypeInfo().Assembly.Location); + var currentWorkingDirectory = Path.Combine(Path.GetDirectoryName(typeof(DefaultTestHostManager).GetTypeInfo().Assembly.Location), "..//"); var argumentsString = " " + connectionInfo.ToCommandLineOptions(); var currentProcessPath = this.processHelper.GetCurrentProcessFileName(); @@ -198,9 +205,10 @@ public IEnumerable GetTestPlatformExtensions(IEnumerable sources return Enumerable.Empty(); } - public bool CanExecuteCurrentRunConfiguration(string runConfiguration) + /// + public bool CanExecuteCurrentRunConfiguration(string runsettingsXml) { - RunConfiguration config = XmlRunSettingsUtilities.GetRunConfigurationNode(runConfiguration); + var config = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml); var framework = config.TargetFrameworkVersion; // This is expected to be called once every run so returning a new instance every time. @@ -213,26 +221,42 @@ public bool CanExecuteCurrentRunConfiguration(string runConfiguration) return true; } + /// + /// Raises HostLaunched event + /// + /// hostprovider event args public void OnHostLaunched(HostProviderEventArgs e) { this.HostLaunched.SafeInvoke(this, e, "HostProviderEvents.OnHostLaunched"); } + /// + /// Raises HostExited event + /// + /// hostprovider event args public void OnHostExited(HostProviderEventArgs e) { if (!this.hostExitedEventRaised) { this.hostExitedEventRaised = true; this.HostExited.SafeInvoke(this, e, "HostProviderEvents.OnHostError"); - } + } } - public void Initialize(IMessageLogger logger) + /// + public void Initialize(IMessageLogger logger, string runsettingsXml) { + var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml); + this.messageLogger = logger; + this.architecture = runConfiguration.TargetPlatform; + this.processHelper = new ProcessHelper(); + this.testHostProcess = null; + + this.Shared = !runConfiguration.DisableAppDomain; + this.hostExitedEventRaised = false; } - /// private CancellationTokenSource GetCancellationTokenSource() { this.hostLaunchCts = new CancellationTokenSource(this.TimeOut); @@ -248,7 +272,8 @@ private int LaunchHost(TestProcessStartInfo testHostStartInfo) if (this.customTestHostLauncher == null) { - this.testHostProcess = this.processHelper.LaunchProcess(testHostStartInfo.FileName, testHostStartInfo.Arguments, testHostStartInfo.WorkingDirectory, testHostStartInfo.EnvironmentVariables, this.ErrorReceivedCallback, this.ExitCallBack); + EqtTrace.Verbose("DefaultTestHostManager: Starting process '{0}' with command line '{1}'", testHostStartInfo.FileName, testHostStartInfo.Arguments); + this.testHostProcess = this.processHelper.LaunchProcess(testHostStartInfo.FileName, testHostStartInfo.Arguments, testHostStartInfo.WorkingDirectory, testHostStartInfo.EnvironmentVariables, this.ErrorReceivedCallback, this.ExitCallBack) as Process; } else { @@ -262,8 +287,9 @@ private int LaunchHost(TestProcessStartInfo testHostStartInfo) return -1; } - this.OnHostLaunched(new HostProviderEventArgs("Test Runtime launched with Pid: " + this.testHostProcess.Id)); - return this.testHostProcess.Id; + var pId = this.testHostProcess != null ? this.testHostProcess.Id : 0; + this.OnHostLaunched(new HostProviderEventArgs("Test Runtime launched with Pid: " + pId)); + return pId; } } } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs similarity index 86% rename from src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs rename to src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 934cf4210d..fa828deb96 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -16,12 +16,13 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Resources; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; @@ -36,13 +37,18 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting /// Note that some functionality of this entity overlaps with that of . That is /// intentional since we want to move this to a separate assembly (with some runtime extensibility discovery). /// + [ExtensionUri(DotnetTestHostUri)] + [FriendlyName(DotnetTestHostFriendltName)] public class DotnetTestHostManager : ITestRuntimeProvider { - private readonly IDotnetHostHelper dotnetHostHelper; + private const string DotnetTestHostUri = "HostProvider://DotnetTestHost"; + private const string DotnetTestHostFriendltName = "DotnetTestHost"; - private readonly IProcessHelper processHelper; + private IDotnetHostHelper dotnetHostHelper; - private readonly IFileHelper fileHelper; + private IProcessHelper processHelper; + + private IFileHelper fileHelper; private ITestHostLauncher testHostLauncher; @@ -69,7 +75,7 @@ public DotnetTestHostManager() /// /// Process helper instance. /// File helper instance. - /// File helper instance. + /// DotnetHostHelper helper instance. internal DotnetTestHostManager( IProcessHelper processHelper, IFileHelper fileHelper, @@ -81,12 +87,14 @@ internal DotnetTestHostManager( this.hostExitedEventRaised = false; } + /// public event EventHandler HostLaunched; + /// public event EventHandler HostExited; /// - /// Gets a value indicating if the test host can be shared for multiple sources. + /// Gets a value indicating whether gets a value indicating if the test host can be shared for multiple sources. /// /// /// Dependency resolution for .net core projects are pivoted by the test project. Hence each test @@ -94,25 +102,31 @@ internal DotnetTestHostManager( /// public bool Shared => false; + /// + /// Gets or sets the error length for runtime error stream. + /// protected int ErrorLength { get; set; } = 1000; + /// + /// Gets or sets the Timeout for runtime to initialize. + /// protected int TimeOut { get; set; } = 10000; /// - /// Callback on process exit + /// Gets callback on process exit /// - private Action ExitCallBack => ((process) => + private Action ExitCallBack => (process) => { var exitCode = 0; this.processHelper.TryGetExitCode(process, out exitCode); - this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, process.Id)); - }); + this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, (process as Process).Id)); + }; /// - /// Callback to read from process error stream + /// Gets callback to read from process error stream /// - private Action ErrorReceivedCallback => (process, data) => + private Action ErrorReceivedCallback => (process, data) => { var exitCode = 0; if (!string.IsNullOrEmpty(data)) @@ -140,14 +154,18 @@ internal DotnetTestHostManager( if (this.processHelper.TryGetExitCode(process, out exitCode)) { EqtTrace.Error("Test host exited with error: {0}", this.testHostProcessStdError); - this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, process.Id)); + this.OnHostExited(new HostProviderEventArgs(this.testHostProcessStdError.ToString(), exitCode, (process as Process).Id)); } }; /// - public void Initialize(IMessageLogger logger) + public void Initialize(IMessageLogger logger, string runsettingsXml) { this.messageLogger = logger; + this.processHelper = new ProcessHelper(); + this.fileHelper = new FileHelper(); + this.dotnetHostHelper = new DotnetHostHelper(); + this.hostExitedEventRaised = false; } /// @@ -156,6 +174,7 @@ public void SetCustomLauncher(ITestHostLauncher customLauncher) this.testHostLauncher = customLauncher; } + /// public async Task LaunchTestHostAsync(TestProcessStartInfo testHostStartInfo) { return await Task.Run(() => this.LaunchHost(testHostStartInfo), this.GetCancellationTokenSource().Token); @@ -228,7 +247,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( } else { - string message = string.Format(Resources.NoTestHostFileExist, sourcePath); + string message = string.Format(sourcePath); EqtTrace.Verbose("DotnetTestHostmanager: " + message); throw new FileNotFoundException(message); } @@ -241,7 +260,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( // "D:\dd\gh\Microsoft\vstest\tools\dotnet\dotnet.exe" exec // --runtimeconfig G:\tmp\netcore-test\bin\Debug\netcoreapp1.0\netcore-test.runtimeconfig.json // --depsfile G:\tmp\netcore-test\bin\Debug\netcoreapp1.0\netcore-test.deps.json - // --additionalprobingpath C:\Users\username\.nuget\packages\ + // --additionalprobingpath C:\Users\username\.nuget\packages\ // G:\nuget-package-path\microsoft.testplatform.testhost\version\**\testhost.dll // G:\tmp\netcore-test\bin\Debug\netcoreapp1.0\netcore-test.dll startInfo.Arguments = args; @@ -264,9 +283,10 @@ public IEnumerable GetTestPlatformExtensions(IEnumerable sources return Enumerable.Empty(); } - public bool CanExecuteCurrentRunConfiguration(string runConfiguration) + /// + public bool CanExecuteCurrentRunConfiguration(string runsettingsXml) { - RunConfiguration config = XmlRunSettingsUtilities.GetRunConfigurationNode(runConfiguration); + var config = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml); var framework = config.TargetFrameworkVersion; // This is expected to be called once every run so returning a new instance every time. @@ -279,11 +299,19 @@ public bool CanExecuteCurrentRunConfiguration(string runConfiguration) return false; } + /// + /// Raises HostLaunched event + /// + /// hostprovider event args public void OnHostLaunched(HostProviderEventArgs e) { this.HostLaunched.SafeInvoke(this, e, "HostProviderEvents.OnHostLaunched"); } + /// + /// Raises HostExited event + /// + /// hostprovider event args public void OnHostExited(HostProviderEventArgs e) { if (!this.hostExitedEventRaised) @@ -293,13 +321,13 @@ public void OnHostExited(HostProviderEventArgs e) } } - /// private int LaunchHost(TestProcessStartInfo testHostStartInfo) { this.testHostProcessStdError = new StringBuilder(this.ErrorLength, this.ErrorLength); if (this.testHostLauncher == null) { - this.testHostProcess = this.processHelper.LaunchProcess(testHostStartInfo.FileName, testHostStartInfo.Arguments, testHostStartInfo.WorkingDirectory, testHostStartInfo.EnvironmentVariables, this.ErrorReceivedCallback, this.ExitCallBack); + EqtTrace.Verbose("DotnetTestHostManager: Starting process '{0}' with command line '{1}'", testHostStartInfo.FileName, testHostStartInfo.Arguments); + this.testHostProcess = this.processHelper.LaunchProcess(testHostStartInfo.FileName, testHostStartInfo.Arguments, testHostStartInfo.WorkingDirectory, testHostStartInfo.EnvironmentVariables, this.ErrorReceivedCallback, this.ExitCallBack) as Process; } else { @@ -307,9 +335,10 @@ private int LaunchHost(TestProcessStartInfo testHostStartInfo) this.testHostProcess = Process.GetProcessById(processId); } - this.OnHostLaunched(new HostProviderEventArgs("Test Runtime launched with Pid: " + this.testHostProcess.Id)); + var pId = this.testHostProcess != null ? this.testHostProcess.Id : 0; + this.OnHostLaunched(new HostProviderEventArgs("Test Runtime launched with Pid: " + pId)); - return this.testHostProcess.Id; + return pId; } private string GetTestHostPath(string runtimeConfigDevPath, string depsFilePath, string sourceDirectory) diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Microsoft.TestPlatform.TestHostProvider.csproj b/src/Microsoft.TestPlatform.TestHostProvider/Microsoft.TestPlatform.TestHostProvider.csproj new file mode 100644 index 0000000000..7cf05d1119 Binary files /dev/null and b/src/Microsoft.TestPlatform.TestHostProvider/Microsoft.TestPlatform.TestHostProvider.csproj differ diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/TestRunnerConnectionInfoExtensions.cs b/src/Microsoft.TestPlatform.TestHostProvider/TestRunnerConnectionInfoExtensions.cs similarity index 100% rename from src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/TestRunnerConnectionInfoExtensions.cs rename to src/Microsoft.TestPlatform.TestHostProvider/TestRunnerConnectionInfoExtensions.cs diff --git a/src/datacollector/Program.cs b/src/datacollector/Program.cs index fde05e3628..ce3fe24ea1 100644 --- a/src/datacollector/Program.cs +++ b/src/datacollector/Program.cs @@ -12,9 +12,9 @@ namespace Microsoft.VisualStudio.TestPlatform.DataCollector using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.Interfaces; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; using Microsoft.VisualStudio.TestPlatform.Utilities; /// @@ -75,7 +75,8 @@ private static void Run(string[] args) EqtTrace.Info("DataCollector: Monitoring parent process with id: '{0}'", parentProcessId); var processHelper = new ProcessHelper(); - processHelper.SetExitCallback(parentProcessId, + processHelper.SetExitCallback( + parentProcessId, () => { EqtTrace.Info("DataCollector: ParentProcess '{0}' Exited.", parentProcessId); diff --git a/src/package/package/package.csproj b/src/package/package/package.csproj index 3d59f385f6..21543d1d0b 100644 --- a/src/package/package/package.csproj +++ b/src/package/package/package.csproj @@ -43,6 +43,7 @@ + true diff --git a/src/package/sign/sign.proj b/src/package/sign/sign.proj index 346a36724a..fbbd4cbf5e 100644 --- a/src/package/sign/sign.proj +++ b/src/package/sign/sign.proj @@ -50,6 +50,7 @@ + @@ -73,6 +74,7 @@ + @@ -101,6 +103,7 @@ + diff --git a/src/testhost.x86/DefaultEngineInvoker.cs b/src/testhost.x86/DefaultEngineInvoker.cs index 6c80d538aa..06871a8212 100644 --- a/src/testhost.x86/DefaultEngineInvoker.cs +++ b/src/testhost.x86/DefaultEngineInvoker.cs @@ -11,10 +11,10 @@ namespace Microsoft.VisualStudio.TestPlatform.TestHost using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; internal class DefaultEngineInvoker : #if NET46 @@ -62,7 +62,8 @@ public void Invoke(IDictionary argsDictionary) var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessIdArgument); EqtTrace.Info("DefaultEngineInvoker: Monitoring parent process with id: '{0}'", parentProcessId); var processHelper = new ProcessHelper(); - processHelper.SetExitCallback(parentProcessId, + processHelper.SetExitCallback( + parentProcessId, () => { EqtTrace.Info("DefaultEngineInvoker: ParentProcess '{0}' Exited.", parentProcessId); diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/TestPlatformTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/TestPlatformTests.cs index 44dc7c08cb..26f2b32ce1 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/TestPlatformTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/TestPlatformTests.cs @@ -7,6 +7,8 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.UnitTests using System.Collections.Generic; using Microsoft.VisualStudio.TestPlatform.Client.Execution; + using Microsoft.VisualStudio.TestPlatform.Common.Hosting; + using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; @@ -36,17 +38,15 @@ public TestPlatformTests() this.executionManager = new Mock(); this.hostManager = new Mock(); this.mockFileHelper = new Mock(); - } [TestMethod] public void CreateDiscoveryRequestShouldCreateDiscoveryRequestWithGivenCriteriaAndReturnIt() { - this.testEngine.Setup(te => te.GetDefaultTestHostManager(It.IsAny())).Returns(this.hostManager.Object); this.discoveryManager.Setup(dm => dm.Initialize()).Verifiable(); this.testEngine.Setup(te => te.GetDiscoveryManager(this.hostManager.Object, It.IsAny())).Returns(this.discoveryManager.Object); this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object); - var tp = new TestableTestPlatform(this.testEngine.Object); + var tp = new TestableTestPlatform(this.testEngine.Object, this.hostManager.Object); var discoveryCriteria = new DiscoveryCriteria(new List { "foo" }, 1, null); var discoveryRequest = tp.CreateDiscoveryRequest(discoveryCriteria); @@ -66,7 +66,7 @@ public void CreateDiscoveryRequestThrowsIfDiscoveryCriteriaIsNull() public void UpdateExtensionsShouldUpdateTheEngineWithAdditionalExtensions() { this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object); - var tp = new TestableTestPlatform(this.testEngine.Object); + var tp = new TestableTestPlatform(this.testEngine.Object, this.hostManager.Object); var additionalExtensions = new List { "e1.dll", "e2.dll" }; tp.UpdateExtensions(additionalExtensions, loadOnlyWellKnownExtensions: true); @@ -81,12 +81,11 @@ public void CreateTestRunRequestShouldUpdateLoggerExtensionWhenDesingModeIsFalse this.mockFileHelper.Setup(fh => fh.DirectoryExists(It.IsAny())).Returns(true); this.mockFileHelper.Setup(fh => fh.EnumerateFiles(It.IsAny(), It.IsAny(), System.IO.SearchOption.TopDirectoryOnly)).Returns(additionalExtensions); - this.testEngine.Setup(te => te.GetDefaultTestHostManager(It.IsAny())).Returns(this.hostManager.Object); this.executionManager.Setup(dm => dm.Initialize()).Verifiable(); this.testEngine.Setup(te => te.GetExecutionManager(this.hostManager.Object, It.IsAny())).Returns(this.executionManager.Object); this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object); - var tp = new TestableTestPlatform(this.testEngine.Object, mockFileHelper.Object); + var tp = new TestableTestPlatform(this.testEngine.Object, this.mockFileHelper.Object, this.hostManager.Object); string settingsXml = @" @@ -108,12 +107,11 @@ public void CreateTestRunRequestShouldUpdateLoggerExtensionWhenDesingModeIsFalse this.mockFileHelper.Setup(fh => fh.DirectoryExists(It.IsAny())).Returns(true); this.mockFileHelper.Setup(fh => fh.EnumerateFiles(It.IsAny(), It.IsAny(), System.IO.SearchOption.TopDirectoryOnly)).Returns(additionalExtensions); - this.testEngine.Setup(te => te.GetDefaultTestHostManager(It.IsAny())).Returns(this.hostManager.Object); this.executionManager.Setup(dm => dm.Initialize()).Verifiable(); this.testEngine.Setup(te => te.GetExecutionManager(this.hostManager.Object, It.IsAny())).Returns(this.executionManager.Object); this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object); - var tp = new TestableTestPlatform(this.testEngine.Object, mockFileHelper.Object); + var tp = new TestableTestPlatform(this.testEngine.Object, this.mockFileHelper.Object, this.hostManager.Object); string settingsXml = @" @@ -131,11 +129,10 @@ public void CreateTestRunRequestShouldUpdateLoggerExtensionWhenDesingModeIsFalse [TestMethod] public void CreateTestRunRequestShouldCreateTestRunRequestWithSpecifiedCriteria() { - this.testEngine.Setup(te => te.GetDefaultTestHostManager(It.IsAny())).Returns(this.hostManager.Object); this.executionManager.Setup(dm => dm.Initialize()).Verifiable(); this.testEngine.Setup(te => te.GetExecutionManager(this.hostManager.Object, It.IsAny())).Returns(this.executionManager.Object); this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object); - var tp = new TestableTestPlatform(this.testEngine.Object); + var tp = new TestableTestPlatform(this.testEngine.Object, this.hostManager.Object); var testRunCriteria = new TestRunCriteria(new List { "foo" }, 10); var testRunRequest = tp.CreateTestRunRequest(testRunCriteria); @@ -148,11 +145,10 @@ public void CreateTestRunRequestShouldCreateTestRunRequestWithSpecifiedCriteria( public void CreateTestRunRequestShouldSetCustomHostLauncherOnEngineDefaultLauncherIfSpecified() { var mockCustomLauncher = new Mock(); - this.testEngine.Setup(te => te.GetDefaultTestHostManager(It.IsAny())).Returns(this.hostManager.Object); this.executionManager.Setup(dm => dm.Initialize()).Verifiable(); this.testEngine.Setup(te => te.GetExecutionManager(this.hostManager.Object, It.IsAny())).Returns(this.executionManager.Object); this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object); - var tp = new TestableTestPlatform(this.testEngine.Object); + var tp = new TestableTestPlatform(this.testEngine.Object, this.hostManager.Object); var testRunCriteria = new TestRunCriteria(new List { "foo" }, 10, false, null, TimeSpan.Zero, mockCustomLauncher.Object); var testRunRequest = tp.CreateTestRunRequest(testRunCriteria); @@ -172,12 +168,28 @@ public void CreateTestRunRequestThrowsIfTestRunCriteriaIsNull() private class TestableTestPlatform : TestPlatform { - public TestableTestPlatform(ITestEngine testEngine) : base(testEngine, new FileHelper()) + public TestableTestPlatform(ITestEngine testEngine, ITestRuntimeProvider hostProvider) : base(testEngine, new FileHelper(), new TestableTestRuntimeProviderManager(hostProvider)) + { + } + + public TestableTestPlatform(ITestEngine testEngine, IFileHelper fileHelper, ITestRuntimeProvider hostProvider) : base(testEngine, fileHelper, new TestableTestRuntimeProviderManager(hostProvider)) + { + } + } + + private class TestableTestRuntimeProviderManager : TestRuntimeProviderManager + { + private readonly ITestRuntimeProvider hostProvider; + + public TestableTestRuntimeProviderManager(ITestRuntimeProvider hostProvider) + : base(TestSessionMessageLogger.Instance) { + this.hostProvider = hostProvider; } - public TestableTestPlatform(ITestEngine testEngine, IFileHelper fileHelper) : base(testEngine, fileHelper) + public override ITestRuntimeProvider GetTestHostManagerByRunConfiguration(string runConfiguration) { + return this.hostProvider; } } } diff --git a/test/Microsoft.TestPlatform.Common.UnitTests/Hosting/TestHostProviderManagerTests.cs b/test/Microsoft.TestPlatform.Common.UnitTests/Hosting/TestHostProviderManagerTests.cs index 8e19643850..7e81843285 100644 --- a/test/Microsoft.TestPlatform.Common.UnitTests/Hosting/TestHostProviderManagerTests.cs +++ b/test/Microsoft.TestPlatform.Common.UnitTests/Hosting/TestHostProviderManagerTests.cs @@ -14,7 +14,9 @@ namespace TestPlatform.Common.UnitTests.Logging using TestPlatform.Common.UnitTests.ExtensionFramework; using System.Threading.Tasks; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; /// /// Tests the behaviors of the TestLoggerManager class. @@ -29,14 +31,14 @@ public void Initialize() } [TestMethod] - public void TestHostProviderManagerShouldReturnTestHostWhenAppropriateCustomURIProvided() + public void TestHostProviderManagerShouldReturnTestHostWhenAppropriateCustomUriProvided() { var manager = TestRuntimeProviderManager.Instance; Assert.IsNotNull(manager.GetTestHostManagerByUri("executor://CustomTestHost/")); } [TestMethod] - public void TestHostProviderManagerShouldReturnNullWhenInvalidCustomURIProvided() + public void TestHostProviderManagerShouldReturnNullWhenInvalidCustomUriProvided() { var manager = TestRuntimeProviderManager.Instance; Assert.IsNull(manager.GetTestHostManagerByUri("executor://InvalidHost/")); @@ -58,19 +60,105 @@ public void TestHostProviderManagerShouldReturnTestHostBasedOnRunConfiguration() Assert.IsNotNull(manager.GetTestHostManagerByRunConfiguration(runSettingsXml)); } + [TestMethod] + public void GetDefaultTestHostManagerReturnsANonNullInstance() + { + string runSettingsXml = string.Concat( + @" +0 x86 ", + Framework.DefaultFramework.Name, + " "); + + Assert.IsNotNull(TestRuntimeProviderManager.Instance.GetTestHostManagerByRunConfiguration(runSettingsXml)); + } + + [TestMethod] + public void GetDefaultTestHostManagerReturnsANewInstanceEverytime() + { + string runSettingsXml = string.Concat( + @" +0 x86 ", + Framework.DefaultFramework.Name, + " "); + + var instance1 = TestRuntimeProviderManager.Instance.GetTestHostManagerByRunConfiguration(runSettingsXml); + var instance2 = TestRuntimeProviderManager.Instance.GetTestHostManagerByRunConfiguration(runSettingsXml); + + Assert.AreNotEqual(instance1, instance2); + } + + [TestMethod] + public void GetDefaultTestHostManagerReturnsDotnetCoreHostManagerIfFrameworkIsNetCore() + { + string runSettingsXml = string.Concat( + @" +0 x64 ", + ".NETCoreApp,Version=v1.0", + " "); + + var testHostManager = TestRuntimeProviderManager.Instance.GetTestHostManagerByRunConfiguration(runSettingsXml); + + Assert.AreEqual(typeof(DotnetTestHostManager), testHostManager.GetType()); + } + + [TestMethod] + public void GetDefaultTestHostManagerReturnsASharedManagerIfDisableAppDomainIsFalse() + { + string runSettingsXml = string.Concat( + @" +0 x86 ", + ".NETFramework,Version=v4.6", + " "); + + var testHostManager = TestRuntimeProviderManager.Instance.GetTestHostManagerByRunConfiguration(runSettingsXml); + testHostManager.Initialize(null, runSettingsXml); + Assert.IsNotNull(testHostManager); + + Assert.IsTrue(testHostManager.Shared, "Default TestHostManager must be shared if DisableAppDomain is false"); + } + + [TestMethod] + public void GetDefaultTestHostManagerReturnsANonSharedManagerIfDisableAppDomainIsTrue() + { + string runSettingsXml = string.Concat( + @" +0 x86 ", + ".NETFramework,Version=v4.6", + "true "); + + var testHostManager = TestRuntimeProviderManager.Instance.GetTestHostManagerByRunConfiguration(runSettingsXml); + testHostManager.Initialize(null, runSettingsXml); + Assert.IsNotNull(testHostManager); + + Assert.IsFalse(testHostManager.Shared, "Default TestHostManager must NOT be shared if DisableAppDomain is true"); + } + #region implementations [ExtensionUri("executor://CustomTestHost")] [FriendlyName("CustomHost")] private class CustomTestHost : ITestRuntimeProvider { - public bool Shared => throw new NotImplementedException(); - public event EventHandler HostLaunched; + public event EventHandler HostExited; - public bool CanExecuteCurrentRunConfiguration(string runConfiguration) + public bool Shared { get; private set; } + + + public bool CanExecuteCurrentRunConfiguration(string runsettingsXml) { + var config = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml); + var framework = config.TargetFrameworkVersion; + this.Shared = !config.DisableAppDomain; + + // This is expected to be called once every run so returning a new instance every time. + if (framework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0 + || framework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0) + { + return false; + } + return true; } @@ -94,8 +182,89 @@ public IEnumerable GetTestPlatformExtensions(IEnumerable sources throw new NotImplementedException(); } - public void Initialize(IMessageLogger logger) + public void Initialize(IMessageLogger logger, string runsettingsXml) + { + var config = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml); + this.Shared = !config.DisableAppDomain; + } + + public Task LaunchTestHostAsync(TestProcessStartInfo testHostStartInfo) + { + throw new NotImplementedException(); + } + + public void OnHostExited(HostProviderEventArgs e) + { + this.HostExited.Invoke(this, new HostProviderEventArgs("Error")); + } + + public void OnHostLaunched(HostProviderEventArgs e) + { + this.HostLaunched.Invoke(this, new HostProviderEventArgs("Error")); + } + + public void RegisterForExitNotification(Action abortCallback) + { + throw new NotImplementedException(); + } + + public void SetCustomLauncher(ITestHostLauncher customLauncher) + { + throw new NotImplementedException(); + } + } + + [ExtensionUri("executor://DotnetTestHostManager")] + [FriendlyName("DotnetTestHostManager")] + private class DotnetTestHostManager : ITestRuntimeProvider + { + public event EventHandler HostLaunched; + + public event EventHandler HostExited; + + public bool Shared { get; private set; } + + + public bool CanExecuteCurrentRunConfiguration(string runsettingsXml) + { + var config = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml); + var framework = config.TargetFrameworkVersion; + this.Shared = !config.DisableAppDomain; + + // This is expected to be called once every run so returning a new instance every time. + if (framework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0 + || framework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0) + { + return true; + } + + return false; + } + + public void DeregisterForExitNotification() + { + throw new NotImplementedException(); + } + + public CancellationTokenSource GetCancellationTokenSource() + { + throw new NotImplementedException(); + } + + public TestProcessStartInfo GetTestHostProcessStartInfo(IEnumerable sources, IDictionary environmentVariables, TestRunnerConnectionInfo connectionInfo) + { + throw new NotImplementedException(); + } + + public IEnumerable GetTestPlatformExtensions(IEnumerable sources) + { + throw new NotImplementedException(); + } + + public void Initialize(IMessageLogger logger, string runsettingsXml) { + var config = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml); + this.Shared = !config.DisableAppDomain; } public Task LaunchTestHostAsync(TestProcessStartInfo testHostStartInfo) diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs index d1528f8515..9018ae11c5 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs @@ -10,11 +10,11 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.Client using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionLauncherFactoryTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionLauncherFactoryTests.cs index 746c05d745..9242c28cce 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionLauncherFactoryTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionLauncherFactoryTests.cs @@ -4,7 +4,7 @@ namespace Microsoft.TestPlatform.CrossPlatEngine.UnitTests.DataCollection { using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs index 9883052f18..f053a1cb8a 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/ProxyDataCollectionManagerTests.cs @@ -12,10 +12,10 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.DataCollection using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; 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.TestTools.UnitTesting; using Moq; diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Microsoft.TestPlatform.CrossPlatEngine.UnitTests.csproj b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Microsoft.TestPlatform.CrossPlatEngine.UnitTests.csproj index c5370a7dbd..bf32b80203 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Microsoft.TestPlatform.CrossPlatEngine.UnitTests.csproj +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Microsoft.TestPlatform.CrossPlatEngine.UnitTests.csproj @@ -7,14 +7,15 @@ Exe - netcoreapp1.0;net46 Microsoft.TestPlatform.CrossPlatEngine.UnitTests + netcoreapp1.0;net46 $(PackageTargetFallback);dnxcore50;portable-net45+win8 + true diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/TestEngineTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/TestEngineTests.cs index 80cb61c122..e3037de21a 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/TestEngineTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/TestEngineTests.cs @@ -3,29 +3,39 @@ namespace TestPlatform.CrossPlatEngine.UnitTests { + using System; using System.Collections.Generic; + using System.Reflection; + using System.Threading; + using System.Threading.Tasks; + using Microsoft.VisualStudio.TestPlatform.Common.Hosting; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; - using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; + using TestPlatform.Common.UnitTests.ExtensionFramework; + [TestClass] public class TestEngineTests { - private readonly ITestEngine testEngine; + private ITestEngine testEngine; private Mock mockTestHostManager; public TestEngineTests() { + TestPluginCacheTests.SetupMockExtensions(new[] { typeof(TestEngineTests).GetTypeInfo().Assembly.Location }, () => { }); this.testEngine = new TestEngine(); this.mockTestHostManager = new Mock(); @@ -133,53 +143,5 @@ public void GetExtensionManagerShouldReturnANonNullInstance() { Assert.IsNotNull(this.testEngine.GetExtensionManager()); } - - [TestMethod] - public void GetDefaultTestHostManagerReturnsANonNullInstance() - { - var rc = new RunConfiguration() { TargetFrameworkVersion = Framework.DefaultFramework, TargetPlatform = Architecture.X86 }; - Assert.IsNotNull(this.testEngine.GetDefaultTestHostManager(rc)); - } - - [TestMethod] - public void GetDefaultTestHostManagerReturnsANewInstanceEverytime() - { - var rc = new RunConfiguration() { TargetFrameworkVersion = Framework.DefaultFramework, TargetPlatform = Architecture.X86 }; - var instance1 = this.testEngine.GetDefaultTestHostManager(rc); - var instance2 = this.testEngine.GetDefaultTestHostManager(rc); - - Assert.AreNotEqual(instance1, instance2); - } - - [TestMethod] - public void GetDefaultTestHostManagerReturnsDotnetCoreHostManagerIfFrameworkIsNetCore() - { - var rc = new RunConfiguration() { TargetFrameworkVersion = Framework.FromString(".NETCoreApp,Version=v1.0"), TargetPlatform = Architecture.X64 }; - var testHostManager = this.testEngine.GetDefaultTestHostManager(rc); - - Assert.AreEqual(typeof(DotnetTestHostManager), testHostManager.GetType()); - } - - [TestMethod] - public void GetDefaultTestHostManagerReturnsASharedManagerIfDisableAppDomainIsFalse() - { - var rc = new RunConfiguration() { TargetFrameworkVersion = Framework.FromString(".NETFramework,Version=v4.6"), TargetPlatform = Architecture.X86 }; - - var testHostManager = this.testEngine.GetDefaultTestHostManager(rc); - Assert.IsNotNull(testHostManager); - - Assert.IsTrue(testHostManager.Shared, "Default TestHostManager must be shared if DisableAppDomain is false"); - } - - [TestMethod] - public void GetDefaultTestHostManagerReturnsANonSharedManagerIfDisableAppDomainIsFalse() - { - var rc = new RunConfiguration() { TargetFrameworkVersion = Framework.FromString(".NETFramework,Version=v4.6"), TargetPlatform = Architecture.X86, DisableAppDomain = true }; - - var testHostManager = this.testEngine.GetDefaultTestHostManager(rc); - Assert.IsNotNull(testHostManager); - - Assert.IsFalse(testHostManager.Shared, "Default TestHostManager must NOT be shared if DisableAppDomain is true"); - } } } diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs similarity index 92% rename from test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DefaultTestHostManagerTests.cs rename to test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs index 5f8e281ceb..936927dd15 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace TestPlatform.CrossPlatEngine.UnitTests.Hosting +namespace TestPlatform.TestHostProvider.UnitTests.Hosting { using System; using System.Collections.Generic; @@ -9,21 +9,21 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.Hosting using System.IO; using System.Linq; using System.Threading.Tasks; - - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; +#pragma warning disable SA1600 [TestClass] public class DefaultTestHostManagerTests { - private readonly TestProcessStartInfo startInfo; + private readonly TestProcessStartInfo startInfo; private readonly Mock mockMessageLogger; private readonly Mock mockProcessHelper; @@ -37,9 +37,9 @@ public DefaultTestHostManagerTests() { this.mockProcessHelper = new Mock(); this.mockProcessHelper.Setup(ph => ph.GetCurrentProcessFileName()).Returns("vstest.console.exe"); - + this.mockMessageLogger = new Mock(); - + this.testHostManager = new DefaultTestHostManager(Architecture.X64, Framework.DefaultFramework, this.mockProcessHelper.Object, true); this.startInfo = this.testHostManager.GetTestHostProcessStartInfo(Enumerable.Empty(), null, default(TestRunnerConnectionInfo)); } @@ -130,8 +130,8 @@ public void LaunchTestHostShouldReturnTestHostProcessId() It.IsAny(), It.IsAny(), It.IsAny>(), - It.IsAny>(), - It.IsAny>())).Returns(Process.GetCurrentProcess()); + It.IsAny>(), + It.IsAny>())).Returns(Process.GetCurrentProcess()); var testHostManager = new DefaultTestHostManager(Architecture.X64, Framework.DefaultFramework, this.mockProcessHelper.Object, true); var startInfo = testHostManager.GetTestHostProcessStartInfo(Enumerable.Empty(), null, default(TestRunnerConnectionInfo)); @@ -253,7 +253,7 @@ private void ErrorCallBackTestHelper(string errorMessage, int exitCode) this.mockMessageLogger.Object); this.testableTestHostManager.HostExited += this.TestHostManagerHostExited; - + this.mockProcessHelper.Setup( ph => ph.LaunchProcess( @@ -261,9 +261,9 @@ private void ErrorCallBackTestHelper(string errorMessage, int exitCode) It.IsAny(), It.IsAny(), It.IsAny>(), - It.IsAny>(), - It.IsAny>())) - .Callback, Action, Action>( + It.IsAny>(), + It.IsAny>())) + .Callback, Action, Action>( (var1, var2, var3, dictionary, errorCallback, exitCallback) => { var process = Process.GetCurrentProcess(); @@ -271,7 +271,7 @@ private void ErrorCallBackTestHelper(string errorMessage, int exitCode) errorCallback(process, errorMessage); }).Returns(Process.GetCurrentProcess()); - this.mockProcessHelper.Setup(ph => ph.TryGetExitCode(It.IsAny(), out exitCode)).Returns(true); + this.mockProcessHelper.Setup(ph => ph.TryGetExitCode(It.IsAny(), out exitCode)).Returns(true); } private void ExitCallBackTestHelper(int exitCode) @@ -293,16 +293,16 @@ private void ExitCallBackTestHelper(int exitCode) It.IsAny(), It.IsAny(), It.IsAny>(), - It.IsAny>(), - It.IsAny>())) - .Callback, Action, Action>( + It.IsAny>(), + It.IsAny>())) + .Callback, Action, Action>( (var1, var2, var3, dictionary, errorCallback, exitCallback) => { var process = Process.GetCurrentProcess(); exitCallback(process); }).Returns(Process.GetCurrentProcess()); - this.mockProcessHelper.Setup(ph => ph.TryGetExitCode(It.IsAny(), out exitCode)).Returns(true); + this.mockProcessHelper.Setup(ph => ph.TryGetExitCode(It.IsAny(), out exitCode)).Returns(true); } private TestProcessStartInfo GetDefaultStartInfo() @@ -318,12 +318,13 @@ public TestableTestHostManager( IProcessHelper processHelper, bool shared, int errorLength, - IMessageLogger logger) : base(architecture, framework, processHelper, shared) + IMessageLogger logger) + : base(architecture, framework, processHelper, shared) { this.TimeOut = 30000; this.ErrorLength = errorLength; - this.Initialize(logger); } } } +#pragma warning restore SA1600 } diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DotnetTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs similarity index 95% rename from test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DotnetTestHostManagerTests.cs rename to test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs index 043246615a..8b109b921b 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DotnetTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace TestPlatform.CrossPlatEngine.UnitTests.Hosting +namespace TestPlatform.TestHostProvider.UnitTests.Hosting { using System; using System.Collections.Generic; @@ -19,11 +19,14 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.Hosting using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; +#pragma warning disable SA1600 + [TestClass] public class DotnetTestHostManagerTests { @@ -43,7 +46,7 @@ public class DotnetTestHostManagerTests private readonly TestProcessStartInfo defaultTestProcessStartInfo; private readonly TestableDotnetTestHostManager dotnetHostManager; - + private string errorMessage; private int errorLength = 20; @@ -61,9 +64,8 @@ public DotnetTestHostManagerTests() this.dotnetHostManager = new TestableDotnetTestHostManager( this.mockProcessHelper.Object, this.mockFileHelper.Object, - new DotnetHostHelper(this.mockFileHelper.Object), + new DotnetHostHelper(this.mockFileHelper.Object), this.errorLength); - this.dotnetHostManager.Initialize(mockLogger.Object); this.dotnetHostManager.HostExited += this.DotnetHostManagerHostExited; @@ -329,7 +331,7 @@ public async Task LaunchTestHostShouldLaunchProcessWithConnectionInfo() this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.Arguments.Equals(expectedArgs))), Times.Once); } - + [TestMethod] public void GetTestHostProcessStartInfoShouldIncludeTestHostPathFromSourceDirectoryIfDepsFileNotFound() { @@ -509,9 +511,9 @@ private void ErrorCallBackTestHelper(string errorMessage, int exitCode) It.IsAny(), It.IsAny(), It.IsAny>(), - It.IsAny>(), - It.IsAny>())) - .Callback, Action, Action>( + It.IsAny>(), + It.IsAny>())) + .Callback, Action, Action>( (var1, var2, var3, dictionary, errorCallback, exitCallback) => { var process = Process.GetCurrentProcess(); @@ -519,7 +521,7 @@ private void ErrorCallBackTestHelper(string errorMessage, int exitCode) errorCallback(process, errorMessage); }).Returns(Process.GetCurrentProcess()); - this.mockProcessHelper.Setup(ph => ph.TryGetExitCode(It.IsAny(), out exitCode)).Returns(true); + this.mockProcessHelper.Setup(ph => ph.TryGetExitCode(It.IsAny(), out exitCode)).Returns(true); } private void ExitCallBackTestHelper(int exitCode) @@ -531,19 +533,18 @@ private void ExitCallBackTestHelper(int exitCode) It.IsAny(), It.IsAny(), It.IsAny>(), - It.IsAny>(), - It.IsAny>())) - .Callback, Action, Action>( + It.IsAny>(), + It.IsAny>())) + .Callback, Action, Action>( (var1, var2, var3, dictionary, errorCallback, exitCallback) => { var process = Process.GetCurrentProcess(); exitCallback(process); }).Returns(Process.GetCurrentProcess()); - this.mockProcessHelper.Setup(ph => ph.TryGetExitCode(It.IsAny(), out exitCode)).Returns(true); + this.mockProcessHelper.Setup(ph => ph.TryGetExitCode(It.IsAny(), out exitCode)).Returns(true); } - private TestProcessStartInfo GetDefaultStartInfo() { var startInfo = this.dotnetHostManager.GetTestHostProcessStartInfo( @@ -552,14 +553,15 @@ private TestProcessStartInfo GetDefaultStartInfo() this.defaultConnectionInfo); return startInfo; } - } - internal class TestableDotnetTestHostManager : DotnetTestHostManager - { - public TestableDotnetTestHostManager(IProcessHelper processHelper, IFileHelper fileHelper, IDotnetHostHelper dotnetTestHostHelper, int errorLength) - : base(processHelper, fileHelper, dotnetTestHostHelper) + internal class TestableDotnetTestHostManager : DotnetTestHostManager { - this.ErrorLength = errorLength; + public TestableDotnetTestHostManager(IProcessHelper processHelper, IFileHelper fileHelper, IDotnetHostHelper dotnetTestHostHelper, int errorLength) + : base(processHelper, fileHelper, dotnetTestHostHelper) + { + this.ErrorLength = errorLength; + } } } +#pragma warning restore SA1600 } diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs similarity index 90% rename from test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs rename to test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs index e32b7ed916..0a2bdd62b5 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace TestPlatform.CrossPlatEngine.UnitTests.Hosting +namespace TestPlatform.TestHostProvider.UnitTests.Hosting { using System; @@ -9,6 +9,7 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.Hosting using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestTools.UnitTesting; +#pragma warning disable SA1600 [TestClass] public class TestRunnerConnectionInfoExtensionsTests { @@ -35,7 +36,7 @@ public void ToCommandLineOptionsShouldIncludeParentProcessId() [TestMethod] public void ToCommandLineOptionsShouldIncludeDiagnosticsOptionIfEnabled() { - var connectionInfo = new TestRunnerConnectionInfo(); + var connectionInfo = default(TestRunnerConnectionInfo); var options = connectionInfo.ToCommandLineOptions(); @@ -52,4 +53,5 @@ public void ToCommandLineOptionsShouldNotIncludeDiagnosticsOptionIfNotEnabled() StringAssert.EndsWith(options, "--diag log.txt"); } } +#pragma warning restore SA1600 } \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj new file mode 100644 index 0000000000..3ad0a9658d --- /dev/null +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj @@ -0,0 +1,38 @@ + + + + ..\..\ + true + + + + Exe + Microsoft.TestPlatform.TestHostProvider.UnitTests + netcoreapp1.0;net46 + true + $(PackageTargetFallback);dnxcore50;portable-net45+win8 + + + + + + + + + true + + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Program.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Program.cs new file mode 100644 index 0000000000..02b716c787 --- /dev/null +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Program.cs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft. All rights reserved. + +namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.UnitTests +{ +#pragma warning disable SA1600 + public static class Program + { + public static void Main(string[] args) + { + } + } +#pragma warning restore SA1600 +} \ No newline at end of file diff --git a/test/datacollector.PlatformTests/CommunicationLayerIntegrationTests.cs b/test/datacollector.PlatformTests/CommunicationLayerIntegrationTests.cs index 8a817e3d91..d9ea35d57e 100644 --- a/test/datacollector.PlatformTests/CommunicationLayerIntegrationTests.cs +++ b/test/datacollector.PlatformTests/CommunicationLayerIntegrationTests.cs @@ -10,8 +10,8 @@ namespace Microsoft.VisualStudio.TestPlatform.DataCollector.PlatformTests using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; + using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq;