public void ReceiveByCorrelationIdWithTransactionAbort() { string correlationId = Guid.NewGuid() + "\\0"; String body = "foo-" + DateTime.Now.ToString(); Message sent1 = new Message(body, new BinaryMessageFormatter()); sent1.CorrelationId = correlationId; MessageQueue mq = MQUtil.GetQueue(MQUtil.CreateQueueName(), true); Assert.IsTrue(mq.Transactional, "Message Queue should be transactional"); mq.Send(sent1, MessageQueueTransactionType.Single); string id = sent1.Id; using (MessageQueueTransaction tx = new MessageQueueTransaction()) { tx.Begin(); Message received1 = mq.ReceiveByCorrelationId(correlationId, tx); tx.Abort(); } Message received2 = mq.Receive(); Assert.AreEqual(body, received2.Body); }
public void Send2WithLabelWithTransaction() { String label1 = "label1"; String label2 = "label2"; Message sent1 = new Message("Message 1", new BinaryMessageFormatter()); Message sent2 = new Message("Message 2", new BinaryMessageFormatter()); MessageQueue mq = MQUtil.GetQueue(MQUtil.CreateQueueName(), true); mq.MessageReadPropertyFilter.SetAll(); Assert.IsTrue(mq.Transactional, "Message Queue should be transactional"); using (MessageQueueTransaction tx = new MessageQueueTransaction()) { tx.Begin(); mq.Send(sent1, label1, tx); mq.Send(sent2, label2, tx); tx.Commit(); Message received1 = mq.Receive(); Assert.IsNotNull(received1.TransactionId, "TransactionId not set"); Message received2 = mq.Receive(); Assert.IsNotNull(received2.TransactionId, "TransactionId not set"); Assert.AreEqual(received1.TransactionId, received2.TransactionId, "Messages have differing TransactionIds"); Assert.IsTrue(received1.TransactionId.Length > 1); Assert.AreEqual(sent1.Body, received1.Body, "Message 1 not delivered correctly"); Assert.AreEqual(sent2.Body, received2.Body, "Message 2 not delivered correctly"); Assert.AreEqual(label1, received1.Label, "Label 1 not passed correctly"); Assert.AreEqual(label2, received2.Label, "Label 2 not passed correctly"); } }
public void ReceiveWithTransactionTypeAndTimeoutFailure() { MessageQueue mq = MQUtil.GetQueue(MQUtil.CreateQueueName(), true); Assert.IsTrue(mq.Transactional, "Message Queue should be transactional"); Message received1 = mq.Receive(new TimeSpan(0, 0, 2), MessageQueueTransactionType.Single); }
public void SendDefaultMessage() { string path = MQUtil.CreateQueueName(); Thingy body = new Thingy(); body.MyProperty1 = 42; body.MyProperty2 = "Something"; body.MyProperty3 = "Something else"; Message m1 = new Message(body); Assert.IsNull(m1.Formatter); MessageQueue q = MQUtil.GetQueue(path, new XmlMessageFormatter()); q.Send(m1); Message m2 = q.Receive(); m2.Formatter = new XmlMessageFormatter(new Type[] { typeof(Thingy) }); Assert.IsNotNull(m2.Formatter); Assert.AreEqual(typeof(XmlMessageFormatter), m2.Formatter.GetType()); Thingy body2 = (Thingy)m2.Formatter.Read(m2); Assert.AreEqual(body.MyProperty1, body2.MyProperty1); Assert.AreEqual(body.MyProperty2, body2.MyProperty2); Assert.AreEqual(body.MyProperty3, body2.MyProperty3); }
public void GetQueue() { string qName = MQUtil.CreateQueueName(); MessageQueue q1 = MQUtil.GetQueue(qName, true); Assert.IsTrue(q1.Transactional, "Queue should be transactional"); MessageQueue q2 = MQUtil.GetQueue(qName, true); Assert.IsTrue(q2.Transactional, "Queue should be transactional"); }
public void CreateTransactionalQueue() { string qName = MQUtil.CreateQueueName(); Assert.IsFalse(MessageQueue.Exists(qName), "Queue should not exist"); MessageQueue q = MessageQueue.Create(qName, true); Assert.IsTrue(q.Transactional, "Queue should be transactional"); Assert.IsTrue(MessageQueue.Exists(qName), "Queue should exist"); }
public void SendWithTransactionType() { Message sent1 = new Message("Message 1"); MessageQueue mq = MQUtil.GetQueue(MQUtil.CreateQueueName(), true); mq.MessageReadPropertyFilter.SetAll(); mq.Send(sent1, MessageQueueTransactionType.Single); Message received1 = mq.Receive(); Assert.IsNotNull(received1.TransactionId, "TransactionId not set"); }
public void DeleteQueue() { string qName = MQUtil.CreateQueueName(); MessageQueue q = MQUtil.GetQueue(qName); Message m1 = new Message("foobar1", new BinaryMessageFormatter()); q.Send(m1); q.Receive(); MessageQueue.Delete(qName); }
public void ReceiveWithTransactionType() { String body = "foo-" + DateTime.Now.ToString(); Message sent1 = new Message(body, new BinaryMessageFormatter()); MessageQueue mq = MQUtil.GetQueue(MQUtil.CreateQueueName(), true); Assert.IsTrue(mq.Transactional, "Message Queue should be transactional"); mq.Send(sent1, MessageQueueTransactionType.Single); Message received1 = mq.Receive(MessageQueueTransactionType.Single); Assert.AreEqual(body, received1.Body); }
public void ReceiveByIdWithTransactionType() { String body = "Message 4"; Message sent1 = new Message(body, new BinaryMessageFormatter()); MessageQueue mq = MQUtil.GetQueue(MQUtil.CreateQueueName(), true); Assert.IsTrue(mq.Transactional, "Message Queue should be transactional"); mq.Send(sent1, MessageQueueTransactionType.Single); string id = sent1.Id; Message received1 = mq.ReceiveById(id, MessageQueueTransactionType.Single); Assert.AreEqual(body, received1.Body); }
public void SendWithTransactionTypeAndLabel() { Message sent1 = new Message("Message 1"); MessageQueue mq = MQUtil.GetQueue(MQUtil.CreateQueueName(), true); mq.MessageReadPropertyFilter.SetAll(); String label = "mylabel"; mq.Send(sent1, label, MessageQueueTransactionType.Single); Message received1 = mq.Receive(); Assert.IsNotNull(received1.TransactionId, "TransactionId not set"); Assert.AreEqual(label, received1.Label, "Label not set"); }
public void SendDefaultText() { string body = "This is a test"; MessageQueue q = MQUtil.GetQueue(MQUtil.CreateQueueName(), new XmlMessageFormatter()); q.Send(body); Message m2 = q.Receive(); XmlMessageFormatter xmlf = (XmlMessageFormatter)q.Formatter; Assert.AreEqual(typeof(XmlMessageFormatter), m2.Formatter.GetType()); Assert.AreEqual(body, m2.Body); Assert.AreEqual(0, m2.BodyType); }
public void PurgeQueue() { MessageQueue q = MQUtil.GetQueue(MQUtil.CreateQueueName()); Message m1 = new Message("foobar1", new BinaryMessageFormatter()); Message m2 = new Message("foobar2", new BinaryMessageFormatter()); Message m3 = new Message("foobar3", new BinaryMessageFormatter()); Message m4 = new Message("foobar4", new BinaryMessageFormatter()); q.Send(m1); q.Send(m2); q.Send(m3); q.Send(m4); q.Receive(); q.Purge(); q.Receive(new TimeSpan(0, 0, 2)); }
public void Send2WithTransactionAbort() { Message sent1 = new Message("Message 1", new BinaryMessageFormatter()); Message sent2 = new Message("Message 2", new BinaryMessageFormatter()); MessageQueue mq = MQUtil.GetQueue(MQUtil.CreateQueueName(), true); mq.MessageReadPropertyFilter.SetAll(); Assert.IsTrue(mq.Transactional, "Message Queue should be transactional"); using (MessageQueueTransaction tx = new MessageQueueTransaction()) { tx.Begin(); mq.Send(sent1, tx); mq.Send(sent2, tx); tx.Abort(); mq.Receive(new TimeSpan(0, 0, 2)); } }
public void ReceiveByCorrelationIdWithTransactionType() { string correlationId = Guid.NewGuid() + "\\0"; String body = "Message 10"; Message sent1 = new Message(body, new BinaryMessageFormatter()); sent1.CorrelationId = correlationId; MessageQueue mq = MQUtil.GetQueue(MQUtil.CreateQueueName(), true); mq.Formatter = new BinaryMessageFormatter(); Assert.IsTrue(mq.Transactional, "Message Queue should be transactional"); mq.Send(sent1, MessageQueueTransactionType.Single); string id = sent1.Id; Message received1 = mq.ReceiveByCorrelationId(correlationId, MessageQueueTransactionType.Single); Assert.AreEqual(body, received1.Body); }
public void ReceiveWithTransaction() { String body = "Message 4"; Message sent1 = new Message(body, new BinaryMessageFormatter()); MessageQueue mq = MQUtil.GetQueue(MQUtil.CreateQueueName(), true); Assert.IsTrue(mq.Transactional, "Message Queue should be transactional"); mq.Send(sent1, MessageQueueTransactionType.Single); using (MessageQueueTransaction tx = new MessageQueueTransaction()) { tx.Begin(); Message received1 = mq.Receive(tx); tx.Commit(); Assert.AreEqual(body, received1.Body); } }
public void ReceiveByIdWithTransactionAndTimeout() { String body = "foo-" + DateTime.Now.ToString(); Message sent1 = new Message(body, new BinaryMessageFormatter()); MessageQueue mq = MQUtil.GetQueue(MQUtil.CreateQueueName(), true); mq.Formatter = new BinaryMessageFormatter(); Assert.IsTrue(mq.Transactional, "Message Queue should be transactional"); mq.Send(sent1, MessageQueueTransactionType.Single); string id = sent1.Id; using (MessageQueueTransaction tx = new MessageQueueTransaction()) { tx.Begin(); Message received1 = mq.ReceiveById(id, new TimeSpan(0, 0, 2), tx); tx.Commit(); Assert.AreEqual(body, received1.Body); } }
public void SetUp() { qName = MQUtil.CreateQueueName(); }