Skip to content
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
102 changes: 5 additions & 97 deletions src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ private static bool TryAddFakesDataCollectorSettings(
IEnumerable<string> sources,
FrameworkVersion framework)
{
// A new Fakes Configurator API makes the decision to add the right datacollector uri to the configuration
// There now exist two data collector URIs to support two different scenarios. The new scenario involves
// 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.

// Only cross-platform (v2) Fakes is supported. Fallback to v1 is removed.
var crossPlatformConfigurator = TryGetFakesCrossPlatformDataCollectorConfigurator();
if (crossPlatformConfigurator != null)
{
Expand All @@ -118,7 +114,8 @@ private static bool TryAddFakesDataCollectorSettings(
return true;
}

return AddFallbackFakesSettings(runSettings, sources, framework);
// Fakes v1 fallback support removed.
return false;
}

internal static void InsertOrReplaceFakesDataCollectorNode(XmlDocument runSettings, DataCollectorSettings settings)
Expand Down Expand Up @@ -157,55 +154,6 @@ private static IDictionary<string, FrameworkVersion> CreateDictionary(IEnumerabl
return dict;
}

private static bool AddFallbackFakesSettings(
XmlDocument runSettings,
IEnumerable<string> sources,
FrameworkVersion framework)
{

// The fallback settings is for the old implementation of fakes
// that only supports .Net Framework versions
if (framework
is not FrameworkVersion.Framework35
and not FrameworkVersion.Framework40
and not FrameworkVersion.Framework45)
{
return false;
}

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

// if no fakes, return settings unchanged
var fakesConfiguration = netFrameworkConfigurator(sources);
if (fakesConfiguration == null)
{
return false;
}

// integrate fakes settings in configuration
// if the settings don't have any data collector settings, populate with empty settings
EnsureSettingsNode(runSettings, new DataCollectionRunSettings());

// embed fakes settings
var fakesSettings = CreateFakesDataCollectorSettings();
var doc = new XmlDocument();
using (var xmlReader = XmlReader.Create(
new StringReader(fakesConfiguration),
new XmlReaderSettings() { CloseInput = true }))
{
doc.Load(xmlReader);
}

fakesSettings.Configuration = doc.DocumentElement;
XmlRunSettingsUtilities.InsertDataCollectorsNode(runSettings.CreateNavigator()!, fakesSettings);

return true;
}

/// <summary>
/// Ensures that an xml element corresponding to the test run settings exists in the setting document.
/// </summary>
Expand All @@ -225,27 +173,6 @@ private static void EnsureSettingsNode(XmlDocument settings, TestRunSettings set
}
}

private static Func<IEnumerable<string>, string>? TryGetNetFrameworkFakesDataCollectorConfigurator()
{
#if NETFRAMEWORK
try
{
var assembly = LoadTestPlatformAssembly();
var type = assembly?.GetType(ConfiguratorAssemblyQualifiedName, false);
var method = type?.GetMethod(NetFrameworkConfiguratorMethodName, [typeof(IEnumerable<string>)]);
if (method != null)
{
return (Func<IEnumerable<string>, string>)method.CreateDelegate(typeof(Func<IEnumerable<string>, string>));
}
}
catch (Exception ex)
{
EqtTrace.Info("Failed to create Fakes Configurator. Reason:{0} ", ex);
}
#endif
return null;
}

private static Func<IDictionary<string, FrameworkVersion>, DataCollectorSettings>? TryGetFakesCrossPlatformDataCollectorConfigurator()
{
try
Expand Down Expand Up @@ -279,25 +206,6 @@ private static void EnsureSettingsNode(XmlDocument settings, TestRunSettings set
return null;
}

/// <summary>
/// Adds the Fakes data collector settings in the run settings document.
/// </summary>
/// <returns>
/// The <see cref="DataCollectorSettings"/>.
/// </returns>
private static DataCollectorSettings CreateFakesDataCollectorSettings()
{
// embed the fakes run settings
var settings = new DataCollectorSettings
{
AssemblyQualifiedName = FakesMetadata.DataCollectorAssemblyQualifiedName,
FriendlyName = FakesMetadata.FriendlyName,
IsEnabled = true,
Uri = new Uri(FakesMetadata.DataCollectorUriV1)
};
return settings;
}

internal static class FakesMetadata
{
/// <summary>
Expand All @@ -306,12 +214,12 @@ internal static class FakesMetadata
public const string FriendlyName = "UnitTestIsolation";

/// <summary>
/// Gets the URI of the data collector
/// Gets the URI of the data collector (V1, deprecated and removed)
/// </summary>
public const string DataCollectorUriV1 = "datacollector://microsoft/unittestisolation/1.0";

/// <summary>
/// Gets the URI of the data collector
/// Gets the URI of the data collector (V2)
/// </summary>
public const string DataCollectorUriV2 = "datacollector://microsoft/unittestisolation/2.0";

Expand Down
Loading