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