38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
|
|
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;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// CLI 命令测试基类:每个测试一个独立的内存数据库 + 临时目录。
|
||
|
|
/// </summary>
|
||
|
|
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<ParseService>());
|
||
|
|
|
||
|
|
protected AggregateCommand Aggregate() => new(Host.Services.GetRequiredService<AggregationService>());
|
||
|
|
|
||
|
|
protected ExportCommand Export() => new(Host.Services.GetRequiredService<ExportService>());
|
||
|
|
|
||
|
|
protected CleanCommand Clean() => new(Host.Services.GetRequiredService<CleanService>());
|
||
|
|
|
||
|
|
protected AnalyzeCommand Analyze() => new(
|
||
|
|
Host.Services.GetRequiredService<PlossAnalysisService>(),
|
||
|
|
Host.Services.GetRequiredService<QfodCalibrationService>());
|
||
|
|
|
||
|
|
/// <summary>在测试临时目录下新建一个子目录。</summary>
|
||
|
|
protected string NewDir() =>
|
||
|
|
Directory.CreateDirectory(Path.Combine(Host.TempDir, Guid.NewGuid().ToString("N"))).FullName;
|
||
|
|
}
|