< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowActivationStrategies.List.List
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
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/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>
 114internal class List(IEnumerable<IWorkflowActivationStrategy> strategies) : ElsaEndpointWithoutRequest<ListResponse<Workf
 15{
 16    public override void Configure()
 17    {
 118        Get("/descriptors/workflow-activation-strategies");
 119        ConfigurePermissions("read:workflow-activation-strategies");
 120    }
 21
 22    public override Task<ListResponse<WorkflowActivationStrategyDescriptor>> ExecuteAsync(CancellationToken cancellation
 23    {
 024        var descriptors = strategies.Select(WorkflowActivationStrategyDescriptor.FromStrategy).OrderBy(x => x.DisplayNam
 025        var response =new ListResponse<WorkflowActivationStrategyDescriptor>(descriptors);
 026        return Task.FromResult(response);
 27    }
 28}
 29
 30internal record WorkflowActivationStrategyDescriptor(string DisplayName, string Description, string TypeName)
 31{
 32    public static WorkflowActivationStrategyDescriptor FromStrategy(IWorkflowActivationStrategy 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 WorkflowActivationStrategyDescriptor(displayName, description, type.GetSimpleAssemblyQualifiedName())
 42    }
 43}