< 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
95%
Covered lines: 40
Uncovered lines: 2
Coverable lines: 42
Total lines: 68
Line coverage: 95.2%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
StartWorkflowAsync()100%22100%
GetWorkflowAsync()66.66%6677.77%

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
 7419public class DefaultWorkflowStarter(IWorkflowDefinitionService workflowDefinitionService, IWorkflowRuntime workflowRunti
 10{
 11    public DefaultWorkflowStarter(IWorkflowDefinitionService workflowDefinitionService, IWorkflowActivationStrategyEvalu
 74112        : this(workflowDefinitionService, workflowRuntime)
 13    {
 74114    }
 15
 16    public async Task<StartWorkflowResponse> StartWorkflowAsync(StartWorkflowRequest request, CancellationToken cancella
 17    {
 3918        var workflow = await GetWorkflowAsync(request, cancellationToken);
 19
 3920        var workflowClient = await workflowRuntime.CreateClientAsync(cancellationToken);
 3921        var createWorkflowInstanceRequest = new CreateAndRunWorkflowInstanceRequest
 3922        {
 3923            WorkflowDefinitionHandle = WorkflowDefinitionHandle.ByDefinitionVersionId(workflow.Identity.Id),
 3924            CorrelationId = request.CorrelationId,
 3925            Name = request.Name,
 3926            Input = request.Input,
 3927            Variables = request.Variables,
 3928            TriggerActivityId = request.TriggerActivityId,
 3929            ActivityHandle = request.ActivityHandle,
 3930            Properties = request.Properties,
 3931            ParentId = request.ParentId
 3932        };
 33
 3934        var runWorkflowResponse = await workflowClient.CreateAndRunInstanceAsync(createWorkflowInstanceRequest, cancella
 35
 3736        if (runWorkflowResponse.CannotStart)
 337            return new()
 338            {
 339                CannotStart = true
 340            };
 41
 3442        return new()
 3443        {
 3444            CannotStart = false,
 3445            WorkflowInstanceId = runWorkflowResponse.WorkflowInstanceId,
 3446            Status = runWorkflowResponse.Status,
 3447            SubStatus = runWorkflowResponse.SubStatus,
 3448            Bookmarks = runWorkflowResponse.Bookmarks,
 3449            Incidents = runWorkflowResponse.Incidents
 3450        };
 3751    }
 52
 53    private async Task<Workflow> GetWorkflowAsync(StartWorkflowRequest request, CancellationToken cancellationToken)
 54    {
 3955        if (request.Workflow != null)
 2056            return request.Workflow;
 57
 1958        if (request.WorkflowDefinitionHandle == null)
 059            throw new InvalidOperationException("A workflow definition handle must be provided.");
 60
 1961        var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(request.WorkflowDefinitionHandle, can
 62
 1963        if (workflowGraph == null)
 064            throw new WorkflowGraphNotFoundException("Workflow definition not found.", request.WorkflowDefinitionHandle)
 65
 1966        return workflowGraph.Workflow;
 3967    }
 68}