示例#1
0
        protected void AssertMessageIsReadOnly(IMessage message)
        {
            IBytesMessage theMessage = message as IBytesMessage;

            Assert.IsNotNull(theMessage);
            try
            {
                theMessage.WriteBoolean(true);
                theMessage.WriteByte((byte)1);
                theMessage.WriteBytes(new byte[1]);
                theMessage.WriteBytes(new byte[3], 0, 2);
                theMessage.WriteChar('a');
                theMessage.WriteDouble(1.5);
                theMessage.WriteSingle((float)1.5);
                theMessage.WriteInt32(1);
                theMessage.WriteInt64(1);
                theMessage.WriteObject("stringobj");
                theMessage.WriteInt16((short)1);
                theMessage.WriteString("utfstring");
                Assert.Fail("Message should not have been Writable");
            }
            catch (MessageNotWriteableException)
            {
            }
        }
        protected void AssertMessageIsReadOnly(IMessage message)
        {
            Type          writeableExceptionType = typeof(MessageNotWriteableException);
            IBytesMessage theMessage             = message as IBytesMessage;

            Assert.IsNotNull(theMessage);
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteBoolean(true); });
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteByte((byte)1); });
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteBytes(new byte[1]); });
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteBytes(new byte[3], 0, 2); });
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteChar('a'); });
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteDouble(1.5); });
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteSingle((float)1.5); });
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteInt32(1); });
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteInt64(1); });
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteObject("stringobj"); });
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteInt16((short)1); });
            Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteString("utfstring"); });
        }
        public void SendReceiveBytesMessageContent(
            [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection(GetTestClientId()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = CreateDestination(session, DestinationType.Queue);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode = deliveryMode;
                            IBytesMessage request = session.CreateBytesMessage();

                            request.WriteBoolean(true);
                            request.WriteByte((byte)1);
                            request.WriteBytes(new byte[1]);
                            request.WriteBytes(new byte[3], 0, 2);
                            request.WriteChar('a');
                            request.WriteDouble(1.5);
                            request.WriteSingle((float)1.5);
                            request.WriteInt32(1);
                            request.WriteInt64(1);
                            request.WriteObject("stringobj");
                            request.WriteInt16((short)1);
                            request.WriteString("utfstring");

                            producer.Send(request);

                            IMessage message = consumer.Receive(receiveTimeout);
                            AssertMessageIsReadOnly(message);
                            AssertBytesMessageEqual(request, message);
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
                        }
                }
            }
        }
示例#4
0
        public void SendReceiveBytesMessageContentTest(MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = session.CreateTemporaryTopic();
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode   = deliveryMode;
                            producer.RequestTimeout = receiveTimeout;
                            IBytesMessage request = session.CreateBytesMessage();

                            request.WriteBoolean(true);
                            request.WriteByte((byte)1);
                            request.WriteBytes(new byte[1]);
                            request.WriteBytes(new byte[3], 0, 2);
                            request.WriteChar('a');
                            request.WriteDouble(1.5);
                            request.WriteSingle((float)1.5);
                            request.WriteInt32(1);
                            request.WriteInt64(1);
                            request.WriteObject("stringobj");
                            request.WriteInt16((short)1);
                            request.WriteString("utfstring");

                            producer.Send(request);

                            IMessage message = consumer.Receive(receiveTimeout);
                            AssertBytesMessageEqual(request, message);
                            AssertMessageIsReadOnly(message);
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
                        }
                }
            }
        }
 public void WriteObject(object value)
 {
     message.WriteObject(value);
 }