< Summary - SonghayCore

Information
Class: Songhay.Extensions.UriBuilderExtensions
Assembly: SonghayCore
File(s): /home/rasx/sourceRoot/SonghayCore/SonghayCore/Extensions/UriBuilderExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 33
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
WithPath(...)0%40%

File(s)

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

#LineLine coverage
 1namespace Songhay.Extensions;
 2
 3/// <summary>
 4/// Extensions of <see cref="UriBuilder"/>.
 5/// </summary>
 6public static class UriBuilderExtensions
 7{
 8    /// <summary>
 9    /// Returns <see cref="UriBuilder"/>
 10    /// with the specified path.
 11    /// </summary>
 12    /// <param name="builder">The builder.</param>
 13    /// <param name="path">The path.</param>
 14    public static UriBuilder? WithPath(this UriBuilder? builder, string? path)
 015    {
 016        if (builder == null) return null;
 017        if (string.IsNullOrWhiteSpace(path)) return builder;
 18
 19        const string delimiter = "/";
 20        const char delimiterChar = '/';
 21
 022        var baseSegments = builder.Uri.Segments
 023            .Where(i => i != delimiter)
 024            .Select(i => i.Trim(delimiterChar));
 025        var pathSegments = path.Split(delimiterChar)
 026            .Where(i => !string.IsNullOrWhiteSpace(i));
 027        var combinedSegments = baseSegments.Union(pathSegments);
 28
 029        builder.Path = string.Join(delimiter, combinedSegments.ToArray());
 30
 031        return builder;
 032    }
 33}