Exemplo n.º 1
0
        public void TestRecoveredMessageShouldNotBeMutated()
        {
            using (TestAmqpPeer testAmqpPeer = new TestAmqpPeer(Address, User, Password))
            {
                string originalPayload = "testMessage";

                testAmqpPeer.Open();
                testAmqpPeer.RegisterLinkProcessor(new TestLinkProcessor());
                testAmqpPeer.SendMessage("myQueue", originalPayload);

                NmsConnection connection = (NmsConnection)EstablishConnection();
                connection.Start();
                ISession         session     = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
                IQueue           destination = session.GetQueue("myQueue");
                IMessageConsumer consumer    = session.CreateConsumer(destination);

                NmsTextMessage message = consumer.Receive() as NmsTextMessage;
                Assert.NotNull(message);
                message.IsReadOnlyBody = false;
                message.Text           = message.Text + "Received";

                session.Recover();

                ITextMessage recoveredMessage = consumer.Receive() as ITextMessage;
                Assert.IsNotNull(recoveredMessage);
                Assert.AreNotEqual(message.Text, recoveredMessage.Text);
                Assert.AreEqual(originalPayload, recoveredMessage.Text);
                Assert.AreNotSame(message, recoveredMessage);

                consumer.Close();
                session.Close();
                connection.Close();
            }
        }
        public void TestWriteOnlyBody()
        {
            NmsTextMessage textMessage = factory.CreateTextMessage();

            textMessage.IsReadOnly = false;

            try
            {
                textMessage.Text = "test";
                string text = textMessage.Text;
            }
            catch (MessageNotReadableException)
            {
                Assert.Fail("should be readable");
            }

            textMessage.IsReadOnly = true;
            try
            {
                string text = textMessage.Text;
                textMessage.Text = "test";
                Assert.Fail("should throw exception");
            }
            catch (MessageNotReadableException)
            {
                Assert.Fail("should be readable");
            }
            catch (MessageNotWriteableException) { }
        }
Exemplo n.º 3
0
        public NmsTextMessage CreateTextMessage(string payload)
        {
            NmsTextMessage message = CreateTextMessage();

            message.Text = payload;
            return(message);
        }
        public void TestNullText()
        {
            NmsTextMessage textMessage = factory.CreateTextMessage();

            textMessage.Text = null;
            Assert.Null(textMessage.Text);
        }
        public void TestSetText()
        {
            NmsTextMessage nmsTextMessage = factory.CreateTextMessage();
            string         str            = "testText";

            nmsTextMessage.Text = str;
            Assert.AreEqual(str, nmsTextMessage.Text);
        }
        public void TestMessageCopy()
        {
            NmsTextMessage message = factory.CreateTextMessage();

            NmsTextMessage copy = message.Copy() as NmsTextMessage;

            Assert.IsNotNull(copy);
        }
        public void TestCreateTextMessageString()
        {
            AmqpMessageFactory factory = new AmqpMessageFactory(CreateMockAmqpConnection());
            NmsTextMessage     message = factory.CreateTextMessage("SomeValue");
            INmsMessageFacade  facade  = message.Facade;

            Assert.IsInstanceOf <NmsTextMessage>(message);
            Assert.IsInstanceOf <AmqpNmsTextMessageFacade>(facade);
            Assert.AreEqual(MessageSupport.JMS_TYPE_TXT, facade.JmsMsgType);

            Assert.AreEqual("SomeValue", ((AmqpNmsTextMessageFacade)facade).Text);
        }
Exemplo n.º 8
0
        public void TestEmptyForeignTextMessageTransformCreateNewMessage()
        {
            ForeignNmsTextMessage foreignMessage = new ForeignNmsTextMessage();

            NmsMessage transformed = NmsMessageTransformation.TransformMessage(factory, foreignMessage);

            Assert.IsNotNull(transformed);
            Assert.AreNotSame(foreignMessage, transformed);

            Assert.IsInstanceOf <NmsTextMessage>(transformed);
            NmsTextMessage message = (NmsTextMessage)transformed;

            Assert.IsNull(message.Text);
        }
