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

Information
Class: AsyncResponse.Transports.GooglePubSub.GooglePubSubReplyTargetProvider
Assembly: AsyncResponse.Transports.GooglePubSub
File(s): /home/runner/work/AsyncResponse/AsyncResponse/src/Transports/AsyncResponse.Transports.GooglePubSub/GooglePubSubReplyTargetProvider.cs
Line coverage
100%
Covered lines: 38
Uncovered lines: 0
Coverable lines: 38
Total lines: 62
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
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%66100%

File(s)

/home/runner/work/AsyncResponse/AsyncResponse/src/Transports/AsyncResponse.Transports.GooglePubSub/GooglePubSubReplyTargetProvider.cs

#LineLine coverage
 1using Google.Cloud.PubSub.V1;
 2using Microsoft.Extensions.Options;
 3
 4namespace AsyncResponse.Transports.GooglePubSub;
 5
 36internal sealed class GooglePubSubReplyTargetProvider(
 37    IOptions<GooglePubSubAsyncResponseOptions> _options) : IAsyncResponseReplyTargetProvider
 8{
 9    /// <summary>Gets the configured reply target.</summary>
 10    public AsyncResponseReplyTarget GetReplyTarget(string? name = null)
 11    {
 312        var options = _options.Value;
 313        var targetName = string.IsNullOrWhiteSpace(name)
 314            ? options.DefaultReplyTargetName
 315            : name;
 16
 317        var target = ResolveTarget(options, targetName);
 318        var projectId = GooglePubSubOptionsValidator.Required(
 319            target.ProjectId ?? options.ProjectId,
 320            $"{nameof(GooglePubSubReplyTargetOptions)}.{nameof(GooglePubSubReplyTargetOptions.ProjectId)}");
 321        var topicId = GooglePubSubOptionsValidator.Required(
 322            target.TopicId,
 323            $"{nameof(GooglePubSubReplyTargetOptions)}.{nameof(GooglePubSubReplyTargetOptions.TopicId)}");
 24
 325        var properties = new Dictionary<string, string>(target.Properties, StringComparer.Ordinal)
 326        {
 327            ["projectId"] = projectId,
 328            ["topicId"] = topicId
 329        };
 30
 331        return new AsyncResponseReplyTarget
 332        {
 333            Name = targetName,
 334            Transport = GooglePubSubAsyncResponseOptions.TransportName,
 335            Address = TopicName.FromProjectTopic(projectId, topicId).ToString(),
 336            Properties = properties
 337        };
 38    }
 39
 40    private static GooglePubSubReplyTargetOptions ResolveTarget(
 41        GooglePubSubAsyncResponseOptions 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            && !string.IsNullOrWhiteSpace(options.ResponseTopicId))
 49        {
 350            return new GooglePubSubReplyTargetOptions
 351            {
 352                ProjectId = options.ProjectId,
 353                TopicId = options.ResponseTopicId
 354            };
 55        }
 56
 257        throw new InvalidOperationException(
 258            $"Google Pub/Sub async-response reply target '{targetName}' is not configured. " +
 259            $"Configure {nameof(GooglePubSubAsyncResponseOptions.ResponseTopicId)} for the default target " +
 260            $"or add a named target with {nameof(GooglePubSubAsyncResponseOptions.AddReplyTarget)}.");
 61    }
 62}