using Shouldly; using Xunit; namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.Tests; /// /// Confirms the driver's default transport-factory closure — and, by extension, the /// probe's transport construction — routes through /// instead of hardcoding , so an RtuOverTcp-authored /// config actually gets RTU framing rather than silently running as TCP/MBAP. /// [Trait("Category", "Unit")] public sealed class ModbusTransportWiringTests { private static IModbusTransport BuildDefaultTransport(ModbusDriverOptions opts) { using var driver = new ModbusDriver(opts, "wire-test"); var factory = (Func)typeof(ModbusDriver) .GetField("_transportFactory", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)! .GetValue(driver)!; return factory(opts); } [Fact] public void Default_closure_builds_rtu_transport_for_RtuOverTcp() => BuildDefaultTransport(new ModbusDriverOptions { Transport = ModbusTransportMode.RtuOverTcp }) .ShouldBeOfType(); [Fact] public void Default_closure_builds_tcp_transport_for_Tcp() => BuildDefaultTransport(new ModbusDriverOptions()) .ShouldBeOfType(); }