< Summary

Information
Class: Elsa.Workflows.Activities.If
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/If.cs
Line coverage
85%
Covered lines: 18
Uncovered lines: 3
Coverable lines: 21
Total lines: 72
Line coverage: 85.7%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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%
.ctor(...)100%210%
.ctor(...)100%11100%
.ctor(...)100%11100%
get_Condition()100%11100%
get_Then()100%11100%
get_Else()100%11100%
ExecuteAsync()100%22100%
OnChildCompleted()100%11100%

File(s)

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

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2using Elsa.Expressions.Models;
 3using Elsa.Workflows.Attributes;
 4using Elsa.Workflows.Models;
 5using Elsa.Workflows.UIHints;
 6using JetBrains.Annotations;
 7
 8namespace Elsa.Workflows.Activities;
 9
 10/// <summary>
 11/// Evaluate a Boolean condition to determine which activity to execute next.
 12/// </summary>
 13[Activity("Elsa", "Branching", "Evaluate a Boolean condition to determine which activity to execute next.")]
 14[PublicAPI]
 15public class If : Activity<bool>
 16{
 17    /// <inheritdoc />
 4818    public If([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
 19    {
 4820    }
 21
 22    /// <inheritdoc />
 023    public If(Input<bool> condition, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : this
 24    {
 025        Condition = condition;
 026    }
 27
 28    /// <inheritdoc />
 2129    public If(Func<ExpressionExecutionContext, bool> condition, [CallerFilePath] string? source = null, [CallerLineNumbe
 30    {
 2131        Condition = new Input<bool>(condition);
 2132    }
 33
 34    /// <inheritdoc />
 2335    public If(Func<bool> condition, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : this(
 36    {
 2337        Condition = new Input<bool>(condition);
 2338    }
 39
 40    /// <summary>
 41    /// The condition to evaluate.
 42    /// </summary>
 43    [Input(UIHint = InputUIHints.SingleLine)]
 24444    public Input<bool> Condition { get; set; } = new(new Literal<bool>(false));
 45
 46    /// <summary>
 47    /// The activity to execute when the condition evaluates to true.
 48    /// </summary>
 49    [Port]
 13950    public IActivity? Then { get; set; }
 51
 52    /// <summary>
 53    /// The activity to execute when the condition evaluates to false.
 54    /// </summary>
 55    [Port]
 13456    public IActivity? Else { get; set; }
 57
 58    /// <inheritdoc />
 59    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
 60    {
 3861        var result = context.Get(Condition);
 3862        var nextActivity = result ? Then : Else;
 63
 3864        context.Set(Result, result);
 3865        await context.ScheduleActivityAsync(nextActivity, OnChildCompleted);
 3866    }
 67
 68    private async ValueTask OnChildCompleted(ActivityCompletedContext context)
 69    {
 1770        await context.TargetContext.CompleteActivityAsync();
 1771    }
 72}