< Summary

Information
Class: Elsa.Workflows.Activities.Flowchart.Serialization.ObsoleteConnectionJsonConverter
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Serialization/ObsoleteConnectionJsonConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 23
Coverable lines: 23
Total lines: 56
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CanConvert(...)100%210%
.ctor(...)100%210%
Read(...)0%4260%
Write(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Serialization/ObsoleteConnectionJsonConverter.cs

#LineLine coverage
 1using System.Text.Json;
 2using System.Text.Json.Serialization;
 3using Elsa.Workflows.Activities.Flowchart.Models;
 4
 5namespace Elsa.Workflows.Activities.Flowchart.Serialization;
 6
 7/// <summary>
 8/// Converts <see cref="ObsoleteConnection"/> to and from JSON.
 9/// </summary>
 10[Obsolete("Use ConnectionJsonConverter instead.")]
 11public class ObsoleteConnectionJsonConverter : JsonConverter<ObsoleteConnection>
 12{
 13    private readonly IDictionary<string, IActivity> _activities;
 14
 15    /// <inheritdoc />
 016    public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(ObsoleteConnection);
 17
 18    /// <inheritdoc />
 019    public ObsoleteConnectionJsonConverter(IDictionary<string, IActivity> activities)
 20    {
 021        _activities = activities;
 022    }
 23
 24    /// <inheritdoc />
 25    public override ObsoleteConnection Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options
 26    {
 027        if (!JsonDocument.TryParseValue(ref reader, out var doc))
 028            throw new JsonException("Failed to parse JsonDocument");
 29
 030        var sourceId = doc.RootElement.GetProperty("source").GetString()!;
 031        var targetId = doc.RootElement.GetProperty("target").GetString()!;
 032        var sourcePort = doc.RootElement.GetProperty("sourcePort").GetString()!;
 033        var targetPort = doc.RootElement.GetProperty("targetPort").GetString()!;
 34
 035        var source = _activities.TryGetValue(sourceId, out var s) ? s : null!;
 036        var target = _activities.TryGetValue(targetId, out var t) ? t : null!;
 37
 038        return new ObsoleteConnection(source, target, sourcePort, targetPort);
 39    }
 40
 41    /// <inheritdoc />
 42    public override void Write(Utf8JsonWriter writer, ObsoleteConnection value, JsonSerializerOptions options)
 43    {
 044        var (activity, target, sourcePort, targetPort) = value;
 45
 046        var model = new
 047        {
 048            Source = activity.Id,
 049            Target = target.Id,
 050            SourcePort = sourcePort,
 051            TargetPort = targetPort
 052        };
 53
 054        JsonSerializer.Serialize(writer, model, options);
 055    }
 56}