< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.StorageDrivers.List.List
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/StorageDrivers/List/Endpoint.cs
Line coverage
40%
Covered lines: 6
Uncovered lines: 9
Coverable lines: 15
Total lines: 47
Line coverage: 40%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
ExecuteAsync(...)100%210%
FromDriver(...)0%7280%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/StorageDrivers/List/Endpoint.cs

#LineLine coverage
 1using System.ComponentModel;
 2using System.ComponentModel.DataAnnotations;
 3using System.Reflection;
 4using Elsa.Abstractions;
 5using Elsa.Extensions;
 6
 7namespace Elsa.Workflows.Api.Endpoints.StorageDrivers.List;
 8
 9/// <summary>
 10/// Returns a list of registered <see cref="IStorageDriver"/> implementations.
 11/// </summary>
 12public class List : ElsaEndpointWithoutRequest<Response>
 13{
 14    private readonly IStorageDriverManager _registry;
 15
 16    /// <inheritdoc />
 117    public List(IStorageDriverManager registry)
 18    {
 119        _registry = registry;
 120    }
 21
 22    /// <inheritdoc />
 23    public override void Configure()
 24    {
 125        Get("/descriptors/storage-drivers");
 126        ConfigurePermissions("read:*", "read:storage-drivers");
 127    }
 28
 29    /// <inheritdoc />
 30    public override Task<Response> ExecuteAsync(CancellationToken ct)
 31    {
 032        var drivers = _registry.List();
 033        var descriptors = drivers.Select(FromDriver).OrderByDescending(x => x.Priority).ToList();
 034        var response = new Response(descriptors);
 35
 036        return Task.FromResult(response);
 37    }
 38
 39    private static StorageDriverDescriptor FromDriver(IStorageDriver driver)
 40    {
 041        var type = driver.GetType();
 042        var deprecated = type.GetCustomAttribute<ObsoleteAttribute>() != null;
 043        var displayName = type.GetCustomAttribute<DisplayAttribute>()?.Name ?? type.GetCustomAttribute<DisplayNameAttrib
 044        var priority = driver.Priority;
 045        return new StorageDriverDescriptor(type.GetSimpleAssemblyQualifiedName(), displayName, priority, deprecated);
 46    }
 47}