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.
84 lines
3.1 KiB
C#
84 lines
3.1 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Moq;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types;
|
|
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Scripts;
|
|
|
|
/// <summary>
|
|
/// Script-side API tests for
|
|
/// <c>Tracking.Status(TrackedOperationId)</c>. The helper reads the site-local
|
|
/// <see cref="IOperationTrackingStore"/> directly (no central round-trip) and
|
|
/// returns the latest <see cref="TrackingStatusSnapshot"/>, or <c>null</c> when
|
|
/// the id is unknown.
|
|
/// </summary>
|
|
public class TrackingApiTests
|
|
{
|
|
private static ScriptRuntimeContext.TrackingHelper CreateHelper(
|
|
IOperationTrackingStore? store)
|
|
{
|
|
return new ScriptRuntimeContext.TrackingHelper(store, NullLogger.Instance);
|
|
}
|
|
|
|
/// <summary>Verifies that status for an unknown id returns null.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task Status_UnknownId_ReturnsNull()
|
|
{
|
|
var store = new Mock<IOperationTrackingStore>();
|
|
store
|
|
.Setup(s => s.GetStatusAsync(It.IsAny<TrackedOperationId>(), It.IsAny<CancellationToken>()))
|
|
.ReturnsAsync((TrackingStatusSnapshot?)null);
|
|
|
|
var helper = CreateHelper(store.Object);
|
|
var result = await helper.Status(TrackedOperationId.New());
|
|
|
|
Assert.Null(result);
|
|
}
|
|
|
|
/// <summary>Verifies that status for a known id returns the latest snapshot.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task Status_KnownId_ReturnsLatestSnapshot()
|
|
{
|
|
var id = TrackedOperationId.New();
|
|
var expected = new TrackingStatusSnapshot(
|
|
Id: id,
|
|
Kind: "ApiCallCached",
|
|
TargetSummary: "ERP.GetOrder",
|
|
Status: "Delivered",
|
|
RetryCount: 2,
|
|
LastError: null,
|
|
HttpStatus: 200,
|
|
CreatedAtUtc: new DateTime(2026, 5, 20, 10, 0, 0, DateTimeKind.Utc),
|
|
UpdatedAtUtc: new DateTime(2026, 5, 20, 10, 2, 30, DateTimeKind.Utc),
|
|
TerminalAtUtc: new DateTime(2026, 5, 20, 10, 2, 30, DateTimeKind.Utc),
|
|
SourceInstanceId: "Plant.Pump42",
|
|
SourceScript: "ScriptActor:OnTick",
|
|
SourceNode: null);
|
|
|
|
var store = new Mock<IOperationTrackingStore>();
|
|
store
|
|
.Setup(s => s.GetStatusAsync(id, It.IsAny<CancellationToken>()))
|
|
.ReturnsAsync(expected);
|
|
|
|
var helper = CreateHelper(store.Object);
|
|
var result = await helper.Status(id);
|
|
|
|
Assert.NotNull(result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
/// <summary>Verifies that status throws when no tracking store is wired.</summary>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
[Fact]
|
|
public async Task Status_NoStoreWired_Throws()
|
|
{
|
|
var helper = CreateHelper(store: null);
|
|
await Assert.ThrowsAsync<InvalidOperationException>(
|
|
() => helper.Status(TrackedOperationId.New()));
|
|
}
|
|
|
|
}
|