Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.CLI.Tests/Commands/ExternalSystemRetryOptionTests.cs
T
Joseph Doherty 513fa1aa16 docs(tests): fix CommentChecker findings across tests/ — 13,392 → 0 (repo-wide scan clean)
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.
2026-10-07 15:05:49 -04:00

108 lines
4.2 KiB
C#

using System.CommandLine;
using ZB.MOM.WW.ScadaBridge.CLI.Commands;
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests.Commands;
/// <summary>
/// Deferred-work row 27(b): <c>external-system create</c> and <c>external-system update</c>
/// must expose the per-system Store-and-Forward retry policy. Before this the fields existed
/// on the central entity but had NO management surface at all — the only way to set them was
/// a direct DB edit of <c>ExternalSystemDefinitions</c>.
/// <para>
/// The delay flag is named <c>--retry-delay-seconds</c> to match the sibling
/// <c>--timeout-seconds</c> on these same commands (the repo-wide CLI convention is an explicit
/// unit suffix), with <c>--retry-delay</c> kept as an alias.
/// </para>
/// </summary>
public class ExternalSystemRetryOptionTests
{
private static readonly Option<string> Url = new("--url") { Recursive = true };
private static readonly Option<string> Format = new("--format") { Recursive = true };
private static readonly Option<string> Username = new("--username") { Recursive = true };
private static readonly Option<string> Password = new("--password") { Recursive = true };
private static Command Group() => ExternalSystemCommands.Build(Url, Format, Username, Password);
private static Option? FindOption(Command command, string name)
=> command.Options.SingleOrDefault(o => o.Name == name);
/// <summary>Verifies that the create and update subcommands expose the optional retry-policy options.</summary>
/// <param name="subcommand">The name of the subcommand under test.</param>
[Theory]
[InlineData("create")]
[InlineData("update")]
public void HasOptionalRetryPolicyOptions(string subcommand)
{
var cmd = Group().Subcommands.Single(c => c.Name == subcommand);
var maxRetries = FindOption(cmd, "--max-retries");
Assert.NotNull(maxRetries);
Assert.False(maxRetries!.Required);
var retryDelay = FindOption(cmd, "--retry-delay-seconds");
Assert.NotNull(retryDelay);
Assert.False(retryDelay!.Required);
}
/// <summary>Verifies that the create subcommand parses the supplied retry-policy values.</summary>
[Fact]
public void Create_ParsesRetryPolicyValues()
{
var parse = Group().Parse(new[]
{
"create", "--name", "Sys", "--endpoint-url", "http://x", "--auth-type", "none",
"--max-retries", "8", "--retry-delay-seconds", "60",
});
Assert.Empty(parse.Errors);
Assert.Equal(8, parse.GetValue<int?>("--max-retries"));
Assert.Equal(60, parse.GetValue<int?>("--retry-delay-seconds"));
}
/// <summary>Verifies that the update subcommand parses the supplied retry-policy values.</summary>
[Fact]
public void Update_ParsesRetryPolicyValues()
{
var parse = Group().Parse(new[]
{
"update", "--id", "7", "--name", "Sys", "--endpoint-url", "http://x",
"--auth-type", "none", "--max-retries", "3", "--retry-delay-seconds", "10",
});
Assert.Empty(parse.Errors);
Assert.Equal(3, parse.GetValue<int?>("--max-retries"));
Assert.Equal(10, parse.GetValue<int?>("--retry-delay-seconds"));
}
/// <summary>Verifies that the retry-delay option alias is accepted by the parser.</summary>
[Fact]
public void RetryDelayAliasIsAccepted()
{
var parse = Group().Parse(new[]
{
"create", "--name", "Sys", "--endpoint-url", "http://x", "--auth-type", "none",
"--retry-delay", "45",
});
Assert.Empty(parse.Errors);
Assert.Equal(45, parse.GetValue<int?>("--retry-delay-seconds"));
}
/// <summary>
/// Omission must stay distinguishable from an explicit 0 — that is what makes update's
/// "omit to preserve" rule and create's "fall back to the engine default" rule work.
/// </summary>
[Fact]
public void OmittedRetryPolicy_ParsesAsNull()
{
var parse = Group().Parse(new[]
{
"create", "--name", "Sys", "--endpoint-url", "http://x", "--auth-type", "none",
});
Assert.Empty(parse.Errors);
Assert.Null(parse.GetValue<int?>("--max-retries"));
Assert.Null(parse.GetValue<int?>("--retry-delay-seconds"));
}
}