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