Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,133 @@
//
// Test.Mono.Messaging.RabbitMQ
//
// Authors:
// Michael Barker (mike@middlesoft.co.uk)
//
// (C) 2008 Michael Barker
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Messaging;
using System.Reflection;
using System.Threading;
using System.Text.RegularExpressions;
using NUnit.Framework;
namespace MonoTests.System.Messaging
{
[TestFixture]
public class AdminTest {
[Test]
public void CreateNonTransactionalQueue ()
{
string qName = MQUtil.CreateQueueName ();
Assert.IsFalse (MessageQueue.Exists (qName), "Queue should not exist");
MessageQueue q = MessageQueue.Create (qName);
Assert.IsFalse (q.Transactional);
Assert.IsTrue (MessageQueue.Exists (qName), "Queue should exist");
}
[Test]
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");
}
private bool Contains(MessageQueue[] qs, String qName)
{
foreach (MessageQueue q in qs)
{
if (q.QueueName == qName)
return true;
}
return false;
}
[Test]
public void GetPublicQueues ()
{
string qName1 = @".\admin-queue-3";
string qName2 = @".\admin-queue-4";
MQUtil.GetQueue (qName1);
MQUtil.GetQueue (qName2);
MessageQueue[] mq = MessageQueue.GetPublicQueues ();
Console.WriteLine("Number of queues: {0}", mq.Length);
Assert.IsTrue (Contains (mq, "admin-queue-3"), qName1 + " not found");
Assert.IsTrue (Contains (mq, "admin-queue-4"), qName2 + " not found");
}
[Test]
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");
}
[Test]
[ExpectedException (typeof (MessageQueueException))]
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));
}
[Test]
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);
}
}
}

View File

@@ -0,0 +1,140 @@
//
// Test.Mono.Messaging.RabbitMQ
//
// Authors:
// Michael Barker (mike@middlesoft.co.uk)
//
// (C) 2008 Michael Barker
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Messaging;
using System.Reflection;
using System.Threading;
using System.Text.RegularExpressions;
using NUnit.Framework;
namespace MonoTests.System.Messaging
{
[TestFixture]
public class AsyncPeekTest {
bool eventCalled = false;
private void HandleMessage (object source, PeekCompletedEventArgs args) {
eventCalled = true;
}
[Test]
public void BeginPeek()
{
MessageQueue q = MQUtil.GetQueue ();
Message s = new Message (new BinaryMessageFormatter ());
string body = "foo-" + DateTime.Now.ToString ();
s.Body = body;
q.Send (s);
q.PeekCompleted += new PeekCompletedEventHandler (HandleMessage);
IAsyncResult result = q.BeginPeek ();
result.AsyncWaitHandle.WaitOne ();
Message rMsg = q.EndPeek (result);
Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
Assert.IsTrue (eventCalled, "Handle Message not called");
Assert.IsNotNull (q.Receive (), "Message not peeked");
}
[Test]
public void BeginPeekWithTimeout()
{
MessageQueue q = MQUtil.GetQueue ();
Message s = new Message (new BinaryMessageFormatter ());
string body = "foo-" + DateTime.Now.ToString ();
s.Body = body;
q.Send (s);
IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2));
result.AsyncWaitHandle.WaitOne ();
Message rMsg = q.EndPeek (result);
Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
Assert.IsNotNull (q.Receive (), "Message not peeked");
}
[Test]
public void BeginPeekWithStateAndTimeout()
{
MessageQueue q = MQUtil.GetQueue ();
Message s = new Message (new BinaryMessageFormatter ());
string body = "foo-" + DateTime.Now.ToString ();
s.Body = body;
q.Send (s);
IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2), "foo");
result.AsyncWaitHandle.WaitOne ();
Message rMsg = q.EndPeek (result);
Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
Assert.IsNotNull (q.Receive (), "Message not peeked");
}
private bool success = false;
public void TestCallback (IAsyncResult result)
{
success = true;
}
[Test]
public void BeginPeekWithStateAndTimeoutAndCallback()
{
MessageQueue q = MQUtil.GetQueue ();
Message s = new Message (new BinaryMessageFormatter ());
string body = "foo-" + DateTime.Now.ToString ();
s.Body = body;
q.Send (s);
AsyncCallback ac = new AsyncCallback (TestCallback);
IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2), "foo", ac);
result.AsyncWaitHandle.WaitOne ();
Message rMsg = q.EndPeek (result);
Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
Assert.IsTrue (success, "Callback not run");
Assert.IsNotNull (q.Receive (), "Message not peeked");
}
[Test]
[ExpectedException (typeof (MessageQueueException))]
public void BeginPeekWithException()
{
MessageQueue q = MQUtil.GetQueue ();
IAsyncResult result = q.BeginPeek (new TimeSpan (0, 0, 2));
result.AsyncWaitHandle.WaitOne ();
q.EndPeek (result);
}
}
}

View File

@@ -0,0 +1,140 @@
//
// Test.Mono.Messaging.RabbitMQ
//
// Authors:
// Michael Barker (mike@middlesoft.co.uk)
//
// (C) 2008 Michael Barker
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Messaging;
using System.Reflection;
using System.Threading;
using System.Text.RegularExpressions;
using NUnit.Framework;
namespace MonoTests.System.Messaging
{
[TestFixture]
public class AsyncReceiveTest {
private Message m;
private string failureMessage = null;
private string state = null;
private void HandleMessage (object source, ReceiveCompletedEventArgs args) {
try {
MessageQueue q = (MessageQueue) source;
m = q.EndReceive (args.AsyncResult);
state = (string) args.AsyncResult.AsyncState;
} catch (Exception e) {
failureMessage = e.Message;
}
}
[Test]
public void BeginReceive()
{
MessageQueue q = MQUtil.GetQueue ();
Message s = new Message (new BinaryMessageFormatter ());
string body = "foo-" + DateTime.Now.ToString ();
s.Body = body;
q.Send (s);
q.ReceiveCompleted += new ReceiveCompletedEventHandler (HandleMessage);
IAsyncResult result = q.BeginReceive ();
result.AsyncWaitHandle.WaitOne ();
Message rMsg = q.EndReceive (result);
Assert.IsNotNull (rMsg, "No message received");
Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
}
[Test]
public void BeginReceiveWithTimeout()
{
MessageQueue q = MQUtil.GetQueue ();
Message s = new Message (new BinaryMessageFormatter ());
string body = "foo-" + DateTime.Now.ToString ();
s.Body = body;
q.Send (s);
IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2));
result.AsyncWaitHandle.WaitOne ();
Message rMsg = q.EndReceive (result);
Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
}
[Test]
public void BeginReceiveWithStateAndTimeout()
{
MessageQueue q = MQUtil.GetQueue ();
Message s = new Message (new BinaryMessageFormatter ());
string body = "foo-" + DateTime.Now.ToString ();
s.Body = body;
q.Send (s);
IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2), "foo");
result.AsyncWaitHandle.WaitOne ();
Message rMsg = q.EndReceive (result);
Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
}
private bool success = false;
public void TestCallback (IAsyncResult result)
{
success = true;
}
[Test]
public void BeginReceiveWithStateAndTimeoutAndCallback()
{
MessageQueue q = MQUtil.GetQueue ();
Message s = new Message (new BinaryMessageFormatter ());
string body = "foo-" + DateTime.Now.ToString ();
s.Body = body;
q.Send (s);
AsyncCallback ac = new AsyncCallback (TestCallback);
IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2), "foo", ac);
result.AsyncWaitHandle.WaitOne ();
Message rMsg = q.EndReceive (result);
Assert.AreEqual (body, rMsg.Body, "Async Send Failed, bodies not equal");
Assert.AreEqual ("foo", result.AsyncState, "State not passed properly");
Assert.IsTrue (success, "Callback not run");
}
[Test]
[ExpectedException (typeof (MessageQueueException))]
public void BeginReceiveWithException()
{
MessageQueue q = MQUtil.GetQueue ();
IAsyncResult result = q.BeginReceive (new TimeSpan (0, 0, 2));
result.AsyncWaitHandle.WaitOne ();
q.EndReceive (result);
}
}
}

View File

