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 @@ -158,6 +158,12 @@ public override void Delete(string path, bool recursive)
" is not an empty directory.");
}

bool isFile = !mockFileDataAccessor.GetFile(path).IsDirectory;
if (isFile)
{
throw new IOException("The directory name is invalid.");
}

foreach (var affectedPath in affectedPaths)
{
mockFileDataAccessor.RemoveFile(affectedPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ public override void Delete(string path)
throw CommonExceptions.ProcessCannotAccessFileInUse(path);
}

if (file != null && file.IsDirectory)
{
throw new UnauthorizedAccessException($"Access to the path '{path}' is denied.");
}

mockFileDataAccessor.RemoveFile(path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,22 @@
Assert.That(fileSystem.Directory.Exists(XFS.Path(@"c:\bar\bar2")), Is.False);
}

[Test]
public void MockDirectory_Delete_ShouldThrowIOException_WhenPathIsAFile()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ XFS.Path(@"c:\foo.txt"), new MockFileData("Demo text content") },
});

// Act
TestDelegate action = () => fileSystem.Directory.Delete(XFS.Path(@"c:\foo.txt"));

// Assert
Assert.Throws<IOException>(action);
}

[Test]
public void MockDirectory_GetFileSystemEntries_Returns_Files_And_Directories()
{
Expand Down Expand Up @@ -2069,7 +2085,7 @@
var fileSystem = new MockFileSystem();

// Act
Assert.Throws<DirectoryNotFoundException>(() => fileSystem.Directory.GetAccessControl(XFS.Path(@"c:\foo")));

Check warning on line 2088 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

This call site is reachable on all platforms. 'DirectoryAclExtensions.GetAccessControl(IDirectory, string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 2088 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

This call site is reachable on all platforms. 'DirectoryAclExtensions.GetAccessControl(IDirectory, string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 2088 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

This call site is reachable on all platforms. 'DirectoryAclExtensions.GetAccessControl(IDirectory, string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,22 @@
fileSystem.File.Delete(filePath);
}

[Test]
public void MockFile_Delete_ShouldThrowUnauthorizedAccessException_WhenPathIsADirectory()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ XFS.Path(@"c:\bar"), new MockDirectoryData() },
});

// Act
TestDelegate action = () => fileSystem.File.Delete(XFS.Path(@"c:\bar"));

// Assert
Assert.Throws<UnauthorizedAccessException>(action);
}

[Test]
public void MockFile_AppendText_AppendTextToAnExistingFile()
{
Expand Down Expand Up @@ -585,7 +601,7 @@
});

// Act
fileSystem.File.Encrypt(filePath);

Check warning on line 604 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

This call site is reachable on all platforms. 'IFile.Encrypt(string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 604 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

This call site is reachable on all platforms. 'IFile.Encrypt(string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 604 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

This call site is reachable on all platforms. 'IFile.Encrypt(string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
var attributes = fileSystem.File.GetAttributes(filePath);

// Assert
Expand All @@ -603,10 +619,10 @@
{
{filePath, fileData }
});
fileSystem.File.Encrypt(filePath);

Check warning on line 622 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

This call site is reachable on all platforms. 'IFile.Encrypt(string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 622 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

This call site is reachable on all platforms. 'IFile.Encrypt(string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 622 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

This call site is reachable on all platforms. 'IFile.Encrypt(string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

// Act
fileSystem.File.Decrypt(filePath);

Check warning on line 625 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

This call site is reachable on all platforms. 'IFile.Decrypt(string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 625 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

This call site is reachable on all platforms. 'IFile.Decrypt(string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 625 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

This call site is reachable on all platforms. 'IFile.Decrypt(string)' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
var attributes = fileSystem.File.GetAttributes(filePath);

// Assert
Expand Down
Loading