feat(cli): add enable/disable condition commands (H4 client path)
This commit is contained in:
@@ -1174,6 +1174,88 @@ public class OpcUaClientServiceTests : IDisposable
|
||||
result.Code.ShouldBe(StatusCodes.BadConditionAlreadyShelved);
|
||||
}
|
||||
|
||||
// --- Enable / Disable tests (H4 client path) ---
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that EnableAsync invokes the ConditionType_Enable method with no input
|
||||
/// arguments and returns <see cref="StatusCodes.Good"/> on success.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task EnableAsync_OnSuccess_CallsEnableMethodWithNoArgs()
|
||||
{
|
||||
var session = new FakeSessionAdapter();
|
||||
_sessionFactory.EnqueueSession(session);
|
||||
await _service.ConnectAsync(ValidSettings());
|
||||
|
||||
var result = await _service.EnableAsync("ns=2;s=Cond");
|
||||
|
||||
result.ShouldBe(StatusCodes.Good);
|
||||
session.CallMethodCount.ShouldBe(1);
|
||||
session.CallMethodMethodIds[0].ShouldBe(MethodIds.ConditionType_Enable);
|
||||
session.CallMethodInputArgs[0].ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that DisableAsync invokes the ConditionType_Disable method with no input
|
||||
/// arguments and returns <see cref="StatusCodes.Good"/> on success.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DisableAsync_OnSuccess_CallsDisableMethodWithNoArgs()
|
||||
{
|
||||
var session = new FakeSessionAdapter();
|
||||
_sessionFactory.EnqueueSession(session);
|
||||
await _service.ConnectAsync(ValidSettings());
|
||||
|
||||
var result = await _service.DisableAsync("ns=2;s=Cond");
|
||||
|
||||
result.ShouldBe(StatusCodes.Good);
|
||||
session.CallMethodCount.ShouldBe(1);
|
||||
session.CallMethodMethodIds[0].ShouldBe(MethodIds.ConditionType_Disable);
|
||||
session.CallMethodInputArgs[0].ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a <see cref="ServiceResultException"/> from the session is captured and
|
||||
/// returned as a bad <see cref="StatusCode"/> rather than propagating to the caller.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task EnableAsync_OnServiceResultException_ReturnsBadStatusCode()
|
||||
{
|
||||
var session = new FakeSessionAdapter
|
||||
{
|
||||
CallMethodException = new ServiceResultException(
|
||||
StatusCodes.BadConditionAlreadyEnabled, "already enabled")
|
||||
};
|
||||
_sessionFactory.EnqueueSession(session);
|
||||
await _service.ConnectAsync(ValidSettings());
|
||||
|
||||
var result = await _service.EnableAsync("ns=2;s=Cond");
|
||||
|
||||
StatusCode.IsBad(result).ShouldBeTrue();
|
||||
result.Code.ShouldBe(StatusCodes.BadConditionAlreadyEnabled);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a <see cref="ServiceResultException"/> from the session is captured and
|
||||
/// returned as a bad <see cref="StatusCode"/> rather than propagating to the caller.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DisableAsync_OnServiceResultException_ReturnsBadStatusCode()
|
||||
{
|
||||
var session = new FakeSessionAdapter
|
||||
{
|
||||
CallMethodException = new ServiceResultException(
|
||||
StatusCodes.BadConditionAlreadyDisabled, "already disabled")
|
||||
};
|
||||
_sessionFactory.EnqueueSession(session);
|
||||
await _service.ConnectAsync(ValidSettings());
|
||||
|
||||
var result = await _service.DisableAsync("ns=2;s=Cond");
|
||||
|
||||
StatusCode.IsBad(result).ShouldBeTrue();
|
||||
result.Code.ShouldBe(StatusCodes.BadConditionAlreadyDisabled);
|
||||
}
|
||||
|
||||
// --- Alarm fallback path (Client.Shared-011) ---
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user