using System.CommandLine; using ZB.MOM.WW.ScadaBridge.CLI.Commands; namespace ZB.MOM.WW.ScadaBridge.CLI.Tests.Commands; /// /// PLAN-06 Task 11: external-system create and external-system update /// must expose an optional --timeout-seconds (?) flag that /// carries the per-system ESG HTTP timeout. Omitting it preserves the existing value /// (update) / uses the gateway default (create). /// public class ExternalSystemTimeoutOptionTests { private static readonly Option Url = new("--url") { Recursive = true }; private static readonly Option Format = new("--format") { Recursive = true }; private static readonly Option Username = new("--username") { Recursive = true }; private static readonly Option 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); [Fact] public void Create_HasOptionalTimeoutSecondsOption() { var create = Group().Subcommands.Single(c => c.Name == "create"); var option = FindOption(create, "--timeout-seconds"); Assert.NotNull(option); Assert.False(option!.Required); } [Fact] public void Update_HasOptionalTimeoutSecondsOption() { var update = Group().Subcommands.Single(c => c.Name == "update"); var option = FindOption(update, "--timeout-seconds"); Assert.NotNull(option); Assert.False(option!.Required); } [Fact] public void Create_ParsesTimeoutSecondsValue() { var parse = Group().Parse(new[] { "create", "--name", "Sys", "--endpoint-url", "http://x", "--auth-type", "none", "--timeout-seconds", "15", }); Assert.Empty(parse.Errors); Assert.Equal(15, parse.GetValue("--timeout-seconds")); } [Fact] public void Update_ParsesTimeoutSecondsValue() { var parse = Group().Parse(new[] { "update", "--id", "7", "--name", "Sys", "--endpoint-url", "http://x", "--auth-type", "none", "--timeout-seconds", "20", }); Assert.Empty(parse.Errors); Assert.Equal(20, parse.GetValue("--timeout-seconds")); } [Fact] public void Create_OmittedTimeoutSeconds_ParsesWithoutError() { var parse = Group().Parse(new[] { "create", "--name", "Sys", "--endpoint-url", "http://x", "--auth-type", "none", }); Assert.Empty(parse.Errors); Assert.Null(parse.GetValue("--timeout-seconds")); } }