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.Mono.Messaging.RabbitMQ
39 public class PeekTest {
42 public void PeekMessage ()
44 String body = "foo-" + DateTime.Now.ToString ();
45 Message s1 = new Message(body, new BinaryMessageFormatter());
46 MessageQueue mq = MQUtil.GetQueue (@".\private$\peek-queue-1");
49 Message r1 = mq.Peek ();
50 Assert.AreEqual (body, r1.Body);
52 Message r2 = mq.Receive ();
53 Assert.AreEqual (body, r2.Body);
57 public void PeekMessageWithTimeout ()
59 String body = "foo-" + DateTime.Now.ToString();
60 Message s1 = new Message(body, new BinaryMessageFormatter());
61 MessageQueue mq = MQUtil.GetQueue(@".\private$\peek-queue-2");
64 Message r1 = mq.Peek (new TimeSpan (0, 0, 2));
65 Assert.AreEqual (body, r1.Body);
67 Message r2 = mq.Receive ();
68 Assert.AreEqual (body, r2.Body);
72 [ExpectedException (typeof (MessageQueueException))]
73 public void PeekNoMessageWithTimeout ()
75 MessageQueue mq = MQUtil.GetQueue(@".\private$\peek-queue-3");
76 Message r1 = mq.Peek (new TimeSpan (0, 0, 2));
80 public void PeekById ()
82 String body = "Foo-" + DateTime.Now.ToString ();
83 Message s1 = new Message (body, new BinaryMessageFormatter());
84 MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-4");
89 Message r1 = q.PeekById (id);
90 Assert.AreEqual (body, r1.Body, "Unable to PeekById correctly");
97 public void PeekByIdWithTimeout ()
99 String body = "Foo-" + DateTime.Now.ToString ();
100 Message s1 = new Message (body, new BinaryMessageFormatter());
101 MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-5");
106 Message r1 = q.PeekById (id, new TimeSpan (0, 0, 2));
107 Assert.AreEqual (body, r1.Body, "Unable to PeekById correctly");
114 [ExpectedException (typeof (InvalidOperationException))]
115 public void PeekByIdNotFound ()
117 String body = "Foo-" + DateTime.Now.ToString ();
118 Message s1 = new Message (body, new BinaryMessageFormatter());
119 MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-6");
125 Message r1 = q.PeekById (id);
132 public void PeekByCorrelationId ()
134 String correlationId = Guid.NewGuid () + "\\0";
135 String body = "Foo-" + DateTime.Now.ToString ();
136 Message s1 = new Message (body, new BinaryMessageFormatter());
137 s1.CorrelationId = correlationId;
138 MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-7");
139 q.Formatter = new BinaryMessageFormatter ();
143 Message r1 = q.PeekByCorrelationId (correlationId);
144 Assert.AreEqual (body, r1.Body, "Unable to PeekByCorrelationId correctly");
151 [ExpectedException (typeof (InvalidOperationException))]
152 public void PeekByCorrelationIdNotFound ()
154 String body = "Foo-" + DateTime.Now.ToString ();
155 Message s1 = new Message (body);
156 String correlationId = Guid.NewGuid() + "\\0";
157 MessageQueue q = MQUtil.GetQueue(@".\private$\peek-queue-8");
158 q.Formatter = new BinaryMessageFormatter ();
162 Message r1 = q.PeekByCorrelationId ("fail!");
169 public void PeekByCorrelationIdWithTimeout ()
171 String correlationId = Guid.NewGuid () + "\\0";
172 String body = "Foo-" + DateTime.Now.ToString ();
173 Message s1 = new Message (body, new BinaryMessageFormatter());
174 s1.CorrelationId = correlationId;
175 MessageQueue q = MQUtil.GetQueue (@".\private$\peek-queue-9");
176 q.Formatter = new BinaryMessageFormatter ();
180 Message r1 = q.PeekByCorrelationId (correlationId, new TimeSpan (0, 0, 2));
181 Assert.AreEqual (body, r1.Body, "Unable to PeekByCorrelationId correctly");