< Summary

Information
Class: Elsa.Mediator.Middleware.Command.CommandPipelineBuilder
Assembly: Elsa.Mediator
File(s): /home/runner/work/elsa-core/elsa-core/src/common/Elsa.Mediator/Middleware/Command/CommandPipelineBuilder.cs
Line coverage
65%
Covered lines: 15
Uncovered lines: 8
Coverable lines: 23
Total lines: 77
Line coverage: 65.2%
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_ApplicationServices()100%11100%
set_ApplicationServices(...)100%11100%
Use(...)100%11100%
Use(...)100%210%
Remove(...)100%210%
RemoveAt(...)100%210%
Clear()100%210%
Build()100%44100%
GetProperty(...)50%22100%
SetProperty(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/common/Elsa.Mediator/Middleware/Command/CommandPipelineBuilder.cs

#LineLine coverage
 1using Elsa.Mediator.Middleware.Command.Contracts;
 2
 3namespace Elsa.Mediator.Middleware.Command;
 4
 5/// <inheritdoc />
 6public class CommandPipelineBuilder : ICommandPipelineBuilder
 7{
 8    private const string ServicesKey = "mediator.Services";
 19    private readonly List<Func<CommandMiddlewareDelegate, CommandMiddlewareDelegate>> _components = new();
 10
 11    /// <summary>
 12    /// Initializes a new instance of the <see cref="CommandPipelineBuilder"/> class.
 13    /// </summary>
 114    public CommandPipelineBuilder(IServiceProvider serviceProvider)
 15    {
 116        ApplicationServices = serviceProvider;
 117    }
 18
 19    /// <inheritdoc />
 420    public IDictionary<string, object?> Properties { get; } = new Dictionary<string, object?>();
 21
 22    /// <inheritdoc />
 23    public IServiceProvider ApplicationServices
 24    {
 225        get => GetProperty<IServiceProvider>(ServicesKey)!;
 126        set => SetProperty(ServicesKey, value);
 27    }
 28
 29    /// <inheritdoc />
 30    public ICommandPipelineBuilder Use(Func<CommandMiddlewareDelegate, CommandMiddlewareDelegate> middleware)
 31    {
 232        _components.Add(middleware);
 233        return this;
 34    }
 35
 36    /// <inheritdoc />
 37    public ICommandPipelineBuilder Use(int index, Func<CommandMiddlewareDelegate, CommandMiddlewareDelegate> middleware)
 38    {
 039        _components.Insert(index, middleware);
 040        return this;
 41    }
 42
 43    /// <inheritdoc />
 44    public ICommandPipelineBuilder Remove(Func<CommandMiddlewareDelegate, CommandMiddlewareDelegate> middleware)
 45    {
 046        _components.Remove(middleware);
 047        return this;
 48    }
 49
 50    /// <inheritdoc />
 51    public ICommandPipelineBuilder RemoveAt(int index)
 52    {
 053        _components.RemoveAt(index);
 054        return this;
 55    }
 56
 57    /// <inheritdoc />
 58    public ICommandPipelineBuilder Clear()
 59    {
 060        _components.Clear();
 061        return this;
 62    }
 63
 64    /// <inheritdoc />
 65    public CommandMiddlewareDelegate Build()
 66    {
 5667        CommandMiddlewareDelegate pipeline = _ => new();
 68
 669        for (var i = _components.Count - 1; i >= 0; i--)
 270            pipeline = _components[i](pipeline);
 71
 172        return pipeline;
 73    }
 74
 275    private T? GetProperty<T>(string key) => Properties.TryGetValue(key, out var value) ? (T?)value : default;
 176    private void SetProperty<T>(string key, T value) => Properties[key] = value;
 77}