< Summary

Information
Class: Elsa.Workflows.Management.Services.WorkflowInstanceVariableManager
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Services/WorkflowInstanceVariableManager.cs
Line coverage
61%
Covered lines: 24
Uncovered lines: 15
Coverable lines: 39
Total lines: 76
Line coverage: 61.5%
Branch coverage
30%
Covered branches: 3
Total branches: 10
Branch coverage: 30%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetVariablesAsync()50%22100%
GetVariablesAsync(...)100%11100%
GetVariablesAsync()100%210%
GetVariablesAsync()0%620%
SetVariablesAsync()0%620%
SetVariablesAsync(...)100%210%
GetWorkflowExecutionContextAsync()50%2283.33%
GetWorkflowExecutionContextAsync()50%2288.88%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Services/WorkflowInstanceVariableManager.cs

#LineLine coverage
 1using Elsa.Workflows.Management.Entities;
 2using Elsa.Workflows.State;
 3
 4namespace Elsa.Workflows.Management.Services;
 5
 36public class WorkflowInstanceVariableManager(
 37    IWorkflowInstanceManager workflowInstanceManager,
 38    IWorkflowDefinitionService workflowDefinitionService,
 39    IServiceProvider serviceProvider,
 310    IWorkflowInstanceVariableReader variableReader,
 311    IWorkflowInstanceVariableWriter variableWriter) : IWorkflowInstanceVariableManager
 12{
 13    public async Task<IEnumerable<ResolvedVariable>> GetVariablesAsync(string workflowInstanceId, IEnumerable<string>? e
 14    {
 115        var workflowExecutionContext = await GetWorkflowExecutionContextAsync(workflowInstanceId, cancellationToken);
 116        if (workflowExecutionContext == null) return [];
 117        return await variableReader.GetVariables(workflowExecutionContext, excludeTags, cancellationToken);
 118    }
 19
 20    public Task<IEnumerable<ResolvedVariable>> GetVariablesAsync(WorkflowExecutionContext workflowExecutionContext, IEnu
 21    {
 122        return variableReader.GetVariables(workflowExecutionContext, excludeTags, cancellationToken);
 23    }
 24
 25    public async Task<IEnumerable<ResolvedVariable>> GetVariablesAsync(WorkflowInstance workflowInstance, IEnumerable<st
 26    {
 027        return await GetVariablesAsync(workflowInstance.WorkflowState, excludeTags, cancellationToken);
 028    }
 29
 30    public async Task<IEnumerable<ResolvedVariable>> GetVariablesAsync(WorkflowState workflowState, IEnumerable<string>?
 31    {
 032        var workflowExecutionContext = await GetWorkflowExecutionContextAsync(workflowState, cancellationToken);
 033        if (workflowExecutionContext == null) return [];
 034        return await variableReader.GetVariables(workflowExecutionContext, excludeTags, cancellationToken);
 035    }
 36
 37    public async Task<IEnumerable<ResolvedVariable>> SetVariablesAsync(string workflowInstanceId, IEnumerable<VariableUp
 38    {
 039        var workflowExecutionContext = await GetWorkflowExecutionContextAsync(workflowInstanceId, cancellationToken);
 040        if (workflowExecutionContext == null) return [];
 041        var resolvedVariables = await variableWriter.SetVariables(workflowExecutionContext, variables, cancellationToken
 042        await workflowInstanceManager.SaveAsync(workflowExecutionContext, cancellationToken);
 043        return resolvedVariables;
 044    }
 45
 46    public Task<IEnumerable<ResolvedVariable>> SetVariablesAsync(WorkflowExecutionContext workflowExecutionContext, IEnu
 47    {
 048        return variableWriter.SetVariables(workflowExecutionContext, variables, cancellationToken);
 49    }
 50
 51    private async Task<WorkflowExecutionContext?> GetWorkflowExecutionContextAsync(string workflowInstanceId, Cancellati
 52    {
 153        var workflowInstance = await workflowInstanceManager.FindByIdAsync(workflowInstanceId, cancellationToken);
 54
 155        if (workflowInstance == null)
 056            return null;
 57
 158        var workflowState = workflowInstance.WorkflowState;
 59
 160        return await GetWorkflowExecutionContextAsync(workflowState, cancellationToken);
 161    }
 62
 63    private async Task<WorkflowExecutionContext?> GetWorkflowExecutionContextAsync(WorkflowState workflowState, Cancella
 64    {
 165        var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(workflowState.DefinitionVersionId, ca
 66
 167        if (workflowGraph == null)
 068            return null;
 69
 170        return await WorkflowExecutionContext.CreateAsync(
 171            serviceProvider,
 172            workflowGraph,
 173            workflowState,
 174            cancellationToken: cancellationToken);
 175    }
 76}