< Summary

Information
Class: Elsa.Expressions.JavaScript.Providers.VariableTypeDefinitionProvider
Assembly: Elsa.Expressions.JavaScript
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Providers/VariableTypeDefinitionProvider.cs
Line coverage
5%
Covered lines: 1
Uncovered lines: 17
Coverable lines: 18
Total lines: 41
Line coverage: 5.5%
Branch coverage
0%
Covered branches: 0
Total branches: 10
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%
GetTypeDefinitions()0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Providers/VariableTypeDefinitionProvider.cs

#LineLine coverage
 1using System.Dynamic;
 2using Elsa.Extensions;
 3using Elsa.Expressions.JavaScript.TypeDefinitions.Abstractions;
 4using Elsa.Expressions.JavaScript.TypeDefinitions.Contracts;
 5using Elsa.Expressions.JavaScript.TypeDefinitions.Models;
 6using Elsa.Workflows.Management.Options;
 7using JetBrains.Annotations;
 8using Microsoft.Extensions.Options;
 9
 10namespace Elsa.Expressions.JavaScript.Providers;
 11
 12/// <summary>
 13/// Produces <see cref="TypeDefinition"/>s for variable types.
 14/// </summary>
 15[UsedImplicitly]
 116internal class VariableTypeDefinitionProvider(ITypeDescriber typeDescriber, IOptions<ManagementOptions> options) : TypeD
 17{
 18    protected override IEnumerable<TypeDefinition> GetTypeDefinitions(TypeDefinitionContext context)
 19    {
 020        var excludedTypes = new Func<Type, bool>[]
 021        {
 022            type => type == typeof(ExpandoObject),
 023            type => type.IsPrimitive,
 024            type => type.ContainsGenericParameters,
 025            type => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IDictionary<,>),
 026            type => type == typeof(object),
 027            type => type == typeof(string)
 028        };
 29
 030        var variableTypes =
 031            from variableDescriptor in options.Value.VariableDescriptors
 032            let variableType = variableDescriptor.Type
 033            where (variableType.IsClass || variableType.IsInterface || variableType.IsEnum) && !excludedTypes.Any(x => x
 034            select variableType;
 35
 036        foreach (var variableType in variableTypes.Distinct())
 37        {
 038            yield return typeDescriber.DescribeType(variableType);
 39        }
 040    }
 41}