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

Information
Class: AsyncResponse.Transports.AzureServiceBus.AzureServiceBusCorrelationIdExtractor
Assembly: AsyncResponse.Transports.AzureServiceBus
File(s): /_/src/Transports/AsyncResponse.Transports.AzureServiceBus/AzureServiceBusCorrelationIdExtractor.cs
Line coverage
90%
Covered lines: 20
Uncovered lines: 2
Coverable lines: 22
Total lines: 48
Line coverage: 90.9%
Branch coverage
90%
Covered branches: 20
Total branches: 22
Branch coverage: 90.9%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Extract(...)100%1010100%
TryConvertProperty(...)83.33%121285.71%

File(s)

/_/src/Transports/AsyncResponse.Transports.AzureServiceBus/AzureServiceBusCorrelationIdExtractor.cs

#LineLine coverage
 1using System.Globalization;
 2using System.Text;
 3
 4namespace AsyncResponse.Transports.AzureServiceBus;
 5
 6/// <summary>
 7/// Extracts the AsyncResponse correlation id from an inbound response message: first from the
 8/// broker's own CorrelationId, then the configured application property, then from the JSON body
 9/// via the configured paths (walked by the shared <see cref="CorrelationIdJsonPaths"/>).
 10/// </summary>
 11internal static class AzureServiceBusCorrelationIdExtractor
 12{
 13    /// <summary>Extracts the correlation id from the supplied Service Bus delivery.</summary>
 14    public static string? Extract(
 15        AzureServiceBusTransportDelivery delivery,
 16        string messageJson,
 17        AzureServiceBusAsyncResponseOptions options)
 18    {
 4419        if (!string.IsNullOrWhiteSpace(delivery.CorrelationId))
 420            return delivery.CorrelationId;
 21
 4022        if (!string.IsNullOrWhiteSpace(options.CorrelationIdProperty)
 4023            && delivery.ApplicationProperties.TryGetValue(options.CorrelationIdProperty, out var property)
 4024            && TryConvertProperty(property) is { } propertyValue
 4025            && !string.IsNullOrWhiteSpace(propertyValue))
 26        {
 1627            return propertyValue;
 28        }
 29
 2430        return CorrelationIdJsonPaths.Extract(messageJson, options.CorrelationIdJsonPaths);
 31    }
 32
 33    internal static string? TryConvertProperty(object? property)
 1834        => property switch
 1835        {
 036            null => null,
 437            string s => s,
 238            byte[] bytes => Encoding.UTF8.GetString(bytes),
 239            ReadOnlyMemory<byte> memory => Encoding.UTF8.GetString(memory.Span),
 240            BinaryData data => data.ToString(),
 1841            // AMQP application properties legally carry numeric/timestamp values, and the id must
 1842            // render the same on every consumer: a locale-formatted "1,5" here never matches the
 1843            // "1.5" the waiter registered under, so the wait runs to timeout on hosts with another
 1844            // CurrentCulture.
 845            IFormattable formattable => formattable.ToString(null, CultureInfo.InvariantCulture),
 046            _ => property.ToString()
 1847        };
 48}