@@ -0,0 +1,470 @@
//
// Test.Mono.Messaging.RabbitMQ
//
// Authors:
// Michael Barker (mike@middlesoft.co.uk)
//
// (C) 2008 Michael Barker
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Messaging;
using System.Reflection;
using System.Threading;
using System.Text.RegularExpressions;
using NUnit.Framework;
namespace MonoTests.System.Messaging
{
[TestFixture]
public class BasicMessagingTest {
[Test]
public void SendReceiveBinaryMessage ()
{
MessageQueue mq = MQUtil.GetQueue ();
String s = "Test: " + DateTime.Now;
Message m = new Message (s, new BinaryMessageFormatter ());
m.CorrelationId = Guid.NewGuid () + "\\0";
mq.MessageReadPropertyFilter.SetAll ();
mq.Send (m);
Message m2 = mq.Receive ();
m2.Formatter = new BinaryMessageFormatter ();
Assert.AreEqual (s, m2.Body);
//Assert.IsTrue (DateTime.MinValue == m.ArrivedTime);
Assert.IsNotNull(m2.Id, "Id is null");
Assert.IsTrue (Guid.Empty.ToString () != m2.Id, "Id is Empty");
Assert.IsTrue (DateTime.MinValue != m2.ArrivedTime, "Arrived Time is not set");
Assert.AreEqual (Acknowledgment.None, m2.Acknowledgment, "Acknowledgment");
Assert.AreEqual (m.CorrelationId, m2.CorrelationId, "CorrelationId not set properly");
//Assert.IsTrue (0 != m2.SenderVersion);
// TODO: This is not supported on a workgroup installation.
//Assert.IsNotNull (m2.SourceMachine, "SourceMachine is null");
Assert.AreEqual (mq.QueueName, m2.DestinationQueue.QueueName, "Destination Queue not set");
mq.Close ();
}
[Test]
public void SendMessageWithLabel ()
{
MessageQueue mq = MQUtil.GetQueue ();
String label = "mylabel";
String s = "Test: " + DateTime.Now;
Message m = new Message (s, new BinaryMessageFormatter ());
m.CorrelationId = Guid.NewGuid () + "\\0" ;
mq.Send (m, label);
Message m2 = mq.Receive ();
m2.Formatter = new BinaryMessageFormatter ();
Assert.AreEqual (s, m2.Body, "Message not passed correctly");
Assert.AreEqual (label, m2.Label, "Label not passed correctly");
}
[Test]
public void CheckDefaults ()
{
Message m = new Message ("Test", new BinaryMessageFormatter ());
Assert.AreEqual (true, m.AttachSenderId, "AttachSenderId has incorrect default");
Assert.AreEqual (Guid.Empty.ToString () + "\\0", m.Id, "Id has incorrect default");
Assert.AreEqual ("Microsoft Base Cryptographic Provider, Ver. 1.0",
m.AuthenticationProviderName,
"AuthenticationProviderName has incorrect default");
Assert.AreEqual (0, m.Extension.Length, "Extension has incorrect default");
Assert.AreEqual ("", m.Label, "Label has incorrect default");
Assert.IsFalse (m.Recoverable, "Recoverable has incorrect default");
Assert.IsFalse (m.IsFirstInTransaction, "IsFirstInTransaction has incorrect default");
Assert.IsFalse (m.IsLastInTransaction, "IsLastInTransaction has incorrect default");
Assert.AreEqual ("", m.TransactionId, "TransactionId has incorrect default");
Assert.AreEqual (MessagePriority.Normal, m.Priority, "MessagePriority has incorrect default");
}
private static void CheckInvalidOperation (Message m, String property)
{
PropertyInfo pi = m.GetType ().GetProperty (property);
try {
Assert.IsNotNull (pi, "Property not defined: " + property);
object o = pi.GetValue (m, null);
Assert.Fail (property + ": " + o);
} catch (InvalidOperationException) {
} catch (TargetInvocationException e) {
Assert.AreEqual (typeof (InvalidOperationException),
e.InnerException.GetType ());
}
}
[Test]
public void CheckInvalidPropertyOperations ()
{
Message m = new Message ("Test", new BinaryMessageFormatter ());
CheckInvalidOperation (m, "Acknowledgment");
CheckInvalidOperation (m, "ArrivedTime");
CheckInvalidOperation (m, "Authenticated");
CheckInvalidOperation (m, "DestinationQueue");
//CheckInvalidOperation (m, "Id");
//CheckInvalidOperation (m, "IsFirstInTransaction");
//CheckInvalidOperation (m, "IsLastInTransaction");
// TODO: Support 2.0 features.
//CheckInvalidOperation (m, "LookupId");
CheckInvalidOperation (m, "MessageType");
CheckInvalidOperation (m, "SenderId");
CheckInvalidOperation (m, "SenderVersion");
CheckInvalidOperation (m, "SentTime");
CheckInvalidOperation (m, "SourceMachine");
//CheckInvalidOperation (m, "TransactionId");
}
private static void CheckArgumentInvalid(Message m, String property, Type exceptionType)
{
PropertyInfo pi = m.GetType().GetProperty(property);
try {
Assert.IsNotNull(pi, "Property not defined: " + property);
pi.SetValue(m, null, null);
Assert.Fail(property);
} catch (InvalidOperationException) {
} catch (TargetInvocationException e) {
Assert.AreEqual(exceptionType,
e.InnerException.GetType(),
property);
}
}
[Test]
public void CheckArgumentInvalidForProperties ()
{
Message m = new Message ("Stuff");
CheckArgumentInvalid (m, "DestinationSymmetricKey", typeof (ArgumentNullException));
CheckArgumentInvalid (m, "DigitalSignature", typeof(ArgumentNullException));
CheckArgumentInvalid (m, "Extension", typeof(ArgumentNullException));
}
[Test]
public void SendReceiveBinaryMessageWithAllPropertiesSet ()
{
MessageQueue mq = MQUtil.GetQueue ();
mq.MessageReadPropertyFilter.SetAll ();
MessageQueue adminQ = MQUtil.GetQueue (@".\private$\myadmin");
MessageQueue responseQ = MQUtil.GetQueue (@".\private$\myresponse");
Guid connectorType = Guid.NewGuid ();
String s = "Test: " + DateTime.Now;
Message m = new Message (s, new BinaryMessageFormatter ());
m.CorrelationId = Guid.NewGuid () + "\\0";
m.AcknowledgeType = AcknowledgeTypes.PositiveArrival;
m.AdministrationQueue = adminQ;
m.AppSpecific = 5;
//m.AuthenticationProviderName = "Test Provider Name";
//m.AuthenticationProviderType = CryptographicProviderType.None;
//m.ConnectorType = connectorType;
//m.DestinationSymmetricKey = new byte[] { 0x0A, 0x0B, 0x0C };
//m.DigitalSignature = new byte[] { 0x0C, 0x0D, 0x0E };
//m.EncryptionAlgorithm = EncryptionAlgorithm.Rc4;
m.Extension = new byte[] { 0x01, 0x02, 0x03 };
//m.HashAlgorithm = HashAlgorithm.Sha;
m.Label = "MyLabel";
m.Priority = MessagePriority.AboveNormal;
m.Recoverable = true;
m.ResponseQueue = responseQ;
m.SenderCertificate = new byte[] { 0x04, 0x05, 0x06 };
m.TimeToBeReceived = new TimeSpan(0, 0, 10);
m.TimeToReachQueue = new TimeSpan(0, 0, 5);
//m.UseAuthentication = true;
m.UseDeadLetterQueue = true;
//m.UseEncryption = true;
mq.Send (m);
Message m2 = mq.Receive ();
m2.Formatter = new BinaryMessageFormatter ();
Assert.AreEqual (s, m2.Body);
Assert.AreEqual (AcknowledgeTypes.PositiveArrival, m2.AcknowledgeType,
"AcknowledgeType not passed correctly");
Assert.AreEqual (adminQ.QueueName, m2.AdministrationQueue.QueueName,
"AdministrationQueue not passed correctly");
Assert.AreEqual (5, m2.AppSpecific, "AppSpecific not passed correctly");
//Assert.AreEqual (m.AuthenticationProviderName, m2.AuthenticationProviderName,
// "AuthenticationProviderName not passed correctly");
//Assert.AreEqual (m.AuthenticationProviderType, m2.AuthenticationProviderType,
// "AuthenticationProviderType not passed correctly");
//Assert.AreEqual (connectorType, m2.ConnectorType,
// "ConnectorType not passed correctly");
Assert.AreEqual (m.CorrelationId, m2.CorrelationId,
"CorrelationId not passed correctly");
//AreEqual (m.DestinationSymmetricKey, m2.DestinationSymmetricKey,
// "DestinationSymmetricKey not passed correctly");
//AreEqual (m.DigitalSignature, m2.DigitalSignature,
// "DigitalSignature not passed properly");
//Assert.AreEqual (EncryptionAlgorithm.Rc4, m2.EncryptionAlgorithm,
// "EncryptionAlgorithm not passed properly");
AreEqual (m.Extension, m2.Extension, "Extension not passed properly");
//Assert.AreEqual (m.HashAlgorithm, m2.HashAlgorithm,
// "HashAlgorithm not passed properly");
Assert.AreEqual (m.Label, m2.Label, "Label not passed correctly");
Assert.AreEqual (MessagePriority.AboveNormal, m2.Priority,
"Priority not passed properly");
Assert.AreEqual (true, m2.Recoverable, "Recoverable not passed properly");
Assert.AreEqual (responseQ.QueueName, m2.ResponseQueue.QueueName,
"ResponseQueue not passed properly");
AreEqual (m.SenderCertificate, m2.SenderCertificate,
"SenderCertificate not passed properly");
Assert.AreEqual (m.TimeToBeReceived, m2.TimeToBeReceived,
"TimeToBeReceived not passed properly");
Assert.AreEqual (m.TimeToReachQueue, m2.TimeToReachQueue,
"TimeToReachQueue not passed properly");
//Assert.IsTrue (m2.UseAuthentication,
// "UseAuthentication not passed properly");
Assert.IsTrue (m2.UseDeadLetterQueue,
"UseDeadLetterQueue not passed properly");
//Assert.IsTrue (m2.UseEncryption, "UseEncryption not pass properly");
//Assert.AreEqual ();
Assert.IsNotNull (m2.Id, "Id is null");
Assert.IsTrue (Guid.Empty.ToString () != m2.Id, "Id is Empty");
Assert.IsTrue (DateTime.MinValue != m2.ArrivedTime, "Arrived Time is not set");
Assert.AreEqual (Acknowledgment.None, m2.Acknowledgment, "Acknowledgment");
//Assert.IsTrue (0 != m2.SenderVersion);
//Assert.IsNotNull (m2.SourceMachine, "SourceMachine is null");
}
private static void AreEqual(byte[] expected, byte[] actual, string message)
{
Assert.AreEqual (expected.Length, actual.Length, message);
for (int i = 0; i < expected.Length; i++)
Assert.AreEqual (expected[i], actual[i], message);
}
//[Test]
// No supported by Rabbit
public void SendPriorityMessages ()
{
MessageQueue mq = MQUtil.GetQueue ();
Message sent1 = new Message ("Highest", new BinaryMessageFormatter ());
sent1.Priority = MessagePriority.Highest;
Message sent2 = new Message ("Lowest", new BinaryMessageFormatter ());
sent2.Priority = MessagePriority.Lowest;
mq.Send (sent1);
mq.Send (sent2);
Message received1 = mq.Receive ();
Message received2 = mq.Receive ();
Assert.AreEqual (MessagePriority.Highest, received2.Priority,
"Priority delivery incorrect");
Assert.AreEqual (MessagePriority.Lowest, received1.Priority,
"Priority delivery incorrect");
}
[Test]
public void SendReceiveXmlMessage ()
{
MessageQueue mq = MQUtil.GetQueue ();
String s = "Test: " + DateTime.Now;
Message m = new Message (s, new XmlMessageFormatter (new Type[] { typeof (string) }));
mq.MessageReadPropertyFilter.SetAll();
mq.Send (m);
Message m2 = mq.Receive ();
m2.Formatter = new XmlMessageFormatter (new Type[] { typeof (string) });
Assert.AreEqual (s, m2.Body);
Assert.AreEqual (Acknowledgment.None, m2.Acknowledgment, "Acknowledgment");
Assert.IsNotNull (m2.ArrivedTime, "Acknowledgment");
Assert.IsNotNull (m2.Id, "Id");
}
[Test]
public void SendBinaryText ()
{
string body = "This is a test";
MessageQueue q = MQUtil.GetQueue ();
q.Formatter = new BinaryMessageFormatter ();
q.Send (body);
Message m2 = q.Receive ();
Assert.IsNotNull (m2.Formatter, "Formatter is null");
Assert.AreEqual (typeof (BinaryMessageFormatter), m2.Formatter.GetType ());
Assert.AreEqual (body, m2.Body);
}
[Test]
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);
}
[Test]
public void SendBinaryObject ()
{
Thingy body = new Thingy ();
body.MyProperty1 = 42;
body.MyProperty2 = "Something";
body.MyProperty3 = "Something else";
MessageQueue q = MQUtil.GetQueue ();
q.Formatter = new BinaryMessageFormatter ();
q.Send (body);
Message m2 = q.Receive ();
Thingy body2 = (Thingy) m2.Body;
Assert.AreEqual (typeof (BinaryMessageFormatter), m2.Formatter.GetType ());
Assert.AreEqual (body.MyProperty1, body2.MyProperty1);
Assert.AreEqual (body.MyProperty2, body2.MyProperty2);
Assert.AreEqual (body.MyProperty3, body2.MyProperty3);
Assert.AreEqual (768, m2.BodyType);
}
[Test]
public void SendDefaultObject ()
{
string path = MQUtil.CreateQueueName ();
Thingy body = new Thingy();
body.MyProperty1 = 42;
body.MyProperty2 = "Something";
body.MyProperty3 = "Something else";
MessageQueue q = MQUtil.GetQueue (path, new XmlMessageFormatter ());
q.Send (body);
MessageQueue q2 = MQUtil.GetQueue (path);
q2.Formatter = new XmlMessageFormatter (new Type[] { typeof(Thingy) });
Message m2 = q2.Receive ();
Thingy body2 = (Thingy) m2.Body;
Assert.AreEqual (typeof (XmlMessageFormatter), m2.Formatter.GetType ());
Assert.AreEqual (body.MyProperty1, body2.MyProperty1);
Assert.AreEqual (body.MyProperty2, body2.MyProperty2);
Assert.AreEqual (body.MyProperty3, body2.MyProperty3);
}
[Test]
public void SendBinaryMessage ()
{
Thingy body = new Thingy ();
body.MyProperty1 = 42;
body.MyProperty2 = "Something";
body.MyProperty3 = "Something else";
Message m1 = new Message (body);
m1.Formatter = new BinaryMessageFormatter ();
MessageQueue q = MQUtil.GetQueue ();
q.Send (m1);
Message m2 = q.Receive ();
m2.Formatter = new BinaryMessageFormatter ();
Assert.IsNotNull (m2.Formatter);
Assert.AreEqual (typeof (BinaryMessageFormatter), 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);
}
[Test]
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);
}
}
[Serializable]
public class Thingy
{
private int myVar1;
public int MyProperty1
{
get { return myVar1; }
set { myVar1 = value; }
}
private string myVar2;
public string MyProperty2
{
get { return myVar2; }
set { myVar2 = value; }
}
private string myVar3;
public string MyProperty3
{
get { return myVar3; }
set { myVar3 = value; }
}
}
}

