using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.AdminUI.Uns.TagEditors; using ZB.MOM.WW.OtOpcUa.ControlPlane.AdminOperations; using ZB.MOM.WW.OtOpcUa.Core.Abstractions; namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns; /// #244/#245/#247: one address authority (AbLegacyAddress.Validate) behind the editor and the deploy gate. public sealed class AbLegacyFamilyAddressGateTests { private static string Cfg(string address) => "{\"address\":\"" + address + "\",\"dataType\":\"Int\"}"; [Theory] [InlineData("{\"PlcFamily\":\"Plc5\"}", "I:018", true)] // octal 8 on PLC-5 [InlineData("{\"PlcFamily\":\"Plc5\"}", "I:017/07", false)] [InlineData("{\"PlcFamily\":\"Slc500\"}", "I:018", false)] // control: decimal on SLC [InlineData("{\"plcFamily\":\"plc5\"}", "I:018", true)] // key + value case-insensitive [InlineData("{\"PlcFamily\":\"Slc500\"}", "RTC:0.HR", true)] // function file off MicroLogix [InlineData("{\"PlcFamily\":\"MicroLogix\"}", "RTC:0.HR", false)] [InlineData(null, "RTC:0.HR", true)] // absent family = runtime default SLC 500 [InlineData("{\"PlcFamily\":\"Bogus\"}", "I:018", false)] // unknown family: never stricter than the runtime [InlineData("{\"PlcFamily\":\"Slc500\"}", "Q9:0", true)] public void Gate_checks_the_address_against_the_device_family(string? deviceConfig, string address, bool warns) { var w = EquipmentTagConfigInspector.Inspect(DriverTypeNames.AbLegacy, Cfg(address), deviceConfig); (w.Count > 0).ShouldBe(warns, string.Join("; ", w)); } [Fact] public void Gate_does_not_warn_about_indirect_addresses_which_the_driver_resolves() { EquipmentTagConfigInspector.Inspect(DriverTypeNames.AbLegacy, Cfg("N7:[N7:0]"), "{\"PlcFamily\":\"Slc500\"}") .ShouldBeEmpty(); } [Theory] [InlineData("N7:0", null)] [InlineData("I:018", null)] // family unknown to the editor: another family accepts it [InlineData("RTC:0.HR", null)] // MicroLogix accepts it [InlineData("Q9:0", "any PLC family")] public void Editor_validates_only_the_family_independent_shape(string address, string? error) { var result = AbLegacyTagConfigModel.FromJson(Cfg(address)).Validate(); if (error is null) result.ShouldBeNull(); else result!.ShouldContain(error); } [Fact] public void Editor_is_never_stricter_than_the_gate() { const string address = "Q9:0"; AbLegacyTagConfigModel.FromJson(Cfg(address)).Validate().ShouldNotBeNull(); EquipmentTagConfigInspector.Inspect(DriverTypeNames.AbLegacy, Cfg(address), null).ShouldNotBeEmpty(); } }