-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unit test failure with console output by making IAnsiConsole user…
…-providable
- Loading branch information
Showing
6 changed files
with
125 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Spectre.Console; | ||
using Xunit.Abstractions; | ||
|
||
namespace Rucksack.Tests.Util; | ||
|
||
public static class LoadTestOptionsFactory | ||
{ | ||
public static LoadTestOptions Create(ILoadStrategy strategy, ITestOutputHelper testOutputHelper) | ||
=> new() | ||
{ | ||
LoadStrategy = strategy, | ||
LoggerFactory = LoggerFactory.Create(builder => | ||
{ | ||
builder.AddXUnit(testOutputHelper); | ||
}), | ||
Console = AnsiConsole.Create(new AnsiConsoleSettings | ||
{ | ||
Ansi = AnsiSupport.No, | ||
ColorSystem = ColorSystemSupport.NoColors, | ||
Out = new AnsiConsoleOutput(new TestOutputHelperTextWriterAdapter(testOutputHelper)), | ||
}) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Text; | ||
using Xunit.Abstractions; | ||
|
||
namespace Rucksack.Tests.Util; | ||
|
||
public class TestOutputHelperTextWriterAdapter(ITestOutputHelper output) | ||
: TextWriter | ||
{ | ||
private string currentLine = ""; | ||
|
||
public override void Write(char value) | ||
{ | ||
if (value == '\n') | ||
{ | ||
WriteCurrentLine(); | ||
} | ||
else | ||
{ | ||
currentLine += value; | ||
} | ||
} | ||
|
||
public override Encoding Encoding => Encoding.Default; | ||
|
||
private void WriteCurrentLine() | ||
{ | ||
output.WriteLine(currentLine); | ||
currentLine = ""; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (currentLine != "") | ||
{ | ||
WriteCurrentLine(); | ||
} | ||
|
||
base.Dispose(disposing); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters