2009-05-26 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.ServiceModel / Test / System.ServiceModel.Channels / PeerTransportBindingElementTest.cs
1 //
2 // PeerTransportBindingElementTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
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
37 namespace MonoTests.System.ServiceModel.Channels
38 {
39         [TestFixture]
40         public class PeerTransportBindingElementTest
41         {
42                 [Test]
43                 public void CanBuildChannelFactoryListener ()
44                 {
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?
54
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.
61                 }
62
63                 [Test]
64                 [ExpectedException (typeof (ArgumentException))]
65                 public void BuildRequestChannelFactory ()
66                 {
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 ());
75
76                         var f = be.BuildChannelFactory<IRequestChannel> (ctx);
77                         Assert.IsNotNull (f.GetProperty<IOnlineStatus> (), "#1");
78                         Assert.IsNotNull (f.GetProperty<PeerNode> (), "#2");
79                 }
80
81                 [Test]
82                 public void BuildOutputChannelFactory ()
83                 {
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);
92                 }
93                 [Test]
94                 [ExpectedException (typeof (ArgumentException))]
95                 public void BuildReplyChannelListener ()
96                 {
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);
106                 }
107
108                 [Test]
109                 public void BuildInputChannelListener ()
110                 {
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);
120                 }
121
122                 [Test]
123                 [ExpectedException (typeof (ArgumentException))]
124                 [Category ("NotWorking")]
125                 public void InvalidListenIPAddress ()
126                 {
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);
137                 }
138
139                 [Test]
140                 [Ignore ("It is documented that MaxBufferPoolSize must be greater than MaxReceivedMessageSize, but not really checked (at least here)")]
141                 public void MaxBufferPoolSizeTooSmall ()
142                 {
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);
153                 }
154         }
155 }