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

Information
Class: AsyncResponse.Transports.GooglePubSub.GooglePubSubReplyTargetProvider
Assembly: AsyncResponse.Transports.GooglePubSub
File(s): /_/src/Transports/AsyncResponse.Transports.GooglePubSub/GooglePubSubReplyTargetProvider.cs
Line coverage
100%
Covered lines: 44
Uncovered lines: 0
Coverable lines: 44
Total lines: 76
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
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%88100%
ResolveTarget(...)100%66100%

File(s)

/_/src/Transports/AsyncResponse.Transports.GooglePubSub/GooglePubSubReplyTargetProvider.cs

#LineLine coverage
 1using Google.Cloud.PubSub.V1;
 2using Microsoft.Extensions.Options;
 3
 4namespace AsyncResponse.Transports.GooglePubSub;
 5
 2066internal sealed class GooglePubSubReplyTargetProvider(
 2067    IOptions<GooglePubSubAsyncResponseOptions> _options) : IAsyncResponseReplyTargetProvider
 8{
 9    /// <summary>Gets the configured reply target.</summary>
 10    public AsyncResponseReplyTarget GetReplyTarget(string? name = null)
 11    {
 1412        var options = _options.Value;
 13        // Options-validator parity with the other transports' providers: a hand-off address must
 14        // come from a configuration that passes the transport's own checks.
 1415        GooglePubSubOptionsValidator.ValidateTimeouts(options);
 1416        var targetName = string.IsNullOrWhiteSpace(name)
 1417            ? options.DefaultReplyTargetName
 1418            : name;
 19
 1420        var target = ResolveTarget(options, targetName);
 1021        var projectId = GooglePubSubOptionsValidator.Required(
 1022            target.ProjectId ?? options.ProjectId,
 1023            $"{nameof(GooglePubSubReplyTargetOptions)}.{nameof(GooglePubSubReplyTargetOptions.ProjectId)}");
 1024        var topicId = GooglePubSubOptionsValidator.Required(
 1025            target.TopicId,
 1026            $"{nameof(GooglePubSubReplyTargetOptions)}.{nameof(GooglePubSubReplyTargetOptions.TopicId)}");
 27
 28        // A NAMED target must not be the worker topic in the transport's own project
 29        // (DB-transport parity): its responses would be consumed as worker jobs while the waiter
 30        // times out.
 1031        if (StringComparer.Ordinal.Equals(projectId, options.ProjectId)
 1032            && StringComparer.Ordinal.Equals(topicId, options.WorkerTopicId))
 33        {
 234            throw new InvalidOperationException(
 235                $"Google Pub/Sub async-response reply target '{targetName}' uses topic '{topicId}' in project '{projectI
 236                $"{nameof(GooglePubSubAsyncResponseOptions.WorkerTopicId)}; its responses would be consumed as worker jo
 37        }
 38
 839        var properties = new Dictionary<string, string>(target.Properties, StringComparer.Ordinal)
 840        {
 841            ["projectId"] = projectId,
 842            ["topicId"] = topicId
 843        };
 44
 845        return new AsyncResponseReplyTarget
 846        {
 847            Name = targetName,
 848            Transport = GooglePubSubAsyncResponseOptions.TransportName,
 849            Address = TopicName.FromProjectTopic(projectId, topicId).ToString(),
 850            Properties = properties
 851        };
 52    }
 53
 54    private static GooglePubSubReplyTargetOptions ResolveTarget(
 55        GooglePubSubAsyncResponseOptions options,
 56        string targetName)
 57    {
 1458        if (options.ReplyTargets.TryGetValue(targetName, out var configured))
 859            return configured;
 60
 661        if (StringComparer.Ordinal.Equals(targetName, options.DefaultReplyTargetName)
 662            && !string.IsNullOrWhiteSpace(options.ResponseTopicId))
 63        {
 264            return new GooglePubSubReplyTargetOptions
 265            {
 266                ProjectId = options.ProjectId,
 267                TopicId = options.ResponseTopicId
 268            };
 69        }
 70
 471        throw new InvalidOperationException(
 472            $"Google Pub/Sub async-response reply target '{targetName}' is not configured. " +
 473            $"Configure {nameof(GooglePubSubAsyncResponseOptions.ResponseTopicId)} for the default target " +
 474            $"or add a named target with {nameof(GooglePubSubAsyncResponseOptions.AddReplyTarget)}.");
 75    }
 76}