public void WebDownloader_DownLoad() { // ARRANGE using var writer = new StringWriter(); Console.SetOut(writer); var webClientFactory = new TestableWebClientFactory(); // ACT var downloader = new WebDownloader(webClientFactory); downloader.DownLoad("some web file", "myfile.csv"); webClientFactory.TestClient .InvokeDownloadProgressChanged(10, 1024) .InvokeDownloadProgressChanged(100, 1024 * 100) .InvokeDownloadCompleted(); writer.Flush();// Ensure writer is flushed // ASSERT var expectedOutput = new[] { "Downloading some web file...", "Downloading...10% complete (1,024 bytes)", "Downloading...100% complete (102,400 bytes)", "Downloaded to myfile.csv ", string.Empty }; var actualConsoleLines = writer.ToString().Split(Environment.NewLine); CollectionAssert.AreEqual(expectedOutput, actualConsoleLines); }