Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AdminTest.cs « Mono.Messaging.RabbitMQ « Test « Mono.Messaging.RabbitMQ « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 612f401988de7df3259e765ba536cf04b916b236 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// 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.Mono.Messaging.RabbitMQ
{
	[TestFixture]
	public class AdminTest {
		
		[Test]
		public void CreateNonTransactionalQueue ()
		{
			string qName = @".\private$\admin-queue-1";
			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 = @".\private$\admin-queue-2";
			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";
			
			MessageQueue.Create (qName1);
			MessageQueue.Create (qName2);
			
			MessageQueue[] mq = MessageQueue.GetPublicQueues ();
			Assert.IsTrue (Contains (mq, "admin-queue-3"), qName1 + " not found");
			Assert.IsTrue (Contains (mq, "admin-queue-4"), qName2 + " not found");
		}
		
		[Test]
		public void GetQueue ()
		{
			MessageQueue q1 = MQUtil.GetQueue(@".\private$\admin-queue-5", true);
			Assert.IsTrue (q1.Transactional, "Queue should be transactional");
			MessageQueue q2 = MQUtil.GetQueue(@".\private$\admin-queue-5", true);
			Assert.IsTrue (q2.Transactional, "Queue should be transactional");
		}
		
		[Test]
		[ExpectedException (typeof (MessageQueueException))]
		public void PurgeQueue ()
		{
			MessageQueue q = MQUtil.GetQueue(@".\private$\purge-queue");
			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);
			
			Message received = q.Receive ();			
			q.Purge ();
			q.Receive (new TimeSpan (0, 0, 2));
		}
				
		[Test]
		public void DeleteQueue ()
		{
			MessageQueue q = MQUtil.GetQueue(@".\private$\delete-queue");
			Message m1 = new Message ("foobar1", new BinaryMessageFormatter ());
			
			q.Send (m1);
			
			Message received = q.Receive ();

			MessageQueue.Delete(@".\private$\delete-queue");
		}
	}
}