< Summary

Information
Class: Elsa.Workflows.Runtime.Handlers.DispatchWorkflowCommandHandler
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Handlers/DispatchWorkflowRequestHandler.cs
Line coverage
27%
Covered lines: 14
Uncovered lines: 37
Coverable lines: 51
Total lines: 82
Line coverage: 27.4%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
HandleAsync()100%210%
HandleAsync()100%11100%
HandleAsync()100%210%
HandleAsync()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Handlers/DispatchWorkflowRequestHandler.cs

#LineLine coverage
 1using Elsa.Mediator.Contracts;
 2using Elsa.Mediator.Models;
 3using Elsa.Workflows.Models;
 4using Elsa.Workflows.Runtime.Commands;
 5using Elsa.Workflows.Runtime.Messages;
 6using JetBrains.Annotations;
 7
 8namespace Elsa.Workflows.Runtime.Handlers;
 9
 10// ReSharper disable once UnusedType.Global
 11[UsedImplicitly]
 5312internal class DispatchWorkflowCommandHandler(IStimulusSender stimulusSender, IWorkflowRuntime workflowRuntime) :
 13    ICommandHandler<DispatchTriggerWorkflowsCommand>,
 14    ICommandHandler<DispatchWorkflowDefinitionCommand>,
 15    ICommandHandler<DispatchWorkflowInstanceCommand>,
 16    ICommandHandler<DispatchResumeWorkflowsCommand>
 17{
 18    public virtual async Task<Unit> HandleAsync(DispatchTriggerWorkflowsCommand command, CancellationToken cancellationT
 19    {
 020        var activityTypeName = command.ActivityTypeName;
 021        var stimulus = command.Stimulus;
 022        var metadata = new StimulusMetadata
 023        {
 024            CorrelationId = command.CorrelationId,
 025            ActivityInstanceId = command.ActivityInstanceId,
 026            WorkflowInstanceId = command.WorkflowInstanceId,
 027            Input = command.Input,
 028            Properties = command.Properties,
 029        };
 030        await stimulusSender.SendAsync(activityTypeName, stimulus, metadata, cancellationToken);
 31
 032        return Unit.Instance;
 033    }
 34
 35    public virtual async Task<Unit> HandleAsync(DispatchWorkflowDefinitionCommand command, CancellationToken cancellatio
 36    {
 2337        var client = await workflowRuntime.CreateClientAsync(command.InstanceId, cancellationToken);
 2338        var createRequest = new CreateAndRunWorkflowInstanceRequest
 2339        {
 2340            WorkflowDefinitionHandle = WorkflowDefinitionHandle.ByDefinitionVersionId(command.DefinitionVersionId),
 2341            CorrelationId = command.CorrelationId,
 2342            Input = command.Input,
 2343            Properties = command.Properties,
 2344            ParentId = command.ParentWorkflowInstanceId,
 2345            TriggerActivityId = command.TriggerActivityId
 2346        };
 2347        await client.CreateAndRunInstanceAsync(createRequest, cancellationToken);
 2348        return Unit.Instance;
 2349    }
 50
 51    public virtual async Task<Unit> HandleAsync(DispatchWorkflowInstanceCommand command, CancellationToken cancellationT
 52    {
 053        var runRequest = new RunWorkflowInstanceRequest
 054        {
 055            BookmarkId = command.BookmarkId,
 056            ActivityHandle = command.ActivityHandle,
 057            Input = command.Input,
 058            Properties = command.Properties
 059        };
 060        var client = await workflowRuntime.CreateClientAsync(command.InstanceId, cancellationToken);
 061        await client.RunInstanceAsync(runRequest, cancellationToken);
 62
 063        return Unit.Instance;
 064    }
 65
 66    public virtual async Task<Unit> HandleAsync(DispatchResumeWorkflowsCommand command, CancellationToken cancellationTo
 67    {
 068        var activityTypeName = command.ActivityTypeName;
 069        var stimulus = command.Stimulus;
 070        var metadata = new StimulusMetadata
 071        {
 072            CorrelationId = command.CorrelationId,
 073            WorkflowInstanceId = command.WorkflowInstanceId,
 074            ActivityInstanceId = command.ActivityInstanceId,
 075            Properties = command.Properties,
 076            Input = command.Input
 077        };
 078        await stimulusSender.SendAsync(activityTypeName, stimulus, metadata, cancellationToken);
 79
 080        return Unit.Instance;
 081    }
 82}