Inheritance: ActiveMQMessage, ITextMessage
 public void TestSetText() 
 {
     ActiveMQTextMessage msg = new ActiveMQTextMessage();
     string str = "testText";
     msg.Text = str;
     Assert.AreEqual(msg.Text, str);
 }
        public void ProcessMessage_OrchistratesParticipatingComponentsCorrectly()
        {
            const string NmsType = "TheNmsType";
            const string CorrelationId = "TheCorrelationId";
            const string ReplyToQueue = "TheReplyToQueue";

            var type = typeof(object);
            var deserializedMessage = new object();
            var correlationIdAndAddress = new CorrelationIdAndAddress(null, null);
            var amqMessage = new ActiveMQTextMessage
            {
                NMSType = NmsType,
                CorrelationId = CorrelationId,
                NMSReplyTo = new ActiveMQQueue(ReplyToQueue),
                NMSDestination = new ActiveMQQueue("Doesn't matter"),
            };

            A.CallTo(() => this.messageTypeInterpreter.GetTypeFromNmsType(NmsType)).Returns(type);
            A.CallTo(() => this.messageDeserializer.DeserializeMessage(amqMessage, type)).Returns(deserializedMessage);
            A.CallTo(() => this.correlationIdAndAddressTranscoder.TranscodeCorrelationIdAndAddress(CorrelationId, ReplyToQueue))
                .Returns(correlationIdAndAddress);

            this.testee.ProcessMessage(amqMessage);

            A.CallTo(() => this.messageSender.SendMessage(deserializedMessage, correlationIdAndAddress, type))
                .MustHaveHappened();
        }
 public void TestShallowCopy()
 {
     ActiveMQTextMessage msg = new ActiveMQTextMessage();
     string testString = "str";
     msg.Text = testString;
     Message copy = msg.Clone() as Message;
     Assert.IsTrue(msg.Text == ((ActiveMQTextMessage) copy).Text);
 }
 public void TestGetBytes() 
 {
     ActiveMQTextMessage msg = new ActiveMQTextMessage();
     String str = "testText";
     msg.Text = str;
     msg.BeforeMarshall(null);
     
     byte[] bytes = msg.Content;
     msg = new ActiveMQTextMessage();
     msg.Content = bytes;
     
     Assert.AreEqual(msg.Text, str);
 }
        public void DeserializeMessage()
        {
            const string Content = "The Message expectedContent";
            var expectedResult = new object();
            var message = new ActiveMQTextMessage(Content);
            var type = typeof(ActiveMqMessageDeserializerTest);

            A.CallTo(() => this.nsbMessageSerializer.Deserialize(A.Dummy<Stream>(), A.Dummy<IList<Type>>()))
                .WhenArgumentsMatch(this.VerifyDeserializationArguments(Content, type))
                .Returns(new[] { expectedResult });

            var result = this.testee.DeserializeMessage(message, type);

            result.Should().Be(expectedResult);
        }
        public void ProcessMessage_WhenNoExceptionOccurs_ThenNoErrorMessageIsSent()
        {
            const string Queue = "SomeQueue";

            var amqMessage = new ActiveMQTextMessage
            {
                NMSTimestamp = DateTime.Now,
                Destination = new ActiveMQQueue(Queue)
            };

            this.testee.ProcessMessage(amqMessage, this.errorMessageProducer);

            A.CallTo(() => this.messageHandler.ProcessMessage(amqMessage)).MustHaveHappened();
            A.CallTo(() => this.errorMessageProducer.Send(A.Dummy<Apache.NMS.IMessage>())).MustNotHaveHappened();
        }
        public void TestCommand()
        {
            ActiveMQTextMessage message = new ActiveMQTextMessage();

            Assert.IsNull(message.Text);            

            // Test with ASCII Data.
            message.Text = "Hello World";
            Assert.IsNotNull(message.Text);
            Assert.AreEqual("Hello World", message.Text);

            String unicodeString =
                "This unicode string contains two characters " +
                "with codes outside an 8-bit code range, " +
                "Pi (\u03a0) and Sigma (\u03a3).";

            message.Text = unicodeString;
            Assert.IsNotNull(message.Text);
            Assert.AreEqual(unicodeString, message.Text);
        }
        public void ProcessMessage_WhenExceptionOccurs_ThenErrorMessageIsSent()
        {
            const string Queue = "SomeQueue";
            const string Message = "TheExceptionMessage";
            var exception = new Exception(Message);

            var amqMessage = new ActiveMQTextMessage
            {
                NMSTimestamp = DateTime.Now,
                Destination = new ActiveMQQueue(Queue)
            };

            A.CallTo(() => this.messageHandler.ProcessMessage(amqMessage)).Throws(exception);

            this.testee.ProcessMessage(amqMessage, this.errorMessageProducer);

            this.ErrorMessageShouldBeSent(
                amqMessage,
                exceptionMessage => exceptionMessage.StartsWith("System.Exception: TheExceptionMessage"),
                "queue://" + Queue);
        }
 public void TestClearBody()
 {
     ActiveMQTextMessage textMessage = new ActiveMQTextMessage();
     textMessage.Text = "string";
     textMessage.ClearBody();
     Assert.IsFalse(textMessage.ReadOnlyBody);
     Assert.IsNull(textMessage.Text);
     try
     {
         textMessage.Text = "String";
         Assert.IsTrue(textMessage.Text.Length > 0);
     }
     catch(MessageNotWriteableException)
     {
         Assert.Fail("should be writeable");
     }
     catch(MessageNotReadableException)
     {
         Assert.Fail("should be readable");
     }
 }
        public ITextMessage CreateActiveMqTextMessageFromMsmqTransportMessage(
            TransportMessage transportMessage,
            string messageType,
            Func<string> defaultQueueCallback)
        {
            messageType = messageType.Split(',')[0];
            var body = Encoding.UTF8.GetString(transportMessage.Body);
            string receivedCorrelationId = transportMessage.CorrelationId ?? transportMessage.Id;
            CorrelationIdAndAddress correlationIdAndAddress = this.correlationIdAndAddressTranscoder.DecodeCorrelationId(receivedCorrelationId);
            string address = correlationIdAndAddress.Address ?? defaultQueueCallback();
            var destination = transportMessage.MessageIntent == MessageIntentEnum.Publish
                                  ? (IDestination)new ActiveMQTopic("VirtualTopic." + messageType)
                                  : (IDestination)new ActiveMQQueue(address);

            ITextMessage amqMessage = new ActiveMQTextMessage(body);

            amqMessage.NMSCorrelationID = this.correlationIdAndAddressTranscoder.EncodeAddressToCorrelationId(receivedCorrelationId, correlationIdAndAddress.CorrelationId, TryToGetReplyToQueueName(transportMessage));
            amqMessage.NMSType = messageType;
            amqMessage.NMSReplyTo = new ActiveMQQueue(this.replyToQueue);
            amqMessage.NMSDestination = destination;

            return amqMessage;
        }