Exemplo n.º 9
0
        public void TestForeignTextMessageTransformCreateNewMessage()
        {
            string messageBody = "TEST-MESSAGE-BODY";
            ForeignNmsTextMessage foreignMessage = new ForeignNmsTextMessage {
                Text = messageBody
            };

            NmsMessage transformed = NmsMessageTransformation.TransformMessage(factory, foreignMessage);

            Assert.IsNotNull(transformed);
            Assert.AreNotSame(foreignMessage, transformed);

            Assert.IsInstanceOf <NmsTextMessage>(transformed);
            NmsTextMessage message = (NmsTextMessage)transformed;

            Assert.AreEqual(messageBody, message.Text);
        }
        public async Task TestRecoveredMessageShouldNotBeMutated()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                IConnection connection = await EstablishConnectionAsync(testPeer);

                await connection.StartAsync();

                testPeer.ExpectBegin();
                ISession session = await connection.CreateSessionAsync(AcknowledgementMode.ClientAcknowledge);

                IQueue destination = await session.GetQueueAsync("myQueue");

                string originalPayload = "testMessage";

                testPeer.ExpectReceiverAttach();
                testPeer.ExpectLinkFlowRespondWithTransfer(message: new Amqp.Message {
                    BodySection = new AmqpValue()
                    {
                        Value = originalPayload
                    }
                }, count: 1);

                IMessageConsumer consumer = await session.CreateConsumerAsync(destination);

                NmsTextMessage message = await consumer.ReceiveAsync() as NmsTextMessage;

                Assert.NotNull(message);
                message.IsReadOnlyBody = false;
                message.Text           = message.Text + "Received";
                await session.RecoverAsync();

                ITextMessage recoveredMessage = await consumer.ReceiveAsync() as ITextMessage;

                Assert.IsNotNull(recoveredMessage);
                Assert.AreNotEqual(message.Text, recoveredMessage.Text);
                Assert.AreEqual(originalPayload, recoveredMessage.Text);
                Assert.AreNotSame(message, recoveredMessage);

                testPeer.ExpectClose();
                await connection.CloseAsync();

                testPeer.WaitForAllMatchersToComplete(2000);
            }
        }
        public void TestClearBody()
        {
            NmsTextMessage nmsTextMessage = factory.CreateTextMessage();

            nmsTextMessage.Text = "string";
            nmsTextMessage.ClearBody();
            Assert.False(nmsTextMessage.IsReadOnly);
            Assert.IsNull(nmsTextMessage.Text);
            try
            {
                nmsTextMessage.Text = "String";
                var text = nmsTextMessage.Text;
            }
            catch (MessageNotWriteableException)
            {
                Assert.Fail("Should be writable");
            }
            catch (MessageNotReadableException)
            {
                Assert.Fail("should be readable");
            }
        }
        public void TestRecoveredMessageShouldNotBeMutated()
        {
            using (TestAmqpPeer testPeer = new TestAmqpPeer())
            {
                var context = EstablishNMSContext(testPeer, acknowledgementMode: AcknowledgementMode.ClientAcknowledge);
                context.Start();

                testPeer.ExpectBegin();
                IQueue destination     = context.GetQueue("myQueue");
                string originalPayload = "testMessage";

                testPeer.ExpectReceiverAttach();
                testPeer.ExpectLinkFlowRespondWithTransfer(message: new Amqp.Message {
                    BodySection = new AmqpValue()
                    {
                        Value = originalPayload
                    }
                }, count: 1);

                var            consumer = context.CreateConsumer(destination);
                NmsTextMessage message  = consumer.Receive() as NmsTextMessage;
                Assert.NotNull(message);
                message.IsReadOnlyBody = false;
                message.Text           = message.Text + "Received";
                context.Recover();

                ITextMessage recoveredMessage = consumer.Receive() as ITextMessage;
                Assert.IsNotNull(recoveredMessage);
                Assert.AreNotEqual(message.Text, recoveredMessage.Text);
                Assert.AreEqual(originalPayload, recoveredMessage.Text);
                Assert.AreNotSame(message, recoveredMessage);

                testPeer.ExpectEnd();
                testPeer.ExpectClose();
                context.Close();

                testPeer.WaitForAllMatchersToComplete(2000);
            }
        }
        public void TestToString()
        {
            NmsTextMessage textMessage = factory.CreateTextMessage();

            Assert.True(textMessage.ToString().StartsWith("NmsTextMessage"));
        }