Repository navigation
Expand file tree
/
Copy pathRunSettingsAdapter.cs
More file actions
84 lines (71 loc) · 3.42 KB
/
Copy pathRunSettingsAdapter.cs
File metadata and controls
84 lines (71 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Testing.Extensions.VSTestBridge.Helpers;
using Microsoft.Testing.Extensions.VSTestBridge.Resources;
using Microsoft.Testing.Platform.CommandLine;
using Microsoft.Testing.Platform.Configurations;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Logging;
using Microsoft.Testing.Platform.Services;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
namespace Microsoft.Testing.Extensions.VSTestBridge.ObjectModel;
/// <summary>
/// A Microsoft Testing Platform oriented implementation of the VSTest <see cref="IRunSettings"/>.
/// </summary>
internal sealed class RunSettingsAdapter : IRunSettings
{
private static readonly string[] UnsupportedRunConfigurationSettings = [
"DotnetHostPath",
"MaxCpuCount",
"TargetFrameworkVersion",
"TargetPlatform",
"TestAdaptersPaths",
"TestSessionTimeout",
"TreatNoTestsAsError",
"TreatTestAdapterErrorsAsWarnings",
];
public RunSettingsAdapter(
ICommandLineOptions commandLineOptions,
IFileSystem fileSystem,
IConfiguration configuration,
IClientInfo client,
ILoggerFactory loggerFactory,
IMessageLogger messageLogger)
{
string runSettingsXml = RunSettingsHelpers.ReadRunSettings(commandLineOptions, fileSystem);
XDocument runSettingsDocument = RunSettingsPatcher.Patch(runSettingsXml, configuration, client, commandLineOptions);
WarnOnUnsupportedEntries(runSettingsDocument, messageLogger);
SettingsXml = runSettingsDocument.ToString();
ILogger<RunSettingsAdapter> logger = loggerFactory.CreateLogger<RunSettingsAdapter>();
logger.LogDebug($"Execution will use the following runsettings:{Environment.NewLine}{SettingsXml}");
}
/// <inheritdoc />
public string? SettingsXml { get; }
/// <inheritdoc />
// Needs to be implemented if used by adapters. It is not used by MSTest.
public ISettingsProvider? GetSettings(string? settingsName) => throw new NotImplementedException();
private static void WarnOnUnsupportedEntries(XDocument document, IMessageLogger messageLogger)
{
XElement runSettingsElement = document.Element("RunSettings")!;
if (runSettingsElement.Element("LoggerRunSettings") is not null)
{
messageLogger.SendMessage(TestMessageLevel.Warning, ExtensionResources.UnsupportedRunsettingsLoggers);
}
if (runSettingsElement.Element("DataCollectionRunSettings") is not null)
{
messageLogger.SendMessage(TestMessageLevel.Warning, ExtensionResources.UnsupportedRunsettingsDatacollectors);
}
if (runSettingsElement.Element("RunConfiguration") is not { } runConfigurationElement)
{
return;
}
foreach (string unsupportedRunConfigurationSetting in UnsupportedRunConfigurationSettings)
{
if (runConfigurationElement.Element(unsupportedRunConfigurationSetting) is not null)
{
messageLogger.SendMessage(TestMessageLevel.Warning, string.Format(CultureInfo.InvariantCulture, ExtensionResources.UnsupportedRunconfigurationSetting, unsupportedRunConfigurationSetting));
}
}
}
}