Baseball.Tasks.OutputStatTest.ExecuteAndCaptureOutput C# (CSharp) Method

ExecuteAndCaptureOutput() static private method

static private ExecuteAndCaptureOutput ( Task task ) : string
task Task
return string
        static string ExecuteAndCaptureOutput(Task task)
        {
            string output;

            using (var stream = new MemoryStream())
            using (var writer = new StreamWriter(stream))
            using (var reader = new StreamReader(stream))
            {
                var previousOut = Console.Out;
                Console.SetOut(writer);
                task.Execute();
                Console.SetOut(previousOut);

                writer.Flush();
                stream.Seek(0, SeekOrigin.Begin);
                output = reader.ReadToEnd();
            }

            return output;
        }