Move tests that do not reference RabbitMQ to System.Messaging.
[mono.git] / mcs / class / System.Messaging / Test / System.Messaging / SelectorTest.cs
1 //
2 // Test.Mono.Messaging.RabbitMQ
3 //
4 // Authors:
5 //        Michael Barker (mike@middlesoft.co.uk)
6 //
7 // (C) 2008 Michael Barker
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using System;
32 using System.Messaging;
33
34 using NUnit.Framework;
35
36 namespace MonoTests.Mono.Messaging.RabbitMQ
37 {
38         [TestFixture]
39         public class SelectorTest
40         {
41                 
42                 [Test]
43                 public void SelectById ()
44                 {
45                         String body = "Foo-" + DateTime.Now.ToString ();
46                         Message s1 = new Message (body, new BinaryMessageFormatter());
47                         MessageQueue q = MQUtil.GetQueue (@".\private$\selector-queue-1");
48                         q.Send (s1);
49                         
50                         String id = s1.Id;
51                         
52                         Message r1 = q.ReceiveById (id);
53                         
54                         Assert.AreEqual (body, r1.Body, "Unable to ReceiveById correctly");
55                 }
56                 
57                 [Test]
58                 [ExpectedException (typeof (InvalidOperationException))]
59                 public void SelectByIdNotFound ()
60                 {
61                         String body = "Foo-" + DateTime.Now.ToString();
62                         Message s1 = new Message(body, new BinaryMessageFormatter());
63                         MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-2");
64                         q.Send (s1);
65                         
66                         String id = "fail!";
67                         
68                         try {
69                                 Message r1 = q.ReceiveById (id);
70                         } finally {
71                                 q.Purge ();
72                         }
73                 }
74                 
75                 [Test]
76                 public void SelectByCorrelationId ()
77                 {
78                         string correlationId = Guid.NewGuid () + "\\0";
79                         String body = "Foo-" + DateTime.Now.ToString();
80                         Message s1 = new Message(body, new BinaryMessageFormatter());
81                         s1.CorrelationId = correlationId;
82                         MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-3");
83                         q.Send (s1);
84                         
85                         Message r1 = q.ReceiveByCorrelationId (correlationId);
86                         
87                         Assert.AreEqual (body, r1.Body, "Unable to ReceiveByCorrelationId correctly");
88                 }
89                 
90                 [Test]
91                 [ExpectedException (typeof (InvalidOperationException))]
92                 public void SelectByCorrelationIdNotFound ()
93                 {
94                         string correlationId = Guid.NewGuid() + "\\0";
95                         String body = "Foo-" + DateTime.Now.ToString();
96                         Message s1 = new Message(body, new BinaryMessageFormatter());
97                         s1.CorrelationId = correlationId;
98                         MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-4");
99                         q.Send (s1);
100                         
101                         try {
102                                 Message r1 = q.ReceiveByCorrelationId ("fail!");
103                         } finally {
104                                 q.Purge ();
105                         }
106                 }
107                 
108                 [Test]
109                 public void SelectByIdWithTimeout ()
110                 {
111                         String body = "Foo-" + DateTime.Now.ToString();
112                         Message s1 = new Message(body, new BinaryMessageFormatter());
113                         MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-5");
114                         q.Send (s1);
115                         
116                         String id = s1.Id;
117                         
118                         Message r1 = q.ReceiveById (id, new TimeSpan (0, 0, 2));
119                         
120                         Assert.AreEqual (body, r1.Body, "Unable to ReceiveById correctly");
121                 }
122                                 
123                 [Test]
124                 public void SelectByCorrelationIdWithTimeout ()
125                 {
126                         string correlationId = Guid.NewGuid() + "\\0";
127                         String body = "Foo-" + DateTime.Now.ToString();
128                         Message s1 = new Message(body, new BinaryMessageFormatter());
129                         s1.CorrelationId = correlationId;
130                         MessageQueue q = MQUtil.GetQueue(@".\private$\selector-queue-3");
131                         q.Send (s1);
132                         
133                         Message r1 = q.ReceiveByCorrelationId (correlationId, new TimeSpan (0, 0, 2));
134                         
135                         Assert.AreEqual (body, r1.Body, "Unable to ReceiveByCorrelationId correctly");
136                 }
137         }
138 }