using Gpulse.WCT.DataAnalyzer.Commands; using Gpulse.WCT.DataAnalyzer.Core.Application; using Gpulse.WCT.DataAnalyzer.Core.Application.Analysis; using Microsoft.Extensions.DependencyInjection; namespace Gpulse.WCT.DataAnalyzer.Tests; /// /// CLI 命令测试基类:每个测试一个独立的内存数据库 + 临时目录。 /// public abstract class CommandTestBase { protected CliTestHost Host { get; private set; } = null!; [SetUp] public async Task SetUp() => Host = await CliTestHost.CreateAsync(); [TearDown] public void TearDown() => Host.Dispose(); // 命令构造方式与 Program.Main 一致:从 DI 解析服务再构造命令 protected ParseCommand Parse() => new(Host.Services.GetRequiredService()); protected AggregateCommand Aggregate() => new(Host.Services.GetRequiredService()); protected ExportCommand Export() => new(Host.Services.GetRequiredService()); protected CleanCommand Clean() => new(Host.Services.GetRequiredService()); protected AnalyzeCommand Analyze() => new( Host.Services.GetRequiredService(), Host.Services.GetRequiredService()); /// 在测试临时目录下新建一个子目录。 protected string NewDir() => Directory.CreateDirectory(Path.Combine(Host.TempDir, Guid.NewGuid().ToString("N"))).FullName; }