< 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: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 54
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
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%22100%
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.Lifecycle;
 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(IShellRegistry shellRegistry, 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")!;
 222        var result = await shellRegistry.ReloadAsync(shellId, cancellationToken);
 23
 24        // CShells 0.0.15 surfaces failures via ReloadResult.Error rather than throwing — translate to 404
 25        // (which historically signalled "blueprint not found") for any composition / initialization error.
 226        if (result.Error is not null)
 27        {
 128            var failedResponse = new ShellReloadResponse
 129            {
 130                Status = ShellReloadStatus.NotFound,
 131                RequestedShellId = shellId,
 132                Timestamp = DateTimeOffset.UtcNow,
 133                Message = result.Error.Message
 134            };
 135            await SendResponseAsync(failedResponse, StatusCodes.Status404NotFound, cancellationToken);
 136            return;
 37        }
 38
 139        var response = new ShellReloadResponse
 140        {
 141            Status = ShellReloadStatus.Completed,
 142            RequestedShellId = shellId,
 143            Timestamp = DateTimeOffset.UtcNow
 144        };
 145        await SendResponseAsync(response, StatusCodes.Status200OK, cancellationToken);
 246    }
 47
 48    private async Task SendResponseAsync(ShellReloadResponse response, int statusCode, CancellationToken cancellationTok
 49    {
 250        var serializerOptions = apiSerializer.GetOptions();
 251        HttpContext.Response.StatusCode = statusCode;
 252        await HttpContext.Response.WriteAsJsonAsync(response, serializerOptions, cancellationToken);
 253    }
 54}