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

Information
Class: AsyncResponse.Transports.Redis.RedisCorrelationIdExtractor
Assembly: AsyncResponse.Transports.Redis
File(s): /_/src/Transports/AsyncResponse.Transports.Redis/RedisCorrelationIdExtractor.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 44
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
Extract(...)100%22100%
TryReadField(...)100%66100%

File(s)

/_/src/Transports/AsyncResponse.Transports.Redis/RedisCorrelationIdExtractor.cs

#LineLine coverage
 1using StackExchange.Redis;
 2
 3namespace AsyncResponse.Transports.Redis;
 4
 5/// <summary>
 6/// Extracts the AsyncResponse correlation id from an inbound response message: first from the
 7/// configured stream field, then from the JSON body via the configured paths (walked by the shared
 8/// <see cref="CorrelationIdJsonPaths"/>).
 9/// </summary>
 10internal static class RedisCorrelationIdExtractor
 11{
 12    /// <summary>Extracts the correlation id from the supplied message.</summary>
 13    public static string? Extract(
 14        StreamEntry entry,
 15        string messageJson,
 16        RedisAsyncResponseTransportOptions options)
 17    {
 3218        var field = RedisTransportOptionsValidator.Required(
 3219            options.CorrelationIdField,
 3220            nameof(options.CorrelationIdField));
 21
 3222        var fieldValue = TryReadField(entry, field);
 3223        if (!string.IsNullOrWhiteSpace(fieldValue))
 224            return fieldValue;
 25
 3026        return CorrelationIdJsonPaths.Extract(messageJson, options.CorrelationIdJsonPaths);
 27    }
 28
 29    internal static string? TryReadField(StreamEntry entry, string fieldName)
 30    {
 31        // A tombstone left after trimming (an entry still referenced by a PEL but deleted from the
 32        // stream) has null Values; treat it as a missing field rather than throwing.
 93833        if (entry.Values is null)
 234            return null;
 35
 342736        foreach (var value in entry.Values)
 37        {
 107338            if (StringComparer.Ordinal.Equals(value.Name.ToString(), fieldName))
 59139                return value.Value.ToString();
 40        }
 41
 34542        return null;
 43    }
 44}