< Summary

Information
Class: Elsa.Workflows.DefaultWorkflowInstanceVariableWriter
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/DefaultWorkflowInstanceVariableWriter.cs
Line coverage
4%
Covered lines: 1
Uncovered lines: 22
Coverable lines: 23
Total lines: 39
Line coverage: 4.3%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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%
SetVariables()0%4260%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/DefaultWorkflowInstanceVariableWriter.cs

#LineLine coverage
 1namespace Elsa.Workflows;
 2
 33public class DefaultWorkflowInstanceVariableWriter(IVariablePersistenceManager variablePersistenceManager) : IWorkflowIn
 4{
 5    public async Task<IEnumerable<ResolvedVariable>> SetVariables(WorkflowExecutionContext workflowExecutionContext, IEn
 6    {
 07        var workflow = workflowExecutionContext.Workflow;
 08        var workflowVariables = workflow.Variables;
 09        var rootWorkflowActivityExecutionContext = workflowExecutionContext.ActivityExecutionContexts.FirstOrDefault(x =
 10
 011        if (rootWorkflowActivityExecutionContext == null)
 012            return [];
 13
 014        await variablePersistenceManager.LoadVariablesAsync(workflowExecutionContext);
 015        var variablesToUpdate = variables.ToDictionary(x => x.Id, x => x.Value);
 016        var resolvedVariables = new Dictionary<string, ResolvedVariable>();
 17
 018        foreach (var workflowVariable in workflowVariables)
 19        {
 020            var currentValue = workflowVariable.Get(rootWorkflowActivityExecutionContext.ExpressionExecutionContext);
 021            var resolvedVariable = new ResolvedVariable(workflowVariable, currentValue);
 022            resolvedVariables[workflowVariable.Id] = resolvedVariable;
 23
 024            if (!variablesToUpdate.TryGetValue(workflowVariable.Id, out var value))
 25                continue;
 26
 027            workflowVariable.Set(rootWorkflowActivityExecutionContext.ExpressionExecutionContext, value);
 028            resolvedVariable = resolvedVariable with
 029            {
 030                Value = value
 031            };
 32
 033            resolvedVariables[workflowVariable.Id] = resolvedVariable;
 34        }
 35
 036        await variablePersistenceManager.SaveVariablesAsync(workflowExecutionContext);
 037        return resolvedVariables.Values;
 038    }
 39}