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.
106 lines
4.1 KiB
C#
106 lines
4.1 KiB
C#
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);
|
|
|
|
/// <summary>Verifies that the default options are valid.</summary>
|
|
[Fact]
|
|
public void DefaultOptions_AreValid()
|
|
{
|
|
var result = Validate(new SiteEventLogOptions());
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that zero retention days is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroRetentionDays_IsRejected()
|
|
{
|
|
var result = Validate(new SiteEventLogOptions { RetentionDays = 0 });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("RetentionDays", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero purge interval is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroPurgeInterval_IsRejected()
|
|
{
|
|
var result = Validate(new SiteEventLogOptions { PurgeInterval = TimeSpan.Zero });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("PurgeInterval", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a maximum query page size below the default page size is rejected.</summary>
|
|
[Fact]
|
|
public void MaxQueryPageSize_BelowQueryPageSize_IsRejected()
|
|
{
|
|
var result = Validate(new SiteEventLogOptions { QueryPageSize = 500, MaxQueryPageSize = 100 });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("MaxQueryPageSize", result.FailureMessage);
|
|
}
|
|
|
|
// ── Register row 34: the per-tick purge ceiling ──
|
|
|
|
/// <summary>Verifies that a negative maximum of purged rows per tick is rejected.</summary>
|
|
[Fact]
|
|
public void NegativeMaxPurgedRowsPerTick_IsRejected()
|
|
{
|
|
// 0 already means "unlimited" explicitly, so a negative value is a typo, not a synonym.
|
|
// Accepting it would silently remove the only bound on a purge tick's CDC oplog burst.
|
|
var result = Validate(new SiteEventLogOptions { MaxPurgedRowsPerTick = -1 });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("MaxPurgedRowsPerTick", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero maximum of purged rows per tick (unlimited) is accepted.</summary>
|
|
[Fact]
|
|
public void ZeroMaxPurgedRowsPerTick_IsAccepted()
|
|
{
|
|
// The documented escape hatch back to unbounded purges.
|
|
var result = Validate(new SiteEventLogOptions { MaxPurgedRowsPerTick = 0 });
|
|
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a zero purge catch-up interval is rejected.</summary>
|
|
[Fact]
|
|
public void ZeroPurgeCatchUpInterval_IsRejected()
|
|
{
|
|
// It is a Task.Delay period on the purge loop; zero would spin a ceiling-limited node.
|
|
var result = Validate(new SiteEventLogOptions { PurgeCatchUpInterval = TimeSpan.Zero });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("PurgeCatchUpInterval", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>Verifies that a purge catch-up interval longer than the purge interval is rejected.</summary>
|
|
[Fact]
|
|
public void PurgeCatchUpInterval_LongerThanPurgeInterval_IsRejected()
|
|
{
|
|
// The catch-up is an ACCELERATED retry; a longer value would make hitting the ceiling
|
|
// delay convergence instead of hastening it — the exact inverse of its purpose.
|
|
var result = Validate(new SiteEventLogOptions
|
|
{
|
|
PurgeInterval = TimeSpan.FromMinutes(10),
|
|
PurgeCatchUpInterval = TimeSpan.FromHours(1),
|
|
});
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("PurgeCatchUpInterval", result.FailureMessage);
|
|
}
|
|
}
|