Skip to content

Commit

Permalink
Moving Desktop,& Dotnet runtime providers to separate dll (microsoft#659
Browse files Browse the repository at this point in the history
)

* Moving Desktop,& Dotnet runtime providers to separate dll
Treating Using this dll as extension, to load appropriate runtimes for

* Minor changes

* PR suggestions

* Refactoring namespace
Refactoring tests

* Test Refactoring
Removing API to get test runtime provider from TestEngine

* Static analysis rules fixes
  • Loading branch information
mayankbansal018 authored Mar 31, 2017
1 parent b6adfb5 commit 876f819
Show file tree
Hide file tree
Showing 58 changed files with 760 additions and 331 deletions.
32 changes: 31 additions & 1 deletion TestPlatform.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
57 changes: 33 additions & 24 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/// <summary>
/// Implementation for TestPlatform
/// </summary>
public class TestPlatform : ITestPlatform
{
private IFileHelper fileHelper;
private readonly TestRuntimeProviderManager testHostProviderManager;

private readonly IFileHelper fileHelper;

/// <summary>
/// Initializes a new instance of the <see cref="TestPlatform"/> class.
/// </summary>
public TestPlatform() : this(new TestEngine(), new FileHelper())
public TestPlatform() : this(new TestEngine(), new FileHelper(), TestRuntimeProviderManager.Instance)
{
this.testHostProviderManager = TestRuntimeProviderManager.Instance;
}

/// <summary>
Expand All @@ -43,19 +44,24 @@ public class TestPlatform : ITestPlatform
/// <param name="testEngine">
/// The test engine.
/// </param>
protected TestPlatform(ITestEngine testEngine, IFileHelper filehelper)
/// <param name="filehelper">
/// The filehelper.
/// </param>
/// <param name="testHostProviderManager">
/// The data.
/// </param>
protected TestPlatform(ITestEngine testEngine, IFileHelper filehelper, TestRuntimeProviderManager testHostProviderManager)
{
this.TestEngine = testEngine;
this.fileHelper = filehelper;
this.testHostProviderManager = testHostProviderManager;
}

/// <summary>
/// Gets or sets Test Engine instance
/// </summary>
private ITestEngine TestEngine { get; set; }

private TestRuntimeProviderManager testHostProviderManager;

/// <summary>
/// The create discovery request.
/// </summary>
Expand All @@ -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();

Expand All @@ -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)
{
Expand Down Expand Up @@ -159,6 +160,9 @@ public void UpdateExtensions(IEnumerable<string> pathToAdditionalExtensions, boo
/// <summary>
/// Update the test adapter paths provided through run settings to be used by the test service
/// </summary>
/// <param name="runSettings">
/// The run Settings.
/// </param>
private void UpdateTestAdapterPaths(string runSettings)
{
IEnumerable<string> customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(runSettings);
Expand All @@ -175,8 +179,10 @@ private void UpdateTestAdapterPaths(string runSettings)
}

List<string> adapterFiles = new List<string>(
this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.TestAdapterRegexPattern, SearchOption.AllDirectories)
);
this.fileHelper.EnumerateFiles(
adapterPath,
TestPlatformConstants.TestAdapterRegexPattern,
SearchOption.AllDirectories));
if (adapterFiles.Count > 0)
{
this.UpdateExtensions(adapterFiles, true);
Expand All @@ -188,6 +194,9 @@ private void UpdateTestAdapterPaths(string runSettings)
/// <summary>
/// Update the test logger paths from source directory
/// </summary>
/// <param name="testRunCriteria">
/// The test Run Criteria.
/// </param>
private void UpdateTestLoggerPath(TestRunCriteria testRunCriteria)
{
IEnumerable<string> sources = testRunCriteria.Sources;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.TestPlatform.Common/Friends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Manages loading and provides access to testhost extensions implementing the
Expand All @@ -17,6 +18,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Hosting
internal class TestRuntimeExtensionManager : TestExtensionManager<ITestRuntimeProvider, ITestRuntimeCapabilities>
{
/// <summary>
/// Initializes a new instance of the <see cref="TestRuntimeExtensionManager"/> class.
/// Default constructor.
/// </summary>
/// <param name="unfilteredTestExtensions">
Expand Down Expand Up @@ -60,5 +62,4 @@ public static TestRuntimeExtensionManager Create(IMessageLogger messageLogger)
return new TestRuntimeExtensionManager(unfilteredTestExtensions, filteredTestExtensions, messageLogger);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Responsible for managing TestRuntimeProviderManager extensions
/// </summary>
internal class TestRuntimeProviderManager
public class TestRuntimeProviderManager
{
#region Fields

private static TestRuntimeProviderManager testHostManager;

/// <summary>
/// Gets an instance of the logger.
/// </summary>
private IMessageLogger messageLogger;
private readonly TestRuntimeExtensionManager testHostExtensionManager;

private TestRuntimeExtensionManager testHostExtensionManager;

#endregion

#region Constructor

/// <summary>
/// Initializes a new instance of the <see cref="TestRuntimeProviderManager"/> class.
/// Default constructor.
/// </summary>
protected TestRuntimeProviderManager(TestSessionMessageLogger sessionLogger)
/// <param name="sessionLogger">
/// The session Logger.
/// </param>
protected TestRuntimeProviderManager(IMessageLogger sessionLogger)
{
this.messageLogger = sessionLogger;
this.testHostExtensionManager = TestRuntimeExtensionManager.Create(sessionLogger);
}

/// <summary>
/// Gets the instance.
/// Gets the instance of TestRuntimeProviderManager
/// </summary>
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

Expand All @@ -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());
}
}

Expand Down
Loading

0 comments on commit 876f819

Please sign in to comment.