feat(ablegacy): Transport option selects native or libplctag across driver, probe and CLI
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using Shouldly;
|
||||
@@ -158,4 +160,44 @@ public sealed class BuildOptionsTests
|
||||
options.Devices.Count.ShouldBe(1);
|
||||
options.Devices[0].PlcFamily.ShouldBe(AbLegacyPlcFamily.Plc5);
|
||||
}
|
||||
|
||||
/// <summary>Verifies the transport defaults to libplctag and --transport reaches the options.</summary>
|
||||
[Fact]
|
||||
public void BuildOptions_defaults_to_libplctag_and_forwards_transport()
|
||||
{
|
||||
var def = new TestCommand { Gateway = "ab://192.168.1.20/1,0" };
|
||||
def.Build([]).Transport.ShouldBe(AbLegacyTransport.Libplctag);
|
||||
|
||||
var native = new TestCommand { Gateway = "ab://192.168.1.20/1,0", Transport = AbLegacyTransport.Native };
|
||||
native.Build([]).Transport.ShouldBe(AbLegacyTransport.Native);
|
||||
}
|
||||
|
||||
/// <summary>Verifies CliFx really parses <c>--transport native</c> (case-insensitive) into the property.</summary>
|
||||
[Theory]
|
||||
[InlineData("native", AbLegacyTransport.Native)]
|
||||
[InlineData("Native", AbLegacyTransport.Native)]
|
||||
[InlineData("libplctag", AbLegacyTransport.Libplctag)]
|
||||
public async Task Transport_flag_is_parsed_by_the_cli(string value, AbLegacyTransport expected)
|
||||
{
|
||||
CapturingCommand.Captured = null;
|
||||
using var console = new FakeInMemoryConsole();
|
||||
var app = new CliApplicationBuilder().AddCommand(typeof(CapturingCommand)).UseConsole(console).Build();
|
||||
|
||||
var exit = await app.RunAsync(["capture-transport", "--gateway", "ab://1.2.3.4/1,0", "--transport", value]);
|
||||
|
||||
exit.ShouldBe(0, console.ReadErrorString());
|
||||
CapturingCommand.Captured.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Command("capture-transport")]
|
||||
private sealed class CapturingCommand : AbLegacyCommandBase
|
||||
{
|
||||
public static AbLegacyTransport? Captured;
|
||||
|
||||
public override System.Threading.Tasks.ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
Captured = BuildOptions([]).Transport;
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user