feat(cli): add enable/disable condition commands (H4 client path)
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
using Opc.Ua;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Client.CLI.Commands;
|
||||
using ZB.MOM.WW.OtOpcUa.Client.CLI.Tests.Fakes;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Client.CLI.Tests;
|
||||
|
||||
public class DisableCommandTests
|
||||
{
|
||||
/// <summary>Verifies that a successful disable prints a success message and targets the node.</summary>
|
||||
[Fact]
|
||||
public async Task Execute_Success_PrintsSuccessMessage()
|
||||
{
|
||||
var fakeService = new FakeOpcUaClientService
|
||||
{
|
||||
DisableResult = StatusCodes.Good
|
||||
};
|
||||
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
||||
var command = new DisableCommand(factory)
|
||||
{
|
||||
Url = "opc.tcp://localhost:4840",
|
||||
NodeId = "ns=2;s=MyAlarm"
|
||||
};
|
||||
|
||||
using var console = TestConsoleHelper.CreateConsole();
|
||||
await command.ExecuteAsync(console);
|
||||
|
||||
var output = TestConsoleHelper.GetOutput(console);
|
||||
output.ShouldContain("Disable successful");
|
||||
fakeService.DisableCalls.Count.ShouldBe(1);
|
||||
fakeService.DisableCalls[0].ShouldBe("ns=2;s=MyAlarm");
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a bad StatusCode from the service prints a failure message.</summary>
|
||||
[Fact]
|
||||
public async Task Execute_BadStatus_PrintsFailureMessage()
|
||||
{
|
||||
var fakeService = new FakeOpcUaClientService
|
||||
{
|
||||
DisableResult = StatusCodes.BadConditionAlreadyDisabled
|
||||
};
|
||||
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
||||
var command = new DisableCommand(factory)
|
||||
{
|
||||
Url = "opc.tcp://localhost:4840",
|
||||
NodeId = "ns=2;s=MyAlarm"
|
||||
};
|
||||
|
||||
using var console = TestConsoleHelper.CreateConsole();
|
||||
await command.ExecuteAsync(console);
|
||||
|
||||
var output = TestConsoleHelper.GetOutput(console);
|
||||
output.ShouldContain("Disable failed");
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the command disconnects and disposes in the finally block.</summary>
|
||||
[Fact]
|
||||
public async Task Execute_DisconnectsInFinally()
|
||||
{
|
||||
var fakeService = new FakeOpcUaClientService();
|
||||
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
||||
var command = new DisableCommand(factory)
|
||||
{
|
||||
Url = "opc.tcp://localhost:4840",
|
||||
NodeId = "ns=2;s=MyAlarm"
|
||||
};
|
||||
|
||||
using var console = TestConsoleHelper.CreateConsole();
|
||||
await command.ExecuteAsync(console);
|
||||
|
||||
fakeService.DisconnectCalled.ShouldBeTrue();
|
||||
fakeService.DisposeCalled.ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using Opc.Ua;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Client.CLI.Commands;
|
||||
using ZB.MOM.WW.OtOpcUa.Client.CLI.Tests.Fakes;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Client.CLI.Tests;
|
||||
|
||||
public class EnableCommandTests
|
||||
{
|
||||
/// <summary>Verifies that a successful enable prints a success message and targets the node.</summary>
|
||||
[Fact]
|
||||
public async Task Execute_Success_PrintsSuccessMessage()
|
||||
{
|
||||
var fakeService = new FakeOpcUaClientService
|
||||
{
|
||||
EnableResult = StatusCodes.Good
|
||||
};
|
||||
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
||||
var command = new EnableCommand(factory)
|
||||
{
|
||||
Url = "opc.tcp://localhost:4840",
|
||||
NodeId = "ns=2;s=MyAlarm"
|
||||
};
|
||||
|
||||
using var console = TestConsoleHelper.CreateConsole();
|
||||
await command.ExecuteAsync(console);
|
||||
|
||||
var output = TestConsoleHelper.GetOutput(console);
|
||||
output.ShouldContain("Enable successful");
|
||||
fakeService.EnableCalls.Count.ShouldBe(1);
|
||||
fakeService.EnableCalls[0].ShouldBe("ns=2;s=MyAlarm");
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a bad StatusCode from the service prints a failure message.</summary>
|
||||
[Fact]
|
||||
public async Task Execute_BadStatus_PrintsFailureMessage()
|
||||
{
|
||||
var fakeService = new FakeOpcUaClientService
|
||||
{
|
||||
EnableResult = StatusCodes.BadConditionAlreadyEnabled
|
||||
};
|
||||
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
||||
var command = new EnableCommand(factory)
|
||||
{
|
||||
Url = "opc.tcp://localhost:4840",
|
||||
NodeId = "ns=2;s=MyAlarm"
|
||||
};
|
||||
|
||||
using var console = TestConsoleHelper.CreateConsole();
|
||||
await command.ExecuteAsync(console);
|
||||
|
||||
var output = TestConsoleHelper.GetOutput(console);
|
||||
output.ShouldContain("Enable failed");
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the command disconnects and disposes in the finally block.</summary>
|
||||
[Fact]
|
||||
public async Task Execute_DisconnectsInFinally()
|
||||
{
|
||||
var fakeService = new FakeOpcUaClientService();
|
||||
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
||||
var command = new EnableCommand(factory)
|
||||
{
|
||||
Url = "opc.tcp://localhost:4840",
|
||||
NodeId = "ns=2;s=MyAlarm"
|
||||
};
|
||||
|
||||
using var console = TestConsoleHelper.CreateConsole();
|
||||
await command.ExecuteAsync(console);
|
||||
|
||||
fakeService.DisconnectCalled.ShouldBeTrue();
|
||||
fakeService.DisposeCalled.ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
@@ -262,6 +262,32 @@ public sealed class FakeOpcUaClientService : IOpcUaClientService
|
||||
return Task.FromResult(ShelveAlarmResult);
|
||||
}
|
||||
|
||||
/// <summary>Gets the list of condition node IDs passed to EnableAsync calls.</summary>
|
||||
public List<string> EnableCalls { get; } = [];
|
||||
|
||||
/// <summary>Gets or sets the status code returned by EnableAsync.</summary>
|
||||
public StatusCode EnableResult { get; set; } = StatusCodes.Good;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<StatusCode> EnableAsync(string conditionNodeId, CancellationToken ct = default)
|
||||
{
|
||||
EnableCalls.Add(conditionNodeId);
|
||||
return Task.FromResult(EnableResult);
|
||||
}
|
||||
|
||||
/// <summary>Gets the list of condition node IDs passed to DisableAsync calls.</summary>
|
||||
public List<string> DisableCalls { get; } = [];
|
||||
|
||||
/// <summary>Gets or sets the status code returned by DisableAsync.</summary>
|
||||
public StatusCode DisableResult { get; set; } = StatusCodes.Good;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<StatusCode> DisableAsync(string conditionNodeId, CancellationToken ct = default)
|
||||
{
|
||||
DisableCalls.Add(conditionNodeId);
|
||||
return Task.FromResult(DisableResult);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<IReadOnlyList<DataValue>> HistoryReadRawAsync(
|
||||
NodeId nodeId, DateTime startTime, DateTime endTime, int maxValues = 1000, CancellationToken ct = default)
|
||||
|
||||
Reference in New Issue
Block a user