< 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
92%
Covered lines: 23
Uncovered lines: 2
Coverable lines: 25
Total lines: 69
Line coverage: 92%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%22100%
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.Signals;
 5using JetBrains.Annotations;
 6
 7namespace Elsa.Workflows.Activities;
 8
 9/// <summary>
 10/// Execute a set of activities in sequence.
 11/// </summary>
 12[Category("Workflows")]
 13[Activity("Elsa", "Workflows", "Execute a set of activities in sequence.")]
 14[PublicAPI]
 15[Browsable(false)]
 16public class Sequence : Container
 17{
 18    private const string CurrentIndexProperty = "CurrentIndex";
 19
 20    /// <inheritdoc />
 424921    public Sequence([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
 22    {
 424923        OnSignalReceived<BreakSignal>(OnBreakSignalReceived);
 424924    }
 25
 26    /// <inheritdoc />
 27    protected override async ValueTask ScheduleChildrenAsync(ActivityExecutionContext context)
 28    {
 15529        await HandleItemAsync(context);
 15530    }
 31
 32    private async ValueTask HandleItemAsync(ActivityExecutionContext context)
 33    {
 41834        var currentIndex = context.GetProperty<int>(CurrentIndexProperty);
 41835        var childActivities = Activities.ToList();
 36
 41837        if (currentIndex >= childActivities.Count)
 38        {
 11639            await context.CompleteActivityAsync();
 11640            return;
 41        }
 42
 30243        var nextActivity = childActivities.ElementAt(currentIndex);
 30244        await context.ScheduleActivityAsync(nextActivity, OnChildCompleted);
 60445        context.UpdateProperty<int>(CurrentIndexProperty, x => x + 1);
 41846    }
 47
 48    private async ValueTask OnChildCompleted(ActivityCompletedContext context)
 49    {
 27550        var targetContext = context.TargetContext;
 27551        var childContext = context.ChildContext;
 27552        var isBreaking = targetContext.GetIsBreaking();
 27553        var completedActivity = childContext.Activity;
 54
 55        // If the complete activity is a terminal node, complete the sequence immediately.
 27556        if (isBreaking || completedActivity is ITerminalNode)
 57        {
 1258            await targetContext.CompleteActivityAsync();
 1259            return;
 60        }
 61
 26362        await HandleItemAsync(targetContext);
 27563    }
 64
 65    private void OnBreakSignalReceived(BreakSignal signal, SignalContext signalContext)
 66    {
 067        signalContext.ReceiverActivityExecutionContext.SetIsBreaking();
 068    }
 69}