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

Information
Class: AsyncResponse.Transports.SqlServer.SqlServerReplyTargetProvider
Assembly: AsyncResponse.Transports.SqlServer
File(s): /home/runner/work/AsyncResponse/AsyncResponse/src/Transports/AsyncResponse.Transports.SqlServer/SqlServerReplyTargetProvider.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 54
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.SqlServer/SqlServerReplyTargetProvider.cs

#LineLine coverage
 1using Microsoft.Extensions.Options;
 2
 3namespace AsyncResponse.Transports.SqlServer;
 4
 35internal sealed class SqlServerReplyTargetProvider(
 36    IOptions<SqlServerAsyncResponseTransportOptions> _options) : IAsyncResponseReplyTargetProvider
 7{
 8    /// <inheritdoc />
 9    public AsyncResponseReplyTarget GetReplyTarget(string? name = null)
 10    {
 311        var options = _options.Value;
 312        SqlServerTransportOptionsValidator.ValidateCommon(options);
 313        var targetName = string.IsNullOrWhiteSpace(name)
 314            ? options.DefaultReplyTargetName
 315            : name;
 16
 317        var target = ResolveTarget(options, targetName);
 318        var responseQueue = SqlServerTransportOptionsValidator.Required(
 319            target.ResponseQueue,
 320            $"{nameof(SqlServerReplyTargetOptions)}.{nameof(SqlServerReplyTargetOptions.ResponseQueue)}");
 21
 322        var properties = new Dictionary<string, string>(target.Properties, StringComparer.Ordinal)
 323        {
 324            ["schema"] = options.SchemaName,
 325            ["table"] = options.MessageTable,
 326            ["queue"] = responseQueue,
 327            ["correlationIdHeader"] = options.CorrelationIdHeader
 328        };
 29
 330        return new AsyncResponseReplyTarget
 331        {
 332            Name = targetName,
 333            Transport = SqlServerAsyncResponseTransportOptions.TransportName,
 334            Address = responseQueue,
 335            Properties = properties
 336        };
 37    }
 38
 39    private static SqlServerReplyTargetOptions ResolveTarget(
 40        SqlServerAsyncResponseTransportOptions options,
 41        string targetName)
 42    {
 343        if (options.ReplyTargets.TryGetValue(targetName, out var configured))
 344            return configured;
 45
 346        if (StringComparer.Ordinal.Equals(targetName, options.DefaultReplyTargetName))
 347            return new SqlServerReplyTargetOptions { ResponseQueue = options.ResponseQueue };
 48
 349        throw new InvalidOperationException(
 350            $"SQL Server async-response reply target '{targetName}' is not configured. " +
 351            $"Configure {nameof(SqlServerAsyncResponseTransportOptions.ResponseQueue)} for the default target " +
 352            $"or add a named target with {nameof(SqlServerAsyncResponseTransportOptions.AddReplyTarget)}.");
 53    }
 54}