< Summary

Information
Class: Elsa.Workflows.Management.Mappers.WorkflowStateMapper
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Mappers/WorkflowStateMapper.cs
Line coverage
52%
Covered lines: 22
Uncovered lines: 20
Coverable lines: 42
Total lines: 85
Line coverage: 52.3%
Branch coverage
33%
Covered branches: 2
Total branches: 6
Branch coverage: 33.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Map(...)50%2280%
Apply(...)50%2294.73%
Map(...)0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Mappers/WorkflowStateMapper.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Workflows.Management.Entities;
 3using Elsa.Workflows.State;
 4
 5namespace Elsa.Workflows.Management.Mappers;
 6
 7/// <summary>
 8/// Maps a workflow state to a workflow instance.
 9/// </summary>
 10public class WorkflowStateMapper
 11{
 12    /// <summary>
 13    /// [Obsolete] The property key name used to store the workflow instance name.
 14    /// </summary>
 15    [Obsolete("This constant is obsolete and retained only for backward compatibility. Avoid using it in new code.")]
 16    private const string WorkflowInstanceNameKey = "WorkflowInstanceName";
 17
 18    /// <summary>
 19    /// Maps a workflow state to a workflow instance.
 20    /// </summary>
 21    public WorkflowInstance? Map(WorkflowState? source)
 22    {
 32723        if (source == null)
 024            return null;
 25
 32726        var workflowInstance = new WorkflowInstance();
 32727        Apply(source, workflowInstance);
 28
 32729        return workflowInstance;
 30    }
 31
 32    /// <summary>
 33    /// Maps a workflow state to a workflow instance.
 34    /// </summary>
 35    public void Apply(WorkflowState source, WorkflowInstance target)
 36    {
 32737        target.Id = source.Id;
 32738        target.CreatedAt = source.CreatedAt;
 32739        target.DefinitionId = source.DefinitionId;
 32740        target.DefinitionVersionId = source.DefinitionVersionId;
 32741        target.Version = source.DefinitionVersion;
 32742        target.ParentWorkflowInstanceId = source.ParentWorkflowInstanceId;
 32743        target.Status = source.Status;
 32744        target.SubStatus = source.SubStatus;
 32745        target.IsExecuting = source.IsExecuting;
 32746        target.CorrelationId = source.CorrelationId;
 32747        target.Name = source.Name;
 32748        target.IncidentCount = source.Incidents.Count;
 32749        target.IsSystem = source.IsSystem;
 32750        target.UpdatedAt = source.UpdatedAt;
 32751        target.FinishedAt = source.FinishedAt;
 32752        target.WorkflowState = source;
 53
 54        // Keep for backward compatibility with workflow instances created before the introduction of the Name property.
 32755        if (source.Properties.TryGetValue<string>(WorkflowInstanceNameKey, out var name))
 056            target.Name = name;
 32757    }
 58
 59    /// <summary>
 60    /// Maps a workflow instance to a workflow state.
 61    /// </summary>
 62    public WorkflowState? Map(WorkflowInstance? source)
 63    {
 064        if (source == null)
 065            return null;
 66
 067        var workflowState = source.WorkflowState;
 068        workflowState.Id = source.Id;
 069        workflowState.CreatedAt = source.CreatedAt;
 070        workflowState.DefinitionId = source.DefinitionId;
 071        workflowState.DefinitionVersionId = source.DefinitionVersionId;
 072        workflowState.DefinitionVersion = source.Version;
 073        workflowState.ParentWorkflowInstanceId = source.ParentWorkflowInstanceId;
 074        workflowState.Status = source.Status;
 075        workflowState.SubStatus = source.SubStatus;
 076        workflowState.IsExecuting = source.IsExecuting;
 077        workflowState.CorrelationId = source.CorrelationId;
 078        workflowState.Name = source.Name;
 079        workflowState.UpdatedAt = source.UpdatedAt;
 080        workflowState.FinishedAt = source.FinishedAt;
 081        workflowState.IsSystem = source.IsSystem;
 82
 083        return workflowState;
 84    }
 85}