< Summary

Information
Class: Elsa.Workflows.Pipelines.WorkflowExecution.WorkflowExecutionPipelineBuilder
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Pipelines/WorkflowExecution/WorkflowExecutionPipelineBuilder.cs
Line coverage
90%
Covered lines: 20
Uncovered lines: 2
Coverable lines: 22
Total lines: 71
Line coverage: 90.9%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
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_Properties()100%11100%
get_Components()100%11100%
get_ServiceProvider()100%11100%
set_ServiceProvider(...)100%11100%
Use(...)100%11100%
Build()100%44100%
Reset()100%11100%
Insert(...)100%210%
Replace(...)100%11100%
GetProperty(...)50%22100%
SetProperty(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Pipelines/WorkflowExecution/WorkflowExecutionPipelineBuilder.cs

#LineLine coverage
 1namespace Elsa.Workflows.Pipelines.WorkflowExecution;
 2
 3/// <inheritdoc />
 4public class WorkflowExecutionPipelineBuilder : IWorkflowExecutionPipelineBuilder
 5{
 6    private const string ServicesKey = "workflow-execution.Services";
 4257    private readonly IList<Func<WorkflowMiddlewareDelegate, WorkflowMiddlewareDelegate>> _components = new List<Func<Wor
 8
 9    /// <summary>
 10    /// Constructor.
 11    /// </summary>
 42512    public WorkflowExecutionPipelineBuilder(IServiceProvider serviceProvider)
 13    {
 42514        ServiceProvider = serviceProvider;
 42515    }
 16
 17    /// <inheritdoc />
 297518    public IDictionary<object, object?> Properties { get; } = new Dictionary<object, object?>();
 19
 20    /// <inheritdoc />
 421    public IEnumerable<Func<WorkflowMiddlewareDelegate, WorkflowMiddlewareDelegate>> Components => _components.ToList();
 22
 23    /// <inheritdoc />
 24    public IServiceProvider ServiceProvider
 25    {
 212526        get => GetProperty<IServiceProvider>(ServicesKey)!;
 42527        set => SetProperty(ServicesKey, value);
 28    }
 29
 30    /// <inheritdoc />
 31    public IWorkflowExecutionPipelineBuilder Use(Func<WorkflowMiddlewareDelegate, WorkflowMiddlewareDelegate> middleware
 32    {
 212533        _components.Add(middleware);
 212534        return this;
 35    }
 36
 37    /// <inheritdoc />
 38    public WorkflowMiddlewareDelegate Build()
 39    {
 86140        WorkflowMiddlewareDelegate pipeline = _ => new ValueTask();
 41
 510042        foreach (var component in _components.Reverse())
 212543            pipeline = component(pipeline);
 44
 42545        return pipeline;
 46    }
 47
 48    /// <inheritdoc />
 49    public IWorkflowExecutionPipelineBuilder Reset()
 50    {
 42551        _components.Clear();
 42552        return this;
 53    }
 54
 55    /// <inheritdoc />
 56    public IWorkflowExecutionPipelineBuilder Insert(int index, Func<WorkflowMiddlewareDelegate, WorkflowMiddlewareDelega
 57    {
 058        _components.Insert(index, middleware);
 059        return this;
 60    }
 61
 62    /// <inheritdoc />
 63    public IWorkflowExecutionPipelineBuilder Replace(int index, Func<WorkflowMiddlewareDelegate, WorkflowMiddlewareDeleg
 64    {
 465        _components[index] = middleware;
 466        return this;
 67    }
 68
 212569    private T? GetProperty<T>(string key) => Properties.TryGetValue(key, out var value) ? (T?)value : default(T);
 42570    private void SetProperty<T>(string key, T value) => Properties[key] = value;
 71}