From acdc502be2c29d00d613a28d1f4ed70cdcf5db89 Mon Sep 17 00:00:00 2001 From: haoliang <821644@qq.com> Date: Mon, 4 May 2026 22:04:07 +0800 Subject: [PATCH] =?UTF-8?q?test(cnc-service):=20=E6=96=B0=E5=A2=9E=20Start?= =?UTF-8?q?ing=20=E7=8A=B6=E6=80=81=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=EF=BC=8C=E9=AA=8C=E8=AF=81=E6=9C=8D=E5=8A=A1=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E4=B8=AD=E7=8A=B6=E6=80=81=E8=BF=94=E5=9B=9E=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CncService.Tests/DashboardServiceTests.cs | 19 ++++++++++ .../TestResults/DashboardServiceTests.trx | 36 +++++++++++-------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/tests/CncService.Tests/DashboardServiceTests.cs b/tests/CncService.Tests/DashboardServiceTests.cs index f768b2a..4af4988 100644 --- a/tests/CncService.Tests/DashboardServiceTests.cs +++ b/tests/CncService.Tests/DashboardServiceTests.cs @@ -88,5 +88,24 @@ namespace CncService.Tests Assert.Equal("Running", serviceStatusVal); Assert.Equal("running", statusVal); } + + [Fact] + public void GetCollectorStatus_With_Starting_ServiceStatus_Returns_Starting_State() + { + var latest = new CollectorHeartbeat { Id = 2, ServiceId = "collector-service", Status = "running", UptimeSeconds = 120, LastCollectTime = DateTime.Now, CreatedAt = DateTime.Now }; + var dashboardRepo = new FakeDashboardRepository(); + var heartbeatRepo = new FakeCollectorHeartbeatRepository(latest); + var checker = new FakeWindowsServiceChecker(CncService.Interface.ServiceStatusEnum.Starting); + var svc = new DashboardService(dashboardRepo, heartbeatRepo, checker); + + var resultObj = svc.GetCollectorStatus(); + var t = resultObj.GetType(); + var serviceStatusProp = t.GetProperty("serviceStatus"); + var statusProp = t.GetProperty("status"); + var serviceStatusVal = serviceStatusProp.GetValue(resultObj) as string; + var statusVal = statusProp.GetValue(resultObj) as string; + Assert.Equal("Starting", serviceStatusVal); + Assert.Equal("running", statusVal); + } } } diff --git a/tests/CncService.Tests/TestResults/DashboardServiceTests.trx b/tests/CncService.Tests/TestResults/DashboardServiceTests.trx index 9dd44da..d0ae61c 100644 --- a/tests/CncService.Tests/TestResults/DashboardServiceTests.trx +++ b/tests/CncService.Tests/TestResults/DashboardServiceTests.trx @@ -1,39 +1,45 @@  - - - - + + + + - - + + + - + + + + + - + - - + + + - + [xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.3+1b45f5407b (64-bit Desktop .NET 4.0.30319.42000) -[xUnit.net 00:00:00.39] Discovering: CncService.Tests -[xUnit.net 00:00:00.53] Discovered: CncService.Tests -[xUnit.net 00:00:00.55] Starting: CncService.Tests -[xUnit.net 00:00:00.74] Finished: CncService.Tests +[xUnit.net 00:00:00.31] Discovering: CncService.Tests +[xUnit.net 00:00:00.41] Discovered: CncService.Tests +[xUnit.net 00:00:00.42] Starting: CncService.Tests +[xUnit.net 00:00:00.55] Finished: CncService.Tests