SSPC-Tester/SSPCTester.Logic/Testing/ProtectTest.cs

45 lines
1.5 KiB
C#
Raw Normal View History

using SSPCTester.Logic.Models;
namespace SSPCTester.Logic.Testing;
/// <summary>
/// 保护功能测试:当前阶段仅生成框架占位结果,不真正触发故障。
/// </summary>
public sealed class ProtectTest : ITestModule
{
public string Name => "保护功能";
private static readonly (string Type, string Trigger)[] _items = new[]
{
("跳闸", "1.5×额定电流"),
("短路", "输出短路"),
("过温", "≥85℃"),
("过压", "≥32V"),
("欠压", "≤22V"),
("限流", "≥1.2A"),
};
public async Task RunAsync(TestContext ctx, IProgress<TestProgress> progress, CancellationToken ct)
{
ctx.Project.ProtectResults.Clear();
for (int i = 0; i < _items.Length; i++)
{
ct.ThrowIfCancellationRequested();
var row = new ProtectRow
{
ProtectType = _items[i].Type,
Trigger = _items[i].Trigger,
Status = TestStatus.Running
};
ctx.Project.ProtectResults.Add(row);
progress.Report(new TestProgress { ModuleName = Name, Step = i, TotalSteps = _items.Length, Message = $"框架占位:{row.ProtectType}" });
await Task.Delay(150, ct).ConfigureAwait(false);
// 框架占位:固定演示数据
row.TripTimeMs = 2.0 + i * 0.3;
row.Status = TestStatus.Pass;
progress.Report(new TestProgress { ModuleName = Name, Step = i + 1, TotalSteps = _items.Length, StepStatus = row.Status });
}
}
}