Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/Browsing/FakeBrowseSession.cs
Joseph Doherty bd6c0b4d3d docs: complete XML doc comments via fixdocs (2757 to 131 findings)
Add missing <returns>/<param>/<summary>/<typeparam> tags and clean up
misused inheritdoc across 481 files so the documented API surface is
complete. Documentation-only (zero code lines changed). The 131 remaining
findings are inheritdoc-style warnings deliberately left to preserve
hand-written implementation rationale (plan-decision notes, race-condition
explanations).
2026-06-03 12:34:34 -04:00

52 lines
2.4 KiB
C#

using ZB.MOM.WW.OtOpcUa.Commons.Browsing;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Browsing;
/// <summary>Test double for <see cref="IBrowseSession"/> used by the registry, reaper,
/// and service tests. All three operations delegate to caller-supplied handlers so each
/// test can shape behaviour; <see cref="DisposeAsync"/> records that it ran and can be
/// instructed to throw via <see cref="ThrowOnDispose"/>.</summary>
internal sealed class FakeBrowseSession : IBrowseSession
{
/// <inheritdoc />
public Guid Token { get; } = Guid.NewGuid();
/// <inheritdoc />
public DateTime LastUsedUtc { get; set; } = DateTime.UtcNow;
/// <summary>True once <see cref="DisposeAsync"/> has run to completion.</summary>
public bool Disposed { get; private set; }
/// <summary>When true, <see cref="DisposeAsync"/> throws to exercise the reaper's
/// best-effort dispose path.</summary>
public bool ThrowOnDispose { get; set; }
// Suppress CS0649: handlers are test seams — some tests leave them null intentionally.
#pragma warning disable CS0649
public Func<CancellationToken, Task<IReadOnlyList<BrowseNode>>>? RootHandler;
public Func<string, CancellationToken, Task<IReadOnlyList<BrowseNode>>>? ExpandHandler;
public Func<string, CancellationToken, Task<IReadOnlyList<AttributeInfo>>>? AttributesHandler;
#pragma warning restore CS0649
/// <inheritdoc />
public Task<IReadOnlyList<BrowseNode>> RootAsync(CancellationToken ct)
=> RootHandler?.Invoke(ct) ?? Task.FromResult<IReadOnlyList<BrowseNode>>(Array.Empty<BrowseNode>());
/// <inheritdoc />
public Task<IReadOnlyList<BrowseNode>> ExpandAsync(string nodeId, CancellationToken ct)
=> ExpandHandler?.Invoke(nodeId, ct) ?? Task.FromResult<IReadOnlyList<BrowseNode>>(Array.Empty<BrowseNode>());
/// <inheritdoc />
public Task<IReadOnlyList<AttributeInfo>> AttributesAsync(string nodeId, CancellationToken ct)
=> AttributesHandler?.Invoke(nodeId, ct) ?? Task.FromResult<IReadOnlyList<AttributeInfo>>(Array.Empty<AttributeInfo>());
/// <summary>Disposes the fake browse session asynchronously, recording completion or throwing if configured.</summary>
/// <returns>A completed value task.</returns>
public ValueTask DisposeAsync()
{
if (ThrowOnDispose) throw new InvalidOperationException("dispose-failed");
Disposed = true;
return ValueTask.CompletedTask;
}
}