Files
suitelinkclient/tests/SuiteLink.Client.Tests/SuiteLinkConnectionOptionsTests.cs
2026-03-17 11:04:19 -04:00

157 lines
4.6 KiB
C#

using SuiteLink.Client;
namespace SuiteLink.Client.Tests;
public sealed class SuiteLinkConnectionOptionsTests
{
public static TheoryData<string?> InvalidRequiredValues =>
new()
{
null,
"",
" ",
"\t"
};
[Theory]
[MemberData(nameof(InvalidRequiredValues))]
public void Constructor_InvalidHost_ThrowsArgumentException(string? host)
{
Assert.Throws<ArgumentException>(() => Create(host: host!));
}
[Theory]
[MemberData(nameof(InvalidRequiredValues))]
public void Constructor_InvalidApplication_ThrowsArgumentException(string? application)
{
Assert.Throws<ArgumentException>(() => Create(application: application!));
}
[Theory]
[MemberData(nameof(InvalidRequiredValues))]
public void Constructor_InvalidTopic_ThrowsArgumentException(string? topic)
{
Assert.Throws<ArgumentException>(() => Create(topic: topic!));
}
[Theory]
[MemberData(nameof(InvalidRequiredValues))]
public void Constructor_InvalidClientName_ThrowsArgumentException(string? clientName)
{
Assert.Throws<ArgumentException>(() => Create(clientName: clientName!));
}
[Theory]
[MemberData(nameof(InvalidRequiredValues))]
public void Constructor_InvalidClientNode_ThrowsArgumentException(string? clientNode)
{
Assert.Throws<ArgumentException>(() => Create(clientNode: clientNode!));
}
[Theory]
[MemberData(nameof(InvalidRequiredValues))]
public void Constructor_InvalidUserName_ThrowsArgumentException(string? userName)
{
Assert.Throws<ArgumentException>(() => Create(userName: userName!));
}
[Theory]
[MemberData(nameof(InvalidRequiredValues))]
public void Constructor_InvalidServerNode_ThrowsArgumentException(string? serverNode)
{
Assert.Throws<ArgumentException>(() => Create(serverNode: serverNode!));
}
[Theory]
[InlineData(0)]
[InlineData(-1)]
[InlineData(65536)]
public void Constructor_InvalidPort_ThrowsArgumentOutOfRangeException(int port)
{
Assert.Throws<ArgumentOutOfRangeException>(() => 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<ArgumentNullException>(() => 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<ArgumentOutOfRangeException>(() => 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);
}
}