feat(dcl): implement IBrowsableDataConnection on OpcUaDataConnection

This commit is contained in:
Joseph Doherty
2026-05-28 11:58:08 -04:00
parent d79d7fdf71
commit 0b4b4c02f6
2 changed files with 48 additions and 1 deletions
@@ -17,7 +17,7 @@ namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Adapters;
/// - Read/Write → Read/Write service calls
/// - Quality → OPC UA StatusCode mapping
/// </summary>
public class OpcUaDataConnection : IDataConnection
public class OpcUaDataConnection : IDataConnection, IBrowsableDataConnection
{
private readonly IOpcUaClientFactory _clientFactory;
private readonly ILogger<OpcUaDataConnection> _logger;
@@ -274,6 +274,12 @@ public class OpcUaDataConnection : IDataConnection
return results;
}
/// <inheritdoc />
public Task<BrowseChildrenResult> BrowseChildrenAsync(
string? parentNodeId,
CancellationToken cancellationToken = default)
=> _client!.BrowseChildrenAsync(parentNodeId, cancellationToken);
/// <inheritdoc />
public async Task<bool> WriteBatchAndWaitAsync(
IDictionary<string, object?> values, string flagPath, object? flagValue,
@@ -0,0 +1,41 @@
using Microsoft.Extensions.Logging.Abstractions;
using NSubstitute;
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Protocol;
using ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Adapters;
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests.Adapters;
/// <summary>
/// Task 9 (opcua-tag-browser): <see cref="OpcUaDataConnection"/> implements
/// <see cref="IBrowsableDataConnection"/> as a one-line forwarder onto the
/// underlying <see cref="IOpcUaClient"/>. This guards that wiring — the
/// adapter must not add its own browse semantics; all browse behaviour lives
/// in the client (and is covered by RealOpcUaClient's own tests).
/// </summary>
public class OpcUaDataConnectionBrowseTests
{
[Fact]
public async Task BrowseChildrenAsync_ForwardsToUnderlyingClient()
{
var client = Substitute.For<IOpcUaClient>();
var factory = Substitute.For<IOpcUaClientFactory>();
factory.Create().Returns(client);
client.IsConnected.Returns(true);
var expected = new BrowseChildrenResult(
new[] { new BrowseNode("ns=2;s=X", "X", BrowseNodeClass.Variable, false) },
Truncated: false);
client.BrowseChildrenAsync("ns=2;s=Parent", Arg.Any<CancellationToken>())
.Returns(expected);
var adapter = new OpcUaDataConnection(factory, NullLogger<OpcUaDataConnection>.Instance);
// ConnectAsync installs the IOpcUaClient instance on the adapter; the
// forwarder dereferences that field directly.
await adapter.ConnectAsync(new Dictionary<string, string>());
var actual = await adapter.BrowseChildrenAsync("ns=2;s=Parent");
Assert.Same(expected, actual);
await client.Received(1).BrowseChildrenAsync("ns=2;s=Parent", Arg.Any<CancellationToken>());
}
}