test: validate grpc data connections with local docker and opcua cli
This commit is contained in:
@@ -8,11 +8,45 @@ namespace ZB.MOM.WW.OtOpcUa.Client.CLI.Tests;
|
||||
|
||||
public class ReadCommandTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(5000)]
|
||||
[InlineData(2147483647)]
|
||||
public async Task Execute_ForwardsMaximumAge(double milliseconds)
|
||||
{
|
||||
var service = new FakeOpcUaClientService();
|
||||
var command = new ReadCommand(new FakeOpcUaClientServiceFactory(service))
|
||||
{
|
||||
Url = "opc.tcp://localhost:4840", NodeId = "ns=2;s=Test", MaxAgeMilliseconds = milliseconds
|
||||
};
|
||||
using var console = TestConsoleHelper.CreateConsole();
|
||||
await command.ExecuteAsync(console);
|
||||
if (milliseconds == 0) service.LastMaximumAge.ShouldBeNull();
|
||||
else service.LastMaximumAge.ShouldBe(TimeSpan.FromMilliseconds(milliseconds));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(2147483648d)]
|
||||
[InlineData(double.NaN)]
|
||||
[InlineData(double.PositiveInfinity)]
|
||||
public async Task Execute_RejectsInvalidMaximumAge(double milliseconds)
|
||||
{
|
||||
var service = new FakeOpcUaClientService();
|
||||
var command = new ReadCommand(new FakeOpcUaClientServiceFactory(service))
|
||||
{
|
||||
Url = "opc.tcp://localhost:4840", NodeId = "ns=2;s=Test", MaxAgeMilliseconds = milliseconds
|
||||
};
|
||||
using var console = TestConsoleHelper.CreateConsole();
|
||||
await Should.ThrowAsync<CliFx.Exceptions.CommandException>(async () => await command.ExecuteAsync(console));
|
||||
service.ReadNodeIds.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>Verifies that execute prints the read value.</summary>
|
||||
[Fact]
|
||||
public async Task Execute_PrintsReadValue()
|
||||
{
|
||||
var sourceTime = new DateTime(2025, 6, 15, 10, 30, 0, DateTimeKind.Utc);
|
||||
var sourceTime = new DateTime(2025, 6, 15, 10, 30, 0, DateTimeKind.Utc).AddTicks(1234567);
|
||||
var serverTime = new DateTime(2025, 6, 15, 10, 30, 1, DateTimeKind.Utc);
|
||||
var fakeService = new FakeOpcUaClientService
|
||||
{
|
||||
@@ -38,6 +72,8 @@ public class ReadCommandTests
|
||||
output.ShouldContain("Status:");
|
||||
output.ShouldContain("Source Time:");
|
||||
output.ShouldContain("Server Time:");
|
||||
output.ShouldContain("Source Time: " + sourceTime.ToString("O", System.Globalization.CultureInfo.InvariantCulture));
|
||||
output.ShouldContain("Server Time: " + serverTime.ToString("O", System.Globalization.CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that execute calls read value with correct node ID.</summary>
|
||||
|
||||
Reference in New Issue
Block a user