Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.CLI.Tests/Commands/CachedCallCommandsTests.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

153 lines
6.5 KiB
C#

using System.CommandLine;
using System.CommandLine.Parsing;
using ZB.MOM.WW.ScadaBridge.CLI.Commands;
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests.Commands;
/// <summary>
/// Tests for <see cref="CachedCallCommands"/> — pins that option parsing maps to the
/// correct management command objects with the correct field values.
/// </summary>
public class CachedCallCommandsTests
{
private static readonly Option<string> Url = new("--url") { Recursive = true };
private static readonly Option<string> Username = new("--username") { Recursive = true };
private static readonly Option<string> Password = new("--password") { Recursive = true };
private static readonly Option<string> Format = CliOptions.CreateFormatOption();
private static Command BuildCachedCall()
=> CachedCallCommands.Build(Url, Format, Username, Password);
// ── retry ──────────────────────────────────────────────────────────────
/// <summary>Verifies that the retry command with a site id and message id produces the expected management command.</summary>
[Fact]
public void Retry_WithSiteIdAndMessageId_ProducesCorrectCommand()
{
var group = BuildCachedCall();
var retry = group.Subcommands.Single(c => c.Name == "retry");
var result = retry.Parse(
["--site-id", "site-a", "--tracked-operation-id", "11111111-2222-3333-4444-555555555555"]);
Assert.Empty(result.Errors);
var cmd = CachedCallCommands.BuildRetryCommand(result);
Assert.Equal("site-a", cmd.SiteIdentifier);
Assert.Equal("11111111-2222-3333-4444-555555555555", cmd.MessageId);
}
/// <summary>Verifies that the retry command requires both the site id and the tracked operation id.</summary>
[Fact]
public void Retry_SiteIdAndTrackedOperationId_AreRequired()
{
var group = BuildCachedCall();
var retry = group.Subcommands.Single(c => c.Name == "retry");
var siteId = retry.Options.Single(o => o.Name == "--site-id");
var opId = retry.Options.Single(o => o.Name == "--tracked-operation-id");
Assert.True(siteId.Required, "--site-id must be required.");
Assert.True(opId.Required, "--tracked-operation-id must be required.");
}
/// <summary>Verifies that the retry command reports parse errors when its options are missing.</summary>
[Fact]
public void Retry_MissingOptions_ProducesParseErrors()
{
var group = BuildCachedCall();
var retry = group.Subcommands.Single(c => c.Name == "retry");
var result = retry.Parse([]);
Assert.NotEmpty(result.Errors);
}
// ── discard ────────────────────────────────────────────────────────────
/// <summary>Verifies that the discard command with a site id and message id produces the expected management command.</summary>
[Fact]
public void Discard_WithSiteIdAndMessageId_ProducesCorrectCommand()
{
var group = BuildCachedCall();
var discard = group.Subcommands.Single(c => c.Name == "discard");
var result = discard.Parse(
["--site-id", "site-b", "--tracked-operation-id", "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"]);
Assert.Empty(result.Errors);
var cmd = CachedCallCommands.BuildDiscardCommand(result);
Assert.Equal("site-b", cmd.SiteIdentifier);
Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", cmd.MessageId);
}
/// <summary>Verifies that the discard command requires both the site id and the tracked operation id.</summary>
[Fact]
public void Discard_SiteIdAndTrackedOperationId_AreRequired()
{
var group = BuildCachedCall();
var discard = group.Subcommands.Single(c => c.Name == "discard");
var siteId = discard.Options.Single(o => o.Name == "--site-id");
var opId = discard.Options.Single(o => o.Name == "--tracked-operation-id");
Assert.True(siteId.Required, "--site-id must be required.");
Assert.True(opId.Required, "--tracked-operation-id must be required.");
}
/// <summary>Verifies that the discard command reports parse errors when its options are missing.</summary>
[Fact]
public void Discard_MissingOptions_ProducesParseErrors()
{
var group = BuildCachedCall();
var discard = group.Subcommands.Single(c => c.Name == "discard");
var result = discard.Parse([]);
Assert.NotEmpty(result.Errors);
}
// ── group shape ────────────────────────────────────────────────────────
/// <summary>Verifies that the cached-call command group contains the retry and discard subcommands.</summary>
[Fact]
public void CachedCallGroup_HasRetryAndDiscard()
{
var group = BuildCachedCall();
var subNames = group.Subcommands.Select(c => c.Name).ToHashSet();
Assert.Contains("retry", subNames);
Assert.Contains("discard", subNames);
}
/// <summary>Verifies that the cached-call command group is named cached-call.</summary>
[Fact]
public void CachedCallGroup_Name_IsCachedCall()
{
var group = BuildCachedCall();
Assert.Equal("cached-call", group.Name);
}
// ── registry round-trip ────────────────────────────────────────────────
/// <summary>Verifies that the retry-parked-message command resolves through the command registry.</summary>
[Fact]
public void RetryParkedMessageCommand_ResolvesViaRegistry()
{
var name = ManagementCommandRegistry.GetCommandName(typeof(RetryParkedMessageCommand));
Assert.False(string.IsNullOrWhiteSpace(name));
Assert.Equal(typeof(RetryParkedMessageCommand), ManagementCommandRegistry.Resolve(name));
}
/// <summary>Verifies that the discard-parked-message command resolves through the command registry.</summary>
[Fact]
public void DiscardParkedMessageCommand_ResolvesViaRegistry()
{
var name = ManagementCommandRegistry.GetCommandName(typeof(DiscardParkedMessageCommand));
Assert.False(string.IsNullOrWhiteSpace(name));
Assert.Equal(typeof(DiscardParkedMessageCommand), ManagementCommandRegistry.Resolve(name));
}
}