using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.Driver.TwinCAT; namespace ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests; /// /// CONV-4 — must resolve an equipment-tag reference /// (raw TagConfig JSON) to its OWN device host so per-host breaker keys are correct for /// equipment tags, not the first-device fallback. /// [Trait("Category", "Unit")] public sealed class TwinCATResolveHostTests { private const string DeviceA = "ads://5.23.91.23.1.1:851"; private const string DeviceB = "ads://5.23.91.23.1.2:851"; private static TwinCATDriver NewDriver() => new( new TwinCATDriverOptions { Devices = [new TwinCATDeviceOptions(DeviceA), new TwinCATDeviceOptions(DeviceB)], Probe = new TwinCATProbeOptions { Enabled = false }, EnableControllerBrowse = false, }, "twincat-1", new FakeTwinCATClientFactory()); /// An equipment-tag ref naming device B resolves to device B's host, not the first device. [Fact] public void ResolveHost_EquipmentTagRef_ReturnsItsOwnDeviceHost() { var drv = NewDriver(); var json = $$"""{"deviceHostAddress":"{{DeviceB}}","symbolPath":"MAIN.Speed","dataType":"DInt"}"""; drv.ResolveHost(json).ShouldBe(DeviceB); } /// An unresolvable ref keeps the current first-device fallback. [Fact] public void ResolveHost_UnknownRef_KeepsCurrentFallback() { var drv = NewDriver(); drv.ResolveHost("totally-unknown").ShouldBe(DeviceA); } }