< 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: 56
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 System.ComponentModel;
 2using System.Reflection;
 3using Elsa.Abstractions;
 4using Elsa.Expressions.Contracts;
 5using Elsa.Extensions;
 6using Elsa.Workflows.Management.Models;
 7using Elsa.Workflows.Management.Options;
 8using JetBrains.Annotations;
 9using Microsoft.Extensions.Options;
 10
 11namespace Elsa.Workflows.Api.Endpoints.VariableTypes.List;
 12
 13/// <summary>
 14/// Returns a list of available variable types.
 15/// </summary>
 16[PublicAPI]
 17internal class List : ElsaEndpointWithoutRequest<Response>
 18{
 19    private readonly IWellKnownTypeRegistry _wellKnownTypeRegistry;
 20    private readonly ManagementOptions _managementOptions;
 21
 22    /// <inheritdoc />
 123    public List(IOptions<ManagementOptions> managementOptions, IWellKnownTypeRegistry wellKnownTypeRegistry)
 24    {
 125        _wellKnownTypeRegistry = wellKnownTypeRegistry;
 126        _managementOptions = managementOptions.Value;
 127    }
 28
 29    /// <inheritdoc />
 30    public override void Configure()
 31    {
 132        Get("/descriptors/variables");
 133        ConfigurePermissions("read:*", "read:variable-descriptors");
 134    }
 35
 36    /// <inheritdoc />
 37    public override Task<Response> ExecuteAsync(CancellationToken cancellationToken)
 38    {
 039        var types = _managementOptions.VariableDescriptors;
 040        var descriptors = types.Select(Map).ToList();
 041        var response = new Response(descriptors);
 42
 043        return Task.FromResult(response);
 44    }
 45
 46    private VariableTypeDescriptor Map(VariableDescriptor descriptor)
 47    {
 048        var type = descriptor.Type;
 049        var hasAlias = _wellKnownTypeRegistry.TryGetAlias(type, out var alias);
 050        var typeName = hasAlias ? alias : type.GetSimpleAssemblyQualifiedName()!;
 051        var displayName = hasAlias ? alias : type.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName ?? type.Name;
 052        var description = descriptor.Description ?? type.GetCustomAttribute<DescriptionAttribute>()?.Description;
 53
 054        return new(typeName, displayName, descriptor.Category, description);
 55    }
 56}