public void AssertingTrueFalseToOKReportsMessagesCorrectly() { var oldOut = Console.Out; StringBuilder builder = new StringBuilder(); Console.SetOut(new TestTextWriter(builder)); var okMessage = "hello!"; var condition = true; var result = TAP.Ok(condition, okMessage); Assert.Equal(condition, result); Assert.Equal("ok 1 - " + okMessage, builder.ToString()); builder.Clear(); condition = false; result = TAP.Ok(condition, okMessage); Assert.Equal(condition, result); Assert.StartsWith("not ok 2 - " + okMessage, builder.ToString()); Console.SetOut(oldOut); }
/******************** Test Area ***********************/ private async static void ExecuteTaskAsynchronousProgrammingExperiments() { PrintIntroText("async/await (TAP)"); //Note: experiments will be held and documented within TAP.cs TAP asyncLib = new TAP(); //1) you can use them to get resources from networks such as the internet string txtContent = await asyncLib.DownloadTXTFromInternetAsync(); Console.WriteLine($"The downloaded .txt contained:\n \\\"{txtContent}\\\""); //2) or to calculate expensive calculations (expens. in runtime or memory) // by giving this Task to another thread, freeing the UI thread (prevents unresponsive GUI). int[,] gameboard = asyncLib.setup2DGameBoard(); Boolean gameIsWon = await asyncLib.isTicTacToeGameWonAsync(gameboard); asyncLib.printGameBoard(gameboard); Console.WriteLine($"Has the TicTacToe match been won: {gameIsWon}"); /* Note: * ..that an async method will always return * - Task<T>, * - Task (for void (an async method returning nothing)) or * (- void (nothing -> nur für EventHandler).) * The await method converts a Task<string> automatically to a string * or return await - delegates it further ( a ..= await will be waiting). */ PrintOutroText("async/await (TAP)"); }
private static void DemonstrateTaskBasedAsynchronousPattern() { TAP tap = new TAP(); tap.ReadFilesSimultaneously(); }