< Summary

Information
Class: Elsa.Common.Converters.VersionOptionsJsonConverter
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Converters/VersionOptionsJsonConverter.cs
Line coverage
33%
Covered lines: 2
Uncovered lines: 4
Coverable lines: 6
Total lines: 27
Line coverage: 33.3%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Read(...)0%2040%
Write(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Converters/VersionOptionsJsonConverter.cs

#LineLine coverage
 1using System.Text.Json;
 2using System.Text.Json.Serialization;
 3using Elsa.Common.Models;
 4
 5namespace Elsa.Common.Converters;
 6
 7/// <summary>
 8/// A JSON converter that serializes <see cref="VersionOptions"/>.
 9/// </summary>
 10public class VersionOptionsJsonConverter : JsonConverter<VersionOptions>
 11{
 12    /// <inheritdoc />
 13    public override VersionOptions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 14    {
 015        if(reader.TokenType == JsonTokenType.Number)
 016            return VersionOptions.SpecificVersion(reader.GetInt32());
 17
 018        var textValue = reader.GetString();
 019        return string.IsNullOrWhiteSpace(textValue) ? VersionOptions.Published : VersionOptions.FromString(textValue);
 20    }
 21
 22    /// <inheritdoc />
 23    public override void Write(Utf8JsonWriter writer, VersionOptions value, JsonSerializerOptions options)
 24    {
 187325        writer.WriteStringValue(value.ToString());
 187326    }
 27}