|
|
@@ -0,0 +1,66 @@
|
|
|
+using System;
|
|
|
+using IvfTl.ControlHost.Debug;
|
|
|
+using IvfTl.ControlHost.Tests.Fakes;
|
|
|
+using Xunit;
|
|
|
+
|
|
|
+namespace IvfTl.ControlHost.Tests
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// Task7-t3:借用(Acquire)成功时回带培养态(cultivating + embryoCount)。
|
|
|
+ /// 纯逻辑、注入式——cultivationOf 委托提供假培养态,不接真实数据源(下个任务才装配)。
|
|
|
+ /// </summary>
|
|
|
+ public class DebugAcquireCultivationTests
|
|
|
+ {
|
|
|
+ private static readonly DateTime Now = new DateTime(2026, 6, 24, 0, 0, 0, DateTimeKind.Utc);
|
|
|
+
|
|
|
+ private DebugSessionManager NewMgr(FakeGate gate, Func<int, (bool, int)> cultivationOf)
|
|
|
+ => new DebugSessionManager(_ => gate, () => Now, ttlMs: 10000, log: null, cultivationOf: cultivationOf);
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Acquire_CultivatingHouse_ReturnsCultivationState()
|
|
|
+ {
|
|
|
+ var gate = new FakeGate(6, new FakeSerial());
|
|
|
+ var mgr = NewMgr(gate, sn => (true, 3));
|
|
|
+
|
|
|
+ var r = mgr.Acquire(6);
|
|
|
+
|
|
|
+ Assert.True(r.Ok);
|
|
|
+ Assert.True(r.Cultivating);
|
|
|
+ Assert.Equal(3, r.EmbryoCount);
|
|
|
+ // Result 仍是 sid 字符串(operate 端靠 r.Result 取 sessionId,不能破坏)
|
|
|
+ Assert.IsType<string>(r.Result);
|
|
|
+ Assert.False(string.IsNullOrEmpty((string)r.Result));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Acquire_EmptyHouse_ReturnsNotCultivating()
|
|
|
+ {
|
|
|
+ var gate = new FakeGate(6, new FakeSerial());
|
|
|
+ var mgr = NewMgr(gate, sn => (false, 0));
|
|
|
+
|
|
|
+ var r = mgr.Acquire(6);
|
|
|
+
|
|
|
+ Assert.True(r.Ok);
|
|
|
+ Assert.False(r.Cultivating);
|
|
|
+ Assert.Equal(0, r.EmbryoCount);
|
|
|
+ Assert.IsType<string>(r.Result);
|
|
|
+ Assert.False(string.IsNullOrEmpty((string)r.Result));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Acquire_NoCultivationProvider_DefaultsFalse()
|
|
|
+ {
|
|
|
+ var gate = new FakeGate(6, new FakeSerial());
|
|
|
+ // cultivationOf 传 null(不提供)——Acquire 不应崩,默认 false/0
|
|
|
+ var mgr = NewMgr(gate, null);
|
|
|
+
|
|
|
+ var r = mgr.Acquire(6);
|
|
|
+
|
|
|
+ Assert.True(r.Ok);
|
|
|
+ Assert.False(r.Cultivating);
|
|
|
+ Assert.Equal(0, r.EmbryoCount);
|
|
|
+ Assert.IsType<string>(r.Result);
|
|
|
+ Assert.False(string.IsNullOrEmpty((string)r.Result));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|