513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
101 lines
4.1 KiB
C#
101 lines
4.1 KiB
C#
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Protocol;
|
|
using ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Adapters;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests;
|
|
|
|
/// <summary>
|
|
/// Verifies that <see cref="StubOpcUaClient"/> serves a small canned address-space
|
|
/// tree so DCL browse/paging flows can be exercised without a live OPC UA server.
|
|
/// The stub also fakes BrowseNext continuation paging on <c>Folder1</c> so the
|
|
/// continuation-token round-trip is testable end-to-end against the contract.
|
|
/// </summary>
|
|
public class StubOpcUaClientBrowseTests
|
|
{
|
|
// StubOpcUaClient is internal; reached here via InternalsVisibleTo on the
|
|
// DataConnectionLayer assembly (the test project is already a friend, since
|
|
// other tests in this project new up internal adapter types).
|
|
private static async Task<IOpcUaClient> ConnectedStubAsync()
|
|
{
|
|
var client = new StubOpcUaClient();
|
|
await client.ConnectAsync("opc.tcp://stub", null, CancellationToken.None);
|
|
return client;
|
|
}
|
|
|
|
/// <summary>Verifies that browsing the root returns two folders with no continuation token.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task BrowseRoot_ReturnsTwoFolders_NoContinuation()
|
|
{
|
|
await using var client = (StubOpcUaClient)await ConnectedStubAsync();
|
|
|
|
var result = await client.BrowseChildrenAsync(parentNodeId: null);
|
|
|
|
Assert.False(result.Truncated);
|
|
Assert.Null(result.ContinuationToken);
|
|
Assert.Collection(
|
|
result.Children,
|
|
n =>
|
|
{
|
|
Assert.Equal("Folder1", n.DisplayName);
|
|
Assert.Equal(BrowseNodeClass.Object, n.NodeClass);
|
|
Assert.True(n.HasChildren);
|
|
},
|
|
n =>
|
|
{
|
|
Assert.Equal("Folder2", n.DisplayName);
|
|
Assert.Equal(BrowseNodeClass.Object, n.NodeClass);
|
|
Assert.False(n.HasChildren);
|
|
});
|
|
}
|
|
|
|
/// <summary>Verifies that browsing Folder1 without a token returns the first tag and a continuation token.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task BrowseFolder1_NoToken_ReturnsTag1_AndContinuationToken()
|
|
{
|
|
await using var client = (StubOpcUaClient)await ConnectedStubAsync();
|
|
|
|
var result = await client.BrowseChildrenAsync(parentNodeId: "Folder1");
|
|
|
|
Assert.True(result.Truncated);
|
|
Assert.Equal("STUB_PAGE2", result.ContinuationToken);
|
|
var only = Assert.Single(result.Children);
|
|
Assert.Equal("Tag1", only.DisplayName);
|
|
Assert.Equal(BrowseNodeClass.Variable, only.NodeClass);
|
|
Assert.False(only.HasChildren);
|
|
}
|
|
|
|
/// <summary>Verifies that browsing Folder1 with the continuation token returns the second tag and no further continuation.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task BrowseFolder1_WithContinuationToken_ReturnsTag2_AndNoFurtherContinuation()
|
|
{
|
|
await using var client = (StubOpcUaClient)await ConnectedStubAsync();
|
|
|
|
var result = await client.BrowseChildrenAsync(
|
|
parentNodeId: "Folder1",
|
|
continuationToken: "STUB_PAGE2");
|
|
|
|
Assert.False(result.Truncated);
|
|
Assert.Null(result.ContinuationToken);
|
|
var only = Assert.Single(result.Children);
|
|
Assert.Equal("Tag2", only.DisplayName);
|
|
Assert.Equal(BrowseNodeClass.Variable, only.NodeClass);
|
|
Assert.False(only.HasChildren);
|
|
}
|
|
|
|
/// <summary>Verifies that browsing a leaf node returns no children and no continuation token.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task BrowseLeaf_ReturnsEmpty_NoContinuation()
|
|
{
|
|
await using var client = (StubOpcUaClient)await ConnectedStubAsync();
|
|
|
|
var result = await client.BrowseChildrenAsync(parentNodeId: "Folder2");
|
|
|
|
Assert.False(result.Truncated);
|
|
Assert.Null(result.ContinuationToken);
|
|
Assert.Empty(result.Children);
|
|
}
|
|
}
|