feat(cli): read --attribute reads one node attribute (e.g. Historizing, AccessLevel) (#921)

This commit is contained in:
Joseph Doherty
2026-11-28 09:28:59 -05:00
parent 05f431f5d8
commit a2a1104f20
7 changed files with 106 additions and 3 deletions
@@ -42,6 +42,41 @@ public class ReadCommandTests
service.ReadNodeIds.ShouldBeEmpty();
}
/// <summary>lmxopcua#921: <c>--attribute Historizing</c> reads that attribute (not the value) and labels the output.</summary>
[Fact]
public async Task Execute_ReadsTheRequestedAttribute()
{
var service = new FakeOpcUaClientService { ReadValueResult = new DataValue(new Variant(false), StatusCodes.Good) };
var command = new ReadCommand(new FakeOpcUaClientServiceFactory(service))
{
Url = "opc.tcp://localhost:4840", NodeId = "ns=2;s=Test", Attribute = "historizing"
};
using var console = TestConsoleHelper.CreateConsole();
await command.ExecuteAsync(console);
service.ReadAttributes.ShouldBe([(new NodeId("Test", 2), Attributes.Historizing)]);
service.ReadNodeIds.ShouldBeEmpty();
var output = TestConsoleHelper.GetOutput(console);
output.ShouldContain("Attribute: historizing");
output.ShouldContain("Value: False");
}
/// <summary>An unknown attribute, or <c>--max-age</c> with a non-Value attribute, is refused before connecting.</summary>
[Theory]
[InlineData("Bogus", 0)]
[InlineData("Historizing", 5000)]
public async Task Execute_RejectsAnUnknownAttributeOrMaxAgeOffTheValue(string attribute, double maxAge)
{
var service = new FakeOpcUaClientService();
var command = new ReadCommand(new FakeOpcUaClientServiceFactory(service))
{
Url = "opc.tcp://localhost:4840", NodeId = "ns=2;s=Test", Attribute = attribute, MaxAgeMilliseconds = maxAge
};
using var console = TestConsoleHelper.CreateConsole();
await Should.ThrowAsync<CliFx.Exceptions.CommandException>(async () => await command.ExecuteAsync(console));
service.ReadAttributes.ShouldBeEmpty();
service.ReadNodeIds.ShouldBeEmpty();
}
/// <summary>Verifies that execute prints the read value.</summary>
[Fact]
public async Task Execute_PrintsReadValue()