Path: redb-route/tests/redb.Route.Tests.Tcp/TcpEndpointOptionsTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Tcp/TcpEndpointOptionsTests.cs ---- using redb.Route.Tcp; namespace redb.Route.Tests.Tcp; public class TcpEndpointOptionsTests { [Fact] public void Defaults_AreCorrect() { var options = new TcpEndpointOptions(); options.Host.Should().Be("0.0.0.0"); options.Port.Should().Be(0); options.Framing.Should().Be(TcpFraming.Raw); options.TextLine.Should().BeFalse(); options.LengthPrefixed.Should().BeFalse(); options.Delimiter.Should().Be("\n"); options.Encoding.Should().Be("utf-8"); options.KeepAlive.Should().BeTrue(); options.NoDelay.Should().BeTrue(); options.ReceiveBufferSize.Should().Be(0); options.SendBufferSize.Should().Be(0); options.ConnectTimeout.Should().Be(10_000); options.Reconnect.Should().BeFalse(); options.ReconnectInterval.Should().Be(5_000); options.MaxReconnectAttempts.Should().Be(0); options.Backlog.Should().Be(128); options.MaxConnections.Should().Be(0); options.InOut.Should().BeFalse(); options.Ssl.Should().BeFalse(); } [Fact] public void Validate_ValidOptions_DoesNotThrow() { var options = new TcpEndpointOptions { Port = 9090 }; var act = () => options.Validate(); act.Should().NotThrow(); } [Fact] public void Validate_InvalidPort_Negative_Throws() { var options = new TcpEndpointOptions { Port = -1 }; var act = () => options.Validate(); act.Should().Throw().WithMessage("*Port*"); } [Fact] public void Validate_InvalidPort_TooHigh_Throws() { var options = new TcpEndpointOptions { Port = 70000 }; var act = () => options.Validate(); act.Should().Throw().WithMessage("*Port*"); } [Fact] public void Validate_InvalidReceiveBufferSize_Throws() { var options = new TcpEndpointOptions { ReceiveBufferSize = -1 }; var act = () => options.Validate(); act.Should().Throw().WithMessage("*ReceiveBufferSize*"); } /// /// A buffer size of 0 leaves the socket as the system made it. A fixed 8192 switched the Linux buffer tuning off, /// and on loopback a 64 KiB frame took about three seconds. /// [Fact] public void ZeroBufferSizes_LeaveTheSystemSizes_AndASetSizeReachesTheSocket() { using var untouched = new System.Net.Sockets.TcpClient(); var systemReceive = untouched.ReceiveBufferSize; var systemSend = untouched.SendBufferSize; using var byDefault = new System.Net.Sockets.TcpClient(); new TcpEndpointOptions().ApplyBufferSizes(byDefault); byDefault.ReceiveBufferSize.Should().Be(systemReceive); byDefault.SendBufferSize.Should().Be(systemSend); new TcpEndpointOptions().ReadChunkSize.Should().Be(TcpEndpointOptions.DefaultReadChunkSize); using var configured = new System.Net.Sockets.TcpClient(); var options = new TcpEndpointOptions { ReceiveBufferSize = 1 << 20, SendBufferSize = 1 << 20 }; options.ApplyBufferSizes(configured); configured.ReceiveBufferSize.Should().NotBe(systemReceive, "a size that was set is applied"); options.ReadChunkSize.Should().Be(1 << 20); } [Fact] public void Validate_InvalidSendBufferSize_Throws() { var options = new TcpEndpointOptions { SendBufferSize = -1 }; var act = () => options.Validate(); act.Should().Throw().WithMessage("*SendBufferSize*"); } [Fact] public void Validate_NegativeConnectTimeout_Throws() { var options = new TcpEndpointOptions { ConnectTimeout = -1 }; var act = () => options.Validate(); act.Should().Throw().WithMessage("*ConnectTimeout*"); } [Fact] public void Validate_InvalidReconnectInterval_Throws() { var options = new TcpEndpointOptions { ReconnectInterval = 0 }; var act = () => options.Validate(); act.Should().Throw().WithMessage("*ReconnectInterval*"); } [Fact] public void Validate_NegativeMaxReconnectAttempts_Throws() { var options = new TcpEndpointOptions { MaxReconnectAttempts = -1 }; var act = () => options.Validate(); act.Should().Throw().WithMessage("*MaxReconnectAttempts*"); } [Fact] public void Validate_InvalidBacklog_Throws() { var options = new TcpEndpointOptions { Backlog = 0 }; var act = () => options.Validate(); act.Should().Throw().WithMessage("*Backlog*"); } [Fact] public void Validate_NegativeMaxConnections_Throws() { var options = new TcpEndpointOptions { MaxConnections = -1 }; var act = () => options.Validate(); act.Should().Throw().WithMessage("*MaxConnections*"); } [Fact] public void Validate_TextLine_SetsFraming() { var options = new TcpEndpointOptions { TextLine = true }; options.Validate(); options.Framing.Should().Be(TcpFraming.TextLine); } [Fact] public void Validate_LengthPrefixed_SetsFraming() { var options = new TcpEndpointOptions { LengthPrefixed = true }; options.Validate(); options.Framing.Should().Be(TcpFraming.LengthPrefixed); } [Fact] public void Validate_BothTextLineAndLengthPrefixed_Throws() { var options = new TcpEndpointOptions { TextLine = true, LengthPrefixed = true }; var act = () => options.Validate(); act.Should().Throw().WithMessage("*TextLine*LengthPrefixed*"); } [Fact] public void Validate_BoundaryValues_AllValid() { var options = new TcpEndpointOptions { Port = 0, ReceiveBufferSize = 1, SendBufferSize = 1, ConnectTimeout = 0, ReconnectInterval = 1, MaxReconnectAttempts = 0, Backlog = 1, MaxConnections = 0 }; var act = () => options.Validate(); act.Should().NotThrow(); } [Fact] public void Validate_Port65535_Valid() { var options = new TcpEndpointOptions { Port = 65535 }; var act = () => options.Validate(); act.Should().NotThrow(); } }