Forráskód Böngészése

feat(control): StatusDto + /ping 工厂 + 单测

阶段1-Task3:本地HTTP返回体骨架(ok/pid/tlSn/started),JSON序列化单测。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
huangjie 3 napja
szülő
commit
33722dfa59

+ 28 - 0
ivf_tl_operate_2.0/control/ivf_tl_ControlHost.Tests/StatusDtoTests.cs

@@ -0,0 +1,28 @@
+using IvfTl.ControlHost;
+using Newtonsoft.Json;
+using Xunit;
+
+namespace IvfTl.ControlHost.Tests
+{
+    public class StatusDtoTests
+    {
+        [Fact]
+        public void Ok_True_SerializesLowercaseFields()
+        {
+            var dto = new StatusDto { Ok = true, Pid = 1234, TlSn = "NEO-1-20230411" };
+            string json = JsonConvert.SerializeObject(dto);
+            Assert.Contains("\"ok\":true", json);
+            Assert.Contains("\"pid\":1234", json);
+            Assert.Contains("NEO-1-20230411", json);
+        }
+
+        [Fact]
+        public void Ping_HasOkAndPid()
+        {
+            var dto = StatusDto.Ping(99, "NEO-1-X");
+            Assert.True(dto.Ok);
+            Assert.Equal(99, dto.Pid);
+            Assert.Equal("NEO-1-X", dto.TlSn);
+        }
+    }
+}

+ 4 - 0
ivf_tl_operate_2.0/control/ivf_tl_ControlHost.Tests/ivf_tl_ControlHost.Tests.csproj

@@ -11,5 +11,9 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="..\ivf_tl_ControlHost\HostArgs.cs" Link="HostArgs.cs" />
+    <Compile Include="..\ivf_tl_ControlHost\StatusDto.cs" Link="StatusDto.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
   </ItemGroup>
 </Project>

+ 19 - 0
ivf_tl_operate_2.0/control/ivf_tl_ControlHost/StatusDto.cs

@@ -0,0 +1,19 @@
+using Newtonsoft.Json;
+
+namespace IvfTl.ControlHost
+{
+    /// <summary>
+    /// control 本地 HTTP /ping、/status 的返回体(阶段1:基础存活 + 现有快照占位)。
+    /// 监控补全(各舱实时活动/线程心跳/串口借用)在阶段2 扩展。
+    /// </summary>
+    public class StatusDto
+    {
+        [JsonProperty("ok")] public bool Ok { get; set; }
+        [JsonProperty("pid")] public int Pid { get; set; }
+        [JsonProperty("tlSn")] public string TlSn { get; set; } = "";
+        [JsonProperty("started")] public bool Started { get; set; }
+
+        public static StatusDto Ping(int pid, string tlSn) =>
+            new StatusDto { Ok = true, Pid = pid, TlSn = tlSn ?? "" };
+    }
+}