Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry Pick #2397 to master #2398

Merged
merged 1 commit into from
Apr 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public static class FakesUtilities
{
private const string ConfiguratorAssemblyQualifiedName = "Microsoft.VisualStudio.TestPlatform.Fakes.FakesDataCollectorConfiguration";

private const string ConfiguratorMethodName = "GetDataCollectorSettingsOrDefault";
private const string NetFrameworkConfiguratorMethodName = "GetDataCollectorSettingsOrDefault";

private const string CrossPlatformConfiguratorMethodName = "GetCrossPlatformDataCollectorSettings";

private const string FakesConfiguratorAssembly = "Microsoft.VisualStudio.TestPlatform.Fakes, Version=16.0.0.0, Culture=neutral";

Expand Down Expand Up @@ -85,11 +87,11 @@ private static bool TryAddFakesDataCollectorSettings(
// using the CLRIE profiler, and the old involves using the Intellitrace profiler (which isn't supported in
// .NET Core scenarios). The old API still exists for fallback measures.

var newConfigurator = TryGetFakesNewDataCollectorConfigurator();
if (newConfigurator != null)
var crossPlatformConfigurator = TryGetFakesCrossPlatformDataCollectorConfigurator();
if (crossPlatformConfigurator != null)
{
var sourceTFMMap = CreateDictionary(sources, framework);
var fakesSettings = newConfigurator(sourceTFMMap);
var fakesSettings = crossPlatformConfigurator(sourceTFMMap);
// if no fakes, return settings unchanged
if (fakesSettings == null)
{
Expand Down Expand Up @@ -132,14 +134,14 @@ private static bool AddFallbackFakesSettings(
return false;
}

Func<IEnumerable<string>, string> oldConfigurator = TryGetFakesDataCollectorConfigurator();
if (oldConfigurator == null)
Func<IEnumerable<string>, string> netFrameworkConfigurator = TryGetNetFrameworkFakesDataCollectorConfigurator();
if (netFrameworkConfigurator == null)
{
return false;
}

// if no fakes, return settings unchanged
var fakesConfiguration = oldConfigurator(sources);
var fakesConfiguration = netFrameworkConfigurator(sources);
if (fakesConfiguration == null)
{
return false;
Expand Down Expand Up @@ -184,14 +186,14 @@ private static void EnsureSettingsNode(XmlDocument settings, TestRunSettings set
}
}

private static Func<IEnumerable<string>, string> TryGetFakesDataCollectorConfigurator()
private static Func<IEnumerable<string>, string> TryGetNetFrameworkFakesDataCollectorConfigurator()
{
#if NET451
try
{
Assembly assembly = Assembly.Load(FakesConfiguratorAssembly);
var type = assembly?.GetType(ConfiguratorAssemblyQualifiedName, false);
var method = type?.GetMethod(ConfiguratorMethodName, new Type[] { typeof(IEnumerable<string>) });
var method = type?.GetMethod(NetFrameworkConfiguratorMethodName, new Type[] { typeof(IEnumerable<string>) });
if (method != null)
{
return (Func<IEnumerable<string>, string>)method.CreateDelegate(typeof(Func<IEnumerable<string>, string>));
Expand All @@ -208,13 +210,13 @@ private static Func<IEnumerable<string>, string> TryGetFakesDataCollectorConfigu
return null;
}

private static Func<IDictionary<string, FrameworkVersion>, DataCollectorSettings> TryGetFakesNewDataCollectorConfigurator()
private static Func<IDictionary<string, FrameworkVersion>, DataCollectorSettings> TryGetFakesCrossPlatformDataCollectorConfigurator()
{
try
{
Assembly assembly = Assembly.Load(FakesConfiguratorAssembly);
var type = assembly?.GetType(ConfiguratorAssemblyQualifiedName, false);
var method = type?.GetMethod(ConfiguratorMethodName, new Type[] { typeof(IDictionary<string, FrameworkVersion>) });
var method = type?.GetMethod(CrossPlatformConfiguratorMethodName, new Type[] { typeof(IDictionary<string, FrameworkVersion>) });
if (method != null)
{
return (Func<IDictionary<string, FrameworkVersion>, DataCollectorSettings>)method.CreateDelegate(typeof(Func<IDictionary<string, FrameworkVersion>, DataCollectorSettings>));
Expand Down