public void GoldenMasterTest() { for (int i = 0; i < 10000; i++) { GameRunner.Main(new[] { i.ToString() }); var expectedContent = _writer.ToString(); var actualContent = GoldenMaster.GetResult(i); Assert.That(actualContent, Is.EqualTo(expectedContent)); _writer.GetStringBuilder().Clear(); } }
private static string GenerateExpectedResult(int i) { TextWriter oldOut = Console.Out; string result; MemoryStream memoryStream = new MemoryStream(); StreamWriter writer = new StreamWriter(memoryStream); Console.SetOut(writer); GameRunner.Main(new[] { i.ToString() }); writer.Flush(); try { File.WriteAllBytes($"{AppDomain.CurrentDomain.BaseDirectory}/resources/output{i}.txt", memoryStream.ToArray()); } catch (IOException e) { Console.WriteLine(e.StackTrace); } finally { memoryStream.Position = 0; StreamReader reader = new StreamReader(memoryStream); result = reader.ReadToEnd(); memoryStream.SetLength(0); Console.SetOut(oldOut); try { memoryStream.Close(); writer.Close(); } catch (IOException e) { Console.WriteLine(e.StackTrace); } } return(result); }