< 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: 52
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 Bpmn.Interchange;
 2using Elsa.Abstractions;
 3using Elsa.Bpmn.Interchange.Services;
 4using JetBrains.Annotations;
 5using Microsoft.AspNetCore.Http;
 6
 7namespace Elsa.Bpmn.Interchange.Endpoints.Bpmn.Analyze;
 8
 9/// <summary>
 10/// Reads a <c>.bpmn</c> document and reports the element-scoped Info/Degraded/Dropped findings a read would produce,
 11/// without persisting anything.
 12/// </summary>
 13/// <remarks>
 14/// A thin wrapper over <see cref="BpmnInterchangeDocumentService.Analyze"/>, which runs the same code
 15/// <see cref="Import.Import"/> reads with — see its remarks for why that is what makes this a genuine preview rather
 16/// than a second opinion that can disagree with the import that follows it.
 17/// </remarks>
 18[UsedImplicitly]
 1419internal sealed class Analyze(BpmnInterchangeDocumentService documentService) : ElsaEndpointWithoutRequest<BpmnImportAna
 20{
 21    /// <inheritdoc />
 22    public override void Configure()
 23    {
 1124        Post("bpmn/analyze");
 1125        AllowFileUploads();
 1126        ConfigurePermissions("read:workflow-definitions");
 1127    }
 28
 29    /// <inheritdoc />
 30    public override async Task HandleAsync(CancellationToken cancellationToken)
 31    {
 332        if (Files.Count != 1)
 33        {
 234            AddError("Upload exactly one .bpmn file.");
 235            await Send.ErrorsAsync(StatusCodes.Status400BadRequest, cancellationToken);
 236            return;
 37        }
 38
 139        var xml = await BpmnUploadedFileReader.ReadTextAsync(Files[0], cancellationToken);
 40
 41        try
 42        {
 143            var analysis = documentService.Analyze(xml);
 144            await Send.OkAsync(BpmnImportAnalysisModel.From(analysis), cancellationToken);
 145        }
 046        catch (BpmnInterchangeException exception)
 47        {
 048            AddError(exception.Message);
 049            await Send.ErrorsAsync(StatusCodes.Status400BadRequest, cancellationToken);
 50        }
 351    }
 52}