public void ReceiveLoggingTest()
        {
            ITextMessage  mockTextMessage           = mocks.NewMock <ITextMessage>();
            IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>();
            string        receivedMessage           = "<?xml version=\"1.0\" encoding=\"utf-8\"?><MethodInvocation><MethodName>TestMethod</MethodName><Parameters><Parameter><DataType>string</DataType><Data>abc</Data></Parameter><Parameter><DataType>integer</DataType><Data>123</Data></Parameter><Parameter /><Parameter><DataType>double</DataType><Data>4.5678899999999999e+002</Data></Parameter></Parameters><ReturnType /></MethodInvocation>";
            string        smallMessage = "<TestMessage>Test message content</TestMessage>";

            using (mocks.Ordered)
            {
                // Expects for Connect()
                Expect.AtLeastOnce.On(mockConnection);
                Expect.Once.On(mockApplicationLogger);
                // Expects for first Receive()
                Expect.Once.On(mockConsumer).Method("Receive").WithAnyArguments().Will(Return.Value(mockTextMessage));
                Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties));
                Expect.Once.On(mockTextMessageProperties).Method("GetString").With("Text").Will(Return.Value(receivedMessage));
                Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteReceiver, LogLevel.Information, "Received message '<?xml version=\"1.0\" encoding=\"utf-8\"?><MethodInvocation><MethodName>TestMethod</MethodName><Parameters><Parameter><DataT' (truncated).");
                Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteReceiver, LogLevel.Debug, "Complete message content: '" + receivedMessage + "'.");
                // Expects for second Receive()
                Expect.Once.On(mockConsumer).Method("Receive").WithAnyArguments().Will(Return.Value(mockTextMessage));
                Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties));
                Expect.Once.On(mockTextMessageProperties).Method("GetString").With("Text").Will(Return.Value(smallMessage));
                Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteReceiver, LogLevel.Information, "Received message '" + smallMessage + "'.");
                Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteReceiver, LogLevel.Debug, "Complete message content: '" + smallMessage + "'.");
            }

            testActiveMqRemoteReceiver.Connect();
            testActiveMqRemoteReceiver.Receive();
            testActiveMqRemoteReceiver.Receive();

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void ReceiveConnectionClosed()
        {
            Exception e = Assert.Throws <Exception>(delegate
            {
                testActiveMqRemoteReceiver.Receive();
            });

            Assert.That(e.Message, NUnit.Framework.Is.StringStarting("Connection to message queue is not open."));
        }
        public void ReceiveMetricsTest()
        {
            ITextMessage  mockTextMessage           = mocks.NewMock <ITextMessage>();
            IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>();
            string        receivedMessage           = "<?xml version=\"1.0\" encoding=\"utf-8\"?><MethodInvocation><MethodName>TestMethod</MethodName><Parameters><Parameter><DataType>string</DataType><Data>abc</Data></Parameter><Parameter><DataType>integer</DataType><Data>123</Data></Parameter><Parameter /><Parameter><DataType>double</DataType><Data>4.5678899999999999e+002</Data></Parameter></Parameters><ReturnType /></MethodInvocation>";

            using (mocks.Ordered)
            {
                // Expects for Connect()
                Expect.AtLeastOnce.On(mockConnection);
                // Expects for first Receive()
                Expect.Once.On(mockConsumer).Method("Receive").WithAnyArguments().Will(Return.Value(mockTextMessage));
                Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties));
                Expect.Once.On(mockTextMessageProperties).Method("GetString").With("Text").Will(Return.Value(receivedMessage));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(381)));
            }

            testActiveMqRemoteReceiver.Connect();
            testActiveMqRemoteReceiver.Receive();

            mocks.VerifyAllExpectationsHaveBeenMet();
        }