Attempted fix for 20.09 timing bug
Cleaned up CartographerTests to match its actual location in the book
MODIFY
src/Chapter20.Tests/CryptographerTests.cs
src/Chapter20.Tests/CryptographerTests.cs
using AddisonWesley.Michaelis.EssentialCSharp.Shared;
using System.Security.Cryptography;
-namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter19.Listing19_05.Tests
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_06.Tests
{
[TestClass]
public class CryptographerTests

MODIFY
src/Chapter20.Tests/Listing20.09.ImplementingCustomAsynchronousMethod.Tests.cs
src/Chapter20.Tests/Listing20.09.ImplementingCustomAsynchronousMethod.Tests.cs
@@ -12,8 +12,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_09.Tests
{
string expected = $@"Invoking Task.Run...(Thread ID: *)
Running task... (Thread ID: *)
-Post notification invoked...(Thread ID: *)
-Post notification invoked...(Thread ID: *)
+Post notification invoked...(Thread ID: *)*
Throwing expected exception....(Thread ID: *)
System.Exception: Expected Exception
*(Thread ID: *)";
@@ -59,7 +58,7 @@ System.Exception: Expected Exception
$"Match {i} was '{matches[i].Groups[0].Value}' when '{expectedThreadId}' was expected");
}
}
- Assert.AreEqual<int>(6, matches.Count, "There were not as many 'Thread Id' matches as expected.");
+ Assert.IsTrue(matches.Count >= 5, "There were not as many 'Thread Id' matches as expected.");
}
}
}

MODIFY
src/Chapter20/Listing20.09.CatchingExceptionFromAsyncVoidMethod.cs
src/Chapter20/Listing20.09.CatchingExceptionFromAsyncVoidMethod.cs
@@ -25,9 +25,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_09
}
finally
{
-#if !WithOutUsingResetEvent
ResetEvent.Set();
-#endif
}
}
@@ -45,9 +43,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_09
}
finally
{
-#if !WithOutUsingResetEvent
ResetEvent.Set();
-#endif
}
}
}
@@ -71,11 +67,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_09
OnEvent(typeof(Program), EventArgs.Empty);
-#if WithOutUsingResetEvent
- Task.Delay(1000).Wait();
-#else
synchronizationContext.ResetEvent.Wait();
-#endif
if (synchronizationContext.Exception != null)
{

Attempted fix for 20.09 timing bug (#338)

Cleaned up CartographerTests to match its actual location in the book