< Summary

Information
Class: Elsa.Bpmn.Interchange.Endpoints.Bpmn.Analyze.Analyze
Assembly: Elsa.Bpmn.Interchange
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Bpmn.Interchange/Endpoints/Bpmn/Analyze/Endpoint.cs
Line coverage
82%
Covered lines: 14
Uncovered lines: 3
Coverable lines: 17
Total lines: 53
Line coverage: 82.3%
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%2275%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Bpmn.Interchange/Endpoints/Bpmn/Analyze/Endpoint.cs

#LineLine coverage
 1using Elsa.Authorization;
 2using Bpmn.Interchange;
 3using Elsa.Abstractions;
 4using Elsa.Bpmn.Interchange.Services;
 5using JetBrains.Annotations;
 6using Microsoft.AspNetCore.Http;
 7
 8namespace Elsa.Bpmn.Interchange.Endpoints.Bpmn.Analyze;
 9
 10/// <summary>
 11/// Reads a <c>.bpmn</c> document and reports the element-scoped Info/Degraded/Dropped findings a read would produce,
 12/// without persisting anything.
 13/// </summary>
 14/// <remarks>
 15/// A thin wrapper over <see cref="BpmnInterchangeDocumentService.Analyze"/>, which runs the same code
 16/// <see cref="Import.Import"/> reads with — see its remarks for why that is what makes this a genuine preview rather
 17/// than a second opinion that can disagree with the import that follows it.
 18/// </remarks>
 19[UsedImplicitly]
 1420internal sealed class Analyze(BpmnInterchangeDocumentService documentService) : ElsaEndpointWithoutRequest<BpmnImportAna
 21{
 22    /// <inheritdoc />
 23    public override void Configure()
 24    {
 1125        Post("bpmn/analyze");
 1126        AllowFileUploads();
 1127        RequirePermission(Elsa.Bpmn.Interchange.Permissions.BpmnPermissions.Definitions, CoreVerbs.View);
 1128    }
 29
 30    /// <inheritdoc />
 31    public override async Task HandleAsync(CancellationToken cancellationToken)
 32    {
 333        if (Files.Count != 1)
 34        {
 235            AddError("Upload exactly one .bpmn file.");
 236            await Send.ErrorsAsync(StatusCodes.Status400BadRequest, cancellationToken);
 237            return;
 38        }
 39
 140        var xml = await BpmnUploadedFileReader.ReadTextAsync(Files[0], cancellationToken);
 41
 42        try
 43        {
 144            var analysis = documentService.Analyze(xml);
 145            await Send.OkAsync(BpmnImportAnalysisModel.From(analysis), cancellationToken);
 146        }
 047        catch (BpmnInterchangeException exception)
 48        {
 049            AddError(exception.Message);
 050            await Send.ErrorsAsync(StatusCodes.Status400BadRequest, cancellationToken);
 51        }
 352    }
 53}