using Gpulse.WCT.DataAnalyzer.Commands; using Gpulse.WCT.DataAnalyzer.Core.Application; using Gpulse.WCT.DataAnalyzer.Core.Application.Analysis; using Microsoft.Extensions.DependencyInjection; using System.CommandLine; namespace Gpulse.WCT.DataAnalyzer.Tests; [TestFixture] public class CliStructureTests : CommandTestBase { /// 按 Program.Main 的方式组装根命令。 private RootCommand BuildRoot() { var root = new RootCommand("Gpulse.WCT.DataAnalyzer - FOD Log Data Parser"); root.AddCommand(new ParseCommand(Host.Services.GetRequiredService())); root.AddCommand(new AggregateCommand(Host.Services.GetRequiredService())); root.AddCommand(new ExportCommand(Host.Services.GetRequiredService())); root.AddCommand(new CleanCommand(Host.Services.GetRequiredService())); root.AddCommand(new AnalyzeCommand( Host.Services.GetRequiredService(), Host.Services.GetRequiredService())); return root; } [Test] public async Task Help_ListsAllSubcommands() { var (code, stdout, _) = await BuildRoot().RunCaptureAsync("--help"); Assert.Multiple(() => { Assert.That(code, Is.EqualTo(0)); Assert.That(stdout, Does.Contain("parse")); Assert.That(stdout, Does.Contain("aggregate")); Assert.That(stdout, Does.Contain("export")); Assert.That(stdout, Does.Contain("clean")); Assert.That(stdout, Does.Contain("analyze")); }); } [Test] public async Task UnknownCommand_ReturnsError() { var (code, stdout, stderr) = await BuildRoot().RunCaptureAsync("nosuchcommand"); Assert.Multiple(() => { Assert.That(code, Is.EqualTo(1)); Assert.That(stdout + stderr, Does.Contain("nosuchcommand")); }); } }