< Summary

Information
Class: Elsa.Http.Serialization.HttpStatusCodeCaseForWorkflowInstanceConverter
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Serialization/HttpStatusCodeCaseForWorkflowInstanceConverter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 10
Coverable lines: 10
Total lines: 37
Line coverage: 0%
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(...)100%210%
Write(...)0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Serialization/HttpStatusCodeCaseForWorkflowInstanceConverter.cs

#LineLine coverage
 1using System.Text.Json;
 2using System.Text.Json.Serialization;
 3
 4namespace Elsa.Http.Serialization;
 5
 6/// <summary>
 7/// A custom JSON converter for <see cref="HttpStatusCodeCase"/> objects when serializing workflow states.
 8/// </summary>
 9public class HttpStatusCodeCaseForWorkflowInstanceConverter : JsonConverter<HttpStatusCodeCase>
 10{
 11    /// <inheritdoc />
 12    public override HttpStatusCodeCase Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options
 13    {
 014        throw new NotImplementedException();
 15    }
 16
 17    /// <inheritdoc />
 18    public override void Write(Utf8JsonWriter writer, HttpStatusCodeCase value, JsonSerializerOptions options)
 19    {
 020        var properties = value.GetType().GetProperties();
 21
 022        writer.WriteStartObject();
 23
 024        foreach (var prop in properties)
 25        {
 26            // Don't serialize the Activity property.
 027            if (prop.Name != nameof(HttpStatusCodeCase.Activity))
 28            {
 029                var propValue = prop.GetValue(value);
 030                writer.WritePropertyName(prop.Name);
 031                JsonSerializer.Serialize(writer, propValue, prop.PropertyType, options);
 32            }
 33        }
 34
 035        writer.WriteEndObject();
 036    }
 37}