move to from olive to mcs
[mono.git] / mcs / class / System.ServiceModel / Test / System.ServiceModel.Channels / MsmqTransportBindingElementTest.cs
1 //
2 // MsmqTransportBindingElementTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2007 Novell, Inc.  http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 using System;
29 using System.Collections.ObjectModel;
30 using System.IO;
31 using System.Net;
32 using System.Net.Security;
33 using System.ServiceModel;
34 using System.ServiceModel.Channels;
35 using System.ServiceModel.Description;
36 using System.Threading;
37 using System.Xml;
38 using NUnit.Framework;
39
40 namespace MonoTests.System.ServiceModel.Channels
41 {
42         [TestFixture]
43         public class MsmqTransportBindingElementTest
44         {
45                 static BindingParameterCollection empty_params =
46                         new BindingParameterCollection ();
47
48                 [Test]
49                 public void DefaultValues ()
50                 {
51                         MsmqTransportBindingElement be =
52                                 new MsmqTransportBindingElement ();
53                         Assert.AreEqual (8, be.MaxPoolSize, "#1");
54                         Assert.AreEqual (0x80000, be.MaxBufferPoolSize, "#2");
55                         Assert.AreEqual (QueueTransferProtocol.Native, be.QueueTransferProtocol, "#2");
56                         Assert.AreEqual ("net.msmq", be.Scheme, "#3");
57
58                         Assert.IsNull (be.CustomDeadLetterQueue, "#5");
59                         Assert.AreEqual (DeadLetterQueue.System, be.DeadLetterQueue, "#6");
60                         Assert.IsTrue (be.Durable, "#7");
61                         Assert.IsTrue (be.ExactlyOnce, "#8");
62                         Assert.AreEqual (0x10000, be.MaxReceivedMessageSize, "#9");
63                         Assert.AreEqual (2, be.MaxRetryCycles, "#10");
64                         Assert.AreEqual (ReceiveErrorHandling.Fault, be.ReceiveErrorHandling, "#11");
65                         Assert.AreEqual (5, be.ReceiveRetryCount, "#12");
66                         // hmm, it is documented as 10 minutes but ...
67                         Assert.AreEqual (TimeSpan.FromMinutes (30), be.RetryCycleDelay, "#13");
68                         Assert.AreEqual (TimeSpan.FromDays (1), be.TimeToLive, "#15");
69                         Assert.IsFalse (be.UseMsmqTracing, "#16");
70                         Assert.IsFalse (be.UseSourceJournal, "#17");
71                 }
72
73                 [Test]
74                 public void CanBuildChannelFactory ()
75                 {
76                         MsmqTransportBindingElement be =
77                                 new MsmqTransportBindingElement ();
78                         BindingContext ctx = new BindingContext (
79                                 new CustomBinding (), empty_params);
80                         Assert.IsFalse (be.CanBuildChannelFactory<IRequestChannel> (ctx), "#1");
81                         Assert.IsFalse (be.CanBuildChannelFactory<IInputChannel> (ctx), "#2");
82                         Assert.IsFalse (be.CanBuildChannelFactory<IReplyChannel> (ctx), "#3");
83                         Assert.IsTrue (be.CanBuildChannelFactory<IOutputChannel> (ctx), "#4");
84                         Assert.IsFalse (be.CanBuildChannelFactory<IRequestSessionChannel> (ctx), "#5");
85                         Assert.IsFalse (be.CanBuildChannelFactory<IInputSessionChannel> (ctx), "#6");
86                         Assert.IsFalse (be.CanBuildChannelFactory<IReplySessionChannel> (ctx), "#7");
87                         Assert.IsTrue (be.CanBuildChannelFactory<IOutputSessionChannel> (ctx), "#8");
88
89                         // IServiceChannel is not supported
90                         Assert.IsFalse (be.CanBuildChannelListener<IServiceChannel> (ctx), "#9");
91                 }
92
93                 [Test]
94                 public void CanBuildChannelListener ()
95                 {
96                         MsmqTransportBindingElement be =
97                                 new MsmqTransportBindingElement ();
98                         BindingContext ctx = new BindingContext (
99                                 new CustomBinding (), empty_params);
100                         Assert.IsFalse (be.CanBuildChannelListener<IReplyChannel> (ctx), "#1");
101                         Assert.IsFalse (be.CanBuildChannelListener<IOutputChannel> (ctx), "#2");
102                         Assert.IsFalse (be.CanBuildChannelListener<IRequestChannel> (ctx), "#3");
103                         Assert.IsTrue (be.CanBuildChannelListener<IInputChannel> (ctx), "#4");
104                         Assert.IsFalse (be.CanBuildChannelListener<IReplySessionChannel> (ctx), "#5");
105                         Assert.IsFalse (be.CanBuildChannelListener<IOutputSessionChannel> (ctx), "#6");
106                         Assert.IsFalse (be.CanBuildChannelListener<IRequestSessionChannel> (ctx), "#7");
107                         Assert.IsTrue (be.CanBuildChannelListener<IInputSessionChannel> (ctx), "#8");
108
109                         // IServiceChannel is not supported
110                         Assert.IsFalse (be.CanBuildChannelListener<IServiceChannel> (ctx), "#9");
111                 }
112
113                 [Test]
114                 public void BuildChannelFactory ()
115                 {
116                         MsmqTransportBindingElement be =
117                                 new MsmqTransportBindingElement ();
118                         // Without settings them, it borks when MSMQ setup
119                         // does not support AD integration.
120                         be.MsmqTransportSecurity.MsmqAuthenticationMode =
121                                 MsmqAuthenticationMode.None;
122                         be.MsmqTransportSecurity.MsmqProtectionLevel =
123                                 ProtectionLevel.None;
124
125                         BindingContext ctx = new BindingContext (
126                                 new CustomBinding (be),
127                                 empty_params);
128                         // returns MsmqChannelFactory
129                         IChannelFactory<IOutputChannel> f =
130                                 ctx.BuildInnerChannelFactory<IOutputChannel> ();
131                         f.Open (); // required
132                         IChannel c = f.CreateChannel (new EndpointAddress (
133                                 "net.msmq://nosuchqueueexists"));
134                 }
135
136                 [Test]
137                 [ExpectedException (typeof (InvalidOperationException))]
138                 public void CreateChannelWithoutOpen ()
139                 {
140                         MsmqTransportBindingElement be =
141                                 new MsmqTransportBindingElement ();
142                         // Without settings them, it borks when MSMQ setup
143                         // does not support AD integration.
144                         be.MsmqTransportSecurity.MsmqAuthenticationMode =
145                                 MsmqAuthenticationMode.None;
146                         be.MsmqTransportSecurity.MsmqProtectionLevel =
147                                 ProtectionLevel.None;
148
149                         BindingContext ctx = new BindingContext (
150                                 new CustomBinding (be),
151                                 empty_params);
152                         // returns MsmqChannelFactory
153                         IChannelFactory<IOutputChannel> f =
154                                 ctx.BuildInnerChannelFactory<IOutputChannel> ();
155
156                         IChannel c = f.CreateChannel (new EndpointAddress (
157                                 "net.msmq://nosuchqueueexists"));
158                 }
159
160                 [Test]
161                 [ExpectedException (typeof (ArgumentException))]
162                 public void CreateChannelInvalidScheme ()
163                 {
164                         MsmqTransportBindingElement be =
165                                 new MsmqTransportBindingElement ();
166                         // Without settings them, it borks when MSMQ setup
167                         // does not support AD integration.
168                         be.MsmqTransportSecurity.MsmqAuthenticationMode =
169                                 MsmqAuthenticationMode.None;
170                         be.MsmqTransportSecurity.MsmqProtectionLevel =
171                                 ProtectionLevel.None;
172
173                         BindingContext ctx = new BindingContext (
174                                 new CustomBinding (be),
175                                 empty_params);
176                         // returns MsmqChannelFactory
177                         IChannelFactory<IOutputChannel> f =
178                                 ctx.BuildInnerChannelFactory<IOutputChannel> ();
179                         f.Open ();
180                         f.CreateChannel (new EndpointAddress ("stream:dummy"));
181                 }
182         }
183 }