View File

@@ -0,0 +1,62 @@
2009-07-20 Michael Barker <mike@middlesoft.co.uk>
* AdminTest.cs: Added support for unique queue names
* AsyncPeekTest.cs: Added support for unique queue names
* AsyncReceiveTest.cs: Added support for unique queue names
* BasicMessagingTest.cs: Added support for unique queue names
* MessageEnumeratorTest.cs: Added support for unique queue names
* MQUtil.cs: Added queue name generation and prepending server names
to queue names based on environment variable
* PeekTest.cs: Added support for unique queue names
* SelectorTest.cs: Added support for unique queue names
2009-07-20 Michael Barker <mike@middlesoft.co.uk>
* AdminTest.cs: Fixed namespace
* AsyncPeekTest.cs: Fixed namespace
* AsyncReceiveTest.cs: Fixed namespace
* BasicMessagingTest.cs: Fixed namespace
* MessageEnumeratorTest.cs: Fixed namespace
* MQUtil.cs: Fixed namespace
* PeekTest.cs: Fixed namespace
* SelectorTest.cs: Fixed namespace
2009-07-19 Michael Barker <mike@middlesoft.co.uk>
* AdminTest.cs: Moved to System.Messaging
* AsyncPeekTest.cs: Moved to System.Messaging
* AsyncReceiveTest.cs: Moved to System.Messaging
* BasicMessagingTest.cs: Moved to System.Messaging
* MessageEnumeratorTest.cs: Moved to System.Messaging
* MQUtil.cs: Moved to System.Messaging
* PeekTest.cs: Moved to System.Messaging
* SelectorTest.cs: Moved to System.Messaging
2009-01-05 Michael Barker <mike@middlesoft.co.uk>
* BinaryMessageFormatter.cs, XMLMessageFormatterTest.cs, TestUtils.cs,
MessageTest.cs: Moved to Mono.Messaging.RabbitMQ namespace.
2008-09-29 Michael Barker <mike@middlesoft.co.uk>
* BinaryMessageFormatter.cs: New
2008-09-10 Michael Barker <mike@middlesoft.co.uk>
* XMLMessageFormatterTest.cs: New
* TestUtils.cs: New, utility method for creating Messages.
2008-09-09 Michael Barker <mike@middlesoft.co.uk>
* MessageTest.cs: New
* MessageQueueTest.cs: New
2005-09-22 Sebastien Pouliot <sebastien@ximian.com>
* MessageQueuePermissionAttributeTest.cs: Removed *Choice security
actions. Char #133 is accepted in 2.0.
2004-09-10 Sebastien Pouliot <sebastien@ximian.com>
* MessageQueuePermissionAttributeTest.cs: New. Unit tests for Message
QueuePermissionAttribute.

