< Summary - SonghayCore

Information
Class: Songhay.Extensions.UriTemplateExtensions
Assembly: SonghayCore
File(s): /home/rasx/sourceRoot/SonghayCore/SonghayCore/Extensions/UriTemplateExtensions.cs
Line coverage
83%
Covered lines: 15
Uncovered lines: 3
Coverable lines: 18
Total lines: 48
Line coverage: 83.3%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
BindByPosition(...)100%1100%
BindByPosition(...)60%1082.35%

File(s)

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

#LineLine coverage
 1namespace Songhay.Extensions;
 2
 3/// <summary>
 4/// Extensions of <see cref="UriTemplate"/>
 5/// </summary>
 6public static class UriTemplateExtensions
 7{
 8    /// <summary>
 9    /// Binds the <see cref="UriTemplate"/>
 10    /// to the specified <c>params</c> by position.
 11    /// </summary>
 12    /// <param name="template">The template.</param>
 13    /// <param name="values">The values.</param>
 14    public static Uri? BindByPosition(this UriTemplate? template, params string[] values) =>
 315        template.BindByPosition(baseUri: null, values: values);
 16
 17    /// <summary>
 18    /// Binds the <see cref="UriTemplate" />
 19    /// to the specified <c>params</c> by position.
 20    /// </summary>
 21    /// <param name="template">The template.</param>
 22    /// <param name="baseUri">The base URI.</param>
 23    /// <param name="values">The values.</param>
 24    public static Uri? BindByPosition(this UriTemplate? template, Uri? baseUri, params string[] values)
 325    {
 326        ArgumentNullException.ThrowIfNull(template);
 27
 328        var keys = template.GetParameterNames().ToReferenceTypeValueOrThrow().ToArray();
 29
 1630        for (int i = 0; i < keys.Length; i++)
 531        {
 532            template.AddParameter(keys[i], values.ElementAtOrDefault(i));
 533        }
 34
 335        var resolved = template.Resolve();
 336        if (baseUri != null)
 037        {
 038            return new UriBuilder(baseUri).WithPath(resolved)!.Uri;
 39        }
 40
 341        var isAbsolute = Uri.IsWellFormedUriString(resolved, UriKind.Absolute);
 342        var isRelative = Uri.IsWellFormedUriString(resolved, UriKind.Relative);
 343        if (!isAbsolute && !isRelative)
 044            throw new FormatException($"The resolved URI template, {resolved}, is in an unknown format.");
 45
 346        return isAbsolute ? new Uri(resolved, UriKind.Absolute) : new Uri(resolved, UriKind.Relative);
 347    }
 48}