< Summary

Information
Class: Amusoft.DotnetNew.Tests.Utility.CrossPlatformPath
Assembly: Amusoft.DotnetNew.Tests
File(s): /home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/src/Amusoft.DotnetNew.Tests/Utility/CrossPlatformPath.cs
Tag: 127_14865883074
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 88
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%22100%
get_OriginalPath()100%11100%
get_VirtualPath()100%11100%
ToString()100%11100%
GetHashCode()100%11100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Diagnostics.CodeAnalysis;
 3using System.Runtime.InteropServices;
 4
 5namespace Amusoft.DotnetNew.Tests.Utility;
 6
 7/// <summary>
 8/// Unix and Windows systems have different path seperators which makes testing templates harder
 9/// if you for example develop on windows but run your tests on unix
 10/// </summary>
 11public class CrossPlatformPath : IEquatable<CrossPlatformPath>
 12{
 13  private readonly string _originalPath;
 14  private readonly string _virtualPath;
 15
 16  /// <summary>
 17  ///
 18  /// </summary>
 19  /// <param name="originalPath"></param>
 16420  public CrossPlatformPath(string originalPath)
 21  {
 16422    _originalPath = originalPath;
 16423    _virtualPath =
 16424      RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
 16425      ? originalPath.Replace('\\', '/')
 16426      : originalPath;
 16427  }
 28
 29  /// <summary>
 30  /// Native path
 31  /// </summary>
 8832  public string OriginalPath => _originalPath;
 33
 34  /// <summary>
 35  /// Path that is the same accross multiple operating systems
 36  /// </summary>
 11437  public string VirtualPath => _virtualPath;
 38
 39  /// <summary>
 40  /// Why are you looking at this tooltip?
 41  /// </summary>
 42  /// <returns></returns>
 43  public override string ToString()
 44  {
 145    return $"{OriginalPath} -> {VirtualPath}";
 46  }
 47
 48  /// <summary>
 49  ///
 50  /// </summary>
 51  /// <param name="other"></param>
 52  /// <returns></returns>
 53  [ExcludeFromCodeCoverage]
 54  public bool Equals(CrossPlatformPath? other)
 55  {
 56    if (ReferenceEquals(null, other))
 57      return false;
 58    if (ReferenceEquals(this, other))
 59      return true;
 60    return _virtualPath == other._virtualPath;
 61  }
 62
 63  /// <summary>
 64  ///
 65  /// </summary>
 66  /// <param name="obj"></param>
 67  /// <returns></returns>
 68  [ExcludeFromCodeCoverage]
 69  public override bool Equals(object? obj)
 70  {
 71    if (ReferenceEquals(null, obj))
 72      return false;
 73    if (ReferenceEquals(this, obj))
 74      return true;
 75    if (obj.GetType() != this.GetType())
 76      return false;
 77    return Equals((CrossPlatformPath)obj);
 78  }
 79
 80  /// <summary>
 81  ///
 82  /// </summary>
 83  /// <returns></returns>
 84  public override int GetHashCode()
 85  {
 286    return _virtualPath.GetHashCode();
 87  }
 88}