View File

@@ -0,0 +1,83 @@
//
// Test.Mono.Messaging.RabbitMQ
//
// Authors:
// Michael Barker (mike@middlesoft.co.uk)
//
// (C) 2008 Michael Barker
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Messaging;
namespace MonoTests.System.Messaging
{
public class MQUtil
{
public static string CreateQueueName ()
{
string testServer = Environment.GetEnvironmentVariable ("MONO_TEST_RABBITMQ_SERVER");
if (testServer == null)
{
testServer = @".\private$";
}
return testServer + @"\" + Guid.NewGuid ().ToString ();
}
public static MessageQueue GetQueue (string path)
{
return GetQueue (path, false);
}
public static MessageQueue GetQueue ()
{
return GetQueue (CreateQueueName ());
}
public static MessageQueue GetQueue (string path, bool isTransactional)
{
return GetQueue (path, isTransactional,
new BinaryMessageFormatter ());
}
public static MessageQueue GetQueue (string path, IMessageFormatter formatter)
{
return GetQueue (path, false, formatter);
}
public static MessageQueue GetQueue (string path, bool isTransactional,
IMessageFormatter formatter)
{
MessageQueue q;
if (MessageQueue.Exists (path)) {
q = new MessageQueue (path);
} else {
q = MessageQueue.Create (path, isTransactional);
}
q.Formatter = formatter;
return q;
}
}
}

View File

@@ -0,0 +1,202 @@
//
// Test.Mono.Messaging.RabbitMQ
//
// Authors:
// Michael Barker (mike@middlesoft.co.uk)
//
// (C) 2008 Michael Barker
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Messaging;
using NUnit.Framework;
namespace MonoTests.System.Messaging
{
[TestFixture]
[Ignore]
public class MessageEnumeratorTest {
string qName;
[SetUp]
public void SetUp()
{
qName = MQUtil.CreateQueueName ();
}
private void SendMessage (string s) {
MessageQueue mq = MQUtil.GetQueue (qName);
using (mq) {
Message m = new Message (s, new BinaryMessageFormatter ());
m.CorrelationId = Guid.NewGuid () + "\\0";
mq.Send (m);
}
}
[Test]
public void GetMessagesInOrder ()
{
SendMessage ("message 1");
SendMessage ("message 2");
SendMessage ("message 3");
SendMessage ("message 4");
MessageQueue mq0 = MQUtil.GetQueue (qName);
MessageEnumerator me0 = mq0.GetMessageEnumerator ();
me0.MoveNext ();
Console.WriteLine("Message0 {0}", me0.Current.Body);
me0.MoveNext ();
Console.WriteLine("Message0 {0}", me0.Current.Body);
me0.MoveNext ();
Console.WriteLine("Message0 {0}", me0.Current.Body);
me0.MoveNext ();
Console.WriteLine("Message0 {0}", me0.Current.Body);
me0.Dispose ();
mq0.Dispose ();
MessageQueue mq1 = MQUtil.GetQueue (qName);
MessageEnumerator me1 = mq1.GetMessageEnumerator ();
me1.MoveNext ();
Console.WriteLine("Message1 {0}", me1.Current.Body);
me1.MoveNext ();
Console.WriteLine("Message1 {0}", me1.Current.Body);
me1.MoveNext ();
Console.WriteLine("Message1 {0}", me1.Current.Body);
me1.MoveNext ();
Console.WriteLine("Message1 {0}", me1.Current.Body);
Message m1 = me1.Current;
m1.Formatter = new BinaryMessageFormatter ();
Assert.AreEqual ("message 4", (String) m1.Body, "body incorrect");
mq1.Purge ();
MessageQueue.Delete (qName);
}
[Test]
public void RemoveMessage ()
{
SendMessage ("message 1");
SendMessage ("message 2");
SendMessage ("message 3");
SendMessage ("message 4");
MessageQueue mq0 = MQUtil.GetQueue (qName);
MessageEnumerator me0 = mq0.GetMessageEnumerator ();
me0.MoveNext ();
me0.MoveNext ();
me0.MoveNext ();
Message m0 = me0.RemoveCurrent ();
me0.MoveNext ();
me0.Dispose ();
mq0.Dispose ();
MessageQueue mq1 = MQUtil.GetQueue (qName);
MessageEnumerator me1 = mq1.GetMessageEnumerator ();
me1.MoveNext();
me1.MoveNext();
me1.MoveNext();
Message m1 = me1.Current;
m1.Formatter = new BinaryMessageFormatter ();
Assert.AreEqual ("message 4", (String) m1.Body, "body incorrect");
mq1.Purge ();
MessageQueue.Delete (qName);
}
[Test]
public void RemoveMessageWithTimeout ()
{
SendMessage ("message 1");
SendMessage ("message 2");
SendMessage ("message 3");
SendMessage ("message 4");
MessageQueue mq0 = MQUtil.GetQueue (qName);
MessageEnumerator me0 = mq0.GetMessageEnumerator ();
TimeSpan ts = new TimeSpan (0, 0, 2);
me0.MoveNext (ts);
me0.MoveNext (ts);
me0.MoveNext (ts);
Message m0 = me0.RemoveCurrent (ts);
me0.MoveNext (ts);
me0.Dispose ();
mq0.Dispose ();
MessageQueue mq1 = MQUtil.GetQueue (qName);
MessageEnumerator me1 = mq1.GetMessageEnumerator ();
me1.MoveNext (ts);
me1.MoveNext (ts);
me1.MoveNext (ts);
Message m1 = me1.Current;
m1.Formatter = new BinaryMessageFormatter ();
Assert.AreEqual ("message 4", (String) m1.Body, "body incorrect");
mq1.Purge ();
MessageQueue.Delete (qName);
}
//[Test]
// Not supported with AMQP
public void RemoveMessageWithTx ()
{
MessageQueue q = MQUtil.GetQueue (qName);
q.Formatter = new BinaryMessageFormatter ();
q.Send ("foo1");
q.Send ("foo2");
MessageEnumerator me1 = q.GetMessageEnumerator ();
MessageQueueTransaction tx = new MessageQueueTransaction ();
me1.MoveNext ();
Message m1 = me1.Current;
me1.RemoveCurrent (tx);
tx.Commit ();
me1.Close ();
MessageEnumerator me2 = q.GetMessageEnumerator ();
Assert.IsTrue (me1.MoveNext ());
me2.RemoveCurrent ();
Assert.IsFalse (me2.MoveNext ());
}
}
}

