diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs
index 5ec85d35f..ad8a0f005 100644
--- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs
+++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs
@@ -424,7 +424,15 @@ public override DateTime GetLastWriteTimeUtc(SafeFileHandle fileHandle)
///
public override UnixFileMode GetUnixFileMode(string path)
{
- throw CommonExceptions.NotImplemented();
+ mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");
+
+ if (!mockFileDataAccessor.FileExists(path))
+ {
+ throw CommonExceptions.FileNotFound(path);
+ }
+
+ var mockFileData = mockFileDataAccessor.GetFile(path);
+ return mockFileData.UnixMode;
}
#endif
@@ -954,7 +962,15 @@ public override void SetLastWriteTimeUtc(SafeFileHandle fileHandle, DateTime las
///
public override void SetUnixFileMode(string path, UnixFileMode mode)
{
- throw CommonExceptions.NotImplemented();
+ mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");
+
+ if (!mockFileDataAccessor.FileExists(path))
+ {
+ throw CommonExceptions.FileNotFound(path);
+ }
+
+ var mockFileData = mockFileDataAccessor.GetFile(path);
+ mockFileData.UnixMode = mode;
}
#endif
diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs
index e77e214da..7fcf94514 100644
--- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs
+++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs
@@ -201,6 +201,16 @@ public FileSecurity AccessControl
/// Gets or sets the File sharing mode for this file, this allows you to lock a file for reading or writing.
///
public FileShare AllowedFileShare { get; set; } = FileShare.ReadWrite | FileShare.Delete;
+
+#if FEATURE_UNIX_FILE_MODE
+ ///
+ /// Gets or sets the Unix file mode (permissions) for this file.
+ /// This allows you to configure the read, write and execute access for user, group and other.
+ ///
+ public UnixFileMode UnixMode { get; set; } = UnixFileMode.UserRead | UnixFileMode.GroupRead |
+ UnixFileMode.OtherRead | UnixFileMode.UserWrite;
+#endif
+
///
/// Checks whether the file is accessible for this type of FileAccess.
/// MockFileData can be configured to have FileShare.None, which indicates it is locked by a 'different process'.
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetUnixFileModeTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetUnixFileModeTests.cs
new file mode 100644
index 000000000..85fd7b35c
--- /dev/null
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetUnixFileModeTests.cs
@@ -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
+ {
+ { 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
+ {
+ { 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
\ No newline at end of file
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSetUnixFileModeTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSetUnixFileModeTests.cs
new file mode 100644
index 000000000..02f944c8a
--- /dev/null
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSetUnixFileModeTests.cs
@@ -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
+ {
+ { 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
+ {
+ { 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
\ No newline at end of file
diff --git a/version.json b/version.json
index faa1bcb8f..081fbf157 100644
--- a/version.json
+++ b/version.json
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
- "version": "21.0",
+ "version": "21.1",
"assemblyVersion": {
"precision": "major"
},