using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.AdminUI.Uns; namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns; /// /// G2-F2: a Sparkplug array / unsupported-type metric is refused at commit with a "not bindable in this /// version" message that echoes the browser's descriptor — not the "attribute lookup returned nothing" /// text, which is reserved for a lookup that really did return nothing. /// [Trait("Category", "Unit")] public sealed class MqttUnbindableLeafMessageTests { [Fact] public void An_array_metric_says_it_is_not_bindable_and_echoes_the_descriptor() { const string descriptor = "Metric · Int32Array · alias 7 · array metrics are not read in v1 — not bindable"; var error = RawBrowseCommitMapper.DescribeUncommittableLeaf("Mqtt", "Pressures", addressFields: null, descriptor); error.ShouldNotBeNull(); error!.ShouldContain("'Pressures' cannot be bound in this version"); error.ShouldContain(descriptor); error.ShouldNotContain("attribute lookup returned nothing"); } [Fact] public void A_lookup_that_returned_nothing_keeps_the_original_message() { // Positive control: the new branch is selected by the descriptor, not by MQTT in general. RawBrowseCommitMapper.DescribeUncommittableLeaf("Mqtt", "Temperature", addressFields: null, descriptor: null)! .ShouldContain("attribute lookup returned nothing"); RawBrowseCommitMapper.DescribeUncommittableLeaf("Mqtt", "Temperature", null, "Metric · Double")! .ShouldContain("attribute lookup returned nothing"); } [Fact] public void A_bindable_leaf_is_never_refused_whatever_its_descriptor_says() => RawBrowseCommitMapper.DescribeUncommittableLeaf( "Mqtt", "Temperature", new Dictionary { [ZB.MOM.WW.OtOpcUa.Driver.Mqtt.MqttTagConfigKeys.MetricName] = "Temperature" }, "anything · not bindable") .ShouldBeNull(); [Fact] public void The_marker_matches_what_the_sparkplug_browser_writes() { var dir = new DirectoryInfo(AppContext.BaseDirectory); while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "ZB.MOM.WW.OtOpcUa.slnx"))) dir = dir.Parent; var browser = File.ReadAllText(Path.Combine(dir!.FullName, "src", "Drivers", "ZB.MOM.WW.OtOpcUa.Driver.Mqtt.Browser", "MqttBrowseSession.cs")); browser.ShouldContain("— " + RawBrowseCommitMapper.NotBindableMarker + "\")"); AdminUiSource.Read("Components", "Shared", "Raw", "RawBrowseModal.razor") .ShouldContain("DescribeUncommittableLeaf(_driverType, s.Name, s.AddressFields, s.Descriptor)"); } }