feat(options): eager startup validation for site-pipeline options (SiteRuntime, S&F, SiteEventLog) (arch-review 08 §1.5)

Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
Joseph Doherty
2026-07-10 06:51:05 -04:00
parent af2cfde484
commit 8b775f4ae1
10 changed files with 342 additions and 3 deletions
@@ -0,0 +1,50 @@
using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.SiteEventLogging.Tests;
/// <summary>
/// <see cref="SiteEventLogOptions"/> retention/purge values drive the daily purge
/// PeriodicTimer (zero/negative trips its constructor) and the paging bounds gate
/// query result sizes. These tests assert the
/// <see cref="SiteEventLogOptionsValidator"/> rejects a bad
/// <c>ScadaBridge:SiteEventLog</c> section with a clear, key-naming message.
/// </summary>
public class SiteEventLogOptionsValidatorTests
{
private static ValidateOptionsResult Validate(SiteEventLogOptions options) =>
new SiteEventLogOptionsValidator().Validate(Options.DefaultName, options);
[Fact]
public void DefaultOptions_AreValid()
{
var result = Validate(new SiteEventLogOptions());
Assert.True(result.Succeeded, result.FailureMessage);
}
[Fact]
public void ZeroRetentionDays_IsRejected()
{
var result = Validate(new SiteEventLogOptions { RetentionDays = 0 });
Assert.True(result.Failed);
Assert.Contains("RetentionDays", result.FailureMessage);
}
[Fact]
public void ZeroPurgeInterval_IsRejected()
{
var result = Validate(new SiteEventLogOptions { PurgeInterval = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("PurgeInterval", result.FailureMessage);
}
[Fact]
public void MaxQueryPageSize_BelowQueryPageSize_IsRejected()
{
var result = Validate(new SiteEventLogOptions { QueryPageSize = 500, MaxQueryPageSize = 100 });
Assert.True(result.Failed);
Assert.Contains("MaxQueryPageSize", result.FailureMessage);
}
}
@@ -0,0 +1,60 @@
using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests;
/// <summary>
/// <see cref="SiteRuntimeOptions"/> values size the staggered Instance-Actor
/// startup batches, the dedicated script-execution thread scheduler, and the
/// site-wide stream buffer. A zero/negative count crashes actor construction with
/// an opaque <see cref="ArgumentOutOfRangeException"/>; these tests assert the
/// <see cref="SiteRuntimeOptionsValidator"/> rejects a bad
/// <c>ScadaBridge:SiteRuntime</c> section with a clear, key-naming message.
/// </summary>
public class SiteRuntimeOptionsValidatorTests
{
private static ValidateOptionsResult Validate(SiteRuntimeOptions options) =>
new SiteRuntimeOptionsValidator().Validate(Options.DefaultName, options);
[Fact]
public void DefaultOptions_AreValid()
{
var result = Validate(new SiteRuntimeOptions());
Assert.True(result.Succeeded, result.FailureMessage);
}
[Fact]
public void ZeroStartupBatchSize_IsRejected()
{
var result = Validate(new SiteRuntimeOptions { StartupBatchSize = 0 });
Assert.True(result.Failed);
Assert.Contains("StartupBatchSize", result.FailureMessage);
}
[Fact]
public void ZeroScriptExecutionThreadCount_IsRejected()
{
var result = Validate(new SiteRuntimeOptions { ScriptExecutionThreadCount = 0 });
Assert.True(result.Failed);
Assert.Contains("ScriptExecutionThreadCount", result.FailureMessage);
}
[Fact]
public void ZeroStreamBufferSize_IsRejected()
{
var result = Validate(new SiteRuntimeOptions { StreamBufferSize = 0 });
Assert.True(result.Failed);
Assert.Contains("StreamBufferSize", result.FailureMessage);
}
[Fact]
public void NegativeStartupBatchDelayMs_IsRejected()
{
var result = Validate(new SiteRuntimeOptions { StartupBatchDelayMs = -1 });
Assert.True(result.Failed);
Assert.Contains("StartupBatchDelayMs", result.FailureMessage);
}
}
@@ -0,0 +1,50 @@
using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.StoreAndForward.Tests;
/// <summary>
/// <see cref="StoreAndForwardOptions"/> retry intervals feed the background sweep
/// timer (zero/negative trips the timer constructor) and the SQLite path backs the
/// buffer. These tests assert the <see cref="StoreAndForwardOptionsValidator"/>
/// rejects a bad <c>ScadaBridge:StoreAndForward</c> section with a clear,
/// key-naming message rather than crashing later with an opaque exception.
/// </summary>
public class StoreAndForwardOptionsValidatorTests
{
private static ValidateOptionsResult Validate(StoreAndForwardOptions options) =>
new StoreAndForwardOptionsValidator().Validate(Options.DefaultName, options);
[Fact]
public void DefaultOptions_AreValid()
{
var result = Validate(new StoreAndForwardOptions());
Assert.True(result.Succeeded, result.FailureMessage);
}
[Fact]
public void ZeroDefaultRetryInterval_IsRejected()
{
var result = Validate(new StoreAndForwardOptions { DefaultRetryInterval = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("DefaultRetryInterval", result.FailureMessage);
}
[Fact]
public void ZeroRetryTimerInterval_IsRejected()
{
var result = Validate(new StoreAndForwardOptions { RetryTimerInterval = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("RetryTimerInterval", result.FailureMessage);
}
[Fact]
public void EmptySqliteDbPath_IsRejected()
{
var result = Validate(new StoreAndForwardOptions { SqliteDbPath = "" });
Assert.True(result.Failed);
Assert.Contains("SqliteDbPath", result.FailureMessage);
}
}