PeerTransportBindingElementTest.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. var f = be.BuildChannelFactory<IRequestChannel> (ctx);
  73. Assert.IsNotNull (f.GetProperty<IOnlineStatus> (), "#1");
  74. Assert.IsNotNull (f.GetProperty<PeerNode> (), "#2");
  75. }
  76. [Test]
  77. public void BuildOutputChannelFactory ()
  78. {
  79. PeerTransportBindingElement be =
  80. new PeerTransportBindingElement ();
  81. be.Security.Mode = SecurityMode.None;
  82. CustomBinding binding = new CustomBinding (
  83. new HandlerTransportBindingElement (null));
  84. BindingContext ctx = new BindingContext (
  85. binding, new BindingParameterCollection ());
  86. be.BuildChannelFactory<IOutputChannel> (ctx);
  87. }
  88. [Test]
  89. [ExpectedException (typeof (ArgumentException))]
  90. public void BuildReplyChannelListener ()
  91. {
  92. // IReplyChannel is invalid
  93. PeerTransportBindingElement be =
  94. new PeerTransportBindingElement ();
  95. be.Security.Mode = SecurityMode.None;
  96. CustomBinding binding = new CustomBinding (
  97. new HandlerTransportBindingElement (null));
  98. BindingContext ctx = new BindingContext (
  99. binding, new BindingParameterCollection ());
  100. be.BuildChannelListener<IReplyChannel> (ctx);
  101. }
  102. [Test]
  103. public void BuildInputChannelListener ()
  104. {
  105. PeerTransportBindingElement be =
  106. new PeerTransportBindingElement ();
  107. be.Security.Mode = SecurityMode.None;
  108. CustomBinding binding = new CustomBinding (
  109. new HandlerTransportBindingElement (null));
  110. BindingContext ctx = new BindingContext (
  111. binding, new BindingParameterCollection ());
  112. ctx.ListenUriBaseAddress = new Uri ("net.p2p:foobar");
  113. be.BuildChannelListener<IInputChannel> (ctx);
  114. }
  115. [Test]
  116. [ExpectedException (typeof (ArgumentException))]
  117. [Category ("NotWorking")]
  118. public void InvalidListenIPAddress ()
  119. {
  120. PeerTransportBindingElement be =
  121. new PeerTransportBindingElement ();
  122. be.Security.Mode = SecurityMode.None;
  123. be.ListenIPAddress = IPAddress.Parse ("127.0.0.1");
  124. CustomBinding binding = new CustomBinding (
  125. new HandlerTransportBindingElement (null));
  126. BindingContext ctx = new BindingContext (
  127. binding, new BindingParameterCollection ());
  128. ctx.ListenUriBaseAddress = new Uri ("net.p2p:foobar");
  129. be.BuildChannelListener<IInputChannel> (ctx);
  130. }
  131. [Test]
  132. [Ignore ("It is documented that MaxBufferPoolSize must be greater than MaxReceivedMessageSize, but not really checked (at least here)")]
  133. public void MaxBufferPoolSizeTooSmall ()
  134. {
  135. PeerTransportBindingElement be =
  136. new PeerTransportBindingElement ();
  137. be.MaxBufferPoolSize = 0x1000;
  138. be.Security.Mode = SecurityMode.None;
  139. CustomBinding binding = new CustomBinding (
  140. new HandlerTransportBindingElement (null));
  141. BindingContext ctx = new BindingContext (
  142. binding, new BindingParameterCollection ());
  143. ctx.ListenUriBaseAddress = new Uri ("net.p2p:foobar");
  144. be.BuildChannelListener<IInputChannel> (ctx);
  145. }
  146. }
  147. }