NUnit testing asynchronous events
October 25, 2006
In my current project we are using a some asynchronous webservice method calls. The actual call are in turn encapsulated in a layer that is used by the GUI, the “ClientCommand”-layer.
However when writing tests for these method we ran into trouble…. First the NUnit-framework is not very good at handling events at all, but by using this excellent article by Peter Provost I got a nice, compact way of doing the tests.
Then it was the whole asynchronous thing, which really was hard to get by. The solution given above worked out fine as long as not any assertions went threw exceptions - but what is the use of that?
So the simple solution to the problem was to simply wait for the event to fire and be handled. This was solved by setting a bool variable (bEventHandled) and not continue with the assertions until that bool was...