Skip to content

Commit ab8ad2b

Browse files
authored
Remove fakes v1 from FakesUtilities (#15251)
Remove fakes v1 from FakesUtilities
1 parent 8299376 commit ab8ad2b

File tree

1 file changed

+5
-97
lines changed

1 file changed

+5
-97
lines changed

src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs

Lines changed: 5 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ private static bool TryAddFakesDataCollectorSettings(
9797
IEnumerable<string> sources,
9898
FrameworkVersion framework)
9999
{
100-
// A new Fakes Configurator API makes the decision to add the right datacollector uri to the configuration
101-
// There now exist two data collector URIs to support two different scenarios. The new scenario involves
102-
// using the CLRIE profiler, and the old involves using the Intellitrace profiler (which isn't supported in
103-
// .NET Core scenarios). The old API still exists for fallback measures.
104-
100+
// Only cross-platform (v2) Fakes is supported. Fallback to v1 is removed.
105101
var crossPlatformConfigurator = TryGetFakesCrossPlatformDataCollectorConfigurator();
106102
if (crossPlatformConfigurator != null)
107103
{
@@ -118,7 +114,8 @@ private static bool TryAddFakesDataCollectorSettings(
118114
return true;
119115
}
120116

121-
return AddFallbackFakesSettings(runSettings, sources, framework);
117+
// Fakes v1 fallback support removed.
118+
return false;
122119
}
123120

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

160-
private static bool AddFallbackFakesSettings(
161-
XmlDocument runSettings,
162-
IEnumerable<string> sources,
163-
FrameworkVersion framework)
164-
{
165-
166-
// The fallback settings is for the old implementation of fakes
167-
// that only supports .Net Framework versions
168-
if (framework
169-
is not FrameworkVersion.Framework35
170-
and not FrameworkVersion.Framework40
171-
and not FrameworkVersion.Framework45)
172-
{
173-
return false;
174-
}
175-
176-
Func<IEnumerable<string>, string>? netFrameworkConfigurator = TryGetNetFrameworkFakesDataCollectorConfigurator();
177-
if (netFrameworkConfigurator == null)
178-
{
179-
return false;
180-
}
181-
182-
// if no fakes, return settings unchanged
183-
var fakesConfiguration = netFrameworkConfigurator(sources);
184-
if (fakesConfiguration == null)
185-
{
186-
return false;
187-
}
188-
189-
// integrate fakes settings in configuration
190-
// if the settings don't have any data collector settings, populate with empty settings
191-
EnsureSettingsNode(runSettings, new DataCollectionRunSettings());
192-
193-
// embed fakes settings
194-
var fakesSettings = CreateFakesDataCollectorSettings();
195-
var doc = new XmlDocument();
196-
using (var xmlReader = XmlReader.Create(
197-
new StringReader(fakesConfiguration),
198-
new XmlReaderSettings() { CloseInput = true }))
199-
{
200-
doc.Load(xmlReader);
201-
}
202-
203-
fakesSettings.Configuration = doc.DocumentElement;
204-
XmlRunSettingsUtilities.InsertDataCollectorsNode(runSettings.CreateNavigator()!, fakesSettings);
205-
206-
return true;
207-
}
208-
209157
/// <summary>
210158
/// Ensures that an xml element corresponding to the test run settings exists in the setting document.
211159
/// </summary>
@@ -225,27 +173,6 @@ private static void EnsureSettingsNode(XmlDocument settings, TestRunSettings set
225173
}
226174
}
227175

228-
private static Func<IEnumerable<string>, string>? TryGetNetFrameworkFakesDataCollectorConfigurator()
229-
{
230-
#if NETFRAMEWORK
231-
try
232-
{
233-
var assembly = LoadTestPlatformAssembly();
234-
var type = assembly?.GetType(ConfiguratorAssemblyQualifiedName, false);
235-
var method = type?.GetMethod(NetFrameworkConfiguratorMethodName, [typeof(IEnumerable<string>)]);
236-
if (method != null)
237-
{
238-
return (Func<IEnumerable<string>, string>)method.CreateDelegate(typeof(Func<IEnumerable<string>, string>));
239-
}
240-
}
241-
catch (Exception ex)
242-
{
243-
EqtTrace.Info("Failed to create Fakes Configurator. Reason:{0} ", ex);
244-
}
245-
#endif
246-
return null;
247-
}
248-
249176
private static Func<IDictionary<string, FrameworkVersion>, DataCollectorSettings>? TryGetFakesCrossPlatformDataCollectorConfigurator()
250177
{
251178
try
@@ -279,25 +206,6 @@ private static void EnsureSettingsNode(XmlDocument settings, TestRunSettings set
279206
return null;
280207
}
281208

282-
/// <summary>
283-
/// Adds the Fakes data collector settings in the run settings document.
284-
/// </summary>
285-
/// <returns>
286-
/// The <see cref="DataCollectorSettings"/>.
287-
/// </returns>
288-
private static DataCollectorSettings CreateFakesDataCollectorSettings()
289-
{
290-
// embed the fakes run settings
291-
var settings = new DataCollectorSettings
292-
{
293-
AssemblyQualifiedName = FakesMetadata.DataCollectorAssemblyQualifiedName,
294-
FriendlyName = FakesMetadata.FriendlyName,
295-
IsEnabled = true,
296-
Uri = new Uri(FakesMetadata.DataCollectorUriV1)
297-
};
298-
return settings;
299-
}
300-
301209
internal static class FakesMetadata
302210
{
303211
/// <summary>
@@ -306,12 +214,12 @@ internal static class FakesMetadata
306214
public const string FriendlyName = "UnitTestIsolation";
307215

308216
/// <summary>
309-
/// Gets the URI of the data collector
217+
/// Gets the URI of the data collector (V1, deprecated and removed)
310218
/// </summary>
311219
public const string DataCollectorUriV1 = "datacollector://microsoft/unittestisolation/1.0";
312220

313221
/// <summary>
314-
/// Gets the URI of the data collector
222+
/// Gets the URI of the data collector (V2)
315223
/// </summary>
316224
public const string DataCollectorUriV2 = "datacollector://microsoft/unittestisolation/2.0";
317225

0 commit comments

Comments
 (0)