forked from microsoft/vstest
/
InProcessProxyDiscoveryManager.cs
111 lines (96 loc) · 4.46 KB
/
InProcessProxyDiscoveryManager.cs
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
internal class InProcessProxyDiscoveryManager : IProxyDiscoveryManager
{
private ITestHostManagerFactory testHostManagerFactory;
private IDiscoveryManager discoveryManager;
private ITestRuntimeProvider testHostManager;
public bool IsInitialized { get; private set; } = false;
/// <summary>
/// Initializes a new instance of the <see cref="InProcessProxyDiscoveryManager"/> class.
/// </summary>
/// <param name="testHostManager">
/// The test Host Manager.
/// </param>
/// <param name="testHostManagerFactory">
/// Manager factory
/// </param>
public InProcessProxyDiscoveryManager(ITestRuntimeProvider testHostManager, ITestHostManagerFactory testHostManagerFactory)
{
this.testHostManager = testHostManager;
this.testHostManagerFactory = testHostManagerFactory;
this.discoveryManager = this.testHostManagerFactory.GetDiscoveryManager();
}
/// <summary>
/// Initializes test discovery.
/// <param name="skipDefaultAdapters">Skip default adapters flag.</param>
/// </summary>
public void Initialize(bool skipDefaultAdapters)
{
}
/// <summary>
/// Discovers tests
/// </summary>
/// <param name="discoveryCriteria">Settings, parameters for the discovery request</param>
/// <param name="eventHandler">EventHandler for handling discovery events from Engine</param>
public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)
{
Task.Run(() =>
{
try
{
// Initialize extension before discovery
this.InitializeExtensions(discoveryCriteria.Sources);
discoveryCriteria.UpdateDiscoveryCriteria(testHostManager);
this.discoveryManager.DiscoverTests(discoveryCriteria, eventHandler);
}
catch (Exception exception)
{
EqtTrace.Error("InProcessProxyDiscoveryManager.DiscoverTests: Failed to discover tests: {0}", exception);
// Send a discovery complete to caller.
eventHandler.HandleLogMessage(TestMessageLevel.Error, exception.ToString());
var discoveryCompeleteEventsArg = new DiscoveryCompleteEventArgs(-1, true);
eventHandler.HandleDiscoveryComplete(discoveryCompeleteEventsArg, Enumerable.Empty<TestCase>());
}
});
}
/// <summary>
/// Closes the current test operation.
/// This function is of no use in this context as we are not creating any testhost
/// </summary>
public void Close()
{
}
/// <summary>
/// Aborts the test operation.
/// </summary>
public void Abort()
{
Task.Run(() => this.testHostManagerFactory.GetDiscoveryManager().Abort());
}
private void InitializeExtensions(IEnumerable<string> sources)
{
var extensionsFromSource = this.testHostManager.GetTestPlatformExtensions(sources, Enumerable.Empty<string>());
if (extensionsFromSource.Any())
{
TestPluginCache.Instance.UpdateExtensions(extensionsFromSource, false);
}
// We don't need to pass list of extension as we are running inside vstest.console and
// it will use TestPluginCache of vstest.console
discoveryManager.Initialize(Enumerable.Empty<string>(), null);
}
}
}