< Summary

Information
Class: Elsa.Workflows.Runtime.DefaultWorkflowStarter
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/DefaultWorkflowStarter.cs
Line coverage
77%
Covered lines: 35
Uncovered lines: 10
Coverable lines: 45
Total lines: 68
Line coverage: 77.7%
Branch coverage
25%
Covered branches: 2
Total branches: 8
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
StartWorkflowAsync()50%2288.57%
GetWorkflowAsync()16.66%17633.33%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/DefaultWorkflowStarter.cs

#LineLine coverage
 1using Elsa.Workflows.Activities;
 2using Elsa.Workflows.Management;
 3using Elsa.Workflows.Models;
 4using Elsa.Workflows.Runtime.Exceptions;
 5using Elsa.Workflows.Runtime.Messages;
 6
 7namespace Elsa.Workflows.Runtime;
 8
 689public class DefaultWorkflowStarter(IWorkflowDefinitionService workflowDefinitionService, IWorkflowActivationStrategyEva
 10{
 11    public async Task<StartWorkflowResponse> StartWorkflowAsync(StartWorkflowRequest request, CancellationToken cancella
 12    {
 1613        var workflow = await GetWorkflowAsync(request, cancellationToken);
 14
 1615        var canStart = await workflowActivationStrategyEvaluator.CanStartWorkflowAsync(new()
 1616        {
 1617            Workflow = workflow,
 1618            CorrelationId = request.CorrelationId
 1619        });
 20
 1621        if (!canStart)
 022            return new()
 023            {
 024                CannotStart = true
 025            };
 26
 1627        var workflowClient = await workflowRuntime.CreateClientAsync(cancellationToken);
 1628        var createWorkflowInstanceRequest = new CreateAndRunWorkflowInstanceRequest
 1629        {
 1630            WorkflowDefinitionHandle = WorkflowDefinitionHandle.ByDefinitionVersionId(workflow.Identity.Id),
 1631            CorrelationId = request.CorrelationId,
 1632            Name = request.Name,
 1633            Input = request.Input,
 1634            Variables = request.Variables,
 1635            TriggerActivityId = request.TriggerActivityId,
 1636            ActivityHandle = request.ActivityHandle,
 1637            Properties = request.Properties,
 1638            ParentId = request.ParentId
 1639        };
 40
 1641        var runWorkflowResponse = await workflowClient.CreateAndRunInstanceAsync(createWorkflowInstanceRequest, cancella
 1642        return new()
 1643        {
 1644            CannotStart = false,
 1645            WorkflowInstanceId = runWorkflowResponse.WorkflowInstanceId,
 1646            Status = runWorkflowResponse.Status,
 1647            SubStatus = runWorkflowResponse.SubStatus,
 1648            Bookmarks = runWorkflowResponse.Bookmarks,
 1649            Incidents = runWorkflowResponse.Incidents
 1650        };
 1651    }
 52
 53    private async Task<Workflow> GetWorkflowAsync(StartWorkflowRequest request, CancellationToken cancellationToken)
 54    {
 1655        if (request.Workflow != null)
 1656            return request.Workflow;
 57
 058        if (request.WorkflowDefinitionHandle == null)
 059            throw new InvalidOperationException("A workflow definition handle must be provided.");
 60
 061        var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(request.WorkflowDefinitionHandle, can
 62
 063        if (workflowGraph == null)
 064            throw new WorkflowGraphNotFoundException("Workflow definition not found.", request.WorkflowDefinitionHandle)
 65
 066        return workflowGraph.Workflow;
 1667    }
 68}