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

Information
Class: AsyncResponse.Transports.AzureServiceBus.AzureServiceBusReplyTargetProvider
Assembly: AsyncResponse.Transports.AzureServiceBus
File(s): /_/src/Transports/AsyncResponse.Transports.AzureServiceBus/AzureServiceBusReplyTargetProvider.cs
Line coverage
100%
Covered lines: 35
Uncovered lines: 0
Coverable lines: 35
Total lines: 62
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
.ctor(...)100%11100%
GetReplyTarget(...)100%44100%
ResolveTarget(...)100%44100%

File(s)

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

#LineLine coverage
 1using Microsoft.Extensions.Options;
 2
 3namespace AsyncResponse.Transports.AzureServiceBus;
 4
 2035internal sealed class AzureServiceBusReplyTargetProvider(
 2036    IOptions<AzureServiceBusAsyncResponseOptions> _options) : IAsyncResponseReplyTargetProvider
 7{
 8    /// <summary>Gets the configured reply target.</summary>
 9    public AsyncResponseReplyTarget GetReplyTarget(string? name = null)
 10    {
 811        var options = _options.Value;
 812        AzureServiceBusOptionsValidator.ValidateCommon(options);
 813        var targetName = string.IsNullOrWhiteSpace(name)
 814            ? options.DefaultReplyTargetName
 815            : name;
 16
 817        var target = ResolveTarget(options, targetName);
 618        var queue = AzureServiceBusOptionsValidator.Required(
 619            target.Queue,
 620            $"{nameof(AzureServiceBusReplyTargetOptions)}.{nameof(AzureServiceBusReplyTargetOptions.Queue)}");
 21
 22        // A NAMED target must not be the worker queue (DB-transport parity): its responses would
 23        // be consumed as worker jobs, NAK-cycled to the cap and dead-lettered, while the waiter
 24        // times out. (The dead-letter queue is a sub-entity and cannot collide by name.)
 625        if (StringComparer.Ordinal.Equals(queue, options.WorkerQueue))
 26        {
 227            throw new InvalidOperationException(
 228                $"Azure Service Bus async-response reply target '{targetName}' uses queue '{queue}', which collides with
 229                $"{nameof(AzureServiceBusAsyncResponseOptions.WorkerQueue)}; its responses would be consumed as worker j
 30        }
 31
 432        var properties = new Dictionary<string, string>(target.Properties, StringComparer.Ordinal)
 433        {
 434            ["queue"] = queue,
 435            ["correlationIdProperty"] = options.CorrelationIdProperty
 436        };
 37
 438        return new AsyncResponseReplyTarget
 439        {
 440            Name = targetName,
 441            Transport = AzureServiceBusAsyncResponseOptions.TransportName,
 442            Address = queue,
 443            Properties = properties
 444        };
 45    }
 46
 47    private static AzureServiceBusReplyTargetOptions ResolveTarget(
 48        AzureServiceBusAsyncResponseOptions options,
 49        string targetName)
 50    {
 851        if (options.ReplyTargets.TryGetValue(targetName, out var configured))
 452            return configured;
 53
 454        if (StringComparer.Ordinal.Equals(targetName, options.DefaultReplyTargetName))
 255            return new AzureServiceBusReplyTargetOptions { Queue = options.ResponseQueue };
 56
 257        throw new InvalidOperationException(
 258            $"Azure Service Bus async-response reply target '{targetName}' is not configured. " +
 259            $"Configure {nameof(AzureServiceBusAsyncResponseOptions.ResponseQueue)} for the default target " +
 260            $"or add a named target with {nameof(AzureServiceBusAsyncResponseOptions.AddReplyTarget)}.");
 61    }
 62}