Files
WCTDataMiner/tests/Gpulse.WCT.DataAnalyzer.Tests/CliStructureTests.cs

56 lines
2.1 KiB
C#
Raw Normal View History

2026-08-17 09:24:57 +08:00
using Gpulse.WCT.DataAnalyzer.Commands;
using Gpulse.WCT.DataAnalyzer.Core.Application;
using Gpulse.WCT.DataAnalyzer.Core.Application.Analysis;
using Gpulse.WCT.DataAnalyzer.Core.Application.Exporting;
2026-08-17 09:24:57 +08:00
using Microsoft.Extensions.DependencyInjection;
using System.CommandLine;
namespace Gpulse.WCT.DataAnalyzer.Tests;
[TestFixture]
public class CliStructureTests : CommandTestBase
{
/// <summary>按 Program.Main 的方式组装根命令。</summary>
private RootCommand BuildRoot()
{
var root = new RootCommand("Gpulse.WCT.DataAnalyzer - FOD Log Data Parser");
root.AddCommand(new ParseCommand(Host.Services.GetRequiredService<ParseService>()));
root.AddCommand(new AggregateCommand(Host.Services.GetRequiredService<AggregationService>()));
root.AddCommand(new ExportCommand(Host.Services.GetRequiredService<ExportService>()));
root.AddCommand(new CleanCommand(Host.Services.GetRequiredService<CleanService>()));
root.AddCommand(new AnalyzeCommand(
Host.Services.GetRequiredService<PlossAnalysisService>(),
Host.Services.GetRequiredService<QfodCalibrationService>(),
Host.Services.GetRequiredService<AnalyzeExcelExporter>()));
2026-08-17 09:24:57 +08:00
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"));
});
}
}