View File

@@ -0,0 +1,268 @@
//
// MessageQueuePermissionAttributeTest.cs -
// NUnit Test Cases for MessageQueuePermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Messaging;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Messaging {
[TestFixture]
public class MessageQueuePermissionAttributeTest {
[Test]
public void Default ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
Assert.IsNull (a.Category, "Category");
Assert.IsNull (a.Label, "Label");
Assert.IsNull (a.MachineName, "MachineName");
Assert.IsNull (a.Path, "Path");
Assert.AreEqual (MessageQueuePermissionAccess.None, a.PermissionAccess, "PermissionAccess");
a.MachineName = "localhost";
MessageQueuePermission sp = (MessageQueuePermission)a.CreatePermission ();
Assert.IsFalse (sp.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void Action ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void Unrestricted ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.MachineName = "localhost";
a.Unrestricted = true;
MessageQueuePermission mqp = (MessageQueuePermission)a.CreatePermission ();
Assert.IsTrue (mqp.IsUnrestricted (), "IsUnrestricted");
a.Unrestricted = false;
mqp = (MessageQueuePermission)a.CreatePermission ();
Assert.IsFalse (mqp.IsUnrestricted (), "!IsUnrestricted");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void Category_Null ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.Category = null;
}
[Test]
public void Category ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.Category = "Mono";
Assert.AreEqual ("Mono", a.Category, "Category-1");
a.Category = String.Empty;
Assert.AreEqual (String.Empty, a.Category, "Category-2");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void Label_Null ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.Label = null;
}
[Test]
public void Label ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.Label = "Mono";
Assert.AreEqual ("Mono", a.Label, "Label-1");
a.Label = String.Empty;
Assert.AreEqual (String.Empty, a.Label, "Label-2");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void MachineName_Null ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.MachineName = null;
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void MachineName_Invalid ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.MachineName = String.Empty;
}
[Test]
public void MachineName ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.MachineName = "Mono";
Assert.AreEqual ("Mono", a.MachineName, "MachineName-1");
for (int i = 0; i < 256; i++) {
try{
a.MachineName = Convert.ToChar (i).ToString ();
Assert.AreEqual (i, (int)a.MachineName [0], i.ToString ());
}
catch {
switch (i) {
case 9:
case 10:
case 11:
case 12:
case 13:
case 32:
case 92:
#if NET_2_0
case 133:
#endif
case 160:
// known invalid chars
break;
default:
Assert.Fail (i.ToString ());
break;
}
}
}
// all first 256 characters seems to be valid
// is there other rules ?
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void Path_Null ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.Path = null;
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Path_Invalid ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.Path = "Mono";
}
[Test]
public void Path ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.Path = "\\Mono";
Assert.AreEqual ("\\Mono", a.Path, "Path-1");
a.Path = "\\";
Assert.AreEqual ("\\", a.Path, "Path-2");
a.Path = String.Empty;
Assert.AreEqual (String.Empty, a.Path, "Path-3");
}
[Test]
public void PermissionAccess_Invalid ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.PermissionAccess = (MessageQueuePermissionAccess) Int32.MinValue;
Assert.AreEqual (Int32.MinValue, (int)a.PermissionAccess);
}
[Test]
public void PermissionAccess ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.PermissionAccess = MessageQueuePermissionAccess.None;
Assert.AreEqual (MessageQueuePermissionAccess.None, a.PermissionAccess, "None");
a.PermissionAccess = MessageQueuePermissionAccess.Browse;
Assert.AreEqual (MessageQueuePermissionAccess.Browse, a.PermissionAccess, "Browse");
a.PermissionAccess = MessageQueuePermissionAccess.Send;
Assert.AreEqual (MessageQueuePermissionAccess.Send, a.PermissionAccess, "Send");
a.PermissionAccess = MessageQueuePermissionAccess.Peek;
Assert.AreEqual (MessageQueuePermissionAccess.Peek, a.PermissionAccess, "Peek");
a.PermissionAccess = MessageQueuePermissionAccess.Receive;
Assert.AreEqual (MessageQueuePermissionAccess.Receive, a.PermissionAccess, "Receive");
a.PermissionAccess = MessageQueuePermissionAccess.Administer;
Assert.AreEqual (MessageQueuePermissionAccess.Administer, a.PermissionAccess, "Administer");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CreatePermission_WithoutMachineName ()
{
MessageQueuePermissionAttribute a = new MessageQueuePermissionAttribute (SecurityAction.Assert);
a.CreatePermission ();
}
[Test]
public void Attributes ()
{
Type t = typeof (MessageQueuePermissionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Event);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}

