From 9b3c1c188ad95fb09886676be33ec9e4fa6afe0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Mon, 29 Apr 2024 17:11:43 +0200 Subject: [PATCH] Simplify SimulatedPath and NativePath implementation --- .../Helpers/Execute.NativePath.cs | 11 ++++------- .../Helpers/Execute.SimulatedPath.cs | 1 - .../FileSystem/Path/GetPathRootTests.cs | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Source/Testably.Abstractions.Testing/Helpers/Execute.NativePath.cs b/Source/Testably.Abstractions.Testing/Helpers/Execute.NativePath.cs index f5463a80f..28ed33561 100644 --- a/Source/Testably.Abstractions.Testing/Helpers/Execute.NativePath.cs +++ b/Source/Testably.Abstractions.Testing/Helpers/Execute.NativePath.cs @@ -132,17 +132,15 @@ public string GetFullPath(string path) string? pathRoot = System.IO.Path.GetPathRoot(path); string? directoryRoot = System.IO.Path.GetPathRoot(fileSystem.Storage.CurrentDirectory); - if (!string.IsNullOrEmpty(pathRoot) && !string.IsNullOrEmpty(directoryRoot)) + if (pathRoot?.Length < directoryRoot?.Length) { - if (char.ToUpperInvariant(pathRoot[0]) != char.ToUpperInvariant(directoryRoot[0])) + if (pathRoot.Length > 0 && + char.ToUpperInvariant(pathRoot[0]) != char.ToUpperInvariant(directoryRoot[0])) { return System.IO.Path.GetFullPath(path); } - if (pathRoot.Length < directoryRoot.Length) - { - path = path.Substring(pathRoot.Length); - } + path = path.Substring(pathRoot.Length); } return System.IO.Path.GetFullPath(System.IO.Path.Combine( @@ -183,7 +181,6 @@ public string GetRandomFileName() public string GetRelativePath(string relativeTo, string path) { relativeTo.EnsureValidArgument(fileSystem, nameof(relativeTo)); - path.EnsureValidArgument(fileSystem, nameof(path)); relativeTo = fileSystem.Execute.Path.GetFullPath(relativeTo); path = fileSystem.Execute.Path.GetFullPath(path); diff --git a/Source/Testably.Abstractions.Testing/Helpers/Execute.SimulatedPath.cs b/Source/Testably.Abstractions.Testing/Helpers/Execute.SimulatedPath.cs index c81ac1517..5242af70d 100644 --- a/Source/Testably.Abstractions.Testing/Helpers/Execute.SimulatedPath.cs +++ b/Source/Testably.Abstractions.Testing/Helpers/Execute.SimulatedPath.cs @@ -290,7 +290,6 @@ public string GetRandomFileName() public string GetRelativePath(string relativeTo, string path) { relativeTo.EnsureValidArgument(fileSystem, nameof(relativeTo)); - path.EnsureValidArgument(fileSystem, nameof(path)); relativeTo = fileSystem.Execute.Path.GetFullPath(relativeTo); path = fileSystem.Execute.Path.GetFullPath(path); diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Path/GetPathRootTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Path/GetPathRootTests.cs index 758e76dae..b66b759ca 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Path/GetPathRootTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Path/GetPathRootTests.cs @@ -44,7 +44,7 @@ public void GetPathRoot_ShouldReturnDefaultValue(string path) { string? result = FileSystem.Path.GetPathRoot(path); - result.Should().Be(System.IO.Path.GetPathRoot(path)); + result.Should().Be(""); } #if FEATURE_SPAN