using ZB.MOM.WW.ScadaBridge.CLI.Commands; namespace ZB.MOM.WW.ScadaBridge.CLI.Tests.Commands; /// /// Tests for the scadabridge audit verify-chain subcommand. /// v1 is a no-op stub: a valid --month prints the documented "not enabled" /// message and exits 0; a malformed month or a missing --month exits non-zero. /// [Collection("Console")] public class AuditVerifyChainCommandTests { /// Verifies that verifying the chain for a valid month exits with zero and prints the documented message. [Fact] public void VerifyChain_ValidMonth_ExitsZeroWithDocumentedMessage() { var root = AuditCommandTestHarness.BuildRoot(); var (exit, output, _) = AuditCommandTestHarness.Invoke( root, "audit", "verify-chain", "--month", "2026-05"); Assert.Equal(0, exit); Assert.Contains("Hash-chain tamper-evidence is not enabled", output); Assert.Contains("Component-AuditLog.md", output); } /// Verifies that a malformed month value makes the command exit with a non-zero code. [Fact] public void VerifyChain_MalformedMonth_ExitsNonZero() { var root = AuditCommandTestHarness.BuildRoot(); var (exit, _, _) = AuditCommandTestHarness.Invoke( root, "audit", "verify-chain", "--month", "2026-13"); Assert.NotEqual(0, exit); } /// Verifies that omitting the month option produces the required-option error. [Fact] public void VerifyChain_MissingMonth_ProducesRequiredFlagError() { var root = AuditCommandTestHarness.BuildRoot(); var (exit, _, err) = AuditCommandTestHarness.Invoke(root, "audit", "verify-chain"); Assert.NotEqual(0, exit); Assert.Contains("--month", err); } /// Verifies that month validation accepts only values in yyyy-MM format. /// The month string to validate. /// Whether the month is expected to be valid. [Theory] [InlineData("2026-05", true)] [InlineData("2026-01", true)] [InlineData("2026-12", true)] [InlineData("2026-13", false)] [InlineData("2026-00", false)] [InlineData("2026-5", false)] [InlineData("not-a-month", false)] [InlineData("", false)] public void IsValidMonth_ValidatesYyyyMm(string month, bool expected) { Assert.Equal(expected, AuditVerifyChainHelpers.IsValidMonth(month)); } }