< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.LogPersistenceStrategies.List.Endpoint
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/LogPersistenceStrategies/List/Endpoint.cs
Line coverage
50%
Covered lines: 4
Uncovered lines: 4
Coverable lines: 8
Total lines: 45
Line coverage: 50%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
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%

File(s)

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

#LineLine coverage
 1using System.ComponentModel;
 2using System.ComponentModel.DataAnnotations;
 3using System.Reflection;
 4using Elsa.Abstractions;
 5using Elsa.Extensions;
 6using Elsa.Models;
 7using Elsa.Workflows.LogPersistence;
 8using Humanizer;
 9
 10namespace Elsa.Workflows.Api.Endpoints.LogPersistenceStrategies.List;
 11
 12/// <summary>
 13/// Returns list of available <see cref="ILogPersistenceStrategy" /> implementations.
 14/// </summary>
 115internal class Endpoint(ILogPersistenceStrategyService logPersistenceStrategyService) : ElsaEndpointWithoutRequest<ListR
 16{
 17    public override void Configure()
 18    {
 119        Get("/descriptors/log-persistence-strategies");
 120        ConfigurePermissions("read:log-persistence-strategies");
 121    }
 22
 23    public override Task<ListResponse<LogPersistenceStrategyDescriptor>> ExecuteAsync(CancellationToken cancellationToke
 24    {
 025        var strategies = logPersistenceStrategyService.ListStrategies();
 026        var descriptors = strategies.Select(LogPersistenceStrategyDescriptor.FromStrategy).OrderBy(x => x.DisplayName).T
 027        var response =new ListResponse<LogPersistenceStrategyDescriptor>(descriptors);
 028        return Task.FromResult(response);
 29    }
 30}
 31
 32internal record LogPersistenceStrategyDescriptor(string DisplayName, string Description, string TypeName)
 33{
 34    public static LogPersistenceStrategyDescriptor FromStrategy(ILogPersistenceStrategy strategy)
 35    {
 36        var type = strategy.GetType();
 37        var displayNameAttribute = type.GetCustomAttribute<DisplayNameAttribute>();
 38        var descriptionAttribute = type.GetCustomAttribute<DescriptionAttribute>();
 39        var displayAttribute = type.GetCustomAttribute<DisplayAttribute>();
 40        var displayName = displayNameAttribute?.DisplayName ?? displayAttribute?.Name ?? type.Name.Replace("Strategy", "
 41        var description = descriptionAttribute?.Description ?? displayAttribute?.Description ?? "";
 42
 43        return new LogPersistenceStrategyDescriptor(displayName, description, type.GetSimpleAssemblyQualifiedName());
 44    }
 45}