MsmqTransportBindingElementTest.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // MsmqTransportBindingElementTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  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. namespace MonoTests.System.ServiceModel.Channels
  40. {
  41. [TestFixture]
  42. public class MsmqTransportBindingElementTest
  43. {
  44. static BindingParameterCollection empty_params =
  45. new BindingParameterCollection ();
  46. [Test]
  47. public void DefaultValues ()
  48. {
  49. MsmqTransportBindingElement be =
  50. new MsmqTransportBindingElement ();
  51. Assert.AreEqual (8, be.MaxPoolSize, "#1");
  52. Assert.AreEqual (0x80000, be.MaxBufferPoolSize, "#2");
  53. Assert.AreEqual (QueueTransferProtocol.Native, be.QueueTransferProtocol, "#2");
  54. Assert.AreEqual ("net.msmq", be.Scheme, "#3");
  55. Assert.IsNull (be.CustomDeadLetterQueue, "#5");
  56. Assert.AreEqual (DeadLetterQueue.System, be.DeadLetterQueue, "#6");
  57. Assert.IsTrue (be.Durable, "#7");
  58. Assert.IsTrue (be.ExactlyOnce, "#8");
  59. Assert.AreEqual (0x10000, be.MaxReceivedMessageSize, "#9");
  60. Assert.AreEqual (2, be.MaxRetryCycles, "#10");
  61. Assert.AreEqual (ReceiveErrorHandling.Fault, be.ReceiveErrorHandling, "#11");
  62. Assert.AreEqual (5, be.ReceiveRetryCount, "#12");
  63. // hmm, it is documented as 10 minutes but ...
  64. Assert.AreEqual (TimeSpan.FromMinutes (30), be.RetryCycleDelay, "#13");
  65. Assert.AreEqual (TimeSpan.FromDays (1), be.TimeToLive, "#15");
  66. Assert.IsFalse (be.UseMsmqTracing, "#16");
  67. Assert.IsFalse (be.UseSourceJournal, "#17");
  68. }
  69. [Test]
  70. public void CanBuildChannelFactory ()
  71. {
  72. MsmqTransportBindingElement be =
  73. new MsmqTransportBindingElement ();
  74. BindingContext ctx = new BindingContext (
  75. new CustomBinding (), empty_params);
  76. Assert.IsFalse (be.CanBuildChannelFactory<IRequestChannel> (ctx), "#1");
  77. Assert.IsFalse (be.CanBuildChannelFactory<IInputChannel> (ctx), "#2");
  78. Assert.IsFalse (be.CanBuildChannelFactory<IReplyChannel> (ctx), "#3");
  79. Assert.IsTrue (be.CanBuildChannelFactory<IOutputChannel> (ctx), "#4");
  80. Assert.IsFalse (be.CanBuildChannelFactory<IRequestSessionChannel> (ctx), "#5");
  81. Assert.IsFalse (be.CanBuildChannelFactory<IInputSessionChannel> (ctx), "#6");
  82. Assert.IsFalse (be.CanBuildChannelFactory<IReplySessionChannel> (ctx), "#7");
  83. Assert.IsTrue (be.CanBuildChannelFactory<IOutputSessionChannel> (ctx), "#8");
  84. // IServiceChannel is not supported
  85. Assert.IsFalse (be.CanBuildChannelListener<IServiceChannel> (ctx), "#9");
  86. }
  87. [Test]
  88. public void CanBuildChannelListener ()
  89. {
  90. MsmqTransportBindingElement be =
  91. new MsmqTransportBindingElement ();
  92. BindingContext ctx = new BindingContext (
  93. new CustomBinding (), empty_params);
  94. Assert.IsFalse (be.CanBuildChannelListener<IReplyChannel> (ctx), "#1");
  95. Assert.IsFalse (be.CanBuildChannelListener<IOutputChannel> (ctx), "#2");
  96. Assert.IsFalse (be.CanBuildChannelListener<IRequestChannel> (ctx), "#3");
  97. Assert.IsTrue (be.CanBuildChannelListener<IInputChannel> (ctx), "#4");
  98. Assert.IsFalse (be.CanBuildChannelListener<IReplySessionChannel> (ctx), "#5");
  99. Assert.IsFalse (be.CanBuildChannelListener<IOutputSessionChannel> (ctx), "#6");
  100. Assert.IsFalse (be.CanBuildChannelListener<IRequestSessionChannel> (ctx), "#7");
  101. Assert.IsTrue (be.CanBuildChannelListener<IInputSessionChannel> (ctx), "#8");
  102. // IServiceChannel is not supported
  103. Assert.IsFalse (be.CanBuildChannelListener<IServiceChannel> (ctx), "#9");
  104. }
  105. [Test]
  106. public void BuildChannelFactory ()
  107. {
  108. MsmqTransportBindingElement be =
  109. new MsmqTransportBindingElement ();
  110. // Without settings them, it borks when MSMQ setup
  111. // does not support AD integration.
  112. be.MsmqTransportSecurity.MsmqAuthenticationMode =
  113. MsmqAuthenticationMode.None;
  114. be.MsmqTransportSecurity.MsmqProtectionLevel =
  115. ProtectionLevel.None;
  116. BindingContext ctx = new BindingContext (
  117. new CustomBinding (be),
  118. empty_params);
  119. // returns MsmqChannelFactory
  120. IChannelFactory<IOutputChannel> f =
  121. ctx.BuildInnerChannelFactory<IOutputChannel> ();
  122. f.Open (); // required
  123. IChannel c = f.CreateChannel (new EndpointAddress (
  124. "net.msmq://nosuchqueueexists"));
  125. }
  126. [Test]
  127. [ExpectedException (typeof (InvalidOperationException))]
  128. public void CreateChannelWithoutOpen ()
  129. {
  130. MsmqTransportBindingElement be =
  131. new MsmqTransportBindingElement ();
  132. // Without settings them, it borks when MSMQ setup
  133. // does not support AD integration.
  134. be.MsmqTransportSecurity.MsmqAuthenticationMode =
  135. MsmqAuthenticationMode.None;
  136. be.MsmqTransportSecurity.MsmqProtectionLevel =
  137. ProtectionLevel.None;
  138. BindingContext ctx = new BindingContext (
  139. new CustomBinding (be),
  140. empty_params);
  141. // returns MsmqChannelFactory
  142. IChannelFactory<IOutputChannel> f =
  143. ctx.BuildInnerChannelFactory<IOutputChannel> ();
  144. IChannel c = f.CreateChannel (new EndpointAddress (
  145. "net.msmq://nosuchqueueexists"));
  146. }
  147. [Test]
  148. [ExpectedException (typeof (ArgumentException))]
  149. public void CreateChannelInvalidScheme ()
  150. {
  151. MsmqTransportBindingElement be =
  152. new MsmqTransportBindingElement ();
  153. // Without settings them, it borks when MSMQ setup
  154. // does not support AD integration.
  155. be.MsmqTransportSecurity.MsmqAuthenticationMode =
  156. MsmqAuthenticationMode.None;
  157. be.MsmqTransportSecurity.MsmqProtectionLevel =
  158. ProtectionLevel.None;
  159. BindingContext ctx = new BindingContext (
  160. new CustomBinding (be),
  161. empty_params);
  162. // returns MsmqChannelFactory
  163. IChannelFactory<IOutputChannel> f =
  164. ctx.BuildInnerChannelFactory<IOutputChannel> ();
  165. f.Open ();
  166. f.CreateChannel (new EndpointAddress ("stream:dummy"));
  167. }
  168. }
  169. }