using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.ManagementService.Tests;
///
/// Arch-review 08 §1.5: supplies the Ask timeouts
/// the ManagementActor client uses for command and long-running transport/deploy calls. A
/// zero/negative timeout makes every command fail (or Ask forever); reject it fast at startup
/// with a key-naming message. is
/// deliberately NOT required positive — a non-positive value legitimately disables server-side
/// secured-write expiry.
///
public class ManagementServiceOptionsValidatorTests
{
private static ValidateOptionsResult Validate(ManagementServiceOptions options) =>
new ManagementServiceOptionsValidator().Validate(Options.DefaultName, options);
/// Verifies that the long-running command timeout must leave a grace margin for the response.
/// The long-running command timeout, in seconds.
[Theory]
[InlineData(1)]
[InlineData(5)]
public void LongRunningTimeoutMustLeaveResponseGrace(int seconds)
{
Assert.True(Validate(new ManagementServiceOptions { LongRunningCommandTimeout = TimeSpan.FromSeconds(seconds) }).Failed);
}
/// Verifies that the default options are valid.
[Fact]
public void DefaultOptions_AreValid()
{
var result = Validate(new ManagementServiceOptions());
Assert.True(result.Succeeded, result.FailureMessage);
}
/// Verifies that a non-positive secured-write pending TTL is valid.
[Fact]
public void NonPositiveSecuredWritePendingTtl_IsValid()
{
// A non-positive TTL disables server-side expiry by design — not a config error.
var result = Validate(new ManagementServiceOptions { SecuredWritePendingTtl = TimeSpan.Zero });
Assert.True(result.Succeeded, result.FailureMessage);
}
/// Verifies that a zero command timeout is rejected.
[Fact]
public void ZeroCommandTimeout_IsRejected()
{
var result = Validate(new ManagementServiceOptions { CommandTimeout = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("CommandTimeout", result.FailureMessage);
}
/// Verifies that a negative command timeout is rejected.
[Fact]
public void NegativeCommandTimeout_IsRejected()
{
var result = Validate(new ManagementServiceOptions { CommandTimeout = TimeSpan.FromSeconds(-1) });
Assert.True(result.Failed);
Assert.Contains("CommandTimeout", result.FailureMessage);
}
/// Verifies that a zero long-running command timeout is rejected.
[Fact]
public void ZeroLongRunningCommandTimeout_IsRejected()
{
var result = Validate(new ManagementServiceOptions { LongRunningCommandTimeout = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("LongRunningCommandTimeout", result.FailureMessage);
}
}