Skip to content

Commit

Permalink
fix: always keep FileAttributes.Directory on directories (#970)
Browse files Browse the repository at this point in the history
Fix #957:
Always keep `FileAttributes.Directory` on directories (and never on files).
  • Loading branch information
vbreuss authored Apr 18, 2023
1 parent 659f7b4 commit 6ade494
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override IFileSystemInfo ResolveLinkTarget(bool returnFinalTarget)
public override FileAttributes Attributes
{
get { return GetMockFileDataForRead().Attributes; }
set { GetMockFileDataForWrite().Attributes = value; }
set { GetMockFileDataForWrite().Attributes = value | FileAttributes.Directory; }
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public override FileAttributes Attributes
set
{
var mockFileData = GetMockFileDataForWrite();
mockFileData.Attributes = value;
mockFileData.Attributes = value & ~FileAttributes.Directory;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ public void MockDirectoryInfo_Attributes_ShouldReturnMinusOneForNonExistingFile(
Assert.That(directoryInfo.Attributes, Is.EqualTo(expected));
}

[Test]
public void MockDirectoryInfo_Attributes_Clear_ShouldRemainDirectory()
{
var fileSystem = new MockFileSystem();
var path = XFS.Path(@"c:\existing\directory");
fileSystem.Directory.CreateDirectory(path);
var directoryInfo = fileSystem.DirectoryInfo.New(path);
directoryInfo.Attributes = 0;

Assert.That(fileSystem.File.Exists(path), Is.False);
Assert.That(directoryInfo.Attributes, Is.EqualTo(FileAttributes.Directory));
}

[Test]
public void MockDirectoryInfo_Attributes_SetterShouldThrowDirectoryNotFoundExceptionOnNonExistingFileOrDirectory()
{
Expand Down

0 comments on commit 6ade494

Please sign in to comment.