-
Notifications
You must be signed in to change notification settings - Fork 315
/
DesignModeTestEventsRegistrar.cs
66 lines (51 loc) · 2.1 KB
/
DesignModeTestEventsRegistrar.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
// 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.Common.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode;
/// <summary>
/// Registers the discovery and test run events for design mode flow
/// </summary>
public class DesignModeTestEventsRegistrar : ITestDiscoveryEventsRegistrar, ITestRunEventsRegistrar
{
private readonly IDesignModeClient _designModeClient;
public DesignModeTestEventsRegistrar(IDesignModeClient designModeClient)
{
_designModeClient = designModeClient;
}
#region ITestDiscoveryEventsRegistrar
public void RegisterDiscoveryEvents(IDiscoveryRequest discoveryRequest)
{
discoveryRequest.OnRawMessageReceived += OnRawMessageReceived;
}
public void UnregisterDiscoveryEvents(IDiscoveryRequest discoveryRequest)
{
discoveryRequest.OnRawMessageReceived -= OnRawMessageReceived;
}
#endregion
#region ITestRunEventsRegistrar
public void RegisterTestRunEvents(ITestRunRequest testRunRequest)
{
testRunRequest.OnRawMessageReceived += OnRawMessageReceived;
}
public void UnregisterTestRunEvents(ITestRunRequest testRunRequest)
{
testRunRequest.OnRawMessageReceived -= OnRawMessageReceived;
}
#endregion
/// <summary>
/// RawMessage received handler for getting rawmessages directly from the host
/// </summary>
/// <param name="sender"></param>
/// <param name="rawMessage">RawMessage from the testhost</param>
private void OnRawMessageReceived(object? sender, string rawMessage)
{
// Directly send the data to translation layer instead of de-serializing it here
_designModeClient.SendRawMessage(rawMessage);
}
public void LogWarning(string? message)
{
_designModeClient.SendTestMessage(TestMessageLevel.Warning, message);
}
}