< Summary

Information
Class: Amusoft.DotnetNew.Tests.Utility.PathTranslator
Assembly: Amusoft.DotnetNew.Tests
File(s): /home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/src/Amusoft.DotnetNew.Tests/Utility/PathTranslator.cs
Tag: 127_14865883074
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 50
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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%
GetAbsolutePath(...)100%44100%
GetRelativePath(...)100%11100%

File(s)

/home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/src/Amusoft.DotnetNew.Tests/Utility/PathTranslator.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3
 4namespace Amusoft.DotnetNew.Tests.Utility;
 5
 6/// <summary>
 7/// Utility class to provide pathing details
 8/// </summary>
 9public class PathTranslator
 10{
 11  private readonly CrossPlatformPath _referenceDirectory;
 12
 13  /// <summary>
 14  /// Constructor
 15  /// </summary>
 16  /// <param name="referenceDirectory">absolute path to directory</param>
 3717  internal PathTranslator(string referenceDirectory)
 18  {
 3719    _referenceDirectory = new CrossPlatformPath(referenceDirectory.TrimEnd(Path.DirectorySeparatorChar));
 3720  }
 21
 22  /// <summary>
 23  /// Retrieves the absolute path based on the relative path in relation to the reference path
 24  /// </summary>
 25  /// <param name="relativePath">e.g. ../a/b/c</param>
 26  /// <returns></returns>
 27  /// <exception cref="ArgumentException"></exception>
 28  public CrossPlatformPath GetAbsolutePath(string relativePath)
 29  {
 2030    if (relativePath.StartsWith("./") || relativePath.StartsWith(".\\"))
 131      throw new ArgumentException("Relative paths should not start with the current location pattern or resolution would
 32
 1933    var absoluteUri = new Uri(new Uri(_referenceDirectory.VirtualPath + Path.DirectorySeparatorChar, UriKind.Absolute), 
 34
 1935    return new CrossPlatformPath(absoluteUri.AbsolutePath);
 36  }
 37
 38  /// <summary>
 39  /// Retrieves the relative path based on the absolute path in relation to the reference path
 40  /// </summary>
 41  /// <param name="absolutePath"></param>
 42  /// <returns></returns>
 43  public CrossPlatformPath GetRelativePath(string absolutePath)
 44  {
 1345    var baseUri = new Uri(_referenceDirectory.VirtualPath.TrimEnd('/') + '/', UriKind.Absolute);
 1346    var refUri = new Uri(new CrossPlatformPath(absolutePath).VirtualPath.TrimEnd('/') + '/', UriKind.Absolute);
 1347    var relUri = baseUri.MakeRelativeUri(refUri);
 1348    return new CrossPlatformPath(relUri.OriginalString.TrimEnd('/'));
 49  }
 50}