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.
127 lines
5.3 KiB
C#
127 lines
5.3 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>
|
|
/// <see cref="StubOpcUaClient"/> searches its canned address-space
|
|
/// tree (root → Folder1/Folder2; Folder1 → Tag1/Tag2) so DCL address-space
|
|
/// search flows can be exercised without a live OPC UA server. The stub fakes
|
|
/// BrowseNext continuation paging on <c>Folder1</c>, so finding both Tag1 and
|
|
/// Tag2 also verifies that the BFS loops the continuation per node.
|
|
/// </summary>
|
|
public class StubOpcUaClientSearchTests
|
|
{
|
|
// StubOpcUaClient is internal; reached here via InternalsVisibleTo on the
|
|
// DataConnectionLayer assembly (mirrors StubOpcUaClientBrowseTests).
|
|
private static async Task<StubOpcUaClient> ConnectedStubAsync()
|
|
{
|
|
var client = new StubOpcUaClient();
|
|
await client.ConnectAsync("opc.tcp://stub", null, CancellationToken.None);
|
|
return client;
|
|
}
|
|
|
|
/// <summary>Verifies that search tag finds both tags with root relative paths.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task Search_Tag_FindsBothTags_WithRootRelativePaths()
|
|
{
|
|
await using var client = await ConnectedStubAsync();
|
|
|
|
var result = await client.SearchAddressSpaceAsync("Tag", maxDepth: 5, maxResults: 50);
|
|
|
|
Assert.False(result.CapReached);
|
|
// Tag2 lives on page 2 of Folder1's children, so finding it proves the
|
|
// BFS loops the stub's continuation token rather than stopping at page 1.
|
|
var paths = result.Matches.Select(m => m.Path).OrderBy(p => p).ToArray();
|
|
Assert.Equal(new[] { "/Folder1/Tag1", "/Folder1/Tag2" }, paths);
|
|
Assert.All(result.Matches, m => Assert.Contains("Tag", m.Node.DisplayName));
|
|
}
|
|
|
|
/// <summary>Verifies that search folder matches on display name and path.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task Search_Folder_MatchesOnDisplayNameAndPath()
|
|
{
|
|
await using var client = await ConnectedStubAsync();
|
|
|
|
var result = await client.SearchAddressSpaceAsync("Folder", maxDepth: 5, maxResults: 50);
|
|
|
|
Assert.False(result.CapReached);
|
|
// The contract matches DisplayName OR root-relative path. "Folder" hits
|
|
// both folders by DisplayName AND both tags by path (they live under
|
|
// /Folder1), so all four nodes match.
|
|
var paths = result.Matches.Select(m => m.Path).OrderBy(p => p).ToArray();
|
|
Assert.Equal(new[] { "/Folder1", "/Folder1/Tag1", "/Folder1/Tag2", "/Folder2" }, paths);
|
|
}
|
|
|
|
/// <summary>Verifies that search folder 2 matches only the folder by display name.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task Search_Folder2_MatchesOnlyTheFolderByDisplayName()
|
|
{
|
|
await using var client = await ConnectedStubAsync();
|
|
|
|
// "Folder2" appears in no other node's DisplayName or path, so it isolates
|
|
// a single match — proving the substring match is not over-broad.
|
|
var result = await client.SearchAddressSpaceAsync("Folder2", maxDepth: 5, maxResults: 50);
|
|
|
|
Assert.False(result.CapReached);
|
|
var only = Assert.Single(result.Matches);
|
|
Assert.Equal("/Folder2", only.Path);
|
|
Assert.Equal("Folder2", only.Node.DisplayName);
|
|
}
|
|
|
|
/// <summary>Verifies that search is case insensitive.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task Search_IsCaseInsensitive()
|
|
{
|
|
await using var client = await ConnectedStubAsync();
|
|
|
|
var result = await client.SearchAddressSpaceAsync("tag", maxDepth: 5, maxResults: 50);
|
|
|
|
Assert.Equal(2, result.Matches.Count);
|
|
}
|
|
|
|
/// <summary>Verifies that search max results one stops early with cap reached.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task Search_MaxResultsOne_StopsEarly_WithCapReached()
|
|
{
|
|
await using var client = await ConnectedStubAsync();
|
|
|
|
var result = await client.SearchAddressSpaceAsync("Tag", maxDepth: 5, maxResults: 1);
|
|
|
|
Assert.True(result.CapReached);
|
|
var only = Assert.Single(result.Matches);
|
|
Assert.Contains("Tag", only.Node.DisplayName);
|
|
}
|
|
|
|
/// <summary>Verifies that search empty query returns no matches.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task Search_EmptyQuery_ReturnsNoMatches()
|
|
{
|
|
await using var client = await ConnectedStubAsync();
|
|
|
|
var result = await client.SearchAddressSpaceAsync("", maxDepth: 5, maxResults: 50);
|
|
|
|
Assert.Empty(result.Matches);
|
|
Assert.False(result.CapReached);
|
|
}
|
|
|
|
/// <summary>Verifies that search whitespace query returns no matches.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task Search_WhitespaceQuery_ReturnsNoMatches()
|
|
{
|
|
await using var client = await ConnectedStubAsync();
|
|
|
|
var result = await client.SearchAddressSpaceAsync(" ", maxDepth: 5, maxResults: 50);
|
|
|
|
Assert.Empty(result.Matches);
|
|
Assert.False(result.CapReached);
|
|
}
|
|
}
|