PeerTransportBindingElementTest.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // PeerTransportBindingElementTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2009 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.Net;
  31. using System.ServiceModel;
  32. using System.ServiceModel.Channels;
  33. using System.ServiceModel.Description;
  34. using System.Text;
  35. using NUnit.Framework;
  36. namespace MonoTests.System.ServiceModel.Channels
  37. {
  38. [TestFixture]
  39. public class PeerTransportBindingElementTest
  40. {
  41. [Test]
  42. public void CanBuildChannelFactoryListener ()
  43. {
  44. var be = new PeerTransportBindingElement ();
  45. var binding = new CustomBinding (new HandlerTransportBindingElement (null));
  46. var ctx = new BindingContext (binding, new BindingParameterCollection ());
  47. Assert.IsFalse (be.CanBuildChannelFactory<IRequestChannel> (ctx), "#1");
  48. Assert.IsTrue (be.CanBuildChannelFactory<IOutputChannel> (ctx), "#2");
  49. Assert.IsTrue (be.CanBuildChannelFactory<IDuplexChannel> (ctx), "#3");
  50. Assert.IsFalse (be.CanBuildChannelFactory<IRequestSessionChannel> (ctx), "#4");
  51. Assert.IsFalse (be.CanBuildChannelFactory<IOutputSessionChannel> (ctx), "#5"); // oh?
  52. Assert.IsFalse (be.CanBuildChannelFactory<IDuplexSessionChannel> (ctx), "#6"); // really?
  53. Assert.IsFalse (be.CanBuildChannelListener<IReplyChannel> (ctx), "#7");
  54. Assert.IsTrue (be.CanBuildChannelListener<IInputChannel> (ctx), "#8");
  55. Assert.IsTrue (be.CanBuildChannelListener<IDuplexChannel> (ctx), "#9");
  56. Assert.IsFalse (be.CanBuildChannelListener<IReplySessionChannel> (ctx), "#10");
  57. Assert.IsFalse (be.CanBuildChannelListener<IInputSessionChannel> (ctx), "#11"); // hrm...
  58. Assert.IsFalse (be.CanBuildChannelListener<IDuplexSessionChannel> (ctx), "#12"); // ...k.
  59. }
  60. [Test]
  61. [ExpectedException (typeof (ArgumentException))]
  62. public void BuildRequestChannelFactory ()
  63. {
  64. // IRequestChannel is invalid
  65. PeerTransportBindingElement be =
  66. new PeerTransportBindingElement ();
  67. be.Security.Mode = SecurityMode.None;
  68. CustomBinding binding = new CustomBinding (
  69. new HandlerTransportBindingElement (null));
  70. BindingContext ctx = new BindingContext (
  71. binding, new BindingParameterCollection ());
  72. be.BuildChannelFactory<IRequestChannel> (ctx);
  73. }
  74. [Test]
  75. public void BuildOutputChannelFactory ()
  76. {
  77. PeerTransportBindingElement be =
  78. new PeerTransportBindingElement ();
  79. be.Security.Mode = SecurityMode.None;
  80. CustomBinding binding = new CustomBinding (
  81. new HandlerTransportBindingElement (null));
  82. BindingContext ctx = new BindingContext (
  83. binding, new BindingParameterCollection ());
  84. be.BuildChannelFactory<IOutputChannel> (ctx);
  85. }
  86. [Test]
  87. [ExpectedException (typeof (ArgumentException))]
  88. public void BuildReplyChannelListener ()
  89. {
  90. // IReplyChannel is invalid
  91. PeerTransportBindingElement be =
  92. new PeerTransportBindingElement ();
  93. be.Security.Mode = SecurityMode.None;
  94. CustomBinding binding = new CustomBinding (
  95. new HandlerTransportBindingElement (null));
  96. BindingContext ctx = new BindingContext (
  97. binding, new BindingParameterCollection ());
  98. be.BuildChannelListener<IReplyChannel> (ctx);
  99. }
  100. [Test]
  101. public void BuildInputChannelListener ()
  102. {
  103. PeerTransportBindingElement be =
  104. new PeerTransportBindingElement ();
  105. be.Security.Mode = SecurityMode.None;
  106. CustomBinding binding = new CustomBinding (
  107. new HandlerTransportBindingElement (null));
  108. BindingContext ctx = new BindingContext (
  109. binding, new BindingParameterCollection ());
  110. ctx.ListenUriBaseAddress = new Uri ("net.p2p:foobar");
  111. be.BuildChannelListener<IInputChannel> (ctx);
  112. }
  113. [Test]
  114. [ExpectedException (typeof (ArgumentException))]
  115. [Category ("NotWorking")]
  116. public void InvalidListenIPAddress ()
  117. {
  118. PeerTransportBindingElement be =
  119. new PeerTransportBindingElement ();
  120. be.Security.Mode = SecurityMode.None;
  121. be.ListenIPAddress = IPAddress.Parse ("127.0.0.1");
  122. CustomBinding binding = new CustomBinding (
  123. new HandlerTransportBindingElement (null));
  124. BindingContext ctx = new BindingContext (
  125. binding, new BindingParameterCollection ());
  126. ctx.ListenUriBaseAddress = new Uri ("net.p2p:foobar");
  127. be.BuildChannelListener<IInputChannel> (ctx);
  128. }
  129. [Test]
  130. [Ignore ("It is documented that MaxBufferPoolSize must be greater than MaxReceivedMessageSize, but not really checked (at least here)")]
  131. public void MaxBufferPoolSizeTooSmall ()
  132. {
  133. PeerTransportBindingElement be =
  134. new PeerTransportBindingElement ();
  135. be.MaxBufferPoolSize = 0x1000;
  136. be.Security.Mode = SecurityMode.None;
  137. CustomBinding binding = new CustomBinding (
  138. new HandlerTransportBindingElement (null));
  139. BindingContext ctx = new BindingContext (
  140. binding, new BindingParameterCollection ());
  141. ctx.ListenUriBaseAddress = new Uri ("net.p2p:foobar");
  142. be.BuildChannelListener<IInputChannel> (ctx);
  143. }
  144. }
  145. }