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.
102 lines
4.2 KiB
C#
102 lines
4.2 KiB
C#
using Microsoft.Extensions.Options;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.NotificationOutbox.Tests;
|
|
|
|
/// <summary>
|
|
/// Tests for the options validator: <see cref="NotificationOutboxOptions"/> had no
|
|
/// registered validator before this — the dispatch/purge/KPI cadences and the
|
|
/// delivered-throughput KPI window (<see cref="NotificationOutboxOptions.DeliveredKpiWindow"/>)
|
|
/// could be zero/negative with no boot-time signal, which would spin an Akka
|
|
/// scheduler or — because <c>NotificationOutboxKpiSampleSource</c> divides by
|
|
/// <c>DeliveredKpiWindow</c> to rescale onto <c>KpiHistoryOptions.SampleInterval</c>
|
|
/// — divide by zero. <see cref="NotificationOutboxOptions.MaxParallelDeliveries"/>
|
|
/// is validated on its BASE property, not the clamped
|
|
/// <see cref="NotificationOutboxOptions.ResolvedMaxParallelDeliveries"/>, so a
|
|
/// misconfigured non-positive value fails fast instead of silently clamping to 1.
|
|
/// </summary>
|
|
public class NotificationOutboxOptionsValidatorTests
|
|
{
|
|
private static ValidateOptionsResult Validate(NotificationOutboxOptions options) =>
|
|
new NotificationOutboxOptionsValidator().Validate(Options.DefaultName, options);
|
|
|
|
/// <summary>Verifies that the default options are valid.</summary>
|
|
[Fact]
|
|
public void DefaultOptions_AreValid()
|
|
{
|
|
var result = Validate(new NotificationOutboxOptions());
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero dispatch interval is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroDispatchInterval_IsRejected()
|
|
{
|
|
var result = Validate(new NotificationOutboxOptions { DispatchInterval = TimeSpan.Zero });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("DispatchInterval", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero dispatch batch size is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroDispatchBatchSize_IsRejected()
|
|
{
|
|
var result = Validate(new NotificationOutboxOptions { DispatchBatchSize = 0 });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("DispatchBatchSize", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero stuck-age threshold is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroStuckAgeThreshold_IsRejected()
|
|
{
|
|
var result = Validate(new NotificationOutboxOptions { StuckAgeThreshold = TimeSpan.Zero });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("StuckAgeThreshold", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero terminal-row retention is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroTerminalRetention_IsRejected()
|
|
{
|
|
var result = Validate(new NotificationOutboxOptions { TerminalRetention = TimeSpan.Zero });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("TerminalRetention", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero purge interval is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroPurgeInterval_IsRejected()
|
|
{
|
|
var result = Validate(new NotificationOutboxOptions { PurgeInterval = TimeSpan.Zero });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("PurgeInterval", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero delivered-KPI window is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroDeliveredKpiWindow_IsRejected()
|
|
{
|
|
var result = Validate(new NotificationOutboxOptions { DeliveredKpiWindow = TimeSpan.Zero });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("DeliveredKpiWindow", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a negative delivered-KPI window is rejected.</summary>
|
|
[Fact]
|
|
public void NegativeDeliveredKpiWindow_IsRejected()
|
|
{
|
|
var result = Validate(new NotificationOutboxOptions { DeliveredKpiWindow = TimeSpan.FromSeconds(-1) });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("DeliveredKpiWindow", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero maximum parallel deliveries value is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroMaxParallelDeliveries_IsRejected()
|
|
{
|
|
var result = Validate(new NotificationOutboxOptions { MaxParallelDeliveries = 0 });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("MaxParallelDeliveries", result.FailureMessage);
|
|
}
|
|
}
|