< Summary

Information
Class: Elsa.Shells.Api.Endpoints.Shells.Reload.Reload
Assembly: Elsa.Shells.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Shells.Api/Endpoints/Shells/Reload/Endpoint.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 56
Line coverage: 100%
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%
Configure()100%11100%
HandleAsync()100%11100%
SendResponseAsync()100%11100%

File(s)

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

#LineLine coverage
 1using CShells.Management;
 2using Elsa.Abstractions;
 3using Elsa.Shells.Api.Endpoints.Shells;
 4using Elsa.Workflows;
 5using JetBrains.Annotations;
 6using Microsoft.AspNetCore.Http;
 7
 8namespace Elsa.Shells.Api.Endpoints.Shells.Reload;
 9
 10[PublicAPI]
 611internal class Reload(IShellManager shellManager, IApiSerializer apiSerializer) : ElsaEndpointWithoutRequest
 12{
 13    public override void Configure()
 14    {
 415        Post("/shells/{shellId}/reload");
 416        ConfigurePermissions("actions:shells:reload");
 417    }
 18
 19    public override async Task HandleAsync(CancellationToken cancellationToken)
 20    {
 221        var shellId = Route<string>("shellId")!;
 22
 23        try
 24        {
 225            await shellManager.ReloadShellAsync(shellId, cancellationToken);
 126        }
 127        catch (InvalidOperationException ex)
 28        {
 29            // Shell not found by the provider.
 130            var notFoundResponse = new ShellReloadResponse
 131            {
 132                Status = ShellReloadStatus.NotFound,
 133                RequestedShellId = shellId,
 134                Timestamp = DateTimeOffset.UtcNow,
 135                Message = ex.Message
 136            };
 137            await SendResponseAsync(notFoundResponse, StatusCodes.Status404NotFound, cancellationToken);
 138            return;
 39        }
 40
 141        var response = new ShellReloadResponse
 142        {
 143            Status = ShellReloadStatus.Completed,
 144            RequestedShellId = shellId,
 145            Timestamp = DateTimeOffset.UtcNow
 146        };
 147        await SendResponseAsync(response, StatusCodes.Status200OK, cancellationToken);
 248    }
 49
 50    private async Task SendResponseAsync(ShellReloadResponse response, int statusCode, CancellationToken cancellationTok
 51    {
 252        var serializerOptions = apiSerializer.GetOptions();
 253        HttpContext.Response.StatusCode = statusCode;
 254        await HttpContext.Response.WriteAsJsonAsync(response, serializerOptions, cancellationToken);
 255    }
 56}