< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowActivationStrategies.List.WorkflowActivationStrategyDescriptor
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowActivationStrategies/List/Endpoint.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 43
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/WorkflowActivationStrategies/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.WorkflowActivationStrategies.List;
 10
 11/// <summary>
 12/// Returns list of available <see cref="IWorkflowActivationStrategy" /> implementations.
 13/// </summary>
 14internal class List(IEnumerable<IWorkflowActivationStrategy> strategies) : ElsaEndpointWithoutRequest<ListResponse<Workf
 15{
 16    public override void Configure()
 17    {
 18        Get("/descriptors/workflow-activation-strategies");
 19        ConfigurePermissions("read:workflow-activation-strategies");
 20    }
 21
 22    public override Task<ListResponse<WorkflowActivationStrategyDescriptor>> ExecuteAsync(CancellationToken cancellation
 23    {
 24        var descriptors = strategies.Select(WorkflowActivationStrategyDescriptor.FromStrategy).OrderBy(x => x.DisplayNam
 25        var response =new ListResponse<WorkflowActivationStrategyDescriptor>(descriptors);
 26        return Task.FromResult(response);
 27    }
 28}
 29
 030internal record WorkflowActivationStrategyDescriptor(string DisplayName, string Description, string TypeName)
 31{
 32    public static WorkflowActivationStrategyDescriptor FromStrategy(IWorkflowActivationStrategy strategy)
 33    {
 034        var type = strategy.GetType();
 035        var displayNameAttribute = type.GetCustomAttribute<DisplayNameAttribute>();
 036        var descriptionAttribute = type.GetCustomAttribute<DescriptionAttribute>();
 037        var displayAttribute = type.GetCustomAttribute<DisplayAttribute>();
 038        var displayName = displayNameAttribute?.DisplayName ?? displayAttribute?.Name ?? type.Name.Replace("Strategy", "
 039        var description = descriptionAttribute?.Description ?? displayAttribute?.Description ?? "";
 40
 041        return new WorkflowActivationStrategyDescriptor(displayName, description, type.GetSimpleAssemblyQualifiedName())
 42    }
 43}