< Summary

Information
Class: Elsa.Workflows.Behaviors.BreakBehavior
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Behaviors/BreakBehavior.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 46
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
OnCompleteCompositeAsync()100%11100%
OnBreak(...)100%11100%
CancelDescendantsAsync()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Behaviors/BreakBehavior.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Workflows.Activities;
 3using Elsa.Workflows.Signals;
 4
 5namespace Elsa.Workflows.Behaviors;
 6
 7/// <summary>
 8/// Implements a "break" behavior that handles the <see cref="BreakSignal"/> signal.
 9/// Stops propagation of the signal, which is useful for looping activities such as <see cref="While"/>, <see cref="For"
 10/// </summary>
 11public class BreakBehavior : Behavior
 12{
 13    /// <summary>
 14    /// Constructor.
 15    /// </summary>
 24316    public BreakBehavior(IActivity owner) : base(owner)
 17    {
 24318        OnSignalReceived<BreakSignal>(OnBreak);
 24319        OnSignalReceived<CompleteCompositeSignal>(OnCompleteCompositeAsync);
 24320    }
 21
 22    private async ValueTask OnCompleteCompositeAsync(CompleteCompositeSignal signal, SignalContext context)
 23    {
 124        context.ReceiverActivityExecutionContext.SetIsBreaking();
 25
 26        // Cancel each descendant to clear bookmarks and cancel jobs etc.
 127        await CancelDescendantsAsync(context);
 28
 29        // Mark this activity as completed.
 130        await context.ReceiverActivityExecutionContext.CompleteActivityAsync();
 131    }
 32
 33    private void OnBreak(BreakSignal signal, SignalContext context)
 34    {
 35        // Prevent bubbling.
 136        context.StopPropagation();
 37
 38        // Set the IsBreaking property to true.
 139        context.ReceiverActivityExecutionContext.SetIsBreaking();
 140    }
 41
 42    private async Task CancelDescendantsAsync(SignalContext context)
 43    {
 144        await context.ReceiverActivityExecutionContext.CancelActivityAsync();
 145    }
 46}