using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy; namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.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 AbLegacyResolveHostTests { private const string DeviceA = "ab://10.0.0.5/1,0"; private const string DeviceB = "ab://10.0.0.6/1,0"; private static AbLegacyDriver NewDriver() => new( new AbLegacyDriverOptions { Devices = [new AbLegacyDeviceOptions(DeviceA), new AbLegacyDeviceOptions(DeviceB)], Probe = new AbLegacyProbeOptions { Enabled = false }, }, "ablegacy-1", new FakeAbLegacyTagFactory()); /// 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}}","address":"N7:0","dataType":"Int"}"""; 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); } }