-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support for GetUnixFileMode and SetUnixFileMode
* only overload with string path is added, overload with SafeFileHandle fileHandle is not added
- Loading branch information
Showing
5 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetUnixFileModeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#if FEATURE_UNIX_FILE_MODE | ||
using System.Runtime.Versioning; | ||
|
||
namespace System.IO.Abstractions.TestingHelpers.Tests | ||
{ | ||
using Collections.Generic; | ||
|
||
using NUnit.Framework; | ||
|
||
using XFS = MockUnixSupport; | ||
|
||
[UnsupportedOSPlatform("windows")] | ||
[UnixOnly("This feature is not supported on Windows.")] | ||
public class MockFileGetUnixFileModeTests | ||
{ | ||
[Test] | ||
public void MockFile_GetUnixFileMode_ShouldReturnDefaultAccessMode() | ||
{ | ||
// Arrange | ||
var expected = UnixFileMode.UserRead | | ||
UnixFileMode.GroupRead | | ||
UnixFileMode.OtherRead | | ||
UnixFileMode.UserWrite; | ||
|
||
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> | ||
{ | ||
{ XFS.Path(@"C:\something\some.txt"), new MockFileData("Demo text content") } | ||
}); | ||
|
||
// Act | ||
var result = fileSystem.File.GetUnixFileMode(XFS.Path(@"C:\something\some.txt")); | ||
|
||
// Assert | ||
Assert.That(result, Is.EqualTo(expected)); | ||
} | ||
|
||
[Test] | ||
public void MockFile_GetUnixFileMode_ShouldReturnSpecifiedAccessMode([Values] UnixFileMode unixFileMode) | ||
{ | ||
// Arrange | ||
var mockFileData = new MockFileData("Demo text content") | ||
{ | ||
UnixMode = unixFileMode | ||
}; | ||
|
||
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> | ||
{ | ||
{ XFS.Path(@"C:\something\some.txt"), mockFileData } | ||
}); | ||
|
||
// Act | ||
var result = fileSystem.File.GetUnixFileMode(XFS.Path(@"C:\something\some.txt")); | ||
|
||
// Assert | ||
Assert.That(result, Is.EqualTo(unixFileMode)); | ||
} | ||
} | ||
} | ||
#endif |
53 changes: 53 additions & 0 deletions
53
tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSetUnixFileModeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#if FEATURE_UNIX_FILE_MODE | ||
using System.Runtime.Versioning; | ||
|
||
namespace System.IO.Abstractions.TestingHelpers.Tests | ||
{ | ||
using Collections.Generic; | ||
|
||
using NUnit.Framework; | ||
|
||
using XFS = MockUnixSupport; | ||
|
||
[UnsupportedOSPlatform("windows")] | ||
[UnixOnly("This feature is not supported on Windows.")] | ||
public class MockFileSetUnixFileModeTests | ||
{ | ||
[Test] | ||
public void MockFile_SetUnixFileMode_ShouldSetSpecifiedAccessMode([Values] UnixFileMode unixFileMode) | ||
{ | ||
// Arrange | ||
var mockFileData = new MockFileData("Demo text content"); | ||
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> | ||
{ | ||
{ XFS.Path(@"C:\something\some.txt"), mockFileData } | ||
}); | ||
|
||
// Act | ||
fileSystem.File.SetUnixFileMode(XFS.Path(@"C:\something\some.txt"), unixFileMode); | ||
|
||
// Assert | ||
Assert.That(mockFileData.UnixMode, Is.EqualTo(unixFileMode)); | ||
} | ||
|
||
[TestCase(UnixFileMode.UserRead | UnixFileMode.GroupRead | UnixFileMode.OtherRead)] | ||
[TestCase(UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute)] | ||
[TestCase(UnixFileMode.UserExecute | UnixFileMode.OtherWrite | UnixFileMode.GroupRead)] | ||
public void MockFile_SetUnixFileMode_ShouldSetSpecifiedAccessModeFlags(UnixFileMode unixFileMode) | ||
{ | ||
// Arrange | ||
var mockFileData = new MockFileData("Demo text content"); | ||
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> | ||
{ | ||
{ XFS.Path(@"C:\something\some.txt"), mockFileData } | ||
}); | ||
|
||
// Act | ||
fileSystem.File.SetUnixFileMode(XFS.Path(@"C:\something\some.txt"), unixFileMode); | ||
|
||
// Assert | ||
Assert.That(mockFileData.UnixMode, Is.EqualTo(unixFileMode)); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters