feat(dcl): implement IBrowsableDataConnection on OpcUaDataConnection
This commit is contained in:
@@ -17,7 +17,7 @@ namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Adapters;
|
|||||||
/// - Read/Write → Read/Write service calls
|
/// - Read/Write → Read/Write service calls
|
||||||
/// - Quality → OPC UA StatusCode mapping
|
/// - Quality → OPC UA StatusCode mapping
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OpcUaDataConnection : IDataConnection
|
public class OpcUaDataConnection : IDataConnection, IBrowsableDataConnection
|
||||||
{
|
{
|
||||||
private readonly IOpcUaClientFactory _clientFactory;
|
private readonly IOpcUaClientFactory _clientFactory;
|
||||||
private readonly ILogger<OpcUaDataConnection> _logger;
|
private readonly ILogger<OpcUaDataConnection> _logger;
|
||||||
@@ -274,6 +274,12 @@ public class OpcUaDataConnection : IDataConnection
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task<BrowseChildrenResult> BrowseChildrenAsync(
|
||||||
|
string? parentNodeId,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
=> _client!.BrowseChildrenAsync(parentNodeId, cancellationToken);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<bool> WriteBatchAndWaitAsync(
|
public async Task<bool> WriteBatchAndWaitAsync(
|
||||||
IDictionary<string, object?> values, string flagPath, object? flagValue,
|
IDictionary<string, object?> values, string flagPath, object? flagValue,
|
||||||
|
|||||||
+41
@@ -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>());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user