We have a system with deal with messages. Each message has a expiry time associated with it. A worker thread is continously running in the background and collect the messages those are expired and need to be removed. The worker thread sends the id of such messages to next service.
In nunit test cases we are creating dummy messages and checking if its state is set to expired at the end of test case. But for this we have to put thread.sleep in the test cases to wait until the worker thread finishes its task. However the sleep is also not reliable as the respose from worker depend on the number of records in the database.
What should be strategy to test such scenario using nunit and C#.
OnExpiredMessagesReceived) which notifies that service has received ids of expired messages.ManualResetEventin your test to wait until event from the service is received. Then you must compare received ids with expected ones.