I recently developed a stress/load testing tool. One of the classes implemented the Event-based Asynchronous Pattern. A good unit test for this class would be that the event is raised when expected (or at all). I found some posts on how to test events using NUnit. However, I did not see anything directly addressing the multi-threaded asynch event pattern. The following unit test uses an anonymous method and the ManualResetEvent to verify that the RunCompleted event fires after the call to RunAsync.
[Test()] public void AfterRunAsync() { ManualResetEvent manualEvent = new ManualResetEvent(false); TestTestCase tc = new TestTestCase(1, "", 0, 0); bool eventFired = false; tc.RunCompleted += delegate(object sender, AsyncCompletedEventArgs e) { Assert.IsInstanceOfType(typeof (TestTestCase), sender, "sender is TestCase"); bool passed = tc.Passed; string output = tc.Output; eventFired = true; manualEvent.Set(); }; tc.RunAsync(); manualEvent.WaitOne(500, false); Assert.IsTrue(eventFired, "RunCompleted fired"); }