public void OutputStillMatchesCharacterization() { var inputsAndExpectations = new Dictionary <string, string>() { { "empty-fie.txt", "expectation-empty-file.text" }, { "one-field.txt", "expectation-one-field.txt" }, { "malformed-currency-pair.txt", "expectation-malformed-currency-pair.txt" }, { "trade-volume-invalid.txt", "expectation-trade-volume-invalid.txt" }, { "trade-amount-invalid.txt", "expectation-trade-amount-invalid.txt" }, { "correct-format.txt", "expectation-correct-format.txt" } }; var originalConsoleOut = Console.Out; foreach (var pair in inputsAndExpectations) { var input = typeof(GoldMaster).Assembly.GetManifestResourceStream(typeof(GoldMaster), pair.Key); var expectation = File.ReadAllText(Path.Combine(CharacterizationTestOutput, pair.Value)); string actual = null; using (var memoryStream = new MemoryStream()) { using (var streamwriter = new StreamWriter(memoryStream)) { Console.SetOut(streamwriter); var tradeProcessor = new TradeProcessor.TradeProcessor(); tradeProcessor.ProcessTrades(input); streamwriter.Flush(); memoryStream.Seek(0, SeekOrigin.Begin); actual = new StreamReader(memoryStream).ReadToEnd(); } Assert.AreEqual(expectation, actual); } } }
static void Main(string[] args) { var inputs = new List <string>() { "empty-file.txt" }; var originalConsoleOut = Console.Out; foreach (var input in inputs) { var tradeStream = Assembly.GetExecutingAssembly() .GetManifestResourceStream(typeof(Program), input); using (var stramWriter = new StreamWriter(File.OpenWrite($"expectation-{input}"))) { Console.SetOut(stramWriter); var tradeProcessor = new TradeProcessor(); tradeProcessor.ProcessTrades(tradeStream); } } Console.SetOut(originalConsoleOut); Console.ReadKey(); }