< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowInstances.BulkCancel.BulkCancel
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/BulkCancel/Endpoint.cs
Line coverage
28%
Covered lines: 4
Uncovered lines: 10
Coverable lines: 14
Total lines: 36
Line coverage: 28.5%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
ExecuteAsync()0%4260%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/BulkCancel/Endpoint.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Workflows.Runtime;
 3using JetBrains.Annotations;
 4
 5namespace Elsa.Workflows.Api.Endpoints.WorkflowInstances.BulkCancel;
 6
 7/// <summary>
 8/// Represents an endpoint for bulk cancelling workflow instances.
 9/// </summary>
 10[PublicAPI]
 111public class BulkCancel(IWorkflowCancellationService workflowCancellationService) : ElsaEndpoint<Request, Response>
 12{
 13    /// <inheritdoc />
 14    public override void Configure()
 15    {
 116        Post("/bulk-actions/cancel/workflow-instances/");
 117        ConfigurePermissions("cancel:workflow-instances");
 118    }
 19
 20    /// <inheritdoc />
 21    public override async Task<Response> ExecuteAsync(Request request, CancellationToken cancellationToken)
 22    {
 023        var tasks = new List<Task<int>>();
 24
 025        if (request.Ids is not null)
 026            tasks.Add(workflowCancellationService.CancelWorkflowsAsync(request.Ids!, cancellationToken));
 027        if (request.DefinitionVersionId is not null)
 028            tasks.Add(workflowCancellationService.CancelWorkflowByDefinitionVersionAsync(request.DefinitionVersionId!, c
 029        if (request.DefinitionId is not null)
 030            tasks.Add(workflowCancellationService.CancelWorkflowByDefinitionAsync(request.DefinitionId!, request.Version
 31
 032        await Task.WhenAll(tasks);
 33
 034        return new(tasks.Sum(t => t.Result));
 035    }
 36}