public void SendConnectionClosed()
        {
            Exception e = Assert.Throws <Exception>(delegate
            {
                testActiveMqRemoteSender.Send("<TestMessage>Test message content</TestMessage>");
            });

            Assert.That(e.Message, NUnit.Framework.Is.StringStarting("Connection to message queue is not open."));
        }
        public void SendMetricsTest()
        {
            ITextMessage  mockTextMessage           = mocks.NewMock <ITextMessage>();
            IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>();

            Expect.AtLeastOnce.On(mockConnection);
            Expect.AtLeastOnce.On(mockProducer);
            Expect.Once.On(mockSession).Method("CreateTextMessage").Will(Return.Value(mockTextMessage));
            Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties));
            Expect.Once.On(mockTextMessageProperties).Method("SetString").With(new object[2] {
                filterIdentifier, messageFilter
            });
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageSendTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageSendTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageSent()));
            }

            testActiveMqRemoteSender.Connect();
            testActiveMqRemoteSender.Send("<TestMessage>Test message content</TestMessage>");

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
コード例 #3
0
        public void SendLoggingTest()
        {
            ITextMessage  mockTextMessage           = mocks.NewMock <ITextMessage>();
            IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>();

            Expect.AtLeastOnce.On(mockConnection);
            Expect.AtLeastOnce.On(mockProducer);
            Expect.Once.On(mockSession).Method("CreateTextMessage").Will(Return.Value(mockTextMessage));
            Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties));
            Expect.Once.On(mockTextMessageProperties).Method("SetString").With(new object[2] {
                filterIdentifier, messageFilter
            });
            using (mocks.Ordered)
            {
                Expect.Once.On(mockApplicationLogger);
                Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteSender, LogLevel.Information, "Message sent.");
            }

            testActiveMqRemoteSender.Connect();
            testActiveMqRemoteSender.Send("<TestMessage>Test message content</TestMessage>");

            mocks.VerifyAllExpectationsHaveBeenMet();
        }