forked from Azure/azure-sdk-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestOutputHelper.cs
More file actions
85 lines (72 loc) · 1.86 KB
/
TestOutputHelper.cs
File metadata and controls
85 lines (72 loc) · 1.86 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
85
using Azure.Sdk.Tools.Cli.Helpers;
namespace Azure.Sdk.Tools.Cli.Tests.Mocks.Helpers;
/// <summary>
/// An IOutputHelper implementation that can be used in test.
/// It accumulates all the outputs into a List, which you can assert on
/// after the test is complete.
/// </summary>
internal class TestOutputHelper : IOutputHelper
{
/// <summary>
/// All the collected outputs, in the order they were added.
/// The Method is the actual name of the method in the OutputService
/// </summary>
public IEnumerable<(string Method, object OutputValue)> Outputs => outputs;
private readonly List<(string Method, object OutputValue)> outputs;
public TestOutputHelper()
{
outputs = [];
}
public string Format(object response)
{
lock (outputs)
{
outputs.Add((nameof(Format), response));
}
return response?.ToString() ?? string.Empty;
}
public void Output(object output)
{
lock (outputs)
{
outputs.Add((nameof(Output), output));
}
}
public void Output(string output)
{
lock (outputs)
{
outputs.Add((nameof(Output), output));
}
}
public void OutputError(object output)
{
lock (outputs)
{
outputs.Add((nameof(OutputError), output));
}
}
public void OutputError(string output)
{
lock (outputs)
{
outputs.Add((nameof(OutputError), output));
}
}
public void OutputConsole(string output)
{
return;
}
public void OutputConsoleError(string output)
{
return;
}
public string ValidateAndFormat<T>(string response)
{
lock (outputs)
{
outputs.Add((nameof(ValidateAndFormat), response));
}
return response ?? string.Empty;
}
}