< Summary

Information
Class: Amusoft.DotnetNew.Tests.Templating.PathSource
Assembly: Amusoft.DotnetNew.Tests
File(s): /home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/src/Amusoft.DotnetNew.Tests/Templating/PathSource.cs
Tag: 127_14865883074
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 54
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_PathTranslator()100%11100%
get_Directory()100%11100%
get_File()100%11100%

File(s)

/home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/src/Amusoft.DotnetNew.Tests/Templating/PathSource.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.IO;
 3using Amusoft.DotnetNew.Tests.Interfaces;
 4using Amusoft.DotnetNew.Tests.Utility;
 5
 6namespace Amusoft.DotnetNew.Tests.Templating;
 7
 8/// <summary>
 9/// Solution path details
 10/// </summary>
 11public class PathSource : IPathSource
 12{
 13  [ExcludeFromCodeCoverage]
 14  internal PathSource(string fullPath)
 15  {
 16    var paths = GetPathDetails(fullPath);
 17    File = new CrossPlatformPath(paths.File);
 18    Directory = new CrossPlatformPath(paths.Directory);
 19    PathTranslator = new PathTranslator(paths.Directory);
 20  }
 21
 22  [ExcludeFromCodeCoverage]
 23  private (string File, string Directory) GetPathDetails(string fullPath)
 24  {
 25    if (System.IO.File.Exists(fullPath) || System.IO.File.Exists(fullPath))
 26    {
 27      return System.IO.File.GetAttributes(fullPath).HasFlag(FileAttributes.Directory) switch
 28      {
 29        true => (File: fullPath, Directory: fullPath),
 30        false => (File: fullPath, Directory: Path.GetDirectoryName(fullPath)!),
 31      };
 32    }
 33
 34    // Path does not really exist, so we can only guess by extension
 35    return Path.GetExtension(fullPath) is { Length: > 0 }
 36      ? (fullPath, Path.GetDirectoryName(fullPath)!)
 37      : (fullPath, fullPath);
 38  }
 39
 40  /// <summary>
 41  /// Path translator for navigating the file system
 42  /// </summary>
 2443  public PathTranslator PathTranslator { get; }
 44
 45  /// <summary>
 46  /// Path to solution directory
 47  /// </summary>
 5448  public CrossPlatformPath Directory { get; }
 49
 50  /// <summary>
 51  /// Path to solution file
 52  /// </summary>
 1053  public CrossPlatformPath File { get; }
 54}