Skip to content

Commit 797caaa

Browse files
committed
Throw correct exception on Linux/MacOS
1 parent c2b8ea6 commit 797caaa

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ public InMemoryStorage(MockFileSystem fileSystem)
123123
}
124124

125125
/// <inheritdoc cref="IStorage.DeleteContainer(IStorageLocation, FileSystemTypes, bool)" />
126-
public bool DeleteContainer(IStorageLocation location, FileSystemTypes expectedType, bool recursive = false)
126+
public bool DeleteContainer(
127+
IStorageLocation location,
128+
FileSystemTypes expectedType,
129+
bool recursive = false)
127130
{
128131
if (!_containers.TryGetValue(location, out IStorageContainer? container))
129132
{
@@ -140,8 +143,11 @@ public bool DeleteContainer(IStorageLocation location, FileSystemTypes expectedT
140143
{
141144
if (expectedType == FileSystemTypes.Directory)
142145
{
143-
throw ExceptionFactory.InvalidDirectoryName(location.FullPath);
146+
throw _fileSystem.Execute.IsWindows
147+
? ExceptionFactory.InvalidDirectoryName(location.FullPath)
148+
: ExceptionFactory.DirectoryNotFound(location.FullPath);
144149
}
150+
145151
if (expectedType == FileSystemTypes.File)
146152
{
147153
throw ExceptionFactory.AccessToPathDenied(location.FullPath);

Tests/Testably.Abstractions.Tests/FileSystem/Directory/DeleteTests.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,23 @@ void Act()
225225
FileSystem.Directory.Delete(directoryName, true);
226226
}
227227

228-
await That(Act).Throws<IOException>()
229-
.WithMessage($"*The directory name is invalid*{expectedPath}*").AsWildcard().And
230-
.WithHResult(Test.IsNetFramework ? -2146232800 : -2147024629);
228+
if (Test.IsNetFramework)
229+
{
230+
await That(Act).Throws<IOException>()
231+
.WithMessage("*The directory name is invalid*").AsWildcard();
232+
}
233+
else if (Test.RunsOnWindows)
234+
{
235+
await That(Act).Throws<IOException>()
236+
.WithMessage($"*The directory name is invalid*{expectedPath}*").AsWildcard().And
237+
.WithHResult(-2147024629);
238+
}
239+
else
240+
{
241+
await That(Act).Throws<DirectoryNotFoundException>()
242+
.WithMessage($"*Could not find a part of the path*{expectedPath}*").AsWildcard().And
243+
.WithHResult(-2147024893);
244+
}
231245
}
232246

233247
[Theory]

0 commit comments

Comments
 (0)