using SuiteLink.Client; namespace SuiteLink.Client.Tests; public sealed class SuiteLinkConnectionOptionsTests { public static TheoryData InvalidRequiredValues => new() { null, "", " ", "\t" }; [Theory] [MemberData(nameof(InvalidRequiredValues))] public void Constructor_InvalidHost_ThrowsArgumentException(string? host) { Assert.Throws(() => Create(host: host!)); } [Theory] [MemberData(nameof(InvalidRequiredValues))] public void Constructor_InvalidApplication_ThrowsArgumentException(string? application) { Assert.Throws(() => Create(application: application!)); } [Theory] [MemberData(nameof(InvalidRequiredValues))] public void Constructor_InvalidTopic_ThrowsArgumentException(string? topic) { Assert.Throws(() => Create(topic: topic!)); } [Theory] [MemberData(nameof(InvalidRequiredValues))] public void Constructor_InvalidClientName_ThrowsArgumentException(string? clientName) { Assert.Throws(() => Create(clientName: clientName!)); } [Theory] [MemberData(nameof(InvalidRequiredValues))] public void Constructor_InvalidClientNode_ThrowsArgumentException(string? clientNode) { Assert.Throws(() => Create(clientNode: clientNode!)); } [Theory] [MemberData(nameof(InvalidRequiredValues))] public void Constructor_InvalidUserName_ThrowsArgumentException(string? userName) { Assert.Throws(() => Create(userName: userName!)); } [Theory] [MemberData(nameof(InvalidRequiredValues))] public void Constructor_InvalidServerNode_ThrowsArgumentException(string? serverNode) { Assert.Throws(() => Create(serverNode: serverNode!)); } [Theory] [InlineData(0)] [InlineData(-1)] [InlineData(65536)] public void Constructor_InvalidPort_ThrowsArgumentOutOfRangeException(int port) { Assert.Throws(() => Create(port: port)); } [Fact] public void Constructor_NoTimezone_UsesUtcByDefault() { var options = Create(timezone: null); Assert.Equal("UTC", options.Timezone); } [Theory] [InlineData("")] [InlineData(" ")] [InlineData("\t")] public void Constructor_WhitespaceTimezone_UsesUtcByDefault(string timezone) { var options = Create(timezone: timezone); Assert.Equal("UTC", options.Timezone); } [Fact] public void Constructor_ExplicitTimezone_PreservesProvidedValue() { var options = Create(timezone: "America/Indiana/Indianapolis"); Assert.Equal("America/Indiana/Indianapolis", options.Timezone); } [Fact] public void Constructor_DefaultsRuntimeOptions() { var options = Create(); Assert.NotNull(options.Runtime); Assert.Equal(SuiteLinkCatchUpPolicy.None, options.Runtime.CatchUpPolicy); Assert.NotNull(options.Runtime.RetryPolicy); Assert.Equal(TimeSpan.FromSeconds(2), options.Runtime.CatchUpTimeout); } [Fact] public void Constructor_RuntimeWithNullRetryPolicy_ThrowsArgumentNullException() { Assert.Throws(() => Create(runtime: new SuiteLinkRuntimeOptions( retryPolicy: null!, catchUpPolicy: SuiteLinkCatchUpPolicy.None, catchUpTimeout: TimeSpan.FromSeconds(2)))); } [Theory] [InlineData(0)] [InlineData(-1)] public void Constructor_RuntimeWithNonPositiveCatchUpTimeout_ThrowsArgumentOutOfRangeException(int seconds) { Assert.Throws(() => Create(runtime: new SuiteLinkRuntimeOptions( retryPolicy: SuiteLinkRetryPolicy.Default, catchUpPolicy: SuiteLinkCatchUpPolicy.None, catchUpTimeout: TimeSpan.FromSeconds(seconds)))); } private static SuiteLinkConnectionOptions Create( string host = "127.0.0.1", string application = "TestApp", string topic = "TestTopic", string clientName = "Client", string clientNode = "Node", string userName = "User", string serverNode = "Server", string? timezone = null, int port = 5413, SuiteLinkRuntimeOptions? runtime = null) { return new SuiteLinkConnectionOptions( host, application, topic, clientName, clientNode, userName, serverNode, timezone, port, runtime); } }