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

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

/home/runner/work/AsyncResponse/AsyncResponse/src/Transports/AsyncResponse.Transports.MongoDB/MongoDbReplyTargetProvider.cs

#LineLine coverage
 1using Microsoft.Extensions.Options;
 2
 3namespace AsyncResponse.Transports.MongoDB;
 4
 35internal sealed class MongoDbReplyTargetProvider(
 36    IOptions<MongoDbAsyncResponseTransportOptions> _options) : IAsyncResponseReplyTargetProvider
 7{
 8    /// <inheritdoc />
 9    public AsyncResponseReplyTarget GetReplyTarget(string? name = null)
 10    {
 311        var options = _options.Value;
 312        MongoDbTransportOptionsValidator.ValidateCommon(options);
 313        var targetName = string.IsNullOrWhiteSpace(name)
 314            ? options.DefaultReplyTargetName
 315            : name;
 16
 317        var target = ResolveTarget(options, targetName);
 318        var responseQueue = MongoDbTransportOptionsValidator.Required(
 319            target.ResponseQueue,
 320            $"{nameof(MongoDbReplyTargetOptions)}.{nameof(MongoDbReplyTargetOptions.ResponseQueue)}");
 21
 322        var properties = new Dictionary<string, string>(target.Properties, StringComparer.Ordinal)
 323        {
 324            ["collection"] = options.MessageCollection,
 325            ["queue"] = responseQueue,
 326            ["correlationIdHeader"] = options.CorrelationIdHeader
 327        };
 328        if (!string.IsNullOrWhiteSpace(options.DatabaseName))
 329            properties["database"] = options.DatabaseName!;
 30
 331        return new AsyncResponseReplyTarget
 332        {
 333            Name = targetName,
 334            Transport = MongoDbAsyncResponseTransportOptions.TransportName,
 335            Address = responseQueue,
 336            Properties = properties
 337        };
 38    }
 39
 40    private static MongoDbReplyTargetOptions ResolveTarget(
 41        MongoDbAsyncResponseTransportOptions options,
 42        string targetName)
 43    {
 344        if (options.ReplyTargets.TryGetValue(targetName, out var configured))
 345            return configured;
 46
 347        if (StringComparer.Ordinal.Equals(targetName, options.DefaultReplyTargetName))
 348            return new MongoDbReplyTargetOptions { ResponseQueue = options.ResponseQueue };
 49
 350        throw new InvalidOperationException(
 351            $"MongoDB async-response reply target '{targetName}' is not configured. " +
 352            $"Configure {nameof(MongoDbAsyncResponseTransportOptions.ResponseQueue)} for the default target " +
 353            $"or add a named target with {nameof(MongoDbAsyncResponseTransportOptions.AddReplyTarget)}.");
 54    }
 55}