< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.IncidentStrategies.List.List
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/IncidentStrategies/List/Endpoint.cs
Line coverage
57%
Covered lines: 4
Uncovered lines: 3
Coverable lines: 7
Total lines: 43
Line coverage: 57.1%
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/IncidentStrategies/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 Humanizer;
 8
 9namespace Elsa.Workflows.Api.Endpoints.IncidentStrategies.List;
 10
 11/// <summary>
 12/// Returns list of available <see cref="IIncidentStrategy" /> implementations.
 13/// </summary>
 114internal class List(IEnumerable<IIncidentStrategy> strategies) : ElsaEndpointWithoutRequest<ListResponse<IncidentStrateg
 15{
 16    public override void Configure()
 17    {
 118        Get("/descriptors/incident-strategies");
 119        ConfigurePermissions("read:incident-strategies");
 120    }
 21
 22    public override Task<ListResponse<IncidentStrategyDescriptor>> ExecuteAsync(CancellationToken cancellationToken)
 23    {
 024        var descriptors = strategies.Select(IncidentStrategyDescriptor.FromStrategy).OrderBy(x => x.DisplayName).ToList(
 025        var response =new ListResponse<IncidentStrategyDescriptor>(descriptors);
 026        return Task.FromResult(response);
 27    }
 28}
 29
 30internal record IncidentStrategyDescriptor(string DisplayName, string Description, string TypeName)
 31{
 32    public static IncidentStrategyDescriptor FromStrategy(IIncidentStrategy strategy)
 33    {
 34        var type = strategy.GetType();
 35        var displayNameAttribute = type.GetCustomAttribute<DisplayNameAttribute>();
 36        var descriptionAttribute = type.GetCustomAttribute<DescriptionAttribute>();
 37        var displayAttribute = type.GetCustomAttribute<DisplayAttribute>();
 38        var displayName = displayNameAttribute?.DisplayName ?? displayAttribute?.Name ?? type.Name.Replace("Strategy", "
 39        var description = descriptionAttribute?.Description ?? displayAttribute?.Description ?? "";
 40
 41        return new IncidentStrategyDescriptor(displayName, description, type.GetSimpleAssemblyQualifiedName());
 42    }
 43}