Files
lmxopcua/tests/Client/ZB.MOM.WW.OtOpcUa.Client.Shared.Tests/Adapters/DefaultSubscriptionAdapterTests.cs
T
Joseph Doherty b8202e1147
v2-ci / unit-tests (push) Has been cancelled
test: remaining xUnit1051/1031/1030, CS8602/8604, CS0618, CS0219, CS0649, NU1510 fixes (lmxopcua#725)
Awaited deadline oracles get the runner token; sync-over-async tests made async;
nullable child models asserted via ShouldNotBeNull() return values; obsolete SDK
ctors replaced with the telemetry overloads; dead locals/fixture and the redundant
DI PackageReference removed. No suppressions.

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
2026-11-09 13:22:34 -05:00

58 lines
2.0 KiB
C#

using Opc.Ua.Client;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Client.Shared.Adapters;
namespace ZB.MOM.WW.OtOpcUa.Client.Shared.Tests.Adapters;
/// <summary>
/// A deleted subscription must also leave the SDK session's <c>Subscriptions</c> list, or every alarm re-target in the UI
/// leaves a dead <see cref="Subscription"/> behind until the session is disposed.
/// </summary>
public class DefaultSubscriptionAdapterTests
{
/// <summary>DeleteAsync detaches the wrapped subscription exactly once, even when Dispose follows.</summary>
[Fact]
public async Task DeleteAsync_detaches_the_subscription_from_its_session_once()
{
var subscription = new Subscription(ClientTelemetry.Context);
var detached = new List<Subscription>();
var adapter = new DefaultSubscriptionAdapter(subscription, (s, _) =>
{
lock (detached) detached.Add(s);
return Task.CompletedTask;
});
await adapter.DeleteAsync(TestContext.Current.CancellationToken);
adapter.Dispose();
detached.ShouldHaveSingleItem().ShouldBeSameAs(subscription);
}
/// <summary>Dispose alone (no prior DeleteAsync) detaches too.</summary>
[Fact]
public void Dispose_detaches_the_subscription_from_its_session()
{
var detached = 0;
var adapter = new DefaultSubscriptionAdapter(new Subscription(ClientTelemetry.Context), (_, _) =>
{
Interlocked.Increment(ref detached);
return Task.CompletedTask;
});
adapter.Dispose();
detached.ShouldBe(1);
}
/// <summary>A failing detach is logged, not thrown: teardown stays best effort.</summary>
[Fact]
public async Task A_failing_detach_does_not_throw_from_DeleteAsync()
{
var adapter = new DefaultSubscriptionAdapter(new Subscription(ClientTelemetry.Context),
(_, _) => throw new InvalidOperationException("boom"));
await Should.NotThrowAsync(() => adapter.DeleteAsync(TestContext.Current.CancellationToken));
}
}