<PackageReference Include="NUnit" Version="4.3.2" />

PathConstraint

public abstract class PathConstraint : StringConstraint
PathConstraint serves as the abstract base of constraints that operate on paths and provides several helper methods.
using System; using System.IO; using System.Runtime.CompilerServices; namespace NUnit.Framework.Constraints { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public abstract class PathConstraint : StringConstraint { private const char WindowsDirectorySeparatorChar = '\\'; private const char NonWindowsDirectorySeparatorChar = '/'; private static readonly char[] DirectorySeparatorChars = new char[2] { '\\', '/' }; public PathConstraint RespectCase { get { caseInsensitive = false; return this; } } protected PathConstraint(string expected) : base(expected) { caseInsensitive = (Path.DirectorySeparatorChar == '\\'); } protected override string GetStringRepresentation() { return "<" + DisplayName.ToLower() + " \"" + expected + "\" " + (caseInsensitive ? "ignorecase" : "respectcase") + ">"; } protected string Canonicalize(string path) { if (Path.DirectorySeparatorChar != Path.AltDirectorySeparatorChar) path = path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); string text = string.Empty; string text2 = path; char directorySeparatorChar; foreach (char c in text2) { if (c != '\\' && c != '/') break; string str = text; directorySeparatorChar = Path.DirectorySeparatorChar; text = str + directorySeparatorChar.ToString(); } string[] array = path.Split(DirectorySeparatorChars, StringSplitOptions.RemoveEmptyEntries); int num = 0; bool flag = false; string[] array2 = array; foreach (string text3 in array2) { if (!(text3 == ".") && (text3 == null || text3.Length != 0)) { if (text3 == "..") { flag = true; if (num > 0) num--; } else { if (flag) array[num] = text3; num++; } } else flag = true; } string str2 = text; directorySeparatorChar = Path.DirectorySeparatorChar; return str2 + string.Join(directorySeparatorChar.ToString(), array, 0, num); } protected StringComparison DetermineComparisonType() { if (!caseInsensitive) return StringComparison.Ordinal; return StringComparison.OrdinalIgnoreCase; } protected bool IsSubPath(string path1, string path2) { int length = path1.Length; int length2 = path2.Length; if (length >= length2) return false; if (!string.Equals(path1, path2.Substring(0, length), DetermineComparisonType())) return false; if (path2[length - 1] != Path.DirectorySeparatorChar) return path2[length] == Path.DirectorySeparatorChar; return true; } } }