< Summary

Information
Class: Elsa.Api.Client.Resources.WorkflowDefinitions.Extensions.WorkflowDefinitionExtensions
Assembly: Elsa.Api.Client
File(s): /home/runner/work/elsa-core/elsa-core/src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Extensions/WorkflowDefinitionExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 44
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetVariableTestValues(...)0%4260%
GetVariableTestValue(...)0%620%
SetVariableTestValue(...)100%210%
ClearVariableTestValue(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Extensions/WorkflowDefinitionExtensions.cs

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.Api.Client.Resources.WorkflowDefinitions.Models;
 3
 4namespace Elsa.Api.Client.Resources.WorkflowDefinitions.Extensions;
 5
 6public static class WorkflowDefinitionExtensions
 7{
 8    private const string VariableTestValuesKey = "VariableTestValues";
 9
 10    public static IDictionary<string, object?> GetVariableTestValues(this WorkflowDefinition workflowDefinition)
 11    {
 012        if (!workflowDefinition.CustomProperties.TryGetValue(VariableTestValuesKey, out var dictionary))
 13        {
 014            var testValues = new Dictionary<string, object?>();
 015            workflowDefinition.CustomProperties[VariableTestValuesKey] = testValues;
 016            return testValues;
 17        }
 18
 019        if (dictionary is JsonElement jsonElement)
 020            dictionary = JsonSerializer.Deserialize<Dictionary<string, object?>>(jsonElement.GetRawText());
 21
 022        return dictionary as IDictionary<string, object?> ?? throw new InvalidOperationException("Invalid variable test 
 23    }
 24
 25    public static object? GetVariableTestValue(this WorkflowDefinition workflowDefinition, string variableId)
 26    {
 027        var testValues = workflowDefinition.GetVariableTestValues();
 028        return testValues.TryGetValue(variableId, out var value) ? value : null;
 29    }
 30
 31    public static void SetVariableTestValue(this WorkflowDefinition workflowDefinition, string variableId, object? value
 32    {
 033        var testValues = workflowDefinition.GetVariableTestValues();
 034        testValues[variableId] = value;
 035        workflowDefinition.CustomProperties[VariableTestValuesKey] = testValues;
 036    }
 37
 38    public static void ClearVariableTestValue(this WorkflowDefinition workflowDefinition, string variableId)
 39    {
 040        var testValues = workflowDefinition.GetVariableTestValues();
 041        testValues.Remove(variableId);
 042        workflowDefinition.CustomProperties[VariableTestValuesKey] = testValues;
 043    }
 44}