< Summary

Information
Class: Elsa.Workflows.Management.Services.WorkflowInstanceFactory
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Services/WorkflowInstanceFactory.cs
Line coverage
100%
Covered lines: 38
Uncovered lines: 0
Coverable lines: 38
Total lines: 59
Line coverage: 100%
Branch coverage
61%
Covered branches: 11
Total branches: 18
Branch coverage: 61.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
CreateWorkflowState(...)61.11%1818100%
CreateWorkflowInstance(...)100%11100%

File(s)

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

#LineLine coverage
 1using Elsa.Common;
 2using Elsa.Workflows.Activities;
 3using Elsa.Workflows.Management.Contracts;
 4using Elsa.Workflows.Management.Entities;
 5using Elsa.Workflows.Management.Options;
 6using Elsa.Workflows.State;
 7
 8namespace Elsa.Workflows.Management.Services;
 9
 10/// <inheritdoc />
 32111public class WorkflowInstanceFactory(IIdentityGenerator identityGenerator, ISystemClock systemClock) : IWorkflowInstance
 12{
 13    /// <inheritdoc />
 14    public WorkflowState CreateWorkflowState(Workflow workflow, WorkflowInstanceOptions? options = null)
 15    {
 7216        var now = systemClock.UtcNow;
 7217        return new()
 7218        {
 7219            Id = string.IsNullOrEmpty(options?.WorkflowInstanceId) ? identityGenerator.GenerateId() : options.WorkflowIn
 7220            DefinitionId = workflow.Identity.DefinitionId,
 7221            DefinitionVersionId = workflow.Identity.Id,
 7222            DefinitionVersion = workflow.Identity.Version,
 7223            CorrelationId = options?.CorrelationId,
 7224            Name = options?.Name,
 7225            Input = options?.Input ?? new Dictionary<string, object>(),
 7226            Properties = options?.Properties ?? new Dictionary<string, object>(),
 7227            Status = WorkflowStatus.Running,
 7228            SubStatus = WorkflowSubStatus.Pending,
 7229            CreatedAt = now,
 7230            UpdatedAt = now,
 7231            ParentWorkflowInstanceId = options?.ParentWorkflowInstanceId,
 7232            IsSystem = workflow.IsSystem
 7233        };
 34    }
 35
 36    /// <inheritdoc />
 37    public WorkflowInstance CreateWorkflowInstance(Workflow workflow, WorkflowInstanceOptions? options = null)
 38    {
 7239        var workflowState = CreateWorkflowState(workflow, options);
 7240        return new()
 7241        {
 7242            Id = workflowState.Id,
 7243            ParentWorkflowInstanceId = workflowState.ParentWorkflowInstanceId,
 7244            WorkflowState = workflowState,
 7245            DefinitionId = workflowState.DefinitionId,
 7246            DefinitionVersionId = workflowState.DefinitionVersionId,
 7247            Version = workflowState.DefinitionVersion,
 7248            CorrelationId = workflowState.CorrelationId,
 7249            Name = workflowState.Name,
 7250            Status = workflowState.Status,
 7251            SubStatus = workflowState.SubStatus,
 7252            IncidentCount = workflowState.Incidents.Count,
 7253            IsSystem = workflowState.IsSystem,
 7254            CreatedAt = workflowState.CreatedAt,
 7255            UpdatedAt = workflowState.UpdatedAt,
 7256            FinishedAt = workflowState.FinishedAt,
 7257        };
 58    }
 59}