< Summary

Information
Class: Elsa.Workflows.Management.Models.WorkflowReferenceGraph
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Models/WorkflowReferenceGraph.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 95
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
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_RootDefinitionIds()100%11100%
get_Edges()100%11100%
get_AllDefinitionIds()100%11100%
get_ConsumerDefinitionIds()100%11100%
get_OutboundEdges()100%11100%
get_InboundEdges()100%11100%
GetDependencies(...)100%11100%
GetConsumers(...)100%11100%
ComputeAllDefinitionIds(...)100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Models/WorkflowReferenceGraph.cs

#LineLine coverage
 1namespace Elsa.Workflows.Management.Models;
 2
 3/// <summary>
 4/// Represents a single directed edge in the workflow reference graph.
 5/// The edge points from a consumer workflow (Source) to the workflow it references (Target).
 6/// </summary>
 7/// <param name="Source">The workflow definition ID of the consumer (the workflow that contains the reference).</param>
 8/// <param name="Target">The workflow definition ID being referenced (the dependency).</param>
 9public record WorkflowReferenceEdge(string Source, string Target);
 10
 11/// <summary>
 12/// Represents a complete graph of workflow references, built by recursively traversing all consumers
 13/// of a given workflow definition.
 14/// </summary>
 15public class WorkflowReferenceGraph
 16{
 17    /// <summary>
 18    /// Creates a new instance of the <see cref="WorkflowReferenceGraph"/> class.
 19    /// </summary>
 20    /// <param name="rootDefinitionIds">The IDs of the root workflow definitions from which the graph was built.</param>
 21    /// <param name="edges">The collection of edges representing all reference relationships in the graph.</param>
 1822    public WorkflowReferenceGraph(IReadOnlyCollection<string> rootDefinitionIds, IReadOnlyCollection<WorkflowReferenceEd
 23    {
 1824        RootDefinitionIds = rootDefinitionIds;
 1825        Edges = edges;
 26
 27        // Pre-compute useful lookups
 1828        AllDefinitionIds = ComputeAllDefinitionIds(edges, rootDefinitionIds);
 1829        ConsumerDefinitionIds = AllDefinitionIds.Except(rootDefinitionIds).ToHashSet();
 30
 31        // Outbound: Source → Targets (what does this workflow depend on?)
 8432        OutboundEdges = edges.ToLookup(e => e.Source, e => e.Target);
 33
 34        // Inbound: Target → Sources (what workflows consume this one?)
 8435        InboundEdges = edges.ToLookup(e => e.Target, e => e.Source);
 1836    }
 37
 38    /// <summary>
 39    /// The IDs of the root workflow definitions from which the graph was built.
 40    /// </summary>
 641    public IReadOnlyCollection<string> RootDefinitionIds { get; }
 42
 43    /// <summary>
 44    /// The collection of edges representing all reference relationships in the graph.
 45    /// Each edge represents a single Source → Target relationship.
 46    /// </summary>
 3347    public IReadOnlyCollection<WorkflowReferenceEdge> Edges { get; }
 48
 49    /// <summary>
 50    /// All workflow definition IDs in the graph, including the roots and all consumers.
 51    /// </summary>
 1952    public IReadOnlySet<string> AllDefinitionIds { get; }
 53
 54    /// <summary>
 55    /// All workflow definition IDs that consume (directly or indirectly) the root workflow definitions.
 56    /// Does not include the roots themselves.
 57    /// </summary>
 1858    public IReadOnlySet<string> ConsumerDefinitionIds { get; }
 59
 60    /// <summary>
 61    /// A lookup that maps each workflow definition ID to the IDs of workflows it depends on (references).
 62    /// Use this to find: "What workflows does X reference?"
 63    /// </summary>
 264    public ILookup<string, string> OutboundEdges { get; }
 65
 66    /// <summary>
 67    /// A lookup that maps each workflow definition ID to the IDs of workflows that reference it.
 68    /// Use this to find: "What workflows consume X?"
 69    /// </summary>
 170    public ILookup<string, string> InboundEdges { get; }
 71
 72    /// <summary>
 73    /// Gets all workflow definition IDs that the specified workflow depends on (references).
 74    /// </summary>
 175    public IEnumerable<string> GetDependencies(string definitionId) => OutboundEdges[definitionId];
 76
 77    /// <summary>
 78    /// Gets all workflow definition IDs that reference (consume) the specified workflow.
 79    /// </summary>
 180    public IEnumerable<string> GetConsumers(string definitionId) => InboundEdges[definitionId];
 81
 82    private static HashSet<string> ComputeAllDefinitionIds(IReadOnlyCollection<WorkflowReferenceEdge> edges, IReadOnlyCo
 83    {
 1884        var ids = new HashSet<string>(rootDefinitionIds);
 85
 10286        foreach (var edge in edges)
 87        {
 3388            ids.Add(edge.Source);
 3389            ids.Add(edge.Target);
 90        }
 91
 1892        return ids;
 93    }
 94}
 95