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 NUnit.Framework;
36 namespace MonoTests.System.Messaging
39 public class MessageEnumeratorTest {
46 qName = MQUtil.CreateQueueName ();
49 private void SendMessage (string s) {
50 MessageQueue mq = MQUtil.GetQueue (qName);
51 Message m = new Message (s, new BinaryMessageFormatter ());
52 m.CorrelationId = Guid.NewGuid () + "\\0";
57 public void RemoveMessage ()
59 SendMessage ("message 1");
60 SendMessage ("message 2");
61 SendMessage ("message 3");
62 SendMessage ("message 4");
64 MessageQueue mq0 = MQUtil.GetQueue (qName);
65 MessageEnumerator me0 = mq0.GetMessageEnumerator ();
71 Message m0 = me0.RemoveCurrent ();
78 MessageQueue mq1 = MQUtil.GetQueue (qName);
79 MessageEnumerator me1 = mq1.GetMessageEnumerator ();
85 Message m1 = me1.Current;
86 m1.Formatter = new BinaryMessageFormatter ();
87 Assert.AreEqual ("message 4", (String) m1.Body, "body incorrect");
90 MessageQueue.Delete (qName);
94 public void RemoveMessageWithTimeout ()
96 SendMessage ("message 1");
97 SendMessage ("message 2");
98 SendMessage ("message 3");
99 SendMessage ("message 4");
101 MessageQueue mq0 = MQUtil.GetQueue (qName);
102 MessageEnumerator me0 = mq0.GetMessageEnumerator ();
104 TimeSpan ts = new TimeSpan (0, 0, 2);
110 Message m0 = me0.RemoveCurrent (ts);
117 MessageQueue mq1 = MQUtil.GetQueue (qName);
118 MessageEnumerator me1 = mq1.GetMessageEnumerator ();
124 Message m1 = me1.Current;
125 m1.Formatter = new BinaryMessageFormatter ();
126 Assert.AreEqual ("message 4", (String) m1.Body, "body incorrect");
129 MessageQueue.Delete (qName);
133 // Not supported with AMQP
134 public void RemoveMessageWithTx ()
136 MessageQueue q = MQUtil.GetQueue (qName);
138 q.Formatter = new BinaryMessageFormatter ();
142 MessageEnumerator me1 = q.GetMessageEnumerator ();
143 MessageQueueTransaction tx = new MessageQueueTransaction ();
145 Message m1 = me1.Current;
146 me1.RemoveCurrent (tx);
150 MessageEnumerator me2 = q.GetMessageEnumerator ();
151 Assert.IsTrue (me1.MoveNext ());
152 me2.RemoveCurrent ();
153 Assert.IsFalse (me2.MoveNext ());