DotnetStandardStreams/source/DotnetStandardStreamsTests/AnonOutputTargetTests.cs

48 lines
982 B
C#

using System;
using System.Collections.Generic;
using DotnetStandardStreams;
namespace DotnetStandardStreamsTests;
public class AnonOutputTargetTests
{
[Fact]
public void CanConstruct()
{
_ = new AnonOutputTarget(static s => { });
}
[Fact]
public void WritesEachLine()
{
List<string> expected = ["1", "2", "", "4", "5", "6", "7", "8", "9", "10"];
List<string> actual = new();
IOutputTarget target = new AnonOutputTarget(s => actual.Add(s));
foreach (string s in expected)
target.Output(s);
actual.ShouldBe(expected);
}
[Fact]
public void OutputsConditionally()
{
List<string> input = ["1", "2", "", "4", "5", "6", "7", "8", "9", "10"];
List<string> expected = ["2", "4", "6", "8", "10"];
List<string> actual = new();
IOutputTarget target = new AnonOutputTarget(s =>
{
if (int.TryParse(s, out int i))
if (i % 2 == 0)
actual.Add(s);
});
foreach (string s in input)
target.Output(s);
actual.ShouldBe(expected);
}
}