< Summary

Information
Class: Elsa.Workflows.UIHints.Dropdown.StaticDropDownOptionsProvider
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/UIHints/Dropdown/StaticDropDownOptionsProvider.cs
Line coverage
88%
Covered lines: 30
Uncovered lines: 4
Coverable lines: 34
Total lines: 68
Line coverage: 88.2%
Branch coverage
70%
Covered branches: 14
Total branches: 20
Branch coverage: 70%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Priority()100%11100%
GetUIPropertiesAsync(...)70%212087.87%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/UIHints/Dropdown/StaticDropDownOptionsProvider.cs

#LineLine coverage
 1using System.Reflection;
 2using Elsa.Workflows.Attributes;
 3using Elsa.Workflows.Models;
 4
 5namespace Elsa.Workflows.UIHints.Dropdown;
 6
 7/// <summary>
 8/// Provides static drop-down options for a given property.
 9/// </summary>
 10public class StaticDropDownOptionsProvider : IPropertyUIHandler
 11{
 1671612    public float Priority => -1;
 13
 14    /// <inheritdoc />
 15    public ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? context, Cance
 16    {
 289317        var inputAttribute = propertyInfo.GetCustomAttribute<InputAttribute>();
 289318        var inputOptions = inputAttribute?.Options;
 289319        var dictionary = new Dictionary<string, object>();
 289320        var isNullableEnum = false;
 21
 289322        if (inputOptions == null)
 23        {
 24            // Is the property an enum?
 282725            var wrappedPropertyType = propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTyp
 282726                ? propertyInfo.PropertyType.GetGenericArguments()[0]
 282727                : propertyInfo.PropertyType;
 28
 282729            if (!wrappedPropertyType.IsEnum) {
 30
 31                // Is the property a nullable enum?
 182132                var nullablePropertyType = Nullable.GetUnderlyingType(wrappedPropertyType);
 182133                if (nullablePropertyType == null || !nullablePropertyType.IsEnum) {
 182134                    return new(dictionary);
 35                }
 36                else {
 037                    wrappedPropertyType = nullablePropertyType;
 038                    isNullableEnum = true;
 39                }
 40            }
 41
 100642            var enumValues = Enum.GetValues(wrappedPropertyType).Cast<object>().ToList();
 444843            var enumSelectListItems = enumValues.Select(x => new SelectListItem(x.ToString()!, x.ToString()!)).ToList();
 100644            if (isNullableEnum)
 045                enumSelectListItems.Insert(0, new SelectListItem("-",""));
 100646            var enumProps = new DropDownProps
 100647            {
 100648                SelectList = new SelectList(enumSelectListItems)
 100649            };
 50
 100651            dictionary[InputUIHints.DropDown] = enumProps;
 100652            return new(dictionary);
 53        }
 54
 44055        var selectListItems = (inputOptions as ICollection<string>)?.Select(x => new SelectListItem(x, x)).ToList();
 56
 6657        if (selectListItems == null)
 058            return new(dictionary);
 59
 6660        var props = new DropDownProps
 6661        {
 6662            SelectList = new SelectList(selectListItems)
 6663        };
 64
 6665        dictionary[InputUIHints.DropDown] = props;
 6666        return new(dictionary);
 67    }
 68}