2 // MsmqTransportBindingElementTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2007 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 using System.Collections.ObjectModel;
32 using System.Net.Security;
33 using System.ServiceModel;
34 using System.ServiceModel.Channels;
35 using System.ServiceModel.Description;
36 using System.Threading;
38 using NUnit.Framework;
40 namespace MonoTests.System.ServiceModel.Channels
43 public class MsmqTransportBindingElementTest
45 static BindingParameterCollection empty_params =
46 new BindingParameterCollection ();
49 public void DefaultValues ()
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");
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");
74 public void CanBuildChannelFactory ()
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");
89 // IServiceChannel is not supported
90 Assert.IsFalse (be.CanBuildChannelListener<IServiceChannel> (ctx), "#9");
94 public void CanBuildChannelListener ()
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");
109 // IServiceChannel is not supported
110 Assert.IsFalse (be.CanBuildChannelListener<IServiceChannel> (ctx), "#9");
114 public void BuildChannelFactory ()
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;
125 BindingContext ctx = new BindingContext (
126 new CustomBinding (be),
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"));
137 [ExpectedException (typeof (InvalidOperationException))]
138 public void CreateChannelWithoutOpen ()
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;
149 BindingContext ctx = new BindingContext (
150 new CustomBinding (be),
152 // returns MsmqChannelFactory
153 IChannelFactory<IOutputChannel> f =
154 ctx.BuildInnerChannelFactory<IOutputChannel> ();
156 IChannel c = f.CreateChannel (new EndpointAddress (
157 "net.msmq://nosuchqueueexists"));
161 [ExpectedException (typeof (ArgumentException))]
162 public void CreateChannelInvalidScheme ()
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;
173 BindingContext ctx = new BindingContext (
174 new CustomBinding (be),
176 // returns MsmqChannelFactory
177 IChannelFactory<IOutputChannel> f =
178 ctx.BuildInnerChannelFactory<IOutputChannel> ();
180 f.CreateChannel (new EndpointAddress ("stream:dummy"));