Example #11
0
        private IMessage CreateMessage()
        {
            DateTime sendTime = DateTime.Now;
            int messageSize = _random.Next(_simulationParams.MinMessageSize, _simulationParams.MaxMessageSize);

            var messageBody = new string('X', messageSize);

            var activeMqTextMessage = new ActiveMQTextMessage(messageBody);
            activeMqTextMessage.Persistent = false;
            activeMqTextMessage.Properties.SetLong("SendTime", sendTime.Ticks);
            activeMqTextMessage.Properties.SetBool("IsLastMessage", IsLastMessage());

            return activeMqTextMessage;
        }
        public void TestTextMessageTransformation()
        {
            ActiveMQTextMessage message = new ActiveMQTextMessage();

            Assert.AreSame(message, transformer.TransformMessage<ActiveMQMessage>(message));
        }
 public void TestNullText() 
 {
     ActiveMQTextMessage nullMessage = new ActiveMQTextMessage();
     SetContent(nullMessage, null);
     Assert.IsNull(nullMessage.Text);
     Assert.IsTrue(nullMessage.ToString().Contains("Text = null"));
 }
 public void TestShortText() 
 {
     string shortText = "Content";
     ActiveMQTextMessage shortMessage = new ActiveMQTextMessage();
     SetContent(shortMessage, shortText);
     Assert.IsTrue(shortMessage.ToString().Contains("Text = " + shortText));
     Assert.IsTrue(shortMessage.Text == shortText);
     
     string longText = "Very very very very veeeeeeery loooooooooooooooooooooooooooooooooong text";
     string longExpectedText = "Very very very very veeeeeeery looooooooooooo...ooooong text";
     ActiveMQTextMessage longMessage = new ActiveMQTextMessage();
     SetContent(longMessage, longText);
     Assert.IsTrue(longMessage.ToString().Contains("Text = " + longExpectedText));
     Assert.IsTrue(longMessage.Text == longText);         
 }
 public void TtestWriteOnlyBody() 
 { 
     // should always be readable
     ActiveMQTextMessage textMessage = new ActiveMQTextMessage();
     textMessage.ReadOnlyBody = false;
     try 
     {
         textMessage.Text = "test";
         Assert.IsTrue(textMessage.Text.Length > 0);
     } 
     catch(MessageNotReadableException) 
     {
         Assert.Fail("should be readable");
     }
     textMessage.ReadOnlyBody = true;
     try 
     {
         Assert.IsTrue(textMessage.Text.Length > 0);
         textMessage.Text = "test";
         Assert.Fail("should throw exception");
     } 
     catch(MessageNotReadableException)
     {
         Assert.Fail("should be readable");
     } 
     catch(MessageNotWriteableException) 
     {
     }
 }
 protected override ITextMessage DoCreateTextMessage()
 {
     ActiveMQTextMessage message = new ActiveMQTextMessage();
     message.Connection = this.connection;
     return message;
 }
Example #17
0
 public void RequestMessageTest()
 {
     transport.Start();
     ActiveMQTextMessage message = new ActiveMQTextMessage();
     message.Text = "Hello, World";
     transport.Request(message);
     Assert.IsTrue(transport.NumSentMessages == 1);
     Assert.IsTrue(sent.Count == 1);
     Assert.AreEqual(message.Text, (sent[0] as ActiveMQTextMessage).Text);
 }
Example #18
0
 public void RequestFailOnSendTwoMessagesTest()
 {
     transport.FailOnSendMessage = true;
     transport.NumSentMessagesBeforeFail = 2;
     transport.Start();
     ActiveMQTextMessage message = new ActiveMQTextMessage();
     transport.Request(message);
     transport.Request(message);
     transport.Request(message);
 }
Example #19
0
 public void RequestFailOnSendMessageTest()
 {
     transport.FailOnSendMessage = true;
     transport.Start();
     ActiveMQTextMessage message = new ActiveMQTextMessage();
     Assert.IsNotNull(transport.Request(message));
 }
Example #20
0
 public void OneWayFailOnSendMessageTest()
 {
     transport.FailOnSendMessage = true;
     transport.Start();
     ActiveMQTextMessage message = new ActiveMQTextMessage();
     transport.Oneway(message);
 }
Example #21
0
 public ITextMessage CreateTextMessage(string text)
 {
     ActiveMQTextMessage answer = new ActiveMQTextMessage(text);
     return ConfigureMessage(answer) as ITextMessage;
 }