2 // Test.Mono.Messaging.RabbitMQ
5 // Michael Barker (mike@middlesoft.co.uk)
7 // (C) 2008 Michael Barker
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Messaging;
33 using System.Reflection;
34 using System.Threading;
35 using System.Text.RegularExpressions;
37 using NUnit.Framework;
39 namespace MonoTests.Mono.Messaging.RabbitMQ
42 public class AdminTest {
45 public void CreateNonTransactionalQueue ()
47 string qName = @".\private$\admin-queue-1";
48 Assert.IsFalse (MessageQueue.Exists (qName), "Queue should not exist");
49 MessageQueue q = MessageQueue.Create (qName);
50 Assert.IsFalse (q.Transactional);
51 Assert.IsTrue (MessageQueue.Exists (qName), "Queue should exist");
55 public void CreateTransactionalQueue ()
57 string qName = @".\private$\admin-queue-2";
58 Assert.IsFalse (MessageQueue.Exists (qName), "Queue should not exist");
59 MessageQueue q = MessageQueue.Create (qName, true);
60 Assert.IsTrue (q.Transactional, "Queue should be transactional");
61 Assert.IsTrue (MessageQueue.Exists (qName), "Queue should exist");
64 private bool Contains(MessageQueue[] qs, String qName)
66 foreach (MessageQueue q in qs)
68 if (q.QueueName == qName)
75 public void GetPublicQueues ()
77 string qName1 = @".\admin-queue-3";
78 string qName2 = @".\admin-queue-4";
80 MessageQueue.Create (qName1);
81 MessageQueue.Create (qName2);
83 MessageQueue[] mq = MessageQueue.GetPublicQueues ();
84 Assert.IsTrue (Contains (mq, "admin-queue-3"), qName1 + " not found");
85 Assert.IsTrue (Contains (mq, "admin-queue-4"), qName2 + " not found");
89 public void GetQueue ()
91 MessageQueue q1 = MQUtil.GetQueue(@".\private$\admin-queue-5", true);
92 Assert.IsTrue (q1.Transactional, "Queue should be transactional");
93 MessageQueue q2 = MQUtil.GetQueue(@".\private$\admin-queue-5", true);
94 Assert.IsTrue (q2.Transactional, "Queue should be transactional");
98 [ExpectedException (typeof (MessageQueueException))]
99 public void PurgeQueue ()
101 MessageQueue q = MQUtil.GetQueue(@".\private$\purge-queue");
102 Message m1 = new Message ("foobar1", new BinaryMessageFormatter ());
103 Message m2 = new Message ("foobar2", new BinaryMessageFormatter ());
104 Message m3 = new Message ("foobar3", new BinaryMessageFormatter ());
105 Message m4 = new Message ("foobar4", new BinaryMessageFormatter ());
112 Message received = q.Receive ();
114 q.Receive (new TimeSpan (0, 0, 2));
118 public void DeleteQueue ()
120 MessageQueue q = MQUtil.GetQueue(@".\private$\delete-queue");
121 Message m1 = new Message ("foobar1", new BinaryMessageFormatter ());
125 Message received = q.Receive ();
127 MessageQueue.Delete(@".\private$\delete-queue");