< 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: 37
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.Authorization;
 2using Elsa.Abstractions;
 3using Elsa.Workflows.Runtime;
 4using JetBrains.Annotations;
 5
 6namespace Elsa.Workflows.Api.Endpoints.WorkflowInstances.BulkCancel;
 7
 8/// <summary>
 9/// Represents an endpoint for bulk cancelling workflow instances.
 10/// </summary>
 11[PublicAPI]
 312public class BulkCancel(IWorkflowCancellationService workflowCancellationService) : ElsaEndpoint<Request, Response>
 13{
 14    /// <inheritdoc />
 15    public override void Configure()
 16    {
 317        Post("/bulk-actions/cancel/workflow-instances/");
 318        RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.Instances, "cancel");
 319    }
 20
 21    /// <inheritdoc />
 22    public override async Task<Response> ExecuteAsync(Request request, CancellationToken cancellationToken)
 23    {
 024        var tasks = new List<Task<int>>();
 25
 026        if (request.Ids is not null)
 027            tasks.Add(workflowCancellationService.CancelWorkflowsAsync(request.Ids!, cancellationToken));
 028        if (request.DefinitionVersionId is not null)
 029            tasks.Add(workflowCancellationService.CancelWorkflowByDefinitionVersionAsync(request.DefinitionVersionId!, c
 030        if (request.DefinitionId is not null)
 031            tasks.Add(workflowCancellationService.CancelWorkflowByDefinitionAsync(request.DefinitionId!, request.Version
 32
 033        await Task.WhenAll(tasks);
 34
 035        return new(tasks.Sum(t => t.Result));
 036    }
 37}