using System.CommandLine;
using ZB.MOM.WW.ScadaBridge.CLI.Commands;
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests.Commands;
///
/// PLAN-07 Task 17 (arch-review P3): secured-write list must expose --skip
/// / --take offset-paging options alongside the --status / --site
/// filters, and map them onto .
/// Omitting the paging flags preserves the historical unpaged default (skip 0, take 200).
///
public class SecuredWriteListCommandTests
{
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() => SecuredWriteCommands.Build(Url, Format, Username, Password);
private static Command List() => Group().Subcommands.Single(c => c.Name == "list");
private static Option? FindOption(Command command, string name)
=> command.Options.SingleOrDefault(o => o.Name == name);
[Fact]
public void List_HasSkipAndTakeOptions()
{
var list = List();
Assert.NotNull(FindOption(list, "--skip"));
Assert.NotNull(FindOption(list, "--take"));
}
[Fact]
public void List_ParsesSkipTakeAndFilters_ForwardsToCommand()
{
var parse = Group().Parse(new[]
{
"list", "--status", "Pending", "--site", "SITE1", "--skip", "10", "--take", "25",
});
Assert.Empty(parse.Errors);
var command = SecuredWriteCommands.BuildListCommand(parse);
Assert.Equal("Pending", command.Status);
Assert.Equal("SITE1", command.SiteId);
Assert.Equal(10, command.Skip);
Assert.Equal(25, command.Take);
}
[Fact]
public void List_OmittedPaging_UsesUnpagedDefaults()
{
var parse = Group().Parse(new[] { "list" });
Assert.Empty(parse.Errors);
var command = SecuredWriteCommands.BuildListCommand(parse);
Assert.Null(command.Status);
Assert.Null(command.SiteId);
Assert.Equal(0, command.Skip);
Assert.Equal(200, command.Take);
}
}