TcpTransportBindingElementTest.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // TcpTransportBindingElementTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2008 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 TcpTransportBindingElementTest
  43. {
  44. static BindingParameterCollection empty_params =
  45. new BindingParameterCollection ();
  46. [Test]
  47. public void DefaultValues ()
  48. {
  49. TcpTransportBindingElement be =
  50. new TcpTransportBindingElement ();
  51. Assert.AreEqual (TimeSpan.FromSeconds (5), be.ChannelInitializationTimeout, "#1");
  52. Assert.AreEqual (0x2000, be.ConnectionBufferSize, "#2");
  53. Assert.AreEqual (HostNameComparisonMode.StrongWildcard, be.HostNameComparisonMode, "#3");
  54. Assert.AreEqual (0x10000, be.MaxBufferSize, "#4");
  55. Assert.AreEqual (TimeSpan.FromMilliseconds (200), be.MaxOutputDelay, "#5");
  56. Assert.AreEqual (1, be.MaxPendingAccepts, "#6");
  57. Assert.AreEqual (10, be.MaxPendingConnections, "#7");
  58. Assert.AreEqual (TransferMode.Buffered, be.TransferMode, "#8");
  59. Assert.AreEqual (10, be.ListenBacklog, "#9");
  60. Assert.IsFalse (be.PortSharingEnabled, "#10");
  61. Assert.AreEqual ("net.tcp", be.Scheme, "#11");
  62. Assert.IsFalse (be.TeredoEnabled, "#12");
  63. TcpConnectionPoolSettings pool = be.ConnectionPoolSettings;
  64. Assert.IsNotNull (pool, "#13");
  65. Assert.AreEqual ("default", pool.GroupName, "#14");
  66. Assert.AreEqual (TimeSpan.FromSeconds (120), pool.IdleTimeout, "#15");
  67. Assert.AreEqual (TimeSpan.FromSeconds (300), pool.LeaseTimeout, "#16");
  68. Assert.AreEqual (10, pool.MaxOutboundConnectionsPerEndpoint, "#17");
  69. }
  70. [Test]
  71. public void CanBuildChannelFactory ()
  72. {
  73. TcpTransportBindingElement be =
  74. new TcpTransportBindingElement ();
  75. BindingContext ctx = new BindingContext (
  76. new CustomBinding (), empty_params);
  77. Assert.IsFalse (be.CanBuildChannelFactory<IRequestChannel> (ctx), "#1");
  78. Assert.IsFalse (be.CanBuildChannelFactory<IInputChannel> (ctx), "#2");
  79. Assert.IsFalse (be.CanBuildChannelFactory<IReplyChannel> (ctx), "#3");
  80. Assert.IsFalse (be.CanBuildChannelFactory<IOutputChannel> (ctx), "#4");
  81. Assert.IsFalse (be.CanBuildChannelFactory<IRequestSessionChannel> (ctx), "#5");
  82. Assert.IsFalse (be.CanBuildChannelFactory<IInputSessionChannel> (ctx), "#6");
  83. Assert.IsFalse (be.CanBuildChannelFactory<IReplySessionChannel> (ctx), "#7");
  84. Assert.IsFalse (be.CanBuildChannelFactory<IOutputSessionChannel> (ctx), "#8");
  85. // IServiceChannel is not supported
  86. Assert.IsFalse (be.CanBuildChannelFactory<IServiceChannel> (ctx), "#9");
  87. Assert.IsFalse (be.CanBuildChannelFactory<IClientChannel> (ctx), "#10");
  88. Assert.IsFalse (be.CanBuildChannelFactory<IDuplexChannel> (ctx), "#11");
  89. Assert.IsTrue (be.CanBuildChannelFactory<IDuplexSessionChannel> (ctx), "#12");
  90. }
  91. [Test]
  92. public void CanBuildChannelListener ()
  93. {
  94. TcpTransportBindingElement be =
  95. new TcpTransportBindingElement ();
  96. BindingContext ctx = new BindingContext (
  97. new CustomBinding (), empty_params);
  98. Assert.IsFalse (be.CanBuildChannelListener<IReplyChannel> (ctx), "#1");
  99. Assert.IsFalse (be.CanBuildChannelListener<IOutputChannel> (ctx), "#2");
  100. Assert.IsFalse (be.CanBuildChannelListener<IRequestChannel> (ctx), "#3");
  101. Assert.IsFalse (be.CanBuildChannelListener<IInputChannel> (ctx), "#4");
  102. Assert.IsFalse (be.CanBuildChannelListener<IReplySessionChannel> (ctx), "#5");
  103. Assert.IsFalse (be.CanBuildChannelListener<IOutputSessionChannel> (ctx), "#6");
  104. Assert.IsFalse (be.CanBuildChannelListener<IRequestSessionChannel> (ctx), "#7");
  105. Assert.IsFalse (be.CanBuildChannelListener<IInputSessionChannel> (ctx), "#8");
  106. // IServiceChannel is not supported
  107. Assert.IsFalse (be.CanBuildChannelListener<IServiceChannel> (ctx), "#9");
  108. Assert.IsFalse (be.CanBuildChannelListener<IClientChannel> (ctx), "#10");
  109. Assert.IsFalse (be.CanBuildChannelListener<IDuplexChannel> (ctx), "#11");
  110. Assert.IsTrue (be.CanBuildChannelListener<IDuplexSessionChannel> (ctx), "#12");
  111. }
  112. [Test]
  113. public void CanBuildChannelListener2 ()
  114. {
  115. TcpTransportBindingElement be =
  116. new TcpTransportBindingElement ();
  117. be.TransferMode = TransferMode.Streamed;
  118. BindingContext ctx = new BindingContext (
  119. new CustomBinding (), empty_params);
  120. Assert.IsTrue (be.CanBuildChannelListener<IReplyChannel> (ctx), "#1");
  121. Assert.IsFalse (be.CanBuildChannelListener<IOutputChannel> (ctx), "#2");
  122. Assert.IsFalse (be.CanBuildChannelListener<IRequestChannel> (ctx), "#3");
  123. Assert.IsFalse (be.CanBuildChannelListener<IInputChannel> (ctx), "#4");
  124. Assert.IsFalse (be.CanBuildChannelListener<IReplySessionChannel> (ctx), "#5");
  125. Assert.IsFalse (be.CanBuildChannelListener<IOutputSessionChannel> (ctx), "#6");
  126. Assert.IsFalse (be.CanBuildChannelListener<IRequestSessionChannel> (ctx), "#7");
  127. Assert.IsFalse (be.CanBuildChannelListener<IInputSessionChannel> (ctx), "#8");
  128. // IServiceChannel is not supported
  129. Assert.IsFalse (be.CanBuildChannelListener<IServiceChannel> (ctx), "#9");
  130. Assert.IsFalse (be.CanBuildChannelListener<IClientChannel> (ctx), "#10");
  131. Assert.IsFalse (be.CanBuildChannelListener<IDuplexChannel> (ctx), "#11");
  132. Assert.IsFalse (be.CanBuildChannelListener<IDuplexSessionChannel> (ctx), "#12");
  133. }
  134. }
  135. }