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

Information
Class: AsyncResponse.Transports.AzureServiceBus.AzureServiceBusReplyTargetProvider
Assembly: AsyncResponse.Transports.AzureServiceBus
File(s): /home/runner/work/AsyncResponse/AsyncResponse/src/Transports/AsyncResponse.Transports.AzureServiceBus/AzureServiceBusReplyTargetProvider.cs
Line coverage
100%
Covered lines: 31
Uncovered lines: 0
Coverable lines: 31
Total lines: 52
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%22100%
ResolveTarget(...)100%44100%

File(s)

/home/runner/work/AsyncResponse/AsyncResponse/src/Transports/AsyncResponse.Transports.AzureServiceBus/AzureServiceBusReplyTargetProvider.cs

#LineLine coverage
 1using Microsoft.Extensions.Options;
 2
 3namespace AsyncResponse.Transports.AzureServiceBus;
 4
 35internal sealed class AzureServiceBusReplyTargetProvider(
 36    IOptions<AzureServiceBusAsyncResponseOptions> _options) : IAsyncResponseReplyTargetProvider
 7{
 8    /// <summary>Gets the configured reply target.</summary>
 9    public AsyncResponseReplyTarget GetReplyTarget(string? name = null)
 10    {
 311        var options = _options.Value;
 312        AzureServiceBusOptionsValidator.ValidateCommon(options);
 313        var targetName = string.IsNullOrWhiteSpace(name)
 314            ? options.DefaultReplyTargetName
 315            : name;
 16
 317        var target = ResolveTarget(options, targetName);
 318        var queue = AzureServiceBusOptionsValidator.Required(
 319            target.Queue,
 320            $"{nameof(AzureServiceBusReplyTargetOptions)}.{nameof(AzureServiceBusReplyTargetOptions.Queue)}");
 21
 322        var properties = new Dictionary<string, string>(target.Properties, StringComparer.Ordinal)
 323        {
 324            ["queue"] = queue,
 325            ["correlationIdProperty"] = options.CorrelationIdProperty
 326        };
 27
 328        return new AsyncResponseReplyTarget
 329        {
 330            Name = targetName,
 331            Transport = AzureServiceBusAsyncResponseOptions.TransportName,
 332            Address = queue,
 333            Properties = properties
 334        };
 35    }
 36
 37    private static AzureServiceBusReplyTargetOptions ResolveTarget(
 38        AzureServiceBusAsyncResponseOptions options,
 39        string targetName)
 40    {
 341        if (options.ReplyTargets.TryGetValue(targetName, out var configured))
 342            return configured;
 43
 344        if (StringComparer.Ordinal.Equals(targetName, options.DefaultReplyTargetName))
 345            return new AzureServiceBusReplyTargetOptions { Queue = options.ResponseQueue };
 46
 347        throw new InvalidOperationException(
 348            $"Azure Service Bus async-response reply target '{targetName}' is not configured. " +
 349            $"Configure {nameof(AzureServiceBusAsyncResponseOptions.ResponseQueue)} for the default target " +
 350            $"or add a named target with {nameof(AzureServiceBusAsyncResponseOptions.AddReplyTarget)}.");
 51    }
 52}