< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.LogPersistenceStrategies.List.LogPersistenceStrategyDescriptor
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
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 45
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_DisplayName()100%210%
FromStrategy(...)0%272160%

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>
 15internal class Endpoint(ILogPersistenceStrategyService logPersistenceStrategyService) : ElsaEndpointWithoutRequest<ListR
 16{
 17    public override void Configure()
 18    {
 19        Get("/descriptors/log-persistence-strategies");
 20        ConfigurePermissions("read:log-persistence-strategies");
 21    }
 22
 23    public override Task<ListResponse<LogPersistenceStrategyDescriptor>> ExecuteAsync(CancellationToken cancellationToke
 24    {
 25        var strategies = logPersistenceStrategyService.ListStrategies();
 26        var descriptors = strategies.Select(LogPersistenceStrategyDescriptor.FromStrategy).OrderBy(x => x.DisplayName).T
 27        var response =new ListResponse<LogPersistenceStrategyDescriptor>(descriptors);
 28        return Task.FromResult(response);
 29    }
 30}
 31
 032internal record LogPersistenceStrategyDescriptor(string DisplayName, string Description, string TypeName)
 33{
 34    public static LogPersistenceStrategyDescriptor FromStrategy(ILogPersistenceStrategy strategy)
 35    {
 036        var type = strategy.GetType();
 037        var displayNameAttribute = type.GetCustomAttribute<DisplayNameAttribute>();
 038        var descriptionAttribute = type.GetCustomAttribute<DescriptionAttribute>();
 039        var displayAttribute = type.GetCustomAttribute<DisplayAttribute>();
 040        var displayName = displayNameAttribute?.DisplayName ?? displayAttribute?.Name ?? type.Name.Replace("Strategy", "
 041        var description = descriptionAttribute?.Description ?? displayAttribute?.Description ?? "";
 42
 043        return new LogPersistenceStrategyDescriptor(displayName, description, type.GetSimpleAssemblyQualifiedName());
 44    }
 45}