using SSPCTester.Logic.Models; using SSPCTester.Logic.Report; namespace SSPCTester.Tests; public sealed class ReportLayoutTests { [Fact] public void ProfessionalReport_RendersFull24ChannelDocument() { string output = Path.Combine(Path.GetTempPath(), $"SSPCTester-report-{Guid.NewGuid():N}.pdf"); try { var project = BuildProject(); new ReportGenerator().Generate(project, output); Assert.True(File.Exists(output)); Assert.True(new FileInfo(output).Length > 20_000); byte[] header = File.ReadAllBytes(output)[..4]; Assert.Equal("%PDF"u8.ToArray(), header); } finally { if (File.Exists(output)) File.Delete(output); } } private static Project BuildProject() { var project = new Project { Name = "24路固态功率控制器出厂检验", CreatedAt = new DateTime(2026, 6, 23, 8, 30, 0), LastTestedAt = new DateTime(2026, 6, 23, 10, 20, 0), Dut = new DutInfo { ProductName = "固态功率控制器", Model = "SSPC-24CH-28V-1A", SerialNumber = "SSPC-20260623-001", Manufacturer = "示例制造单位" }, Site = new TestSiteInfo { Tester = "测试员", TestDate = new DateTime(2026, 6, 23), TemperatureC = 24.8, HumidityPct = 52.3, PressureKpa = 101.2, Remark = "常温常压条件下进行全项目测试。" } }; for (int channel = 1; channel <= 24; channel++) { bool failed = channel == 8; project.BasicResults.Add(new ChannelResult { Channel = channel, VoltageOn = failed ? 0.12 : 28.01, CurrentOn = failed ? 0 : 1.002, VoltageOff = 0.01, Status = failed ? TestStatus.Fail : TestStatus.Pass }); project.CurveResults.Add(new CurveResultRow { Channel = channel, OnTimeMs = failed ? 6.2 : 1.22, RiseTimeMs = failed ? 3.4 : 0.98, OffTimeMs = 1.18, FallTimeMs = 0.91, Status = failed ? TestStatus.Fail : TestStatus.Pass }); project.PowerResults.Add(new PowerLossRow { Channel = channel, Vin = 28.01, Iin = 1.01, Vout = failed ? 25.7 : 27.62, Iout = 1.0, Status = failed ? TestStatus.Fail : TestStatus.Pass }); } foreach (var item in new[] { ("跳闸", "1.5×额定电流"), ("短路", "输出短路"), ("过温", "≥85℃"), ("过压", "≥32V"), ("欠压", "≤22V"), ("限流", "≥1.2A") }) { project.ProtectResults.Add(new ProtectRow { ProtectType = item.Item1, Trigger = item.Item2, TripTimeMs = 2.15, Status = TestStatus.Pass }); } project.TestFunction.Basic = "各通道依次执行导通、采集及关断操作。"; project.TestFunction.Curve = "曲线指标按照项目阈值进行判定。"; return project; } }