< Summary - AsyncResponse (Release / net8.0+net10.0 / unit+integration)

Information
Class: AsyncResponse.FlowStateJson
Assembly: AsyncResponse.Core
File(s): /home/runner/work/AsyncResponse/AsyncResponse/src/AsyncResponse.Core/FlowStateJson.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 65
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_TypeInfo()100%11100%
Serialize(...)100%11100%
Deserialize(...)100%44100%
JsonEquivalent(...)100%44100%
SerializeSnapshot(...)100%11100%

File(s)

/home/runner/work/AsyncResponse/AsyncResponse/src/AsyncResponse.Core/FlowStateJson.cs

#LineLine coverage
 1using System.Text.Json;
 2using System.Text.Json.Nodes;
 3using System.Text.Json.Serialization.Metadata;
 4
 5namespace AsyncResponse;
 6
 7internal static class FlowStateJson
 8{
 9    // FlowState is a library wire type: its metadata is source-generated
 10    // (AsyncResponseJsonContext), and the ledger omits nulls exactly as before.
 11    private static JsonTypeInfo<FlowState> TypeInfo
 312        => AsyncResponseJson.GetTypeInfo<FlowState>(AsyncResponseJson.IgnoreNullWrites);
 13
 314    public static string Serialize(FlowState state) => JsonSerializer.Serialize(state, TypeInfo);
 15
 16    public static FlowState? Deserialize(string json)
 17    {
 18        try
 19        {
 320            var state = JsonSerializer.Deserialize(json, TypeInfo);
 321            return state is not null && FlowStateSchema.IsReadable(state.SchemaVersion) ? state : null;
 22        }
 223        catch (JsonException)
 24        {
 225            return null;
 26        }
 327    }
 28
 29    public static bool JsonEquivalent(string? left, string right)
 30    {
 331        if (string.Equals(left, right, StringComparison.Ordinal))
 332            return true;
 333        if (left is null)
 234            return false;
 35
 36        try
 37        {
 338            return JsonNode.DeepEquals(JsonNode.Parse(left), JsonNode.Parse(right));
 39        }
 240        catch (JsonException)
 41        {
 242            return false;
 43        }
 344    }
 45
 46    /// <summary>
 47    /// Serializes a child <see cref="FlowState"/> for memoization as a parent step result, without
 48    /// the captured ambient <see cref="FlowState.Context"/>: it is propagation machinery (it can
 49    /// carry principal/tenant values) that the parent never needs, and dropping it keeps nested
 50    /// child snapshots from compounding ledger size.
 51    /// </summary>
 52    public static string SerializeSnapshot(FlowState state)
 53    {
 254        var context = state.Context;
 255        state.Context = null;
 56        try
 57        {
 258            return Serialize(state);
 59        }
 60        finally
 61        {
 262            state.Context = context;
 263        }
 264    }
 65}