diff --git a/projects/Unit/TestConnectionFactory.cs b/projects/Unit/TestConnectionFactory.cs index 225c94f99d..1344a46fd8 100644 --- a/projects/Unit/TestConnectionFactory.cs +++ b/projects/Unit/TestConnectionFactory.cs @@ -30,7 +30,9 @@ //--------------------------------------------------------------------------- using System.Collections.Generic; +using System.Net.Sockets; using RabbitMQ.Client.Exceptions; +using RabbitMQ.Client.Impl; using Xunit; namespace RabbitMQ.Client.Unit @@ -69,6 +71,34 @@ public void TestProperties() Assert.Equal(cf.Endpoint.MaxMessageSize, mms); } + [Fact] + public void TestConnectionFactoryWithCustomSocketFactory() + { + const int bufsz = 1024; + + ConnectionFactory cf = new() + { + SocketFactory = (AddressFamily af) => + { + var socket = new Socket(af, SocketType.Stream, ProtocolType.Tcp) + { + SendBufferSize = bufsz, + ReceiveBufferSize = bufsz, + NoDelay = false + }; + return new TcpClientAdapter(socket); + } + }; + + ITcpClient c = cf.SocketFactory(AddressFamily.InterNetwork); + Assert.IsType(c); + TcpClientAdapter tcpClientAdapter = (TcpClientAdapter)c; + Socket s = tcpClientAdapter.Client; + Assert.Equal(bufsz, s.ReceiveBufferSize); + Assert.Equal(bufsz, s.SendBufferSize); + Assert.False(s.NoDelay); + } + [Fact] public void TestCreateConnectionUsesSpecifiedPort() {