de666b24c3
v2-ci / build (push) Failing after 38s
v2-ci / unit-tests (tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.Host.IntegrationTests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests) (push) Has been skipped
Completes the test side of the in-progress Galaxy-tag workstream: - Phase7ApplierTests / Phase7ApplierHierarchyTests: supply the now-required Galaxy-tag args to Phase7Plan / Phase7CompositionResult. - Add genuine coverage for Phase7Applier.MaterialiseGalaxyTags (folder-per-distinct-path, variable-per-tag node-id derivation, folder dedupe) + added-Galaxy-tags-trigger-rebuild. - S7.Cli.Tests: use the project's S7CpuType (CLI option type) instead of S7.Net.CpuType. Whole solution now builds 0/0; OpcUaServer.Tests 52, S7.Cli.Tests 36 green.
103 lines
3.6 KiB
C#
103 lines
3.6 KiB
C#
using CliFx.Attributes;
|
|
using CliFx.Infrastructure;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.S7;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.S7.Cli;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.S7.Cli.Tests;
|
|
|
|
/// <summary>
|
|
/// Covers <see cref="S7CommandBase.BuildOptions"/> — the pure, deterministic mapping
|
|
/// from the base's host/port/CPU/rack/slot/timeout flags onto an
|
|
/// <c>S7DriverOptions</c>. The CLI is one-shot so the background connectivity probe
|
|
/// must be disabled.
|
|
/// </summary>
|
|
[Trait("Category", "Unit")]
|
|
public sealed class S7CommandBaseBuildOptionsTests
|
|
{
|
|
// Test-only S7CommandBase concrete subclass that exposes the protected BuildOptions
|
|
// helper. The [Command] attribute is required by the CliFx analyzer
|
|
// (CliFx_CommandMustBeAnnotated) — this command is never registered with the CLI app
|
|
// but the analyzer rule fires for every ICommand implementor in the compilation.
|
|
/// <summary>Test-only S7CommandBase concrete subclass that exposes the protected BuildOptions helper.</summary>
|
|
[Command("noop-test", Description = "Test-only probe of S7CommandBase.BuildOptions.")]
|
|
private sealed class ProbeOnly : S7CommandBase
|
|
{
|
|
/// <inheritdoc />
|
|
public override ValueTask ExecuteAsync(IConsole console) => default;
|
|
|
|
/// <summary>Invokes the BuildOptions method with the given tags.</summary>
|
|
/// <param name="tags">The tag definitions to pass to BuildOptions.</param>
|
|
/// <returns>The resulting S7DriverOptions.</returns>
|
|
public S7DriverOptions Invoke(IReadOnlyList<S7TagDefinition> tags) => BuildOptions(tags);
|
|
}
|
|
|
|
/// <summary>Verifies that BuildOptions disables probe for one-shot CLI runs.</summary>
|
|
[Fact]
|
|
public void BuildOptions_disables_probe_for_one_shot_cli_runs()
|
|
{
|
|
var sut = new ProbeOnly
|
|
{
|
|
Host = "10.0.0.5",
|
|
Port = 102,
|
|
CpuType = S7CpuType.S71500,
|
|
Rack = 0,
|
|
Slot = 0,
|
|
TimeoutMs = 5000,
|
|
};
|
|
|
|
var options = sut.Invoke([]);
|
|
|
|
options.Probe.ShouldNotBeNull();
|
|
options.Probe.Enabled.ShouldBeFalse();
|
|
}
|
|
|
|
/// <summary>Verifies that BuildOptions maps TimeoutMs to Timeout TimeSpan.</summary>
|
|
[Fact]
|
|
public void BuildOptions_maps_TimeoutMs_to_Timeout_TimeSpan()
|
|
{
|
|
var sut = new ProbeOnly { Host = "h", TimeoutMs = 7500 };
|
|
|
|
var options = sut.Invoke([]);
|
|
|
|
options.Timeout.ShouldBe(TimeSpan.FromMilliseconds(7500));
|
|
}
|
|
|
|
/// <summary>Verifies that BuildOptions flows host, port, cpu, rack, and slot through.</summary>
|
|
[Fact]
|
|
public void BuildOptions_flows_host_port_cpu_rack_slot_through()
|
|
{
|
|
var sut = new ProbeOnly
|
|
{
|
|
Host = "plc.shop.local",
|
|
Port = 4102,
|
|
CpuType = S7CpuType.S7300,
|
|
Rack = 1,
|
|
Slot = 2,
|
|
TimeoutMs = 3000,
|
|
};
|
|
|
|
var options = sut.Invoke([]);
|
|
|
|
options.Host.ShouldBe("plc.shop.local");
|
|
options.Port.ShouldBe(4102);
|
|
options.CpuType.ShouldBe(S7CpuType.S7300);
|
|
options.Rack.ShouldBe((short)1);
|
|
options.Slot.ShouldBe((short)2);
|
|
}
|
|
|
|
/// <summary>Verifies that BuildOptions forwards the tag list verbatim.</summary>
|
|
[Fact]
|
|
public void BuildOptions_forwards_tag_list_verbatim()
|
|
{
|
|
var sut = new ProbeOnly { Host = "h" };
|
|
var tag = new S7TagDefinition("t", "MW0", S7DataType.Int16, Writable: false);
|
|
|
|
var options = sut.Invoke([tag]);
|
|
|
|
options.Tags.Count.ShouldBe(1);
|
|
options.Tags[0].ShouldBeSameAs(tag);
|
|
}
|
|
}
|