< Summary

Information
Class: Elsa.Workflows.Activities.Container
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Container.cs
Line coverage
81%
Covered lines: 13
Uncovered lines: 3
Coverable lines: 16
Total lines: 63
Line coverage: 81.2%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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%
get_Activities()100%11100%
get_Variables()100%11100%
ExecuteAsync()100%11100%
EnsureNames(...)100%44100%
ScheduleChildrenAsync(...)100%210%
ScheduleChildren(...)100%210%

File(s)

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

#LineLine coverage
 1using System.Collections.ObjectModel;
 2using Elsa.Workflows.Memory;
 3
 4namespace Elsa.Workflows.Activities;
 5
 6/// <summary>
 7/// A base class for activities that control a collection of activities.
 8/// </summary>
 9public abstract class Container : Activity, IVariableContainer
 10{
 11    /// <inheritdoc />
 524412    protected Container(string? source = null, int? line = null) : base(source, line)
 13    {
 524414    }
 15
 16    /// <summary>
 17    /// The <see cref="IActivity"/>s to execute.
 18    /// </summary>
 1855119    public ICollection<IActivity> Activities { get; set; } = new List<IActivity>();
 20
 21    /// <summary>
 22    /// The variables available to this scope.
 23    /// </summary>
 1473324    public ICollection<Variable> Variables { get; set; } = new Collection<Variable>();
 25
 26    /// <inheritdoc />
 27    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
 28    {
 29        // Ensure variables have names.
 83230        EnsureNames(Variables);
 31
 32        // Register variables.
 83233        context.ExpressionExecutionContext.Memory.Declare(Variables);
 34
 35        // Schedule children.
 83236        await ScheduleChildrenAsync(context);
 83237    }
 38
 39    private void EnsureNames(IEnumerable<Variable> variables)
 40    {
 83241        var count = 0;
 42
 172843        foreach (var variable in variables)
 3244            if (string.IsNullOrWhiteSpace(variable.Name))
 2245                variable.Name = $"Variable{++count}";
 83246    }
 47
 48    /// <summary>
 49    /// Schedule the <see cref="Activities"/> for execution.
 50    /// </summary>
 51    protected virtual ValueTask ScheduleChildrenAsync(ActivityExecutionContext context)
 52    {
 053        ScheduleChildren(context);
 054        return ValueTask.CompletedTask;
 55    }
 56
 57    /// <summary>
 58    /// Schedule the <see cref="Activities"/> for execution.
 59    /// </summary>
 60    protected virtual void ScheduleChildren(ActivityExecutionContext context)
 61    {
 062    }
 63}