< Summary

Information
Class: Elsa.Mediator.Middleware.Notification.NotificationPipelineBuilder
Assembly: Elsa.Mediator
File(s): /home/runner/work/elsa-core/elsa-core/src/common/Elsa.Mediator/Middleware/Notification/NotificationPipelineBuilder.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 51
Line coverage: 100%
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%
Build()100%44100%
GetProperty(...)50%22100%
SetProperty(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/common/Elsa.Mediator/Middleware/Notification/NotificationPipelineBuilder.cs

#LineLine coverage
 1using Elsa.Mediator.Middleware.Notification.Contracts;
 2
 3namespace Elsa.Mediator.Middleware.Notification;
 4
 5/// <inheritdoc />
 6public class NotificationPipelineBuilder : INotificationPipelineBuilder
 7{
 8    private const string ServicesKey = "mediator.Services";
 19    private readonly List<Func<NotificationMiddlewareDelegate, NotificationMiddlewareDelegate>> _components = new();
 10
 11    /// <summary>
 12    /// Initializes a new instance of the <see cref="NotificationPipelineBuilder"/> class.
 13    /// </summary>
 114    public NotificationPipelineBuilder(IServiceProvider serviceProvider)
 15    {
 116        ApplicationServices = serviceProvider;
 117    }
 18
 19    /// <inheritdoc />
 320    public IDictionary<string, object?> Properties { get; } = new Dictionary<string, object?>();
 21
 22    /// <inheritdoc />
 23    public IServiceProvider ApplicationServices
 24    {
 125        get => GetProperty<IServiceProvider>(ServicesKey)!;
 126        set => SetProperty(ServicesKey, value);
 27    }
 28
 29    /// <inheritdoc />
 30    public INotificationPipelineBuilder Use(Func<NotificationMiddlewareDelegate, NotificationMiddlewareDelegate> middlew
 31    {
 132        _components.Add(middleware);
 133        return this;
 34    }
 35
 36    /// <inheritdoc />
 37    public NotificationMiddlewareDelegate Build()
 38    {
 1131739        NotificationMiddlewareDelegate pipeline = _ => new ValueTask();
 40
 441        for (int i = _components.Count - 1; i >= 0; i--)
 42        {
 143            pipeline = _components[i](pipeline);
 44        }
 45
 146        return pipeline;
 47    }
 48
 149    private T? GetProperty<T>(string key) => Properties.TryGetValue(key, out var value) ? (T?)value : default(T);
 150    private void SetProperty<T>(string key, T value) => Properties[key] = value;
 51}