feat(options): eager startup validation for edge/management options (InboundAPI, ESG, Notification, ManagementService) (arch-review 08 §1.5)

Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
Joseph Doherty
2026-07-10 06:52:59 -04:00
parent 8b775f4ae1
commit fc918d4679
16 changed files with 404 additions and 4 deletions
@@ -0,0 +1,59 @@
using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.ManagementService.Tests;
/// <summary>
/// Arch-review 08 §1.5: <see cref="ManagementServiceOptions"/> 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. <see cref="ManagementServiceOptions.SecuredWritePendingTtl"/> is
/// deliberately NOT required positive — a non-positive value legitimately disables server-side
/// secured-write expiry.
/// </summary>
public class ManagementServiceOptionsValidatorTests
{
private static ValidateOptionsResult Validate(ManagementServiceOptions options) =>
new ManagementServiceOptionsValidator().Validate(Options.DefaultName, options);
[Fact]
public void DefaultOptions_AreValid()
{
var result = Validate(new ManagementServiceOptions());
Assert.True(result.Succeeded, result.FailureMessage);
}
[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);
}
[Fact]
public void ZeroCommandTimeout_IsRejected()
{
var result = Validate(new ManagementServiceOptions { CommandTimeout = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("CommandTimeout", result.FailureMessage);
}
[Fact]
public void NegativeCommandTimeout_IsRejected()
{
var result = Validate(new ManagementServiceOptions { CommandTimeout = TimeSpan.FromSeconds(-1) });
Assert.True(result.Failed);
Assert.Contains("CommandTimeout", result.FailureMessage);
}
[Fact]
public void ZeroLongRunningCommandTimeout_IsRejected()
{
var result = Validate(new ManagementServiceOptions { LongRunningCommandTimeout = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("LongRunningCommandTimeout", result.FailureMessage);
}
}