< 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: 49
Uncovered lines: 0
Coverable lines: 49
Total lines: 82
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 Elsa.Authorization;
 2using CShells.Lifecycle;
 3using Elsa.Abstractions;
 4using Elsa.Shells.Api.Endpoints.Shells;
 5using Elsa.Workflows;
 6using JetBrains.Annotations;
 7using Microsoft.AspNetCore.Http;
 8
 9namespace Elsa.Shells.Api.Endpoints.Shells.Reload;
 10
 11[PublicAPI]
 1012internal class Reload(IShellRegistry shellRegistry, IApiSerializer apiSerializer) : ElsaEndpointWithoutRequest
 13{
 14    public override void Configure()
 15    {
 616        Post("/shells/{shellId}/reload");
 617        RequirePermission(Elsa.Shells.Api.Permissions.ShellPermissions.Shells, "reload");
 618    }
 19
 20    public override async Task HandleAsync(CancellationToken cancellationToken)
 21    {
 422        var shellId = Route<string>("shellId")!;
 23        ReloadResult result;
 24
 25        try
 26        {
 427            result = await shellRegistry.ReloadAsync(shellId, cancellationToken);
 228        }
 129        catch (ShellBlueprintNotFoundException ex)
 30        {
 131            var notFoundResponse = new ShellReloadResponse
 132            {
 133                Status = ShellReloadStatus.NotFound,
 134                RequestedShellId = shellId,
 135                Timestamp = DateTimeOffset.UtcNow,
 136                Message = ex.Message
 137            };
 138            await SendResponseAsync(notFoundResponse, StatusCodes.Status404NotFound, cancellationToken);
 139            return;
 40        }
 141        catch (ShellBlueprintUnavailableException ex)
 42        {
 143            var unavailableResponse = new ShellReloadResponse
 144            {
 145                Status = ShellReloadStatus.Failed,
 146                RequestedShellId = shellId,
 147                Timestamp = DateTimeOffset.UtcNow,
 148                Message = ex.Message
 149            };
 150            await SendResponseAsync(unavailableResponse, StatusCodes.Status503ServiceUnavailable, cancellationToken);
 151            return;
 52        }
 53
 254        if (result.Error is not null)
 55        {
 156            var failedResponse = new ShellReloadResponse
 157            {
 158                Status = ShellReloadStatus.Failed,
 159                RequestedShellId = shellId,
 160                Timestamp = DateTimeOffset.UtcNow,
 161                Message = result.Error.Message
 162            };
 163            await SendResponseAsync(failedResponse, StatusCodes.Status503ServiceUnavailable, cancellationToken);
 164            return;
 65        }
 66
 167        var response = new ShellReloadResponse
 168        {
 169            Status = ShellReloadStatus.Completed,
 170            RequestedShellId = shellId,
 171            Timestamp = DateTimeOffset.UtcNow
 172        };
 173        await SendResponseAsync(response, StatusCodes.Status200OK, cancellationToken);
 474    }
 75
 76    private async Task SendResponseAsync(ShellReloadResponse response, int statusCode, CancellationToken cancellationTok
 77    {
 478        var serializerOptions = apiSerializer.GetOptions();
 479        HttpContext.Response.StatusCode = statusCode;
 480        await HttpContext.Response.WriteAsJsonAsync(response, serializerOptions, cancellationToken);
 481    }
 82}