using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.Driver.AbCip; namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip.Tests; /// /// CONV-4 — keys per-host resilience (bulkhead / circuit /// breaker). It must resolve an equipment-tag reference (raw TagConfig JSON) to its OWN device /// host, not fall back to the first device — otherwise a broken device B trips device A's /// breaker. Authored tags and unknown refs keep the current fallback. /// [Trait("Category", "Unit")] public sealed class AbCipResolveHostTests { private const string DeviceA = "ab://10.0.0.5/1,0"; private const string DeviceB = "ab://10.0.0.6/1,0"; private static AbCipDriver NewDriver() => new( new AbCipDriverOptions { Devices = [new AbCipDeviceOptions(DeviceA), new AbCipDeviceOptions(DeviceB)], Probe = new AbCipProbeOptions { Enabled = false }, }, "abcip-1", new FakeAbCipTagFactory()); /// 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}}","tagPath":"Motor1.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); } }