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;
34 //using Mono.Messaging;
35 //using Mono.Messaging.RabbitMQ;
37 using NUnit.Framework;
39 namespace MonoTests.Mono.Messaging.RabbitMQ
42 public class MessageEnumeratorTest {
44 private readonly String qName = @".\private$\testq2";
46 private void SendMessage (string s) {
47 MessageQueue mq = MQUtil.GetQueue (qName);
48 Message m = new Message (s, new BinaryMessageFormatter ());
49 m.CorrelationId = Guid.NewGuid () + "\\0";
54 public void RemoveMessage ()
56 SendMessage ("message 1");
57 SendMessage ("message 2");
58 SendMessage ("message 3");
59 SendMessage ("message 4");
61 MessageQueue mq0 = MQUtil.GetQueue (qName);
62 MessageEnumerator me0 = mq0.GetMessageEnumerator ();
68 Message m0 = me0.RemoveCurrent ();
75 MessageQueue mq1 = MQUtil.GetQueue (qName);
76 MessageEnumerator me1 = mq1.GetMessageEnumerator ();
82 Message m1 = me1.Current;
83 m1.Formatter = new BinaryMessageFormatter ();
84 Assert.AreEqual ("message 4", (String) m1.Body, "body incorrect");
87 MessageQueue.Delete (qName);
91 public void RemoveMessageWithTimeout ()
93 SendMessage ("message 1");
94 SendMessage ("message 2");
95 SendMessage ("message 3");
96 SendMessage ("message 4");
98 MessageQueue mq0 = MQUtil.GetQueue (qName);
99 MessageEnumerator me0 = mq0.GetMessageEnumerator ();
101 TimeSpan ts = new TimeSpan (0, 0, 2);
107 Message m0 = me0.RemoveCurrent (ts);
114 MessageQueue mq1 = MQUtil.GetQueue (qName);
115 MessageEnumerator me1 = mq1.GetMessageEnumerator ();
121 Message m1 = me1.Current;
122 m1.Formatter = new BinaryMessageFormatter ();
123 Assert.AreEqual ("message 4", (String) m1.Body, "body incorrect");
126 MessageQueue.Delete (qName);
130 // Not supported with AMQP
131 public void RemoveMessageWithTx ()
133 MessageQueue q = MQUtil.GetQueue ("testq3");
135 q.Formatter = new BinaryMessageFormatter ();
139 MessageEnumerator me1 = q.GetMessageEnumerator ();
140 MessageQueueTransaction tx = new MessageQueueTransaction ();
142 Message m1 = me1.Current;
143 me1.RemoveCurrent (tx);
147 MessageEnumerator me2 = q.GetMessageEnumerator ();
148 Assert.IsTrue (me1.MoveNext ());
149 me2.RemoveCurrent ();
150 Assert.IsFalse (me2.MoveNext ());