public void OnErrorEventIsSecured()
{
int eventHandlerCount = 0;
int buggyEventHandlerCount = 0;
var hGood = new EventHandler<SystemActivityMonitor.LowLevelErrorEventArgs>( ( sender, e ) => { ++eventHandlerCount; } );
var hBad = new EventHandler<SystemActivityMonitor.LowLevelErrorEventArgs>( ( sender, e ) => { ++buggyEventHandlerCount; throw new Exception( "From buggy handler." ); } );
SystemActivityMonitor.OnError += hGood;
SystemActivityMonitor.OnError += hBad;
try
{
ActivityMonitor.CriticalErrorCollector.Add( new CKException( "The-Test-Exception-Message" ), "First call to SystemActivityMonitorTests.OnErrorEventIsSecured" );
ActivityMonitor.CriticalErrorCollector.WaitOnErrorFromBackgroundThreadsPending();
Assert.That( eventHandlerCount, Is.EqualTo( 2 ), "We also received the error of the buggy handler :-)." );
Assert.That( buggyEventHandlerCount, Is.EqualTo( 1 ) );
ActivityMonitor.CriticalErrorCollector.Add( new CKException( "The-Test-Exception-Message" ), "Second call to SystemActivityMonitorTests.OnErrorEventIsSecured" );
ActivityMonitor.CriticalErrorCollector.WaitOnErrorFromBackgroundThreadsPending();
Assert.That( eventHandlerCount, Is.EqualTo( 3 ) );
Assert.That( buggyEventHandlerCount, Is.EqualTo( 1 ) );
}
finally
{
SystemActivityMonitor.OnError -= hGood;
SystemActivityMonitor.OnError -= hBad;
}
}