2 // PeerTransportBindingElementTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2009 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;
31 using System.ServiceModel;
32 using System.ServiceModel.Channels;
33 using System.ServiceModel.Description;
35 using NUnit.Framework;
37 namespace MonoTests.System.ServiceModel.Channels
40 public class PeerTransportBindingElementTest
43 public void CanBuildChannelFactoryListener ()
45 var be = new PeerTransportBindingElement ();
46 var binding = new CustomBinding (new HandlerTransportBindingElement (null));
47 var ctx = new BindingContext (binding, new BindingParameterCollection ());
48 Assert.IsFalse (be.CanBuildChannelFactory<IRequestChannel> (ctx), "#1");
49 Assert.IsTrue (be.CanBuildChannelFactory<IOutputChannel> (ctx), "#2");
50 Assert.IsTrue (be.CanBuildChannelFactory<IDuplexChannel> (ctx), "#3");
51 Assert.IsFalse (be.CanBuildChannelFactory<IRequestSessionChannel> (ctx), "#4");
52 Assert.IsFalse (be.CanBuildChannelFactory<IOutputSessionChannel> (ctx), "#5"); // oh?
53 Assert.IsFalse (be.CanBuildChannelFactory<IDuplexSessionChannel> (ctx), "#6"); // really?
55 Assert.IsFalse (be.CanBuildChannelListener<IReplyChannel> (ctx), "#7");
56 Assert.IsTrue (be.CanBuildChannelListener<IInputChannel> (ctx), "#8");
57 Assert.IsTrue (be.CanBuildChannelListener<IDuplexChannel> (ctx), "#9");
58 Assert.IsFalse (be.CanBuildChannelListener<IReplySessionChannel> (ctx), "#10");
59 Assert.IsFalse (be.CanBuildChannelListener<IInputSessionChannel> (ctx), "#11"); // hrm...
60 Assert.IsFalse (be.CanBuildChannelListener<IDuplexSessionChannel> (ctx), "#12"); // ...k.
64 [ExpectedException (typeof (ArgumentException))]
65 public void BuildRequestChannelFactory ()
67 // IRequestChannel is invalid
68 PeerTransportBindingElement be =
69 new PeerTransportBindingElement ();
70 be.Security.Mode = SecurityMode.None;
71 CustomBinding binding = new CustomBinding (
72 new HandlerTransportBindingElement (null));
73 BindingContext ctx = new BindingContext (
74 binding, new BindingParameterCollection ());
76 var f = be.BuildChannelFactory<IRequestChannel> (ctx);
77 Assert.IsNotNull (f.GetProperty<IOnlineStatus> (), "#1");
78 Assert.IsNotNull (f.GetProperty<PeerNode> (), "#2");
82 public void BuildOutputChannelFactory ()
84 PeerTransportBindingElement be =
85 new PeerTransportBindingElement ();
86 be.Security.Mode = SecurityMode.None;
87 CustomBinding binding = new CustomBinding (
88 new HandlerTransportBindingElement (null));
89 BindingContext ctx = new BindingContext (
90 binding, new BindingParameterCollection ());
91 be.BuildChannelFactory<IOutputChannel> (ctx);
94 [ExpectedException (typeof (ArgumentException))]
95 public void BuildReplyChannelListener ()
97 // IReplyChannel is invalid
98 PeerTransportBindingElement be =
99 new PeerTransportBindingElement ();
100 be.Security.Mode = SecurityMode.None;
101 CustomBinding binding = new CustomBinding (
102 new HandlerTransportBindingElement (null));
103 BindingContext ctx = new BindingContext (
104 binding, new BindingParameterCollection ());
105 be.BuildChannelListener<IReplyChannel> (ctx);
109 public void BuildInputChannelListener ()
111 PeerTransportBindingElement be =
112 new PeerTransportBindingElement ();
113 be.Security.Mode = SecurityMode.None;
114 CustomBinding binding = new CustomBinding (
115 new HandlerTransportBindingElement (null));
116 BindingContext ctx = new BindingContext (
117 binding, new BindingParameterCollection ());
118 ctx.ListenUriBaseAddress = new Uri ("net.p2p:foobar");
119 be.BuildChannelListener<IInputChannel> (ctx);
123 [ExpectedException (typeof (ArgumentException))]
124 [Category ("NotWorking")]
125 public void InvalidListenIPAddress ()
127 PeerTransportBindingElement be =
128 new PeerTransportBindingElement ();
129 be.Security.Mode = SecurityMode.None;
130 be.ListenIPAddress = IPAddress.Parse ("127.0.0.1");
131 CustomBinding binding = new CustomBinding (
132 new HandlerTransportBindingElement (null));
133 BindingContext ctx = new BindingContext (
134 binding, new BindingParameterCollection ());
135 ctx.ListenUriBaseAddress = new Uri ("net.p2p:foobar");
136 be.BuildChannelListener<IInputChannel> (ctx);
140 [Ignore ("It is documented that MaxBufferPoolSize must be greater than MaxReceivedMessageSize, but not really checked (at least here)")]
141 public void MaxBufferPoolSizeTooSmall ()
143 PeerTransportBindingElement be =
144 new PeerTransportBindingElement ();
145 be.MaxBufferPoolSize = 0x1000;
146 be.Security.Mode = SecurityMode.None;
147 CustomBinding binding = new CustomBinding (
148 new HandlerTransportBindingElement (null));
149 BindingContext ctx = new BindingContext (
150 binding, new BindingParameterCollection ());
151 ctx.ListenUriBaseAddress = new Uri ("net.p2p:foobar");
152 be.BuildChannelListener<IInputChannel> (ctx);