Skip to content

Commit

Permalink
Changed new configurator method name (#2398)
Browse files Browse the repository at this point in the history
  • Loading branch information
vritant24 committed Apr 14, 2020
1 parent 732a3a3 commit 3b6c83e
Showing 1 changed file with 13 additions and 11 deletions.
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

0 comments on commit 3b6c83e

Please sign in to comment.