Bläddra i källkod

2009-04-07 Atsushi Enomoto <[email protected]>

	* TcpTransportBindingElement.cs : check build-ability before
	  actually building channels.
	* ConnectionOrientedTransportBindingElement.cs : fixed build-ability
	  conditions according to MSDN.

	* TcpTransportBindingElementTest.cs : more can-build tests.

	* NetTcpBindingTest.cs : new test.

	* System.ServiceModel_test.dll.sources: added NetTcpBindingTest.cs.


svn path=/trunk/mcs/; revision=131222
Atsushi Eno 17 år sedan
förälder
incheckning
e596ffbe11

+ 4 - 0
mcs/class/System.ServiceModel/ChangeLog

@@ -1,3 +1,7 @@
+2009-04-07  Astushi Enomoto  <[email protected]>
+
+	* System.ServiceModel_test.dll.sources: added NetTcpBindingTest.cs.
+
 2009-04-07  Astushi Enomoto  <[email protected]>
 
 	* System.ServiceModel.dll.sources: added IOnlineStatus.cs.

+ 7 - 0
mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog

@@ -1,3 +1,10 @@
+2009-04-07  Atsushi Enomoto  <[email protected]>
+
+	* TcpTransportBindingElement.cs : check build-ability before
+	  actually building channels.
+	* ConnectionOrientedTransportBindingElement.cs : fixed build-ability
+	  conditions according to MSDN.
+
 2009-03-05  Atsushi Enomoto  <[email protected]>
 
 	* MessageHeader.cs, MessageHeaders.cs, MessageImpl.cs :

+ 18 - 4
mcs/class/System.ServiceModel/System.ServiceModel.Channels/ConnectionOrientedTransportBindingElement.cs

@@ -101,18 +101,32 @@ namespace System.ServiceModel.Channels
 			set { transfer_mode = value; }
 		}
 		
-		[MonoTODO]
 		public override bool CanBuildChannelFactory<TChannel> (
 			BindingContext context)
 		{
-			return typeof (TChannel) == typeof (IDuplexSessionChannel);
+			switch (TransferMode) {
+			case TransferMode.Buffered:
+			case TransferMode.StreamedResponse:
+				return typeof (TChannel) == typeof (IDuplexSessionChannel);
+			case TransferMode.Streamed:
+			case TransferMode.StreamedRequest:
+				return typeof (TChannel) == typeof (IRequestChannel);
+			}
+			return false;
 		}
 
-		[MonoTODO]
 		public override bool CanBuildChannelListener<TChannel> (
 			BindingContext context)
 		{
-			return typeof (TChannel) == typeof (IDuplexSessionChannel);
+			switch (TransferMode) {
+			case TransferMode.Buffered:
+			case TransferMode.StreamedRequest:
+				return typeof (TChannel) == typeof (IDuplexSessionChannel);
+			case TransferMode.Streamed:
+			case TransferMode.StreamedResponse:
+				return typeof (TChannel) == typeof (IReplyChannel);
+			}
+			return false;
 		}
 	}
 }

+ 4 - 1
mcs/class/System.ServiceModel/System.ServiceModel.Channels/TcpTransportBindingElement.cs

@@ -87,14 +87,17 @@ namespace System.ServiceModel.Channels
 		public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
 			BindingContext context)
 		{
+			if (!CanBuildChannelFactory<TChannel> (context))
+				throw new InvalidOperationException (String.Format ("Not supported channel factory type '{0}'", typeof (TChannel)));
 			return new TcpChannelFactory<TChannel> (this, context);
 		}
 
-		[MonoTODO]
 		public override IChannelListener<TChannel>
 			BuildChannelListener<TChannel> (
 			BindingContext context)
 		{
+			if (!CanBuildChannelListener<TChannel> (context))
+				throw new InvalidOperationException (String.Format ("Not supported channel listener type '{0}'", typeof (TChannel)));
 			return new TcpChannelListener<TChannel> (this, context);
 		}
 

+ 1 - 0
mcs/class/System.ServiceModel/System.ServiceModel_test.dll.sources

@@ -122,6 +122,7 @@ System.ServiceModel/FaultReasonTest.cs
 System.ServiceModel/IntegratedConnectionTest.cs
 System.ServiceModel/MessageSecurityVersionTest.cs
 System.ServiceModel/NetMsmqBindingTest.cs