View File

@@ -0,0 +1,187 @@
//
// Test.Mono.Messaging.RabbitMQ
//
// Authors:
// Michael Barker (mike@middlesoft.co.uk)
//
// (C) 2008 Michael Barker
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Messaging;
using NUnit.Framework;
namespace MonoTests.System.Messaging
{
[TestFixture]
public class PeekTest {
[Test]
public void PeekMessage ()
{
String body = "foo-" + DateTime.Now.ToString ();
Message s1 = new Message(body, new BinaryMessageFormatter());
MessageQueue mq = MQUtil.GetQueue ();
mq.Send (s1);
Message r1 = mq.Peek ();
Assert.AreEqual (body, r1.Body);
Message r2 = mq.Receive ();
Assert.AreEqual (body, r2.Body);
}
[Test]
public void PeekMessageWithTimeout ()
{
String body = "foo-" + DateTime.Now.ToString();
Message s1 = new Message(body, new BinaryMessageFormatter());
MessageQueue mq = MQUtil.GetQueue();
mq.Send (s1);
Message r1 = mq.Peek (new TimeSpan (0, 0, 2));
Assert.AreEqual (body, r1.Body);
Message r2 = mq.Receive ();
Assert.AreEqual (body, r2.Body);
}
[Test]
[ExpectedException (typeof (MessageQueueException))]
public void PeekNoMessageWithTimeout ()
{
MessageQueue mq = MQUtil.GetQueue();
Message r1 = mq.Peek (new TimeSpan (0, 0, 2));
}
[Test]
public void PeekById ()
{
String body = "Foo-" + DateTime.Now.ToString ();
Message s1 = new Message (body, new BinaryMessageFormatter());
MessageQueue q = MQUtil.GetQueue ();
q.Send (s1);
String id = s1.Id;
try {
Message r1 = q.PeekById (id);
Assert.AreEqual (body, r1.Body, "Unable to PeekById correctly");
} finally {
q.Purge ();
}
}
[Test]
public void PeekByIdWithTimeout ()
{
String body = "Foo-" + DateTime.Now.ToString ();
Message s1 = new Message (body, new BinaryMessageFormatter());
MessageQueue q = MQUtil.GetQueue ();
q.Send (s1);
String id = s1.Id;
try {
Message r1 = q.PeekById (id, new TimeSpan (0, 0, 2));
Assert.AreEqual (body, r1.Body, "Unable to PeekById correctly");
} finally {
q.Purge ();
}
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void PeekByIdNotFound ()
{
String body = "Foo-" + DateTime.Now.ToString ();
Message s1 = new Message (body, new BinaryMessageFormatter());
MessageQueue q = MQUtil.GetQueue ();
q.Send (s1);
String id = "fail!";
try {
Message r1 = q.PeekById (id);
} finally {
q.Purge ();
}
}
[Test]
public void PeekByCorrelationId ()
{
String correlationId = Guid.NewGuid () + "\\0";
String body = "Foo-" + DateTime.Now.ToString ();
Message s1 = new Message (body, new BinaryMessageFormatter());
s1.CorrelationId = correlationId;
MessageQueue q = MQUtil.GetQueue ();
q.Formatter = new BinaryMessageFormatter ();
q.Send (s1);
try {
Message r1 = q.PeekByCorrelationId (correlationId);
Assert.AreEqual (body, r1.Body, "Unable to PeekByCorrelationId correctly");
} finally {
q.Purge ();
}
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void PeekByCorrelationIdNotFound ()
{
String body = "Foo-" + DateTime.Now.ToString ();
Message s1 = new Message (body);
String correlationId = Guid.NewGuid() + "\\0";
MessageQueue q = MQUtil.GetQueue();
q.Formatter = new BinaryMessageFormatter ();
q.Send (s1);
try {
Message r1 = q.PeekByCorrelationId ("fail!");
} finally {
q.Purge ();
}
}
[Test]
public void PeekByCorrelationIdWithTimeout ()
{
String correlationId = Guid.NewGuid () + "\\0";
String body = "Foo-" + DateTime.Now.ToString ();
Message s1 = new Message (body, new BinaryMessageFormatter());
s1.CorrelationId = correlationId;
MessageQueue q = MQUtil.GetQueue ();
q.Formatter = new BinaryMessageFormatter ();
q.Send (s1);
try {
Message r1 = q.PeekByCorrelationId (correlationId, new TimeSpan (0, 0, 2));
Assert.AreEqual (body, r1.Body, "Unable to PeekByCorrelationId correctly");
} finally {
q.Purge ();
}
}
}
}

View File

@@ -0,0 +1,139 @@
//
// Test.Mono.Messaging.RabbitMQ
//
// Authors:
// Michael Barker (mike@middlesoft.co.uk)
//
// (C) 2008 Michael Barker
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Messaging;
using NUnit.Framework;
namespace MonoTests.System.Messaging
{
[TestFixture]
// [Ignore]
public class SelectorTest
{
[Test]
public void SelectById ()
{
String body = "Foo-" + DateTime.Now.ToString ();
Message s1 = new Message (body, new BinaryMessageFormatter());
MessageQueue q = MQUtil.GetQueue ();
q.Send (s1);
String id = s1.Id;
Message r1 = q.ReceiveById (id);
Assert.AreEqual (body, r1.Body, "Unable to ReceiveById correctly");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void SelectByIdNotFound ()
{
String body = "Foo-" + DateTime.Now.ToString();
Message s1 = new Message(body, new BinaryMessageFormatter());
MessageQueue q = MQUtil.GetQueue();
q.Send (s1);
String id = "fail!";
try {
Message r1 = q.ReceiveById (id);
} finally {
q.Purge ();
}
}
[Test]
public void SelectByCorrelationId ()
{
string correlationId = Guid.NewGuid () + "\\0";
String body = "Foo-" + DateTime.Now.ToString();
Message s1 = new Message(body, new BinaryMessageFormatter());
s1.CorrelationId = correlationId;
MessageQueue q = MQUtil.GetQueue();
q.Send (s1);
Message r1 = q.ReceiveByCorrelationId (correlationId);
Assert.AreEqual (body, r1.Body, "Unable to ReceiveByCorrelationId correctly");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void SelectByCorrelationIdNotFound ()
{
string correlationId = Guid.NewGuid() + "\\0";
String body = "Foo-" + DateTime.Now.ToString();
Message s1 = new Message(body, new BinaryMessageFormatter());
s1.CorrelationId = correlationId;
MessageQueue q = MQUtil.GetQueue();
q.Send (s1);
try {
Message r1 = q.ReceiveByCorrelationId ("fail!");
} finally {
q.Purge ();
}
}
[Test]
public void SelectByIdWithTimeout ()
{
String body = "Foo-" + DateTime.Now.ToString();
Message s1 = new Message(body, new BinaryMessageFormatter());
MessageQueue q = MQUtil.GetQueue();
q.Send (s1);
String id = s1.Id;
Message r1 = q.ReceiveById (id, new TimeSpan (0, 0, 2));
Assert.AreEqual (body, r1.Body, "Unable to ReceiveById correctly");
}
[Test]
public void SelectByCorrelationIdWithTimeout ()
{
string correlationId = Guid.NewGuid() + "\\0";
String body = "Foo-" + DateTime.Now.ToString();
Message s1 = new Message(body, new BinaryMessageFormatter());
s1.CorrelationId = correlationId;
MessageQueue q = MQUtil.GetQueue();
q.Send (s1);
Message r1 = q.ReceiveByCorrelationId (correlationId, new TimeSpan (0, 0, 2));
Assert.AreEqual (body, r1.Body, "Unable to ReceiveByCorrelationId correctly");
}
}
}

View File

@@ -0,0 +1,467 @@
//
// Test.Mono.Messaging.RabbitMQ
//
// Authors:
// Michael Barker (mike@middlesoft.co.uk)
//
// (C) 2008 Michael Barker
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Messaging;
using System.Reflection;
using System.Threading;
using System.Text.RegularExpressions;
using NUnit.Framework;
namespace MonoTests.System.Messaging
{
[TestFixture]
public class TransactionMessageTest {
[Test]
public void Send2WithTransaction ()
{
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.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");
}
[Test]
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");
}
}
[Test]
[ExpectedException (typeof (MessageQueueException))]
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));
}
}
[Test]
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);
}
}
[Test]
public void ReceiveWithTransactionAbort ()
{
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);
using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
tx.Begin ();
Message received1 = mq.Receive (tx);
tx.Abort ();
}
Message received2 = mq.Receive ();
Assert.AreEqual (body, received2.Body);
}
[Test]
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);
}
[Test]
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");
}
[Test]
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");
}
[Test]
public void ReceiveByIdWithTransaction ()
{
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;
using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
tx.Begin ();
Message received1 = mq.ReceiveById (id, tx);
tx.Commit ();
Assert.AreEqual (body, received1.Body);
}
}
[Test]
public void ReceiveByIdWithTransactionAbort ()
{
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);
string id = sent1.Id;
using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
tx.Begin ();
Message received1 = mq.ReceiveById (id, tx);
tx.Abort ();
}
Message received2 = mq.Receive ();
Assert.AreEqual (body, received2.Body);
}
[Test]
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);
}
[Test]
public void ReceiveByCorrelationIdWithTransaction ()
{
string correlationId = Guid.NewGuid() + "\\0";
String body = "Message 4";
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.Commit ();
Assert.AreEqual (body, received1.Body);
}
}
[Test]
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);
}
[Test]
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);
}
[Test]
public void ReceiveWithTransactionAndTimeout ()
{
String body = "Message 11";
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);
using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
tx.Begin ();
Message received1 = mq.Receive (new TimeSpan (0, 0, 2), tx);
tx.Commit ();
Assert.AreEqual (body, received1.Body);
}
}
[Test]
public void ReceiveWithTransactionAndTimeoutAndAbort ()
{
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);
using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
tx.Begin ();
Message received1 = mq.Receive (new TimeSpan (0, 0, 2), tx);
tx.Abort ();
}
Message received2 = mq.Receive ();
Assert.AreEqual (body, received2.Body);
}
[Test]
public void ReceiveWithTransactionTypeAndTimeout ()
{
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);
Message received1 = mq.Receive (new TimeSpan (0, 0, 5), MessageQueueTransactionType.Single);
Assert.AreEqual (body, received1.Body);
}
[Test]
[ExpectedException (typeof (MessageQueueException))]
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);
}
[Test]
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);
}
}
[Test]
public void ReceiveByIdWithTransactionTypeAndTimeout ()
{
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);
string id = sent1.Id;
Message received1 = mq.ReceiveById (id, new TimeSpan (0, 0, 2), MessageQueueTransactionType.Single);
Assert.AreEqual (body, received1.Body);
}
[Test]
public void ReceiveByCorrelationIdWithTransactionAndTimeout ()
{
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, new TimeSpan (0, 0, 2), tx);
tx.Commit ();
Assert.AreEqual (body, received1.Body);
}
}
[Test]
public void ReceiveByCorrelationIdWithTransactionTypeAndTimeout ()
{
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;
Message received1 = mq.ReceiveByCorrelationId (correlationId, new TimeSpan (0, 0, 2), MessageQueueTransactionType.Single);
Assert.AreEqual (body, received1.Body);
}
}
}