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 95a470b..dc336db 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,334 @@ 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 optionsByType = t.GetOptionsByType(); + if (optionsByType != null) + { + switch (t.Value.Value) + { + case EnumActionType.Aggregate: + var aggregateOptions = optionsByType.Aggregate; + if (aggregateOptions.DefaultValue?.ColumnPid != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.DefaultValue.ColumnPid.ToString(), t, reverse: true, isLogic: false); + } + + if (aggregateOptions.Equation?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.Equation.Pid.ToString(), t, reverse: true, isLogic: false); + } + + if (aggregateOptions.EquationValue?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.EquationValue.Pid.ToString(), t, reverse: true, isLogic: false); + } + + if (aggregateOptions.GroupBy?.Values != null) + { + foreach ((_, uint? columnPid, _) in aggregateOptions.GroupBy.Values.Where(x => x.columnPid != null)) + { + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); + } + } + + if (aggregateOptions.GroupByTable?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.GroupByTable.Pid.ToString(), t, reverse: true, isLogic: false); + } + + if (aggregateOptions.Join?.ColumnPids != null) + { + foreach (uint? columnPid in aggregateOptions.Join.ColumnPids.Where(pid => pid != null)) + { + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); + } + } + + if (aggregateOptions.Return != null) + { + if (aggregateOptions.Return.Value1 != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.Return.Value1.ToString(), t, reverse: true, isLogic: false); + } + + if (aggregateOptions.Return.Value2 != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.Return.Value2.ToString(), t, reverse: true, isLogic: false); + } + + if (aggregateOptions.Return.Value3 != null) + { + yield return new Reference(this, Mappings.ParamsById, aggregateOptions.Return.Value3.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); + } + } + + 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; + } + } + } + } + + 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 _)) + { + switch (t.Value.Value) + { + case EnumActionType.ReadFile: + yield return new Reference(this, Mappings.ParamsById, nrValue_id, t, reverse: true, isLogic: false); + break; + } + } + } + + if (t?.ReturnValue != null) + { + string returnValue_id = Convert.ToString(t.ReturnValue?.Value); + if (!String.IsNullOrWhiteSpace(returnValue_id)) + { + 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 _)) { - foreach (var r in ref_ids.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) + switch (t.Value.Value) { - switch (t.Value.Value) + case EnumActionType.ReadFile: + yield return new Reference(this, Mappings.ParamsById, startOffsetValue_id, t, reverse: true, isLogic: false); + break; + } + } + } + + var optionsByType = t?.GetOptionsByType(); + if (optionsByType != null) + { + switch (t.Value.Value) + { + case EnumActionType.Merge: { - case EnumActionType.ReadFile: - case EnumActionType.Wmi: - yield return new Reference(this, Mappings.ParamsById, r, t, reverse: true, isLogic: false); - break; + var mergeOptions = optionsByType.Merge; + if (mergeOptions.Destination?.ColumnPids != null) + { + foreach (uint? columnPid in mergeOptions.Destination.ColumnPids.Where(pid => pid != null)) + { + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); + } + } + + if (mergeOptions.DefaultValue?.ColumnPid != null) + { + yield return new Reference(this, Mappings.ParamsById, mergeOptions.DefaultValue.ColumnPid.ToString(), t, reverse: true, isLogic: false); + } + + 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 (mergeOptions.LimitResult?.Pid != null) + { + yield return new Reference(this, Mappings.ParamsById, mergeOptions.LimitResult.Pid.ToString(), 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); + } + + if (mergeOptions.Resolve?.ColumnPids != null) + { + foreach (uint? columnPid in mergeOptions.Resolve.ColumnPids.Where(pid => pid != null)) + { + yield return new Reference(this, Mappings.ParamsById, columnPid.ToString(), t, reverse: true, isLogic: false); + } + } + + 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) + { + if (swapOptions.Swap.TablePid != null) + { + 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; + 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; + } + } + } + + 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; } } } + } - var condition = Condition; - if (condition?.Value != null) + private IEnumerable ProcessResponseActionReferences() + { + var t = Type; + if (t?.Value != null) { - foreach (Match m in Regex.Matches(condition.Value, @"id:(?\d+)")) + string ref_id = Convert.ToString(t.Id?.Value); + if (!String.IsNullOrWhiteSpace(ref_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.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..89897d8 100644 --- a/ProtocolTests/ProtocolTests.csproj +++ b/ProtocolTests/ProtocolTests.csproj @@ -1,7 +1,7 @@  - net48;net6.0;net8.0 + net48;net8.0 false true @@ -9,7 +9,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/ProtocolTests/Read/Linking/RelationManagerTests.cs b/ProtocolTests/Read/Linking/RelationManagerTests.cs index 844a2ae..7768fef 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] @@ -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] diff --git a/ProtocolTests/Read/Protocol/Actions/Action.cs b/ProtocolTests/Read/Protocol/Actions/Action.cs index 075cfd8..4b97e6e 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,636 @@ 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 + // Via On + Assert.AreEqual("1", references[0].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[0].TargetMapping); + + // 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[3].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[2].TargetMapping); + Assert.AreEqual("4", references[4].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[3].TargetMapping); + Assert.AreEqual("5", references[5].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[4].TargetMapping); + Assert.AreEqual("6", references[6].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[5].TargetMapping); + Assert.AreEqual("7", references[7].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[6].TargetMapping); + Assert.AreEqual("8", references[8].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[7].TargetMapping); + Assert.AreEqual("9", references[9].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[8].TargetMapping); + Assert.AreEqual("10", references[10].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[9].TargetMapping); + Assert.AreEqual("11", references[11].TargetId); + Assert.AreEqual(Mappings.ParamsById, references[10].TargetMapping); + Assert.AreEqual("12", references[12].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