+System.ServiceModel/NetTcpBindingTest.cs
 System.ServiceModel/ServiceAssert.cs
 System.ServiceModel/ServiceEndpointCollectionTest.cs
 System.ServiceModel/ServiceEndpointTest.cs

+ 4 - 0
mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog

@@ -1,3 +1,7 @@
+2009-04-07  Atsushi Enomoto  <[email protected]>
+
+	* TcpTransportBindingElementTest.cs : more can-build tests.
+
 2008-04-13  Igor Zelmanovich <[email protected]>
 
 	* BindingTest.cs:

+ 26 - 0
mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/TcpTransportBindingElementTest.cs

@@ -120,5 +120,31 @@ namespace MonoTests.System.ServiceModel.Channels
 			Assert.IsFalse (be.CanBuildChannelListener<IDuplexChannel> (ctx), "#11");
 			Assert.IsTrue (be.CanBuildChannelListener<IDuplexSessionChannel> (ctx), "#12");
 		}
+
+		[Test]
+		public void CanBuildChannelListener2 ()
+		{
+			TcpTransportBindingElement be =
+				new TcpTransportBindingElement ();
+			be.TransferMode = TransferMode.Streamed;
+			BindingContext ctx = new BindingContext (
+				new CustomBinding (), empty_params);
+			Assert.IsTrue (be.CanBuildChannelListener<IReplyChannel> (ctx), "#1");
+			Assert.IsFalse (be.CanBuildChannelListener<IOutputChannel> (ctx), "#2");
+			Assert.IsFalse (be.CanBuildChannelListener<IRequestChannel> (ctx), "#3");
+			Assert.IsFalse (be.CanBuildChannelListener<IInputChannel> (ctx), "#4");
+
+			Assert.IsFalse (be.CanBuildChannelListener<IReplySessionChannel> (ctx), "#5");
+			Assert.IsFalse (be.CanBuildChannelListener<IOutputSessionChannel> (ctx), "#6");
+			Assert.IsFalse (be.CanBuildChannelListener<IRequestSessionChannel> (ctx), "#7");
+			Assert.IsFalse (be.CanBuildChannelListener<IInputSessionChannel> (ctx), "#8");
+
+			// IServiceChannel is not supported
+			Assert.IsFalse (be.CanBuildChannelListener<IServiceChannel> (ctx), "#9");
+			Assert.IsFalse (be.CanBuildChannelListener<IClientChannel> (ctx), "#10");
+
+			Assert.IsFalse (be.CanBuildChannelListener<IDuplexChannel> (ctx), "#11");
+			Assert.IsFalse (be.CanBuildChannelListener<IDuplexSessionChannel> (ctx), "#12");
+		}
 	}
 }

+ 4 - 0
mcs/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog

@@ -1,3 +1,7 @@
+2009-04-07  Atsushi Enomoto  <[email protected]>
+
+	* NetTcpBindingTest.cs : new test.
+
 2009-02-24  Atsushi Enomoto  <[email protected]>
 
 	* ChannelFactory_1Test.cs, ChannelFactoryTest.cs, ClientBaseTest.cs:

+ 55 - 0
mcs/class/System.ServiceModel/Test/System.ServiceModel/NetTcpBindingTest.cs

@@ -0,0 +1,55 @@
+//
+// NetTcpBindingTest.cs
+//
+// Author:
+//	Atsushi Enomoto <[email protected]>
+//
+// Copyright (C) 2009 Novell, Inc.  http://www.novell.com
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Collections.ObjectModel;
+using System.Net.Security;
+using System.ServiceModel;
+using System.ServiceModel.Channels;
+using System.ServiceModel.Security;
+using NUnit.Framework;
+
+namespace MonoTests.System.ServiceModel
+{
+	[TestFixture]
+	public class NetTcpBindingTest
+	{
+		[Test]
+		public void DefaultValues ()
+		{
+			var n = new NetTcpBinding ();
+			Assert.AreEqual (HostNameComparisonMode.StrongWildcard, n.HostNameComparisonMode, "#1");
+			Assert.AreEqual (0, n.ListenBacklog, "#2");
+			Assert.AreEqual (false, n.PortSharingEnabled, "#3");
+
+			var tr = n.CreateBindingElements ().Find<TcpTransportBindingElement> ();
+			Assert.IsNotNull (tr, "#tr1");
+			Assert.AreEqual (false, tr.TeredoEnabled, "#tr2");
+			Assert.AreEqual ("net.tcp", tr.Scheme, "#tr3");
+		}
+	}
+}