< Summary - SonghayCore

Information
Class: Songhay.Extensions.RestApiMetadataExtensions
Assembly: SonghayCore
File(s): /home/rasx/sourceRoot/SonghayCore/SonghayCore/Extensions/RestApiMetadataExtensions.cs
Line coverage
91%
Covered lines: 11
Uncovered lines: 1
Coverable lines: 12
Total lines: 33
Line coverage: 91.6%
Branch coverage
50%
Covered branches: 4
Total branches: 8
Branch coverage: 50%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
ToUri(...)50%891.66%

File(s)

/home/rasx/sourceRoot/SonghayCore/SonghayCore/Extensions/RestApiMetadataExtensions.cs

#LineLine coverage
 1namespace Songhay.Extensions;
 2
 3/// <summary>
 4/// Extensions of <see cref="RestApiMetadata"/>.
 5/// </summary>
 6public static class RestApiMetadataExtensions
 7{
 8    /// <summary>
 9    /// To the URI.
 10    /// </summary>
 11    /// <param name="meta">The meta.</param>
 12    /// <param name="uriTemplateKey">The URI template key.</param>
 13    /// <param name="bindByPositionValues">The bind by position values.</param>
 14    public static Uri? ToUri(this RestApiMetadata? meta, string? uriTemplateKey, params string?[] bindByPositionValues)
 115    {
 116        if (meta == null || meta.ApiBase == null) return null;
 17
 118        bindByPositionValues.ThrowWhenNullOrEmpty();
 19
 220        if (meta.UriTemplates.Keys.All(i => i != uriTemplateKey))
 021            throw new FormatException("The expected REST API metadata URI template key is not here.");
 22
 23        const string forwardSlash = "/";
 124        var uriBase = meta.ApiBase.OriginalString.EndsWith(forwardSlash)
 125            ? string.Concat(meta.ApiBase.OriginalString, meta.UriTemplates[uriTemplateKey!])
 126            : string.Concat(meta.ApiBase.OriginalString, forwardSlash, meta.UriTemplates[uriTemplateKey!]);
 27
 128        var uriTemplate = new UriTemplate(uriBase);
 129        var uri = uriTemplate.BindByPosition(bindByPositionValues!);
 30
 131        return uri;
 132    }
 33}