< 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
58%
Covered lines: 7
Uncovered lines: 5
Coverable lines: 12
Total lines: 44
Line coverage: 58.3%
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%210%
OnBreak(...)100%11100%
CancelDescendantsAsync()100%210%

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>
 12816    public BreakBehavior(IActivity owner) : base(owner)
 17    {
 12818        OnSignalReceived<BreakSignal>(OnBreak);
 12819        OnSignalReceived<CompleteCompositeSignal>(OnCompleteCompositeAsync);
 12820    }
 21
 22    private async ValueTask OnCompleteCompositeAsync(CompleteCompositeSignal signal, SignalContext context)
 23    {
 24        // Cancel each descendant to clear bookmarks and cancel jobs etc.
 025        await CancelDescendantsAsync(context);
 26
 27        // Mark this activity as completed.
 028        await context.ReceiverActivityExecutionContext.CompleteActivityAsync();
 029    }
 30
 31    private void OnBreak(BreakSignal signal, SignalContext context)
 32    {
 33        // Prevent bubbling.
 134        context.StopPropagation();
 35
 36        // Set the IsBreaking property to true.
 137        context.ReceiverActivityExecutionContext.SetProperty("IsBreaking", true);
 138    }
 39
 40    private async Task CancelDescendantsAsync(SignalContext context)
 41    {
 042        await context.ReceiverActivityExecutionContext.CancelActivityAsync();
 043    }
 44}