Can Visual Studio Test Projects Handle Events and Delegates?
I am working on new functionality for a large C # project that is mostly legacy code. The area I'm working on is processing XML Schema messages, creating a schedule for sending them, and putting them in some old timer code that notifies me when they should be sent.
Even though I'm new to them, Visual Studio test projects prove to be useful in that I can test my code without trying to fully start the system (this can take up to 30 minutes on test hardware!).
I have statically tested the event handling code, but now I would like to do it dynamically. Is it possible? If so, how do I make my test project wait for an event without a timeout?
a source to share
If you understand correctly, you could use the wait descriptor to signal this event and have your test project wait for the event to be reported.
void Foo()
{
var eventSource = ...;
var waitHandle = new ManualResetEvent(false);
eventSource.SomeEvent += (sender, e) => waitHandle.Set();
...
// Wait for the event to be fired.
waitHandle.WaitOne();
}
a source to share