513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
75 lines
3.1 KiB
C#
75 lines
3.1 KiB
C#
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);
|
|
|
|
/// <summary>Verifies that the long-running command timeout must leave a grace margin for the response.</summary>
|
|
/// <param name="seconds">The long-running command timeout, in seconds.</param>
|
|
[Theory]
|
|
[InlineData(1)]
|
|
[InlineData(5)]
|
|
public void LongRunningTimeoutMustLeaveResponseGrace(int seconds)
|
|
{
|
|
Assert.True(Validate(new ManagementServiceOptions { LongRunningCommandTimeout = TimeSpan.FromSeconds(seconds) }).Failed);
|
|
}
|
|
|
|
/// <summary>Verifies that the default options are valid.</summary>
|
|
[Fact]
|
|
public void DefaultOptions_AreValid()
|
|
{
|
|
var result = Validate(new ManagementServiceOptions());
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a non-positive secured-write pending TTL is valid.</summary>
|
|
[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);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero command timeout is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroCommandTimeout_IsRejected()
|
|
{
|
|
var result = Validate(new ManagementServiceOptions { CommandTimeout = TimeSpan.Zero });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("CommandTimeout", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a negative command timeout is rejected.</summary>
|
|
[Fact]
|
|
public void NegativeCommandTimeout_IsRejected()
|
|
{
|
|
var result = Validate(new ManagementServiceOptions { CommandTimeout = TimeSpan.FromSeconds(-1) });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("CommandTimeout", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero long-running command timeout is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroLongRunningCommandTimeout_IsRejected()
|
|
{
|
|
var result = Validate(new ManagementServiceOptions { LongRunningCommandTimeout = TimeSpan.Zero });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LongRunningCommandTimeout", result.FailureMessage);
|
|
}
|
|
}
|