< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.Shells.Reload.Reload
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/Shells/Reload/Endpoint.cs
Line coverage
91%
Covered lines: 21
Uncovered lines: 2
Coverable lines: 23
Total lines: 48
Line coverage: 91.3%
Branch coverage
71%
Covered branches: 5
Total branches: 7
Branch coverage: 71.4%
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%
HandleAsync()71.42%7787.5%
SendJsonAsync()100%11100%

File(s)

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

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Workflows.Api.Contracts;
 3using Elsa.Workflows.Api.Endpoints.Shells;
 4using JetBrains.Annotations;
 5using Microsoft.AspNetCore.Http;
 6using Elsa.Workflows;
 7
 8namespace Elsa.Workflows.Api.Endpoints.Shells.Reload;
 9
 10[PublicAPI]
 611internal class Reload(IShellReloadOrchestrator shellReloadOrchestrator, IApiSerializer apiSerializer) : ElsaEndpointWith
 12{
 13    public override void Configure()
 14    {
 315        Post("/shells/{shellId}/reload");
 316        ConfigurePermissions("actions:shells:reload");
 317    }
 18
 19    public override async Task HandleAsync(CancellationToken cancellationToken)
 20    {
 321        var shellId = Route<string>("shellId")!;
 322        var result = await shellReloadOrchestrator.ReloadAsync(shellId, cancellationToken);
 23
 324        if (result.Status == ShellReloadStatus.NotFound)
 25        {
 126            await Send.NotFoundAsync(cancellationToken);
 127            return;
 28        }
 29
 230        var serializerOptions = apiSerializer.GetOptions();
 231        var response = ShellReloadResponse.FromResult(result);
 232        var statusCode = result.Status switch
 233        {
 034            ShellReloadStatus.Busy => StatusCodes.Status409Conflict,
 135            ShellReloadStatus.RequestedShellFailed => StatusCodes.Status422UnprocessableEntity,
 036            ShellReloadStatus.Failed => StatusCodes.Status503ServiceUnavailable,
 137            _ => StatusCodes.Status200OK
 238        };
 39
 240        await SendJsonAsync(response, statusCode, serializerOptions, cancellationToken);
 341    }
 42
 43    private async Task SendJsonAsync(ShellReloadResponse response, int statusCode, System.Text.Json.JsonSerializerOption
 44    {
 245        HttpContext.Response.StatusCode = statusCode;
 246        await HttpContext.Response.WriteAsJsonAsync(response, serializerOptions, cancellationToken);
 247    }
 48}