Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.IO;
using Testably.Abstractions.Testing.Helpers;

namespace Testably.Abstractions.Testing.Statistics;
Expand Down Expand Up @@ -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))
Expand All @@ -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('/', '\\');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IFileInfoFactory, IFileInfo> 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<IFileInfoFactory, IFileInfo> 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("\\")]
Expand Down
Loading