using Shouldly; using Xunit; namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions.Tests; /// Gitea #886 — the Galaxy reference parser the driver and the composer share, and the object it names. public sealed class GalaxyAttributeRefTests { [Theory] [InlineData("""{"attributeRef":"Oven_007.TempHiAlarm"}""", "Oven_007.TempHiAlarm")] [InlineData("""{"AttributeRef":"Oven_007.Temp","alarm":{"alarmType":"LimitAlarm"}}""", "Oven_007.Temp")] [InlineData("""{"attributeRef":" "}""", null)] [InlineData("""{"attributeRef":7}""", null)] [InlineData("""{"FullName":"Oven_007.Temp"}""", null)] [InlineData("""not json""", null)] [InlineData("", null)] [InlineData(null, null)] public void Reads_the_attributeRef(string? tagConfig, string? expected) => GalaxyAttributeRef.TryRead(tagConfig).ShouldBe(expected); [Fact] public void Only_a_galaxy_tag_names_an_aveva_alarm_reference() { const string config = """{"attributeRef":"Oven_007.TempHiAlarm"}"""; GalaxyAttributeRef.AlarmReferenceOf(DriverTypeNames.Galaxy, config).ShouldBe("Oven_007.TempHiAlarm"); GalaxyAttributeRef.AlarmReferenceOf(DriverTypeNames.Modbus, config).ShouldBeNull(); GalaxyAttributeRef.AlarmReferenceOf(null, config).ShouldBeNull(); } [Theory] [InlineData("Oven_007.TempHiAlarm", "Oven_007")] [InlineData("Oven_007.Temp.HiHi", "Oven_007")] [InlineData("Oven_007", "Oven_007")] [InlineData(" Oven_007.Temp ", "Oven_007")] [InlineData(".Temp", null)] [InlineData("", null)] [InlineData(null, null)] public void The_object_is_the_reference_up_to_its_first_dot(string? reference, string? expected) => GalaxyAttributeRef.ObjectNameOf(reference).ShouldBe(expected); }