From 57d7d6e04f67fff57792ceb29e3731137470a3ce Mon Sep 17 00:00:00 2001 From: Pedro Debevere Date: Thu, 30 Oct 2025 10:48:03 +0100 Subject: [PATCH 1/3] Updated relation parsing for actions --- .../Read/Protocol/Actions/Action/Action.cs | 437 +++++++++++- ProtocolTests/ProtocolTests.csproj | 5 +- .../Read/Linking/RelationManagerTests.cs | 2 +- ProtocolTests/Read/Protocol/Actions/Action.cs | 628 ++++++++++++++++++ ProtocolTests/Read/Protocol/Protocol.cs | 1 - 5 files changed, 1052 insertions(+), 21 deletions(-) diff --git a/Protocol/Models/Read/Protocol/Actions/Action/Action.cs b/Protocol/Models/Read/Protocol/Actions/Action/Action.cs index 95a470b..51c9df6 100644 --- a/Protocol/Models/Read/Protocol/Actions/Action/Action.cs +++ b/Protocol/Models/Read/Protocol/Actions/Action/Action.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; + using Skyline.DataMiner.CICD.Models.Protocol.Enums; using Skyline.DataMiner.CICD.Models.Protocol.Read.Linking; @@ -59,11 +60,61 @@ IEnumerable IRelationEvaluator.GetRelations() case EnumActionOn.Timer: yield return new Reference(this, Mappings.TimersById, ref_id, o); break; - } + } } } } + if(o?.Value != null) + { + switch (o.Value) + { + case EnumActionOn.Parameter: + foreach (var reference in ProcessParameterActionReferences()) + { + yield return reference; + } + break; + case EnumActionOn.Protocol: + foreach (var reference in ProcessProtocolActionReferences()) + { + yield return reference; + } + break; + case EnumActionOn.Pair: + foreach (var reference in ProcessPairActionReferences()) + { + yield return reference; + } + break; + case EnumActionOn.Command: + foreach (var reference in ProcessCommandActionReferences()) + { + yield return reference; + } + break; + case EnumActionOn.Response: + foreach (var reference in ProcessResponseActionReferences()) + { + yield return reference; + } + break; + } + } + + var condition = Condition; + if (condition?.Value != null) + { + foreach (Match m in Regex.Matches(condition.Value, @"id:(?\d+)")) + { + string ref_id = m.Groups["id"].Value; + yield return new Reference(this, Mappings.ParamsById, ref_id, condition, "Conditions", "Conditions", isLogic: false); + } + } + } + + private IEnumerable ProcessParameterActionReferences() + { var t = Type; if (t?.Value != null) { @@ -72,43 +123,395 @@ IEnumerable IRelationEvaluator.GetRelations() { switch (t.Value.Value) { + case EnumActionType.Append: + case EnumActionType.AppendData: + case EnumActionType.ChangeLength: case EnumActionType.Copy: case EnumActionType.CopyReverse: case EnumActionType.Normalize: + case EnumActionType.SetAndGetWithWait: + yield return new Reference(this, Mappings.ParamsById, ref_id, t, reverse: true, isLogic: false); + break; + } + } + + var optionsValue = Convert.ToString(t.Options?.Value); + if (!String.IsNullOrWhiteSpace(optionsValue)) + { + switch (t.Value.Value) + { + case EnumActionType.Aggregate: + string[] options = optionsValue.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); + foreach (var option in options) + { + if (option.StartsWith("defaultValue:", StringComparison.OrdinalIgnoreCase)) + { + var defaultValue = option.Substring(12); + string[] defaultValueParts = defaultValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + + if (defaultValueParts.Length > 1 && Int32.TryParse(defaultValueParts[0], out int defaultValueColumnPid)) + { + yield return new Reference(this, Mappings.ParamsById, defaultValueColumnPid.ToString(), t, reverse: true, isLogic: false); + } + } + else if (option.StartsWith("equation:", StringComparison.OrdinalIgnoreCase)) + { + var equationValue = option.Substring(8); + string[] equationValueParts = equationValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + + if (equationValueParts.Length > 1 && Int32.TryParse(equationValueParts[1], out int columnPid)) + { + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); + } + } + else if (option.StartsWith("equationvalue:", StringComparison.OrdinalIgnoreCase)) + { + var equationValue = option.Substring(13); + string[] equationValueParts = equationValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + + if (equationValueParts.Length > 2 && Int32.TryParse(equationValueParts[2], out int columnPid)) + { + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); + } + } + else if(option.StartsWith("groupby:", StringComparison.OrdinalIgnoreCase)) + { + var groupByValue = option.Substring(7); + string[] groupByValueParts = groupByValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + + foreach(var groupByPart in groupByValueParts) + { + string[] groupByEntryParts = groupByPart.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); + + if (groupByEntryParts.Length > 1 && Int32.TryParse(groupByEntryParts[1], out int groupByParamId)) + { + yield return new Reference(this, Mappings.ParamsById, groupByParamId.ToString(), t, reverse: true, isLogic: false); + } + } + } + else if (option.StartsWith("groupbytable:", StringComparison.OrdinalIgnoreCase)) + { + var groupByTableValue = option.Substring(13); + + if (Int32.TryParse(groupByTableValue, out int groupByTableParamId)) + { + yield return new Reference(this, Mappings.ParamsById, groupByTableParamId.ToString(), t, reverse: true, isLogic: false); + } + } + else if (option.StartsWith("join:", StringComparison.OrdinalIgnoreCase)) + { + var joinValue = option.Substring(5); + string[] joinValueParts = joinValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + foreach (var joinPart in joinValueParts) + { + if (Int32.TryParse(joinPart, out int joinParamId)) + { + yield return new Reference(this, Mappings.ParamsById, joinPart, t, reverse: true, isLogic: false); + } + } + } + else if (option.StartsWith("return:", StringComparison.OrdinalIgnoreCase)) + { + var returnValue = option.Substring(7); + string[] returnValueParts = returnValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + foreach (var returnValuePart in returnValueParts) + { + if (Int32.TryParse(returnValuePart, out int returnParamId)) + { + yield return new Reference(this, Mappings.ParamsById, returnValuePart, t, reverse: true, isLogic: false); + } + } + } + else if (option.StartsWith("status:", StringComparison.OrdinalIgnoreCase)) + { + var statusValue = option.Substring(7); + + if (Int32.TryParse(statusValue, out int columnPid)) + { + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); + } + } + else if (option.StartsWith("weight:", StringComparison.OrdinalIgnoreCase)) + { + var weightValue = option.Substring(7); + + if (Int32.TryParse(weightValue, out int columnPid)) + { + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); + } + } + } + break; + } + } + } + } + + private IEnumerable ProcessProtocolActionReferences() + { + var t = Type; + if (t?.Value != null) + { + string ref_id = Convert.ToString(t.Id?.Value); + if (!String.IsNullOrWhiteSpace(ref_id)) + { + switch (t.Value.Value) + { + case EnumActionType.Close: case EnumActionType.ReadFile: - case EnumActionType.Append: yield return new Reference(this, Mappings.ParamsById, ref_id, t, reverse: true, isLogic: false); break; } } + } - var ref_ids = Convert.ToString(t.ReturnValue?.Value); - if (!String.IsNullOrWhiteSpace(ref_ids)) + if (t?.Nr != null) + { + string nrValue_id = Convert.ToString(t.Nr?.Value); + if (!String.IsNullOrWhiteSpace(nrValue_id) && Int32.TryParse(nrValue_id, out _)) { - foreach (var r in ref_ids.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) + switch (t.Value.Value) { - switch (t.Value.Value) - { - case EnumActionType.ReadFile: - case EnumActionType.Wmi: - yield return new Reference(this, Mappings.ParamsById, r, t, reverse: true, isLogic: false); - break; - } + case EnumActionType.ReadFile: + yield return new Reference(this, Mappings.ParamsById, nrValue_id, t, reverse: true, isLogic: false); + break; } } } - var condition = Condition; - if (condition?.Value != null) + if (t?.ReturnValue != null) { - foreach (Match m in Regex.Matches(condition.Value, @"id:(?\d+)")) + string returnValue_id = Convert.ToString(t.ReturnValue?.Value); + if (!String.IsNullOrWhiteSpace(returnValue_id)) { - string ref_id = m.Groups["id"].Value; - yield return new Reference(this, Mappings.ParamsById, ref_id, condition, "Conditions", "Conditions", isLogic: false); + switch (t.Value.Value) + { + case EnumActionType.ReadFile: + if(Int32.TryParse(returnValue_id, out _)) + { + yield return new Reference(this, Mappings.ParamsById, returnValue_id, t, reverse: true, isLogic: false); + } + break; + case EnumActionType.Wmi: + { + string[] parts = returnValue_id.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); + + for (int i = 0; i < parts.Length; i++) + { + string paramId = parts[i]; + if (!String.IsNullOrWhiteSpace(paramId) && Int32.TryParse(paramId, out _)) + { + yield return new Reference(this, Mappings.ParamsById, paramId, t, reverse: true, isLogic: false); + } + } + } + break; + } + } + } + + if (t?.Startoffset != null) + { + string startOffsetValue_id = Convert.ToString(t.Startoffset?.Value); + if (!String.IsNullOrWhiteSpace(startOffsetValue_id) && Int32.TryParse(startOffsetValue_id, out _)) + { + switch (t.Value.Value) + { + case EnumActionType.ReadFile: + yield return new Reference(this, Mappings.ParamsById, startOffsetValue_id, t, reverse: true, isLogic: false); + break; + } + } + } + + if (t?.Options != null) + { + string optionsValue = Convert.ToString(t.Options?.Value); + + if (!String.IsNullOrEmpty(optionsValue)) + { + switch (t.Value.Value) + { + case EnumActionType.Merge: + { + string[] options = optionsValue.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); + foreach (var option in options) + { + if (option.StartsWith("destination:", StringComparison.OrdinalIgnoreCase)) + { + var destinations = option.Substring(12).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + + foreach(var destination in destinations) + { + if (Int32.TryParse(destination, out _)) + { + yield return new Reference(this, Mappings.ParamsById, destination, t, reverse: true, isLogic: false); + } + } + } + else if (option.StartsWith("defaultValue:", StringComparison.OrdinalIgnoreCase)) + { + var defaultValue = option.Substring(13); + int commaIndex = defaultValue.IndexOf(','); + + if (commaIndex > -1 && Int32.TryParse(defaultValue.Substring(0, commaIndex), out int defaultValueColumnPid)) + { + yield return new Reference(this, Mappings.ParamsById, defaultValueColumnPid.ToString(), t, reverse: true, isLogic: false); + } + } + else if (option.StartsWith("destinationfindpk:", StringComparison.OrdinalIgnoreCase)) + { + var destinations = option.Substring(18).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + + foreach (var destination in destinations) + { + if (Int32.TryParse(destination, out _)) + { + yield return new Reference(this, Mappings.ParamsById, destination, t, reverse: true, isLogic: false); + } + } + } + else if (option.StartsWith("limitresult:", StringComparison.OrdinalIgnoreCase)) + { + var limitResultValue = option.Substring(12); + + if (Int32.TryParse(limitResultValue, out _)) + { + yield return new Reference(this, Mappings.ParamsById, limitResultValue, t, reverse: true, isLogic: false); + } + } + else if (option.StartsWith("remoteElements:", StringComparison.OrdinalIgnoreCase)) + { + var remoteElementsValue = option.Substring(15); + + if (Int32.TryParse(remoteElementsValue, out _)) + { + yield return new Reference(this, Mappings.ParamsById, remoteElementsValue, t, reverse: true, isLogic: false); + } + } + else if (option.StartsWith("resolve:", StringComparison.OrdinalIgnoreCase)) + { + var resolveValue = option.Substring(8).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + + foreach (var resolvePid in resolveValue) + { + if (Int32.TryParse(resolvePid, out _)) + { + yield return new Reference(this, Mappings.ParamsById, resolvePid, t, reverse: true, isLogic: false); + } + } + } + else if (option.StartsWith("trigger:", StringComparison.OrdinalIgnoreCase)) + { + var triggerValue = option.Substring(8); + + if (Int32.TryParse(triggerValue, out _)) + { + yield return new Reference(this, Mappings.ParamsById, triggerValue, t, reverse: true, isLogic: false); + } + } + } + } + break; + case EnumActionType.SwapColumn: + { + string[] parts = optionsValue.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); + if(parts.Length > 1) + { + for(int i=1; i < parts.Length; i++) + { + string paramId = parts[i]; + if (!String.IsNullOrWhiteSpace(paramId) && Int32.TryParse(paramId, out _)) + { + yield return new Reference(this, Mappings.ParamsById, paramId, t, reverse: true, isLogic: false); + } + } + } + } + break; + case EnumActionType.Wmi: + { + string[] options = optionsValue.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); + foreach(var option in options) + { + if (option.StartsWith("pwd:", StringComparison.OrdinalIgnoreCase) && Int32.TryParse(option.Substring(4), out int pwdParamId)) + { + yield return new Reference(this, Mappings.ParamsById, pwdParamId.ToString(), t, reverse: true, isLogic: false); + } + else if (option.StartsWith("server:", StringComparison.OrdinalIgnoreCase) && Int32.TryParse(option.Substring(7), out int serverParamId)) + { + yield return new Reference(this, Mappings.ParamsById, serverParamId.ToString(), t, reverse: true, isLogic: false); + } + else if (option.StartsWith("uname:", StringComparison.OrdinalIgnoreCase) && Int32.TryParse(option.Substring(6), out int userParamId)) + { + yield return new Reference(this, Mappings.ParamsById, userParamId.ToString(), t, reverse: true, isLogic: false); + } + else if (option.StartsWith("where:ID:", StringComparison.OrdinalIgnoreCase) && Int32.TryParse(option.Substring(9), out int whereClauseParamId)) + { + yield return new Reference(this, Mappings.ParamsById, whereClauseParamId.ToString(), t, reverse: true, isLogic: false); + } + } + } + break; + } } } } + private IEnumerable ProcessCommandActionReferences() + { + var t = Type; + if (t?.Value != null) + { + string ref_id = Convert.ToString(t.Id?.Value); + if (!String.IsNullOrWhiteSpace(ref_id)) + { + switch (t.Value.Value) + { + case EnumActionType.Replace: + yield return new Reference(this, Mappings.ParamsById, ref_id, t, reverse: true, isLogic: false); + break; + } + } + } + } + + private IEnumerable ProcessResponseActionReferences() + { + var t = Type; + if (t?.Value != null) + { + string ref_id = Convert.ToString(t.Id?.Value); + if (!String.IsNullOrWhiteSpace(ref_id)) + { + switch (t.Value.Value) + { + case EnumActionType.Replace: + yield return new Reference(this, Mappings.ParamsById, ref_id, t, reverse: true, isLogic: false); + break; + } + } + } + } + + private IEnumerable ProcessPairActionReferences() + { + var t = Type; + if (t?.Value != null) + { + string ref_id = Convert.ToString(t.Id?.Value); + if (!String.IsNullOrWhiteSpace(ref_id)) + { + switch (t.Value.Value) + { + case EnumActionType.SetNext: + case EnumActionType.Timeout: + yield return new Reference(this, Mappings.ParamsById, ref_id, t, reverse: true, isLogic: false); + break; + } + } + } + } #endregion } } \ No newline at end of file diff --git a/ProtocolTests/ProtocolTests.csproj b/ProtocolTests/ProtocolTests.csproj index 4406704..0dbf110 100644 --- a/ProtocolTests/ProtocolTests.csproj +++ b/ProtocolTests/ProtocolTests.csproj @@ -1,7 +1,8 @@  - net48;net6.0;net8.0 + net48 + false true @@ -9,7 +10,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/ProtocolTests/Read/Linking/RelationManagerTests.cs b/ProtocolTests/Read/Linking/RelationManagerTests.cs index 844a2ae..d6d03d9 100644 --- a/ProtocolTests/Read/Linking/RelationManagerTests.cs +++ b/ProtocolTests/Read/Linking/RelationManagerTests.cs @@ -14,7 +14,7 @@ public class RelationManagerTests [TestMethod] public void Ctor_MappingsIsNull_ThrowsArgumentNullException() { - Assert.ThrowsException(() => new RelationManager(null)); + Assert.Throws(() => new RelationManager(null)); } [TestMethod] diff --git a/ProtocolTests/Read/Protocol/Actions/Action.cs b/ProtocolTests/Read/Protocol/Actions/Action.cs index 075cfd8..c4c3f26 100644 --- a/ProtocolTests/Read/Protocol/Actions/Action.cs +++ b/ProtocolTests/Read/Protocol/Actions/Action.cs @@ -1,8 +1,11 @@ namespace Models.ProtocolTests.Read.Protocol.Actions { using System; + using System.Collections.Immutable; + using Microsoft.VisualStudio.TestTools.UnitTesting; using Skyline.DataMiner.CICD.Models.Protocol.Read; + using Skyline.DataMiner.CICD.Models.Protocol.Read.Linking; [TestClass] public class Action : ProtocolTestBase @@ -322,6 +325,631 @@ public void On_NotAvailable_IsNull() Assert.AreEqual(null, action.On); } + [TestMethod] + public void AggregateActionRelations() + { + // Arrange. + string xml = @" + + + + + + + + + + + + + + + + + parameter + aggregate + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + Assert.AreEqual("3", references[2].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[2].TargetMapping); + Assert.AreEqual("4", references[3].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[3].TargetMapping); + Assert.AreEqual("5", references[4].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[4].TargetMapping); + Assert.AreEqual("6", references[5].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[5].TargetMapping); + Assert.AreEqual("7", references[6].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[6].TargetMapping); + Assert.AreEqual("8", references[7].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[7].TargetMapping); + Assert.AreEqual("9", references[8].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[8].TargetMapping); + Assert.AreEqual("10", references[9].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[9].TargetMapping); + Assert.AreEqual("11", references[10].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[10].TargetMapping); + Assert.AreEqual("12", references[11].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[11].TargetMapping); + } + + [TestMethod] + public void AppendActionRelations() + { + // Arrange. + string xml = @" + + + + + + + parameter + append + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("728", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("721", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + } + + [TestMethod] + public void AppendDataActionRelations() + { + // Arrange. + string xml = @" + + + + + + + parameter + append data + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + } + + [TestMethod] + public void ChangeLengthActionRelations() + { + // Arrange. + string xml = @" + + + + + + + parameter + change length + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + } + + [TestMethod] + public void CloseActionRelations() + { + // Arrange. + string xml = @" + + + + + + protocol + close + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + } + + [TestMethod] + public void CopyActionRelations() + { + // Arrange. + string xml = @" + + + + + + + parameter + copy + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + } + + [TestMethod] + public void CopyReversActionRelations() + { + // Arrange. + string xml = @" + + + + + + + parameter + copy reverse + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + } + + [TestMethod] + public void MergeActionRelations() + { + // Arrange. + string xml = @" + + + + + + + + + + + + + + protocol + merge + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + Assert.AreEqual("3", references[2].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[2].TargetMapping); + Assert.AreEqual("4", references[3].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[3].TargetMapping); + Assert.AreEqual("5", references[4].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[4].TargetMapping); + Assert.AreEqual("6", references[5].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[5].TargetMapping); + Assert.AreEqual("7", references[6].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[6].TargetMapping); + Assert.AreEqual("8", references[7].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[7].TargetMapping); + Assert.AreEqual("9", references[8].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[8].TargetMapping); + } + + [TestMethod] + public void NormalizeActionRelations() + { + // Arrange. + string xml = @" + + + + + + + parameter + normalize + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + } + + [TestMethod] + public void ReadFileActionRelations() + { + // Arrange. + string xml = @" + + + + + + + + + protocol + read file + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("3", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + Assert.AreEqual("2", references[2].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[2].TargetMapping); + Assert.AreEqual("4", references[3].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[3].TargetMapping); + } + + [TestMethod] + public void ReplaceActionCommandRelations() + { + // Arrange. + string xml = @" + + + + + + + + + command + replace + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.CommandsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + } + + [TestMethod] + public void ReplaceActionResponseRelations() + { + // Arrange. + string xml = @" + + + + + + + + + response + replace + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ResponsesById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + } + + [TestMethod] + public void SetAndGetWithWaitActionRelations() + { + // Arrange. + string xml = @" + + + + + + + parameter + set and get with wait + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + } + + [TestMethod] + public void SetNextActionRelations() + { + // Arrange. + string xml = @" + + + + + + + + + pair + set next + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.PairsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + } + + [TestMethod] + public void SwapColumnActionRelations() + { + // Arrange. + string xml = @" + + + + + + + + protocol + swap column + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + Assert.AreEqual("3", references[2].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[2].TargetMapping); + } + + [TestMethod] + public void TimeoutActionRelations() + { + // Arrange. + string xml = @" + + + + + + + + + + pair + timeout + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.PairsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.PairsById, references[1].TargetMapping); + Assert.AreEqual("3", references[2].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[2].TargetMapping); + } + + [TestMethod] + public void WmiActionRelations() + { + // Arrange. + string xml = @" + + + + + + + + + + + protocol + wmi + + + "; + + // Act. + ProtocolModel model = CreateModelFromXML(xml); + + IProtocol protocol = model.Protocol; + var action = protocol.Actions[0]; + + var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); + + // Assert + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("2", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); + Assert.AreEqual("3", references[2].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[2].TargetMapping); + Assert.AreEqual("4", references[3].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[3].TargetMapping); + Assert.AreEqual("5", references[4].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[4].TargetMapping); + Assert.AreEqual("6", references[5].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[5].TargetMapping); + } + + #endregion } } \ No newline at end of file diff --git a/ProtocolTests/Read/Protocol/Protocol.cs b/ProtocolTests/Read/Protocol/Protocol.cs index e129a12..b9078f5 100644 --- a/ProtocolTests/Read/Protocol/Protocol.cs +++ b/ProtocolTests/Read/Protocol/Protocol.cs @@ -1208,7 +1208,6 @@ public void IsMediation_ValidAttribute_True() // Act. ProtocolModel model = CreateModelFromXML(xml); - IProtocol protocol = model.Protocol; // Assert From a02b701e5d29c807ea2eabcb2af8dc02d0ae7e4b Mon Sep 17 00:00:00 2001 From: Michiel Oda Date: Thu, 11 Dec 2025 15:03:38 +0100 Subject: [PATCH 2/3] Fixes in unit test, fixes in GetOptions for the Action & applied CR remarks --- .../Actions/Action/Type/ActionTypeOptions.cs | 18 +- .../Read/Protocol/Actions/Action/Action.cs | 339 +++++++----------- ProtocolTests/ProtocolTests.csproj | 3 +- ProtocolTests/Read/Protocol/Actions/Action.cs | 29 +- 4 files changed, 169 insertions(+), 220 deletions(-) diff --git a/Protocol/Models/Custom Classes/Protocol/Actions/Action/Type/ActionTypeOptions.cs b/Protocol/Models/Custom Classes/Protocol/Actions/Action/Type/ActionTypeOptions.cs index 03f2fb1..f6948de 100644 --- a/Protocol/Models/Custom Classes/Protocol/Actions/Action/Type/ActionTypeOptions.cs +++ b/Protocol/Models/Custom Classes/Protocol/Actions/Action/Type/ActionTypeOptions.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using System.Linq; public class ActionTypeOptions : OptionsBase { @@ -693,7 +694,7 @@ public JoinClass(string option) : base(option) foreach (var part in secondParts) { - if (UInt32.TryParse(parts[1], out uint v)) + if (UInt32.TryParse(part, out uint v)) { pids.Add(v); } @@ -1049,15 +1050,20 @@ public WhereClass(string option) : base(option) { string[] parts = option.Split(':'); - if (parts.Length != 2) + switch (parts.Length) { - return; + case 2: + Value = parts[1]; + break; + case 3 when String.Equals(parts[1], "ID", StringComparison.OrdinalIgnoreCase) && UInt32.TryParse(parts[2], out uint id): + Pid = id; + break; } - - Value = parts[1]; } - public string Value { get; } + public string Value { get; set; } + + public uint? Pid { get; set; } } } } \ No newline at end of file diff --git a/Protocol/Models/Read/Protocol/Actions/Action/Action.cs b/Protocol/Models/Read/Protocol/Actions/Action/Action.cs index 51c9df6..dc336db 100644 --- a/Protocol/Models/Read/Protocol/Actions/Action/Action.cs +++ b/Protocol/Models/Read/Protocol/Actions/Action/Action.cs @@ -65,7 +65,7 @@ IEnumerable IRelationEvaluator.GetRelations() } } - if(o?.Value != null) + if (o?.Value != null) { switch (o.Value) { @@ -135,113 +135,83 @@ private IEnumerable ProcessParameterActionReferences() } } - var optionsValue = Convert.ToString(t.Options?.Value); - if (!String.IsNullOrWhiteSpace(optionsValue)) + var optionsByType = t.GetOptionsByType(); + if (optionsByType != null) { switch (t.Value.Value) { case EnumActionType.Aggregate: - string[] options = optionsValue.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); - foreach (var option in options) + var aggregateOptions = optionsByType.Aggregate; + if (aggregateOptions.DefaultValue?.ColumnPid != null) { - if (option.StartsWith("defaultValue:", StringComparison.OrdinalIgnoreCase)) - { - var defaultValue = option.Substring(12); - string[] defaultValueParts = defaultValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.DefaultValue.ColumnPid.ToString(), t, reverse: true, isLogic: false); + } - if (defaultValueParts.Length > 1 && Int32.TryParse(defaultValueParts[0], out int defaultValueColumnPid)) - { - yield return new Reference(this, Mappings.ParamsById, defaultValueColumnPid.ToString(), t, reverse: true, isLogic: false); - } - } - else if (option.StartsWith("equation:", StringComparison.OrdinalIgnoreCase)) - { - var equationValue = option.Substring(8); - string[] equationValueParts = equationValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + if (aggregateOptions.Equation?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.Equation.Pid.ToString(), t, reverse: true, isLogic: false); + } - if (equationValueParts.Length > 1 && Int32.TryParse(equationValueParts[1], out int columnPid)) - { - yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); - } - } - else if (option.StartsWith("equationvalue:", StringComparison.OrdinalIgnoreCase)) - { - var equationValue = option.Substring(13); - string[] equationValueParts = equationValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + if (aggregateOptions.EquationValue?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.EquationValue.Pid.ToString(), t, reverse: true, isLogic: false); + } - if (equationValueParts.Length > 2 && Int32.TryParse(equationValueParts[2], out int columnPid)) - { - yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); - } - } - else if(option.StartsWith("groupby:", StringComparison.OrdinalIgnoreCase)) + if (aggregateOptions.GroupBy?.Values != null) + { + foreach ((_, uint? columnPid, _) in aggregateOptions.GroupBy.Values.Where(x => x.columnPid != null)) { - var groupByValue = option.Substring(7); - string[] groupByValueParts = groupByValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); + } + } - foreach(var groupByPart in groupByValueParts) - { - string[] groupByEntryParts = groupByPart.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); + if (aggregateOptions.GroupByTable?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.GroupByTable.Pid.ToString(), t, reverse: true, isLogic: false); + } - if (groupByEntryParts.Length > 1 && Int32.TryParse(groupByEntryParts[1], out int groupByParamId)) - { - yield return new Reference(this, Mappings.ParamsById, groupByParamId.ToString(), t, reverse: true, isLogic: false); - } - } - } - else if (option.StartsWith("groupbytable:", StringComparison.OrdinalIgnoreCase)) + if (aggregateOptions.Join?.ColumnPids != null) + { + foreach (uint? columnPid in aggregateOptions.Join.ColumnPids.Where(pid => pid != null)) { - var groupByTableValue = option.Substring(13); - - if (Int32.TryParse(groupByTableValue, out int groupByTableParamId)) - { - yield return new Reference(this, Mappings.ParamsById, groupByTableParamId.ToString(), t, reverse: true, isLogic: false); - } + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); } - else if (option.StartsWith("join:", StringComparison.OrdinalIgnoreCase)) + } + + if (aggregateOptions.Return != null) + { + if (aggregateOptions.Return.Value1 != null) { - var joinValue = option.Substring(5); - string[] joinValueParts = joinValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - foreach (var joinPart in joinValueParts) - { - if (Int32.TryParse(joinPart, out int joinParamId)) - { - yield return new Reference(this, Mappings.ParamsById, joinPart, t, reverse: true, isLogic: false); - } - } + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.Return.Value1.ToString(), t, reverse: true, isLogic: false); } - else if (option.StartsWith("return:", StringComparison.OrdinalIgnoreCase)) + + if (aggregateOptions.Return.Value2 != null) { - var returnValue = option.Substring(7); - string[] returnValueParts = returnValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - foreach (var returnValuePart in returnValueParts) - { - if (Int32.TryParse(returnValuePart, out int returnParamId)) - { - yield return new Reference(this, Mappings.ParamsById, returnValuePart, t, reverse: true, isLogic: false); - } - } + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.Return.Value2.ToString(), t, reverse: true, isLogic: false); } - else if (option.StartsWith("status:", StringComparison.OrdinalIgnoreCase)) - { - var statusValue = option.Substring(7); - if (Int32.TryParse(statusValue, out int columnPid)) - { - yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); - } - } - else if (option.StartsWith("weight:", StringComparison.OrdinalIgnoreCase)) + if (aggregateOptions.Return.Value3 != null) { - var weightValue = option.Substring(7); + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.Return.Value3.ToString(), t, reverse: true, isLogic: false); + } - if (Int32.TryParse(weightValue, out int columnPid)) - { - yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); - } + if (aggregateOptions.Return.Value4 != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.Return.Value4.ToString(), t, reverse: true, isLogic: false); } } - break; + + if (aggregateOptions.Status?.Value != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.Status.Value.ToString(), t, reverse: true, isLogic: false); + } + + if (aggregateOptions.Weight?.Value != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.Weight.Value.ToString(), t, reverse: true, isLogic: false); + } + + break; } } } @@ -287,7 +257,7 @@ private IEnumerable ProcessProtocolActionReferences() switch (t.Value.Value) { case EnumActionType.ReadFile: - if(Int32.TryParse(returnValue_id, out _)) + if (Int32.TryParse(returnValue_id, out _)) { yield return new Reference(this, Mappings.ParamsById, returnValue_id, t, reverse: true, isLogic: false); } @@ -324,136 +294,105 @@ private IEnumerable ProcessProtocolActionReferences() } } - if (t?.Options != null) + var optionsByType = t?.GetOptionsByType(); + if (optionsByType != null) { - string optionsValue = Convert.ToString(t.Options?.Value); - - if (!String.IsNullOrEmpty(optionsValue)) + switch (t.Value.Value) { - switch (t.Value.Value) - { - case EnumActionType.Merge: + case EnumActionType.Merge: + { + var mergeOptions = optionsByType.Merge; + if (mergeOptions.Destination?.ColumnPids != null) { - string[] options = optionsValue.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); - foreach (var option in options) + foreach (uint? columnPid in mergeOptions.Destination.ColumnPids.Where(pid => pid != null)) { - if (option.StartsWith("destination:", StringComparison.OrdinalIgnoreCase)) - { - var destinations = option.Substring(12).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - - foreach(var destination in destinations) - { - if (Int32.TryParse(destination, out _)) - { - yield return new Reference(this, Mappings.ParamsById, destination, t, reverse: true, isLogic: false); - } - } - } - else if (option.StartsWith("defaultValue:", StringComparison.OrdinalIgnoreCase)) - { - var defaultValue = option.Substring(13); - int commaIndex = defaultValue.IndexOf(','); + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); + } + } - if (commaIndex > -1 && Int32.TryParse(defaultValue.Substring(0, commaIndex), out int defaultValueColumnPid)) - { - yield return new Reference(this, Mappings.ParamsById, defaultValueColumnPid.ToString(), t, reverse: true, isLogic: false); - } - } - else if (option.StartsWith("destinationfindpk:", StringComparison.OrdinalIgnoreCase)) - { - var destinations = option.Substring(18).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - - foreach (var destination in destinations) - { - if (Int32.TryParse(destination, out _)) - { - yield return new Reference(this, Mappings.ParamsById, destination, t, reverse: true, isLogic: false); - } - } - } - else if (option.StartsWith("limitresult:", StringComparison.OrdinalIgnoreCase)) - { - var limitResultValue = option.Substring(12); + if (mergeOptions.DefaultValue?.ColumnPid != null) + { + yield return new Reference(this, Mappings.ParamsById, mergeOptions.DefaultValue.ColumnPid.ToString(), t, reverse: true, isLogic: false); + } - if (Int32.TryParse(limitResultValue, out _)) - { - yield return new Reference(this, Mappings.ParamsById, limitResultValue, t, reverse: true, isLogic: false); - } - } - else if (option.StartsWith("remoteElements:", StringComparison.OrdinalIgnoreCase)) - { - var remoteElementsValue = option.Substring(15); + if (mergeOptions.DestinationFindPk?.ColumnPids != null) + { + foreach (uint? columnPid in mergeOptions.DestinationFindPk.ColumnPids.Where(pid => pid != null)) + { + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); + } + } - if (Int32.TryParse(remoteElementsValue, out _)) - { - yield return new Reference(this, Mappings.ParamsById, remoteElementsValue, t, reverse: true, isLogic: false); - } - } - else if (option.StartsWith("resolve:", StringComparison.OrdinalIgnoreCase)) - { - var resolveValue = option.Substring(8).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - - foreach (var resolvePid in resolveValue) - { - if (Int32.TryParse(resolvePid, out _)) - { - yield return new Reference(this, Mappings.ParamsById, resolvePid, t, reverse: true, isLogic: false); - } - } - } - else if (option.StartsWith("trigger:", StringComparison.OrdinalIgnoreCase)) - { - var triggerValue = option.Substring(8); + if (mergeOptions.LimitResult?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, mergeOptions.LimitResult.Pid.ToString(), t, reverse: true, isLogic: false); + } - if (Int32.TryParse(triggerValue, out _)) - { - yield return new Reference(this, Mappings.ParamsById, triggerValue, t, reverse: true, isLogic: false); - } - } - } + if (mergeOptions.RemoteElements?.ColumnPid != null) + { + yield return new Reference(this, Mappings.ParamsById, mergeOptions.RemoteElements.ColumnPid.ToString(), t, reverse: true, isLogic: false); } - break; - case EnumActionType.SwapColumn: + + if (mergeOptions.Resolve?.ColumnPids != null) { - string[] parts = optionsValue.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); - if(parts.Length > 1) + foreach (uint? columnPid in mergeOptions.Resolve.ColumnPids.Where(pid => pid != null)) { - for(int i=1; i < parts.Length; i++) - { - string paramId = parts[i]; - if (!String.IsNullOrWhiteSpace(paramId) && Int32.TryParse(paramId, out _)) - { - yield return new Reference(this, Mappings.ParamsById, paramId, t, reverse: true, isLogic: false); - } - } + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); } } - break; - case EnumActionType.Wmi: + + if (mergeOptions.Trigger?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, mergeOptions.Trigger.Pid.ToString(), t, reverse: true, isLogic: false); + } + } + break; + case EnumActionType.SwapColumn: + { + var swapOptions = optionsByType.Swap; + if (swapOptions.Swap != null) { - string[] options = optionsValue.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); - foreach(var option in options) + if (swapOptions.Swap.TablePid != null) { - if (option.StartsWith("pwd:", StringComparison.OrdinalIgnoreCase) && Int32.TryParse(option.Substring(4), out int pwdParamId)) - { - yield return new Reference(this, Mappings.ParamsById, pwdParamId.ToString(), t, reverse: true, isLogic: false); - } - else if (option.StartsWith("server:", StringComparison.OrdinalIgnoreCase) && Int32.TryParse(option.Substring(7), out int serverParamId)) - { - yield return new Reference(this, Mappings.ParamsById, serverParamId.ToString(), t, reverse: true, isLogic: false); - } - else if (option.StartsWith("uname:", StringComparison.OrdinalIgnoreCase) && Int32.TryParse(option.Substring(6), out int userParamId)) - { - yield return new Reference(this, Mappings.ParamsById, userParamId.ToString(), t, reverse: true, isLogic: false); - } - else if (option.StartsWith("where:ID:", StringComparison.OrdinalIgnoreCase) && Int32.TryParse(option.Substring(9), out int whereClauseParamId)) - { - yield return new Reference(this, Mappings.ParamsById, whereClauseParamId.ToString(), t, reverse: true, isLogic: false); - } + yield return new Reference(this, Mappings.ParamsById, swapOptions.Swap.TablePid.ToString(), t, reverse: true, isLogic: false); + } + + if (swapOptions.Swap.SourceColumnPid != null) + { + yield return new Reference(this, Mappings.ParamsById, swapOptions.Swap.SourceColumnPid.ToString(), t, reverse: true, isLogic: false); + } + + if (swapOptions.Swap.DestinationColumnPid != null) + { + yield return new Reference(this, Mappings.ParamsById, swapOptions.Swap.DestinationColumnPid.ToString(), t, reverse: true, isLogic: false); } } - break; - } + } + break; + case EnumActionType.Wmi: + { + var wmiOptions = optionsByType.Wmi; + if (wmiOptions.Pwd?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, wmiOptions.Pwd.Pid.ToString(), t, reverse: true, isLogic: false); + } + + if (wmiOptions.Server?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, wmiOptions.Server.Pid.ToString(), t, reverse: true, isLogic: false); + } + + if (wmiOptions.UName?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, wmiOptions.UName.Pid.ToString(), t, reverse: true, isLogic: false); + } + + if (wmiOptions.Where?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, wmiOptions.Where.Pid.ToString(), t, reverse: true, isLogic: false); + } + } + break; } } } diff --git a/ProtocolTests/ProtocolTests.csproj b/ProtocolTests/ProtocolTests.csproj index 0dbf110..89897d8 100644 --- a/ProtocolTests/ProtocolTests.csproj +++ b/ProtocolTests/ProtocolTests.csproj @@ -1,8 +1,7 @@  - net48 - + net48;net8.0 false true diff --git a/ProtocolTests/Read/Protocol/Actions/Action.cs b/ProtocolTests/Read/Protocol/Actions/Action.cs index c4c3f26..4b97e6e 100644 --- a/ProtocolTests/Read/Protocol/Actions/Action.cs +++ b/ProtocolTests/Read/Protocol/Actions/Action.cs @@ -347,7 +347,7 @@ public void AggregateActionRelations() parameter - aggregate + aggregate "; @@ -361,29 +361,34 @@ public void AggregateActionRelations() var references = protocol.Model.RelationManager.GetForwardReferences(action).ToImmutableList(); // Assert + // Via On Assert.AreEqual("1", references[0].TargetId); Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); - Assert.AreEqual("2", references[1].TargetId); + + // Via Type + Assert.AreEqual("1", references[1].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + Assert.AreEqual("2", references[2].TargetId); Assert.AreEqual(Mappings.ParamsById, references[1].TargetMapping); - Assert.AreEqual("3", references[2].TargetId); + Assert.AreEqual("3", references[3].TargetId); Assert.AreEqual(Mappings.ParamsById, references[2].TargetMapping); - Assert.AreEqual("4", references[3].TargetId); + Assert.AreEqual("4", references[4].TargetId); Assert.AreEqual(Mappings.ParamsById, references[3].TargetMapping); - Assert.AreEqual("5", references[4].TargetId); + Assert.AreEqual("5", references[5].TargetId); Assert.AreEqual(Mappings.ParamsById, references[4].TargetMapping); - Assert.AreEqual("6", references[5].TargetId); + Assert.AreEqual("6", references[6].TargetId); Assert.AreEqual(Mappings.ParamsById, references[5].TargetMapping); - Assert.AreEqual("7", references[6].TargetId); + Assert.AreEqual("7", references[7].TargetId); Assert.AreEqual(Mappings.ParamsById, references[6].TargetMapping); - Assert.AreEqual("8", references[7].TargetId); + Assert.AreEqual("8", references[8].TargetId); Assert.AreEqual(Mappings.ParamsById, references[7].TargetMapping); - Assert.AreEqual("9", references[8].TargetId); + Assert.AreEqual("9", references[9].TargetId); Assert.AreEqual(Mappings.ParamsById, references[8].TargetMapping); - Assert.AreEqual("10", references[9].TargetId); + Assert.AreEqual("10", references[10].TargetId); Assert.AreEqual(Mappings.ParamsById, references[9].TargetMapping); - Assert.AreEqual("11", references[10].TargetId); + Assert.AreEqual("11", references[11].TargetId); Assert.AreEqual(Mappings.ParamsById, references[10].TargetMapping); - Assert.AreEqual("12", references[11].TargetId); + Assert.AreEqual("12", references[12].TargetId); Assert.AreEqual(Mappings.ParamsById, references[11].TargetMapping); } From 95234998e3602af3ba50d7dda9cf3a9a3d58b886 Mon Sep 17 00:00:00 2001 From: Michiel Oda Date: Thu, 11 Dec 2025 15:14:59 +0100 Subject: [PATCH 3/3] SonarCloud remarks --- .../Read/Linking/RelationManagerTests.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ProtocolTests/Read/Linking/RelationManagerTests.cs b/ProtocolTests/Read/Linking/RelationManagerTests.cs index d6d03d9..7768fef 100644 --- a/ProtocolTests/Read/Linking/RelationManagerTests.cs +++ b/ProtocolTests/Read/Linking/RelationManagerTests.cs @@ -238,8 +238,8 @@ public void Link_AddForward_LinkCreated() // assert var linksParam = relationManager.GetLinks(dummyParam).ToList(); var linksGroup = relationManager.GetLinks(dummyGroup).ToList(); - Assert.AreEqual(1, linksParam.Count); - Assert.AreEqual(1, linksGroup.Count); + Assert.HasCount(1, linksParam); + Assert.HasCount(1, linksGroup); var link = linksParam.First(); Assert.AreEqual(link, linksGroup.First()); @@ -268,8 +268,8 @@ public void Link_AddReverse_LinkCreated() // assert var linksParam = relationManager.GetLinks(dummyParam).ToList(); var linksGroup = relationManager.GetLinks(dummyGroup).ToList(); - Assert.AreEqual(1, linksParam.Count); - Assert.AreEqual(1, linksGroup.Count); + Assert.HasCount(1, linksParam); + Assert.HasCount(1, linksGroup); var link = linksParam.First(); Assert.AreEqual(link, linksGroup.First()); @@ -309,9 +309,9 @@ public void Link_UpdateForward_LinkUpdated() var linksParam1 = relationManager.GetLinks(dummyParam1).ToList(); var linksParam2 = relationManager.GetLinks(dummyParam2).ToList(); var linksGroup = relationManager.GetLinks(dummyGroup).ToList(); - Assert.AreEqual(0, linksParam1.Count); - Assert.AreEqual(1, linksParam2.Count); - Assert.AreEqual(1, linksGroup.Count); + Assert.HasCount(0, linksParam1); + Assert.HasCount(1, linksParam2); + Assert.HasCount(1, linksGroup); var link = linksParam2.First(); Assert.AreEqual(link, linksGroup.First()); @@ -338,7 +338,7 @@ public void Link_UpdateReverse_LinkUpdated() NotifyAdded(mappings, relationManager, dummyGroup); var links = relationManager.GetLinks(dummyParam).ToList(); - Assert.AreEqual(1, links.Count); + Assert.HasCount(1, links); Assert.AreEqual(r1, links.First().Reference); // act @@ -350,8 +350,8 @@ public void Link_UpdateReverse_LinkUpdated() // assert var linksParam = relationManager.GetLinks(dummyParam).ToList(); var linksGroup = relationManager.GetLinks(dummyGroup).ToList(); - Assert.AreEqual(1, linksParam.Count); - Assert.AreEqual(1, linksGroup.Count); + Assert.HasCount(1, linksParam); + Assert.HasCount(1, linksGroup); var link = linksParam.First(); Assert.AreEqual(link, linksGroup.First()); @@ -385,8 +385,8 @@ public void Link_RemoveForward_LinkRemoved() // assert var linksParam = relationManager.GetLinks(dummyParam).ToList(); var linksGroup = relationManager.GetLinks(dummyGroup).ToList(); - Assert.AreEqual(0, linksParam.Count); - Assert.AreEqual(0, linksGroup.Count); + Assert.HasCount(0, linksParam); + Assert.HasCount(0, linksGroup); } [TestMethod] @@ -413,8 +413,8 @@ public void Link_RemoveReverse_LinkRemoved() // assert var linksParam = relationManager.GetLinks(dummyParam).ToList(); var linksGroup = relationManager.GetLinks(dummyGroup).ToList(); - Assert.AreEqual(0, linksParam.Count); - Assert.AreEqual(0, linksGroup.Count); + Assert.HasCount(0, linksParam); + Assert.HasCount(0, linksGroup); } [TestMethod]