Files
lmxopcua/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests/TwinCATResolveHostTests.cs
T

44 lines
1.6 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Driver.TwinCAT;
namespace ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests;
/// <summary>
/// CONV-4 — <see cref="TwinCATDriver.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, not the first-device fallback.
/// </summary>
[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());
/// <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}}","symbolPath":"MAIN.Speed","dataType":"DInt"}""";
drv.ResolveHost(json).ShouldBe(DeviceB);
}
/// <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);
}
}