public void RegisteredErrorHandlerIsInvokedOnException()
        {
            SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();

            ISession session = (ISession)mocks.CreateMock(typeof(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 = (IConnection)mocks.CreateMock(typeof(IConnection));

            connection.ExceptionListener += container.OnException;
            Expect.Call(connection.CreateSession(container.SessionAcknowledgeMode)).Return(session);
            connection.Start();

            IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));

            Expect.Call(connectionFactory.CreateConnection()).Return(connection);

            IllegalStateException theException = new IllegalStateException(EXCEPTION_MESSAGE);

            IErrorHandler errorHandler = (IErrorHandler)mocks.CreateMock(typeof(IErrorHandler));

            errorHandler.HandleError(theException);

            IMessage message = (IMessage)mocks.CreateMock(typeof(IMessage));

            mocks.ReplayAll();


            container.ConnectionFactory = connectionFactory;
            container.DestinationName   = DESTINATION_NAME;
            container.MessageListener   = new BadSessionAwareMessageListener(theException);
            container.ErrorHandler      = errorHandler;
            container.AfterPropertiesSet();

            // manually trigger an Exception with the above bad MessageListener...
            messageConsumer.SendMessage(message);

            mocks.VerifyAll();
        }
        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();
        }
Exemplo n.º 3
0
        public void RegisteredErrorHandlerIsInvokedOnException()
        {
            SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();

            ISession session = A.Fake <ISession>();

            A.CallTo((() => session.GetQueue(DESTINATION_NAME))).Returns(QUEUE_DESTINATION);
            A.CallTo((() => session.CreateConsumer(QUEUE_DESTINATION, null))).Returns(messageConsumer);
            // an exception is thrown, so the rollback logic is being applied here...
            A.CallTo((() => session.Transacted)).Returns(false);

            IConnection connection = A.Fake <IConnection>();

            connection.ExceptionListener += container.OnException;
            A.CallTo((() => connection.CreateSession(container.SessionAcknowledgeMode))).Returns(session);
            connection.Start();

            IConnectionFactory connectionFactory = A.Fake <IConnectionFactory>();

            A.CallTo((() => connectionFactory.CreateConnection())).Returns(connection);

            IllegalStateException theException = new IllegalStateException(EXCEPTION_MESSAGE);

            IErrorHandler errorHandler = A.Fake <IErrorHandler>();

            errorHandler.HandleError(theException);

            IMessage message = A.Fake <IMessage>();

            container.ConnectionFactory = connectionFactory;
            container.DestinationName   = DESTINATION_NAME;
            container.MessageListener   = new BadSessionAwareMessageListener(theException);
            container.ErrorHandler      = errorHandler;
            container.AfterPropertiesSet();

            // manually trigger an Exception with the above bad MessageListener...
            messageConsumer.SendMessage(message);
        }