using Shouldly; using Xunit; namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.Tests; /// /// Pins the socket-lifecycle surface extracted from into the /// reusable (Task 3). The clamp helper moved with it, and a /// connect to a dead port must still surface the underlying socket failure. /// [Trait("Category", "Unit")] public sealed class ModbusSocketLifecycleTests { /// Verifies the whole-seconds clamp rounds sub-second/negative durations up to a minimum of one. /// The input duration in seconds. /// The expected clamped value in whole seconds. [Theory] [InlineData(0.4, 1)] // sub-second rounds up to 1 (the int-cast truncation guard) [InlineData(2.0, 2)] [InlineData(-5.0, 1)] // negative clamps to 1 public void ClampToWholeSeconds_rounds_up_min_one(double seconds, int expected) => ModbusSocketLifecycle.ClampToWholeSeconds(TimeSpan.FromSeconds(seconds)).ShouldBe(expected); /// Verifies a connect to a dead port surfaces the underlying socket failure. [Fact] public async Task Connect_to_dead_port_surfaces_socket_failure() { var life = new ModbusSocketLifecycle("127.0.0.1", 1, TimeSpan.FromMilliseconds(300), autoReconnect: false); await Should.ThrowAsync( life.ConnectAsync(TestContext.Current.CancellationToken)); } }