< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.VariableTypes.List.List
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/VariableTypes/List/Endpoint.cs
Line coverage
41%
Covered lines: 7
Uncovered lines: 10
Coverable lines: 17
Total lines: 57
Line coverage: 41.1%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
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%
Map(...)0%156120%

File(s)

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

#LineLine coverage
 1using Elsa.Authorization;
 2using System.ComponentModel;
 3using System.Reflection;
 4using Elsa.Abstractions;
 5using Elsa.Expressions.Contracts;
 6using Elsa.Extensions;
 7using Elsa.Workflows.Management.Models;
 8using Elsa.Workflows.Management.Options;
 9using JetBrains.Annotations;
 10using Microsoft.Extensions.Options;
 11
 12namespace Elsa.Workflows.Api.Endpoints.VariableTypes.List;
 13
 14/// <summary>
 15/// Returns a list of available variable types.
 16/// </summary>
 17[PublicAPI]
 18internal class List : ElsaEndpointWithoutRequest<Response>
 19{
 20    private readonly IWellKnownTypeRegistry _wellKnownTypeRegistry;
 21    private readonly ManagementOptions _managementOptions;
 22
 23    /// <inheritdoc />
 324    public List(IOptions<ManagementOptions> managementOptions, IWellKnownTypeRegistry wellKnownTypeRegistry)
 25    {
 326        _wellKnownTypeRegistry = wellKnownTypeRegistry;
 327        _managementOptions = managementOptions.Value;
 328    }
 29
 30    /// <inheritdoc />
 31    public override void Configure()
 32    {
 333        Get("/descriptors/variables");
 334        RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.DescriptorsVariables, CoreVerbs.View);
 335    }
 36
 37    /// <inheritdoc />
 38    public override Task<Response> ExecuteAsync(CancellationToken cancellationToken)
 39    {
 040        var types = _managementOptions.VariableDescriptors;
 041        var descriptors = types.Select(Map).ToList();
 042        var response = new Response(descriptors);
 43
 044        return Task.FromResult(response);
 45    }
 46
 47    private VariableTypeDescriptor Map(VariableDescriptor descriptor)
 48    {
 049        var type = descriptor.Type;
 050        var hasAlias = _wellKnownTypeRegistry.TryGetAlias(type, out var alias);
 051        var typeName = hasAlias ? alias : type.GetSimpleAssemblyQualifiedName()!;
 052        var displayName = hasAlias ? alias : type.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName ?? type.Name;
 053        var description = descriptor.Description ?? type.GetCustomAttribute<DescriptionAttribute>()?.Description;
 54
 055        return new(typeName, displayName, descriptor.Category, description);
 56    }
 57}