Skip to content

Commit 13e5a7e

Browse files
committed
Add test
1 parent 473f039 commit 13e5a7e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

projects/Unit/TestConnectionFactory.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
//---------------------------------------------------------------------------
3131

3232
using System.Collections.Generic;
33+
using System.Net.Sockets;
3334
using RabbitMQ.Client.Exceptions;
35+
using RabbitMQ.Client.Impl;
3436
using Xunit;
3537

3638
namespace RabbitMQ.Client.Unit
@@ -69,6 +71,34 @@ public void TestProperties()
6971
Assert.Equal(cf.Endpoint.MaxMessageSize, mms);
7072
}
7173

74+
[Fact]
75+
public void TestConnectionFactoryWithCustomSocketFactory()
76+
{
77+
const int bufsz = 1024;
78+
79+
ConnectionFactory cf = new()
80+
{
81+
SocketFactory = (AddressFamily af) =>
82+
{
83+
var socket = new Socket(af, SocketType.Stream, ProtocolType.Tcp)
84+
{
85+
SendBufferSize = bufsz,
86+
ReceiveBufferSize = bufsz,
87+
NoDelay = false
88+
};
89+
return new TcpClientAdapter(socket);
90+
}
91+
};
92+
93+
ITcpClient c = cf.SocketFactory(AddressFamily.InterNetwork);
94+
Assert.IsType<TcpClientAdapter>(c);
95+
TcpClientAdapter tcpClientAdapter = (TcpClientAdapter)c;
96+
Socket s = tcpClientAdapter.Client;
97+
Assert.Equal(bufsz, s.ReceiveBufferSize);
98+
Assert.Equal(bufsz, s.SendBufferSize);
99+
Assert.False(s.NoDelay);
100+
}
101+
72102
[Fact]
73103
public void TestCreateConnectionUsesSpecifiedPort()
74104
{

0 commit comments

Comments
 (0)