Inheritance: System.Exception
        public void RegisteredExceptionListenerIsInvokedOnException()
        {
            SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();

            ISession session = mocks.StrictMock<ISession>();
            Expect.Call(session.GetQueue(DESTINATION_NAME)).Return(QUEUE_DESTINATION);
            Expect.Call(session.CreateConsumer(QUEUE_DESTINATION, null)).Return(messageConsumer);
            // an exception is thrown, so the rollback logic is being applied here...
            Expect.Call(session.Transacted).Return(false);

            IConnection connection = mocks.StrictMock<IConnection>();
            connection.ExceptionListener += container.OnException;
            Expect.Call(connection.CreateSession(container.SessionAcknowledgeMode)).Return(session);
            connection.Start();
            
            IConnectionFactory connectionFactory = mocks.StrictMock<IConnectionFactory>();
            Expect.Call(connectionFactory.CreateConnection()).Return(connection);

            NMSException theException = new NMSException(EXCEPTION_MESSAGE);

            IExceptionListener exceptionListener = mocks.StrictMock<IExceptionListener>();
            exceptionListener.OnException(theException);

            IMessage message = mocks.StrictMock<IMessage>();

            mocks.ReplayAll();


            container.ConnectionFactory = connectionFactory;
            container.DestinationName = DESTINATION_NAME;
            container.MessageListener = new BadSessionAwareMessageListener(theException);
            container.ExceptionListener = exceptionListener;
            container.AfterPropertiesSet();

            // manually trigger an Exception with the above bad MessageListener...
            messageConsumer.SendMessage(message);
            mocks.VerifyAll();
        }
 public BadSessionAwareMessageListener(NMSException exception)
 {
     this.exception = exception;
 }