< Summary

Information
Class: Elsa.Workflows.Models.ActivityNode
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Models/ActivityNode.cs
Line coverage
74%
Covered lines: 26
Uncovered lines: 9
Coverable lines: 35
Total lines: 114
Line coverage: 74.2%
Branch coverage
66%
Covered branches: 8
Total branches: 12
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_NodeId()100%44100%
get_Activity()100%11100%
get_Port()100%11100%
get_Parents()100%11100%
get_Children()100%11100%
AddParent(...)100%11100%
AddChild(...)100%11100%
Descendants()0%2040%
Ancestors()100%44100%
Siblings()100%210%
SiblingsAndCousins()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Models/ActivityNode.cs

#LineLine coverage
 1namespace Elsa.Workflows.Models;
 2
 3/// <summary>
 4/// Represents an activity in the context of an hierarchical tree structure, providing access to its siblings, parents a
 5/// </summary>
 6public class ActivityNode
 7{
 175808    private readonly List<ActivityNode> _parents = new();
 175809    private readonly List<ActivityNode> _children = new();
 10    private string? _nodeId;
 11
 12    /// <summary>
 13    /// Initializes a new instance of the <see cref="ActivityNode"/> class.
 14    /// </summary>
 15    /// <param name="activity">The activity.</param>
 16    /// <param name="port">The port to which the activity belongs.</param>
 1758017    public ActivityNode(IActivity activity, string port)
 18    {
 1758019        Activity = activity;
 1758020        Port = port;
 1758021    }
 22
 23    /// <summary>
 24    /// Gets the node ID.
 25    /// </summary>
 26    public string NodeId
 27    {
 28        get
 29        {
 4411930            if (_nodeId == null)
 31            {
 4408632                var ancestorIds = Ancestors().Reverse().Select(x => x.Activity.Id).ToList();
 1579033                _nodeId = ancestorIds.Any() ? $"{string.Join(":", ancestorIds)}:{Activity.Id}" : Activity.Id;
 34            }
 35
 4411936            return _nodeId;
 37        }
 38    }
 39
 40    /// <summary>
 41    /// Gets the activity.
 42    /// </summary>
 25333543    public IActivity Activity { get; }
 44
 45    /// <summary>
 46    /// Gets the port to which the activity belongs.
 47    /// </summary>
 148    public string Port { get; }
 49
 50    /// <summary>
 51    /// Gets the parents of this node.
 52    /// </summary>
 4556453    public IReadOnlyCollection<ActivityNode> Parents => _parents.AsReadOnly();
 54
 55    /// <summary>
 56    /// Gets the children of this node.
 57    /// </summary>
 1824158    public ICollection<ActivityNode> Children => _children.AsReadOnly();
 59
 60    public void AddParent(ActivityNode parent)
 61    {
 1325862        _parents.Add(parent);
 1325863        _nodeId = null;
 1325864    }
 65
 66    public void AddChild(ActivityNode child)
 67    {
 1325868        _children.Add(child);
 1325869    }
 70
 71    /// <summary>
 72    /// Gets the descendants of this node.
 73    /// </summary>
 74    /// <returns></returns>
 75    public IEnumerable<ActivityNode> Descendants()
 76    {
 077        foreach (var child in Children)
 78        {
 079            yield return child;
 80
 081            var descendants = child.Descendants();
 82
 083            foreach (var descendant in descendants)
 084                yield return descendant;
 085        }
 086    }
 87
 88    /// <summary>
 89    /// Gets the ancestors of this node.
 90    /// </summary>
 91    public IEnumerable<ActivityNode> Ancestors()
 92    {
 14912693        foreach (var parent in Parents)
 94        {
 2975095            yield return parent;
 96
 2833197            var ancestors = parent.Ancestors();
 98
 12354999            foreach (var ancestor in ancestors)
 33461100                yield return ancestor;
 28296101        }
 44086102    }
 103
 104    /// <summary>
 105    /// Gets the siblings of this node.
 106    /// </summary>
 0107    public IEnumerable<ActivityNode> Siblings() => Parents.SelectMany(parent => parent.Children);
 108
 109    /// <summary>
 110    /// Gets the siblings and cousins of this node.
 111    /// </summary>
 112    /// <returns></returns>
 0113    public IEnumerable<ActivityNode> SiblingsAndCousins() => Parents.SelectMany(parent => parent.Descendants());
 114}