< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Callback.JsonCallbackBodySerializer
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Callback/JsonCallbackBodySerializer.cs
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 35
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 01/02/2026 - 00:16:25 Line coverage: 100% (7/7) Branch coverage: 83.3% (5/6) Total lines: 35 Tag: Kestrun/Kestrun@8405dc23b786b9d436fba0d65fb80baa4171e1d0 01/02/2026 - 00:16:25 Line coverage: 100% (7/7) Branch coverage: 83.3% (5/6) Total lines: 35 Tag: Kestrun/Kestrun@8405dc23b786b9d436fba0d65fb80baa4171e1d0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Serialize(...)83.33%66100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Callback/JsonCallbackBodySerializer.cs

#LineLine coverage
 1using System.Text.Json;
 2
 3namespace Kestrun.Callback;
 4
 5/// <summary>
 6/// JSON implementation of <see cref="ICallbackBodySerializer"/>.
 7/// </summary>
 8public sealed class JsonCallbackBodySerializer : ICallbackBodySerializer
 9{
 10    /// <summary>
 11    /// Serializes the callback body based on the provided plan and context.
 12    /// </summary>
 13    /// <param name="plan">The callback plan containing the body definition.</param>
 14    /// <param name="ctx">The callback runtime context providing the payload.</param>
 15    /// <returns>A tuple containing the content type and serialized body bytes.</returns>
 16    public (string ContentType, byte[] Body) Serialize(CallbackPlan plan, CallbackRuntimeContext ctx)
 17    {
 18        // If no body defined in plan → send empty
 319        if (plan.Body is null)
 20        {
 121            return ("application/json", Array.Empty<byte>());
 22        }
 23
 224        var ct = plan.Body.MediaType ?? "application/json";
 25
 26        // Your payload must be provided by handler earlier
 227        if (ctx.CallbackPayload is null)
 28        {
 129            return (ct, Array.Empty<byte>());
 30        }
 31
 132        var bytes = JsonSerializer.SerializeToUtf8Bytes(ctx.CallbackPayload);
 133        return (ct, bytes);
 34    }
 35}