< Summary

Information
Class: Elsa.Workflows.Activities.Sequence
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Sequence.cs
Line coverage
93%
Covered lines: 28
Uncovered lines: 2
Coverable lines: 30
Total lines: 75
Line coverage: 93.3%
Branch coverage
100%
Covered branches: 8
Total branches: 8
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%
ScheduleChildrenAsync()100%11100%
HandleItemAsync()100%44100%
OnChildCompleted()100%44100%
OnBreakSignalReceived(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Sequence.cs

#LineLine coverage
 1using System.ComponentModel;
 2using System.Runtime.CompilerServices;
 3using Elsa.Workflows.Attributes;
 4using Elsa.Workflows.Options;
 5using Elsa.Workflows.Signals;
 6using JetBrains.Annotations;
 7
 8namespace Elsa.Workflows.Activities;
 9
 10/// <summary>
 11/// Execute a set of activities in sequence.
 12/// </summary>
 13[Category("Workflows")]
 14[Activity("Elsa", "Workflows", "Execute a set of activities in sequence.")]
 15[PublicAPI]
 16[Browsable(false)]
 17public class Sequence : Container
 18{
 19    private const string CurrentIndexProperty = "CurrentIndex";
 20
 21    /// <inheritdoc />
 1008722    public Sequence([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
 23    {
 1008724        OnSignalReceived<BreakSignal>(OnBreakSignalReceived);
 1008725    }
 26
 27    /// <inheritdoc />
 28    protected override async ValueTask ScheduleChildrenAsync(ActivityExecutionContext context)
 29    {
 16630        await HandleItemAsync(context);
 16631    }
 32
 33    private async ValueTask HandleItemAsync(ActivityExecutionContext context, ActivityExecutionContext? completedChildCo
 34    {
 45135        var currentIndex = context.GetProperty<int>(CurrentIndexProperty);
 45136        var childActivities = Activities.ToList();
 37
 45138        if (currentIndex >= childActivities.Count)
 39        {
 12140            await context.CompleteActivityAsync();
 12141            return;
 42        }
 43
 33044        var nextActivity = childActivities.ElementAt(currentIndex);
 33045        var options = new ScheduleWorkOptions
 33046        {
 33047            CompletionCallback = OnChildCompleted,
 33048            SchedulingActivityExecutionId = completedChildContext?.Id
 33049        };
 33050        await context.ScheduleActivityAsync(nextActivity, options);
 66051        context.UpdateProperty<int>(CurrentIndexProperty, x => x + 1);
 45152    }
 53
 54    private async ValueTask OnChildCompleted(ActivityCompletedContext context)
 55    {
 29656        var targetContext = context.TargetContext;
 29657        var childContext = context.ChildContext;
 29658        var isBreaking = targetContext.GetIsBreaking();
 29659        var completedActivity = childContext.Activity;
 60
 61        // If the complete activity is a terminal node, complete the sequence immediately.
 29662        if (isBreaking || completedActivity is ITerminalNode)
 63        {
 1164            await targetContext.CompleteActivityAsync();
 1165            return;
 66        }
 67
 28568        await HandleItemAsync(targetContext, childContext);
 29669    }
 70
 71    private void OnBreakSignalReceived(BreakSignal signal, SignalContext signalContext)
 72    {
 073        signalContext.ReceiverActivityExecutionContext.SetIsBreaking();
 074    }
 75}