using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy; namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Tests; /// /// Gitea #534 — the authored EtherNet/IP port must reach libplctag's gateway attribute. /// /// /// /// was carried on the record and consumed by nobody: /// the runtime set Tag.Gateway = p.Gateway, the bare host. libplctag does not fail on a /// portless gateway — it substitutes 44818. So the authored port was not ignored in the harmless /// sense; the connection was silently *redirected* to whatever answers on the default port. On the /// test rig that was a different simulator running a different PLC family, which is why the /// AbLegacy integration suite failed in a way that looked like a missing fixture. On a plant /// network it is another PLC, and the driver would read someone else's tags and report them Good. /// /// /// The real guard is the integration suite, which now addresses each PCCC family on its own /// non-default port (44819/44820/44821) and therefore cannot pass unless the port is honoured. /// These unit tests pin the composition itself so the rule survives on a machine with no fixtures. /// /// public sealed class AbLegacyGatewayCompositionTests { private static AbLegacyTagCreateParams Params(string host, int port) => new(Gateway: host, Port: port, CipPath: "1,0", LibplctagPlcAttribute: "slc500", TagName: "N7:0", Timeout: TimeSpan.FromSeconds(5)); [Fact] public void The_authored_port_is_appended_to_the_gateway() { Params("10.100.0.35", 44819).LibplctagGateway.ShouldBe("10.100.0.35:44819"); } [Fact] public void The_default_port_is_still_written_explicitly() { // Not an optimisation opportunity: emitting the port unconditionally is what makes the value // independent of libplctag's own default, so a change to that default cannot move our traffic. Params("plc1.plant.local", 44818).LibplctagGateway.ShouldBe("plc1.plant.local:44818"); } [Theory] [InlineData(0)] [InlineData(-1)] public void A_missing_port_falls_back_to_the_bare_host(int port) { // An unset port must not produce "host:0", which libplctag would take literally. Params("10.100.0.35", port).LibplctagGateway.ShouldBe("10.100.0.35"); } }