< 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 />
 403121    public Sequence([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
 22    {
 403123        OnSignalReceived<BreakSignal>(OnBreakSignalReceived);
 403124    }
 25
 26    /// <inheritdoc />
 27    protected override async ValueTask ScheduleChildrenAsync(ActivityExecutionContext context)
 28    {
 10629        await HandleItemAsync(context);
 10630    }
 31
 32    private async ValueTask HandleItemAsync(ActivityExecutionContext context)
 33    {
 26934        var currentIndex = context.GetProperty<int>(CurrentIndexProperty);
 26935        var childActivities = Activities.ToList();
 36
 26937        if (currentIndex >= childActivities.Count)
 38        {
 6839            await context.CompleteActivityAsync();
 6840            return;
 41        }
 42
 20143        var nextActivity = childActivities.ElementAt(currentIndex);
 20144        await context.ScheduleActivityAsync(nextActivity, OnChildCompleted);
 40245        context.UpdateProperty<int>(CurrentIndexProperty, x => x + 1);
 26946    }
 47
 48    private async ValueTask OnChildCompleted(ActivityCompletedContext context)
 49    {
 17550        var targetContext = context.TargetContext;
 17551        var childContext = context.ChildContext;
 17552        var isBreaking = targetContext.GetIsBreaking();
 17553        var completedActivity = childContext.Activity;
 54
 55        // If the complete activity is a terminal node, complete the sequence immediately.
 17556        if (isBreaking || completedActivity is ITerminalNode)
 57        {
 1258            await targetContext.CompleteActivityAsync();
 1259            return;
 60        }
 61
 16362        await HandleItemAsync(targetContext);
 17563    }
 64
 65    private void OnBreakSignalReceived(BreakSignal signal, SignalContext signalContext)
 66    {
 067        signalContext.ReceiverActivityExecutionContext.SetIsBreaking();
 068    }
 69}