예제 #1
0
        public void ExceptionsAtSubscriberLevel()
        {
            var alarm = new EventHandlerAlarm();

            alarm.OnAlarmRaised += EventArgsAlarmListener1Exception;
            alarm.OnAlarmRaised += EventArgsAlarmListener2;

            Assert.Equal(false, _alarm1Raised);
            Assert.Equal(false, _alarm2Raised);

            Exception ex = Assert.ThrowsAny <Exception>(() => alarm.RaiseAlarm("location1"));

            Assert.Equal("Listener 1 Failed", ex.Message);

            Assert.Equal(true, _alarm1Raised);
            Assert.Equal(false, _alarm2Raised);

            _alarm1Raised = false;
            _alarm2Raised = false;

            AggregateException aggEx = Assert.ThrowsAny <AggregateException>(() => alarm.RaiseAlarmWithAggregateException("location1"));

            Assert.Equal(aggEx.InnerExceptions[0].Message, "Listener 1 Failed");

            Assert.Equal(true, _alarm1Raised);
            Assert.Equal(true, _alarm2Raised);
        }
예제 #2
0
        public void EventHandlerPublishSubscribe()
        {
            var alarm = new EventHandlerAlarm();

            alarm.OnAlarmRaised += EventArgsAlarmListener1;
            alarm.OnAlarmRaised += EventArgsAlarmListener2;

            Assert.Equal(false, _alarm1Raised);
            Assert.Equal(false, _alarm2Raised);

            alarm.RaiseAlarm("location1");

            Assert.Equal(true, _alarm1Raised);
            Assert.Equal(true, _alarm2Raised);
        }