-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathMSTestDiscoverer.cs
More file actions
82 lines (73 loc) · 3.41 KB
/
MSTestDiscoverer.cs
File metadata and controls
82 lines (73 loc) · 3.41 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
// 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.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;
/// <summary>
/// Contains the discovery logic for this adapter.
/// </summary>
[DefaultExecutorUri(MSTestAdapter.PlatformServices.EngineConstants.ExecutorUriString)]
[FileExtension(".xap")]
[FileExtension(".appx")]
[FileExtension(".dll")]
[FileExtension(".exe")]
internal sealed class MSTestDiscoverer : ITestDiscoverer
{
private readonly ITestSourceHandler _testSourceHandler;
#if !WINDOWS_UWP && !WIN_UI
private readonly Func<string, IDictionary<string, object>, Task>? _telemetrySender;
#endif
public MSTestDiscoverer()
: this(new TestSourceHandler())
{
}
internal MSTestDiscoverer(ITestSourceHandler testSourceHandler, Func<string, IDictionary<string, object>, Task>? telemetrySender = null)
{
_testSourceHandler = testSourceHandler;
#if !WINDOWS_UWP && !WIN_UI
_telemetrySender = telemetrySender;
#else
_ = telemetrySender;
#endif
}
/// <summary>
/// Discovers the tests available from the provided source. Not supported for .xap source.
/// </summary>
/// <param name="sources">Collection of test containers.</param>
/// <param name="discoveryContext">Context in which discovery is being performed.</param>
/// <param name="logger">Logger used to log messages.</param>
/// <param name="discoverySink">Used to send testcases and discovery related events back to Discoverer manager.</param>
[System.Security.SecurityCritical]
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Discovery context can be null.")]
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
=> DiscoverTests(sources, discoveryContext, logger, discoverySink, null);
internal void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink, IConfiguration? configuration)
{
Ensure.NotNull(sources);
Ensure.NotNull(logger);
Ensure.NotNull(discoverySink);
// Initialize telemetry collection if not already set (e.g. first call in the session)
#if !WINDOWS_UWP && !WIN_UI
if (!MSTestTelemetryDataCollector.IsTelemetryOptedOut())
{
_ = MSTestTelemetryDataCollector.EnsureInitialized();
}
#endif
try
{
if (MSTestDiscovererHelpers.InitializeDiscovery(sources, discoveryContext, logger, configuration, _testSourceHandler))
{
new UnitTestDiscoverer(_testSourceHandler).DiscoverTests(sources, logger, discoverySink, discoveryContext);
}
}
finally
{
#if !WINDOWS_UWP && !WIN_UI
MSTestTelemetryDataCollector.SendTelemetryAndResetAsync(_telemetrySender).GetAwaiter().GetResult();
#endif
}
}
}