From ac58f0dd27449d1030f8f972eb220b78aac4a7e6 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Sat, 4 Nov 2023 17:49:45 +0100 Subject: [PATCH] Rework logic slightly --- src/Chapter19.Tests/Listing19.07.Tests.cs | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Chapter19.Tests/Listing19.07.Tests.cs b/src/Chapter19.Tests/Listing19.07.Tests.cs index 403133347..b1fcc50d3 100644 --- a/src/Chapter19.Tests/Listing19.07.Tests.cs +++ b/src/Chapter19.Tests/Listing19.07.Tests.cs @@ -1,5 +1,4 @@ - -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter19.Listing19_07.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter19.Listing19_07.Tests; [TestClass] public class ProgramTests @@ -8,14 +7,21 @@ public class ProgramTests public void ValueTaskAsyncReturnTest() { string expected = -@"*:*:Sleeping for 2000 ms -*:*:Throwing exception. -*:*:Event handler starting -*:*:Sleeping for 4000 ms -*:*:Awake -*:*:Finally block running."; +@"Sleeping for 2000 ms +Throwing exception. +Event handler starting +Sleeping for 4000 ms +Awake +Finally block running."; - IntelliTect.TestTools.Console.ConsoleAssert.ExpectLike(expected, - Program.Main); + string output = IntelliTect.TestTools.Console.ConsoleAssert.Execute(string.Empty, + Program.Main).TrimEnd(); + + // Assert that all expected lines are present. + Assert.IsTrue(expected.Split(Environment.NewLine).All(output.Contains)); + + // Assert that the thread ID (first number in each line) is not the same for all lines. + Assert.AreEqual(2, output.Split(Environment.NewLine).Select( + line => line.Split(':')[0]).Distinct().Count()); } } \ No newline at end of file