< Summary

Information
Class: Elsa.Secrets.Models.CaseInsensitiveHashSetConverter
Assembly: Elsa.Secrets
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Secrets/Models/CaseInsensitiveHashSetConverter.cs
Line coverage
78%
Covered lines: 15
Uncovered lines: 4
Coverable lines: 19
Total lines: 40
Line coverage: 78.9%
Branch coverage
71%
Covered branches: 10
Total branches: 14
Branch coverage: 71.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Read(...)66.66%151271.42%
Write(...)100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Secrets/Models/CaseInsensitiveHashSetConverter.cs

#LineLine coverage
 1using System.Text.Json;
 2using System.Text.Json.Serialization;
 3
 4namespace Elsa.Secrets.Models;
 5
 6public class CaseInsensitiveHashSetConverter : JsonConverter<HashSet<string>>
 7{
 8    public override HashSet<string> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 9    {
 810        if (reader.TokenType == JsonTokenType.Null)
 011            return new HashSet<string>(StringComparer.OrdinalIgnoreCase);
 12
 813        if (reader.TokenType != JsonTokenType.StartArray)
 014            throw new JsonException("Expected an array of strings.");
 15
 816        var values = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
 917        while (reader.Read())
 18        {
 919            if (reader.TokenType == JsonTokenType.EndArray)
 820                return values;
 21
 122            if (reader.TokenType != JsonTokenType.String)
 023                throw new JsonException("Expected a string tag.");
 24
 125            var value = reader.GetString();
 126            if (!string.IsNullOrWhiteSpace(value))
 127                values.Add(value);
 28        }
 29
 030        throw new JsonException("Unexpected end of JSON while reading secret tags.");
 31    }
 32
 33    public override void Write(Utf8JsonWriter writer, HashSet<string> value, JsonSerializerOptions options)
 34    {
 735        writer.WriteStartArray();
 1636        foreach (var item in value.Order(StringComparer.OrdinalIgnoreCase))
 137            writer.WriteStringValue(item);
 738        writer.WriteEndArray();
 739    }
 40}