< Summary

Information
Class: Elsa.Workflows.StackBasedActivityScheduler
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/StackBasedActivityScheduler.cs
Line coverage
75%
Covered lines: 12
Uncovered lines: 4
Coverable lines: 16
Total lines: 52
Line coverage: 75%
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_HasAny()100%11100%
Schedule(...)100%11100%
Take()100%11100%
List()100%210%
Any(...)100%210%
Find(...)100%210%
RemoveWhere(...)100%44100%
Clear()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/StackBasedActivityScheduler.cs

#LineLine coverage
 1using Elsa.Workflows.Models;
 2using JetBrains.Annotations;
 3
 4namespace Elsa.Workflows;
 5
 6/// <summary>
 7/// A LIFO stack based activity scheduler.
 8/// </summary>
 9[PublicAPI]
 10public class StackBasedActivityScheduler : IActivityScheduler
 11{
 512    private readonly Stack<ActivityWorkItem> _stack = new();
 13
 14    /// <inheritdoc />
 1515    public bool HasAny => _stack.Any();
 16
 17    /// <inheritdoc />
 1518    public void Schedule(ActivityWorkItem activity) => _stack.Push(activity);
 19
 20    /// <inheritdoc />
 1021    public ActivityWorkItem Take() => _stack.Pop();
 22
 23    /// <inheritdoc />
 024    public IEnumerable<ActivityWorkItem> List() => _stack.ToList();
 25
 26    /// <inheritdoc />
 027    public bool Any(Func<ActivityWorkItem, bool> predicate) => _stack.Any(predicate);
 28
 29    /// <inheritdoc />
 030    public ActivityWorkItem? Find(Func<ActivityWorkItem, bool> predicate) => _stack.FirstOrDefault(predicate);
 31
 32    /// <inheritdoc />
 33    public int RemoveWhere(Func<ActivityWorkItem, bool> predicate)
 34    {
 35        // The stack enumerates top-first, so what survives has to be pushed back in reverse to keep the same top.
 1336        var remaining = _stack.Where(x => !predicate(x)).ToList();
 337        var removedCount = _stack.Count - remaining.Count;
 38
 339        if (removedCount == 0)
 140            return 0;
 41
 242        _stack.Clear();
 43
 844        for (var i = remaining.Count - 1; i >= 0; i--)
 245            _stack.Push(remaining[i]);
 46
 247        return removedCount;
 48    }
 49
 50    /// <inheritdoc />
 051    public void Clear() => _stack.Clear();
 52}