test(drivers): failing repro for CONV-4 equipment-tag ResolveHost mis-keying

This commit is contained in:
Joseph Doherty
2026-07-13 12:23:43 -04:00
parent dd01565d9a
commit 8a7701db3f
5 changed files with 181 additions and 1 deletions
@@ -0,0 +1,52 @@
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Driver.FOCAS;
namespace ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Tests;
/// <summary>
/// CONV-4 — <see cref="FocasDriver.ResolveHost"/> must resolve an equipment-tag reference (raw
/// TagConfig JSON) to its OWN device host so per-host breaker keys are correct for equipment
/// tags. An address-less equipment ref (FOCAS coalesces a missing <c>deviceHostAddress</c> to
/// <c>""</c>) must fall back rather than key an empty host.
/// </summary>
[Trait("Category", "Unit")]
public sealed class FocasResolveHostTests
{
private const string DeviceA = "focas://10.0.0.5:8193";
private const string DeviceB = "focas://10.0.0.6:8193";
private static FocasDriver NewDriver() => new(
new FocasDriverOptions
{
Devices = [new FocasDeviceOptions(DeviceA), new FocasDeviceOptions(DeviceB)],
Probe = new FocasProbeOptions { Enabled = false },
},
"focas-1", new FakeFocasClientFactory());
/// <summary>An equipment-tag ref naming device B resolves to device B's host, not the first device.</summary>
[Fact]
public void ResolveHost_EquipmentTagRef_ReturnsItsOwnDeviceHost()
{
var drv = NewDriver();
var json = $$"""{"deviceHostAddress":"{{DeviceB}}","address":"R100","dataType":"Byte"}""";
drv.ResolveHost(json).ShouldBe(DeviceB);
}
/// <summary>An equipment ref with no deviceHostAddress falls back to the first device, not an empty host.</summary>
[Fact]
public void ResolveHost_EquipmentTagRef_WithoutDeviceHost_FallsBack()
{
var drv = NewDriver();
var json = """{"address":"R100","dataType":"Byte"}""";
drv.ResolveHost(json).ShouldBe(DeviceA);
}
/// <summary>An unresolvable ref keeps the current first-device fallback.</summary>
[Fact]
public void ResolveHost_UnknownRef_KeepsCurrentFallback()
{
var drv = NewDriver();
drv.ResolveHost("totally-unknown").ShouldBe(DeviceA);
}
}