< Summary

Information
Class: Elsa.Api.Client.Shared.Models.ActivityNode
Assembly: Elsa.Api.Client
File(s): /home/runner/work/elsa-core/elsa-core/src/clients/Elsa.Api.Client/Shared/Models/ActivityNode.cs
Line coverage
23%
Covered lines: 7
Uncovered lines: 23
Coverable lines: 30
Total lines: 96
Line coverage: 23.3%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

/home/runner/work/elsa-core/elsa-core/src/clients/Elsa.Api.Client/Shared/Models/ActivityNode.cs

#LineLine coverage
 1using System.Text.Json.Nodes;
 2using System.Text.Json.Serialization;
 3using Elsa.Api.Client.Extensions;
 4
 5namespace Elsa.Api.Client.Shared.Models;
 6
 7/// <summary>
 8/// Represents an activity in the context of an hierarchical tree structure, providing access to its siblings, parents a
 9/// </summary>
 10public class ActivityNode
 11{
 12    [JsonConstructor]
 113    public ActivityNode()
 14    {
 115    }
 16
 017    public ActivityNode(JsonObject activity)
 18    {
 019        Activity = activity;
 020        NodeId = activity.GetNodeId();
 021    }
 22
 023    public ActivityNode(JsonObject activity, string port) : this(activity)
 24    {
 025        Port = port;
 026    }
 27
 28    /// <summary>
 29    /// Gets the activity.
 30    /// </summary>
 331    public JsonObject Activity { get; set; } = default!;
 32
 33    /// <summary>
 34    /// Gets the property name that contains the activity.
 35    /// </summary>
 136    public string? Port { get; set; }
 37
 38    /// <summary>
 39    /// Gets the node ID.
 40    /// </summary>
 141    public string NodeId { get; set; } = default!;
 42
 43    /// <summary>
 44    /// Gets the parents of this node.
 45    /// </summary>
 146    public ICollection<ActivityNode> Parents { get; set; } = new List<ActivityNode>();
 47
 48    /// <summary>
 49    /// Gets the children of this node.
 50    /// </summary>
 151    public ICollection<ActivityNode> Children { get; set; } = new List<ActivityNode>();
 52
 53    /// <summary>
 54    /// Gets the descendants of this node.
 55    /// </summary>
 56    /// <returns></returns>
 57    public IEnumerable<ActivityNode> Descendants()
 58    {
 059        foreach (var child in Children)
 60        {
 061            yield return child;
 62
 063            var descendants = child.Descendants();
 64
 065            foreach (var descendant in descendants)
 066                yield return descendant;
 067        }
 068    }
 69
 70    /// <summary>
 71    /// Gets the ancestors of this node.
 72    /// </summary>
 73    public IEnumerable<ActivityNode> Ancestors()
 74    {
 075        foreach (var parent in Parents)
 76        {
 077            yield return parent;
 78
 079            var ancestors = parent.Ancestors();
 80
 081            foreach (var ancestor in ancestors)
 082                yield return ancestor;
 083        }
 084    }
 85
 86    /// <summary>
 87    /// Gets the siblings of this node.
 88    /// </summary>
 089    public IEnumerable<ActivityNode> Siblings() => Parents.SelectMany(parent => parent.Children);
 90
 91    /// <summary>
 92    /// Gets the siblings and cousins of this node.
 93    /// </summary>
 94    /// <returns></returns>
 095    public IEnumerable<ActivityNode> SiblingsAndCousins() => Parents.SelectMany(parent => parent.Descendants());
 96}