-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathSharedTestOutputHelper.cs
More file actions
53 lines (45 loc) · 1.53 KB
/
SharedTestOutputHelper.cs
File metadata and controls
53 lines (45 loc) · 1.53 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Text;
using Xunit;
using Xunit.Sdk;
using Xunit.v3;
namespace Microsoft.TemplateEngine.TestHelper
{
/// <summary>
/// This is so we can pass ITestOutputHelper to TestCommand constructor
/// when calling from SharedHomeDirectory.
/// </summary>
public class SharedTestOutputHelper : ITestOutputHelper
{
private readonly IMessageSink _sink;
private readonly StringBuilder _output = new();
public SharedTestOutputHelper(IMessageSink sink)
{
this._sink = sink;
}
public string Output => _output.ToString();
public void Write(string message)
{
_output.Append(message);
_sink.OnMessage(new DiagnosticMessage(message));
}
public void Write(string format, params object[] args)
{
string message = string.Format(format, args);
_output.Append(message);
_sink.OnMessage(new DiagnosticMessage(message));
}
public void WriteLine(string message)
{
_output.AppendLine(message);
_sink.OnMessage(new DiagnosticMessage(message));
}
public void WriteLine(string format, params object[] args)
{
string message = string.Format(format, args);
_output.AppendLine(message);
_sink.OnMessage(new DiagnosticMessage(message));
}
}
}