< Summary

Information
Class: Elsa.Workflows.Management.Services.WorkflowSerializer
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Services/WorkflowSerializer.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 10
Coverable lines: 10
Total lines: 38
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Serialize(...)100%210%
Deserialize(...)100%210%
GetWriteOptionsInternal()0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Services/WorkflowSerializer.cs

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.Workflows.Activities;
 3using Elsa.Workflows.Management.Mappers;
 4using Elsa.Workflows.Management.Models;
 5
 6namespace Elsa.Workflows.Management.Services;
 7
 8/// <summary>
 9/// A serializer that parses JSON.
 10/// </summary>
 011public class WorkflowSerializer(IApiSerializer apiSerializer, WorkflowDefinitionMapper workflowDefinitionMapper) : IWork
 12{
 13    private JsonSerializerOptions? _writeOptions;
 14
 15    /// <inheritdoc />
 16    public string Serialize(Workflow workflow)
 17    {
 018        var model = workflowDefinitionMapper.Map(workflow);
 019        var serializerOptions = GetWriteOptionsInternal();
 020        return JsonSerializer.Serialize(model, serializerOptions);
 21    }
 22
 23    /// <inheritdoc />
 24    public Workflow Deserialize(string serializedWorkflow)
 25    {
 026        var model = apiSerializer.Deserialize<WorkflowDefinitionModel>(serializedWorkflow);
 027        return workflowDefinitionMapper.Map(model);
 28    }
 29
 30    private JsonSerializerOptions GetWriteOptionsInternal()
 31    {
 032        if (_writeOptions != null)
 033            return _writeOptions;
 34
 035        var options = apiSerializer.GetOptions();
 036        return _writeOptions = options;
 37    }
 38}