test: 添加 CLI 命令单元测试
This commit is contained in:
53
tests/Gpulse.WCT.DataAnalyzer.Tests/CliStructureTests.cs
Normal file
53
tests/Gpulse.WCT.DataAnalyzer.Tests/CliStructureTests.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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
|
||||
{
|
||||
/// <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>()));
|
||||
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"));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user