/
RunEventHandler.cs
82 lines (68 loc) · 2.35 KB
/
RunEventHandler.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
namespace Microsoft.TestPlatform.PerformanceTests.TranslationLayer;
/// <inheritdoc />
public class RunEventHandler : ITestRunEventsHandler2
{
/// <summary>
/// Gets the test results.
/// </summary>
public List<TestResult> TestResults { get; private set; }
/// <summary>
/// Gets the metrics.
/// </summary>
public IDictionary<string, object> Metrics { get; private set; } = new Dictionary<string, object>();
/// <summary>
/// Gets the log message.
/// </summary>
public List<string> LogMessages { get; } = new List<string>();
public RunEventHandler()
{
TestResults = new List<TestResult>();
}
public void HandleLogMessage(TestMessageLevel level, string message)
{
LogMessages.Add($"[{level.ToString().ToUpperInvariant()}]: {message}");
}
public void HandleTestRunComplete(
TestRunCompleteEventArgs testRunCompleteArgs,
TestRunChangedEventArgs lastChunkArgs,
ICollection<AttachmentSet> runContextAttachments,
ICollection<string> executorUris)
{
if (lastChunkArgs != null && lastChunkArgs.NewTestResults != null)
{
TestResults.AddRange(lastChunkArgs.NewTestResults);
}
Metrics = testRunCompleteArgs.Metrics;
if (testRunCompleteArgs.Error != null)
{
LogMessages.Add($"[ERROR] {testRunCompleteArgs.Error}");
}
}
public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedArgs)
{
if (testRunChangedArgs != null && testRunChangedArgs.NewTestResults != null)
{
TestResults.AddRange(testRunChangedArgs.NewTestResults);
}
}
public void HandleRawMessage(string rawMessage)
{
// No op
}
public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo)
{
// No op
return -1;
}
public bool AttachDebuggerToProcess(int pid)
{
// No op
return true;
}
}