diff --git a/Source/Testably.Abstractions.Testing/Initializer/DirectoryCleaner.cs b/Source/Testably.Abstractions.Testing/Initializer/DirectoryCleaner.cs index d3f7cb54a..7703dadda 100644 --- a/Source/Testably.Abstractions.Testing/Initializer/DirectoryCleaner.cs +++ b/Source/Testably.Abstractions.Testing/Initializer/DirectoryCleaner.cs @@ -45,9 +45,9 @@ public void Dispose() { // It is important to reset the current directory, as otherwise deleting the BasePath // results in a IOException, because the process cannot access the file. - if (string.Equals( - _fileSystem.Directory.GetCurrentDirectory(), - BasePath, + // On Unix the deletion succeeds and leaves the process in a deleted current directory. + if (_fileSystem.Directory.GetCurrentDirectory().StartsWith( + _pathToDelete, _fileSystem.ExecuteOrDefault().StringComparisonMode)) { _fileSystem.Directory.SetCurrentDirectory(_fileSystem.Path.GetTempPath()); diff --git a/Source/Testably.Abstractions.Testing/Statistics/PathStatistics.cs b/Source/Testably.Abstractions.Testing/Statistics/PathStatistics.cs index 777a54343..6375e2905 100644 --- a/Source/Testably.Abstractions.Testing/Statistics/PathStatistics.cs +++ b/Source/Testably.Abstractions.Testing/Statistics/PathStatistics.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Concurrent; -using System.IO; using Testably.Abstractions.Testing.Helpers; namespace Testably.Abstractions.Testing.Statistics; @@ -238,7 +237,7 @@ internal IDisposable RegisterPathProperty(string path, string name, PropertyAcce return release; } - private static string CreateKey(string currentDirectory, string path) + private string CreateKey(string currentDirectory, string path) { string key = string.Empty; if (string.IsNullOrEmpty(path)) @@ -254,7 +253,8 @@ private static string CreateKey(string currentDirectory, string path) } else { - key = Path.GetFullPath(Path.Combine(currentDirectory, path)); + IPath mockPath = _fileSystem.Execute.Path; + key = mockPath.GetFullPath(mockPath.Combine(currentDirectory, path)); } return key.TrimEnd('/', '\\'); diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/PathStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/PathStatisticsTests.cs index 172a63edf..13d39a885 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/PathStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/PathStatisticsTests.cs @@ -66,6 +66,39 @@ public async Task Key_ShouldSimplifyRelativePaths() await That(absolutPath).IsEqualTo(relativePath); } +#if CAN_SIMULATE_OTHER_OS + [Test] + [Arguments(SimulationMode.Linux)] + [Arguments(SimulationMode.MacOS)] + public async Task Key_WhenSimulatingUnix_BackslashShouldBePartOfFileName( + SimulationMode simulationMode) + { + MockFileSystem fileSystem = new(o => o.SimulatingOperatingSystem(simulationMode)); + IPathStatistics sut = fileSystem.Statistics.FileInfo; + + IStatistics withBackslash = sut[@"foo\bar"]; + IStatistics withSlash = sut["foo/bar"]; + + await That(withBackslash).IsNotEqualTo(withSlash) + .Because("on Unix a backslash is a valid file name character and not a directory separator"); + } +#endif + +#if CAN_SIMULATE_OTHER_OS + [Test] + public async Task Key_WhenSimulatingWindows_BackslashAndSlashShouldBeDirectorySeparators() + { + MockFileSystem fileSystem = new(o => o.SimulatingOperatingSystem(SimulationMode.Windows)); + IPathStatistics sut = fileSystem.Statistics.FileInfo; + + IStatistics withBackslash = sut[@"foo\bar"]; + IStatistics withSlash = sut["foo/bar"]; + + await That(withBackslash).IsEqualTo(withSlash) + .Because("on Windows both are directory separators"); + } +#endif + [Test] [Arguments("/")] [Arguments("\\")]