From 0837b0bb5482e0eabde8ba33e72a4bad2c9d0d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Fri, 8 Nov 2024 08:52:47 +0100 Subject: [PATCH] fix: initialization of `UnixFileMode` (#662) * Fix initialization of `UnixFileMode` * Add tests --- .../Storage/InMemoryContainer.cs | 5 ++++- .../FileSystem/File/UnixFileModeTests.cs | 20 +++++++++++++++++++ .../FileSystemInfo/UnixFileModeTests.cs | 9 ++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Source/Testably.Abstractions.Testing/Storage/InMemoryContainer.cs b/Source/Testably.Abstractions.Testing/Storage/InMemoryContainer.cs index 654005f8d..a557753f0 100644 --- a/Source/Testably.Abstractions.Testing/Storage/InMemoryContainer.cs +++ b/Source/Testably.Abstractions.Testing/Storage/InMemoryContainer.cs @@ -92,7 +92,10 @@ public IFileSystemExtensibility Extensibility #if FEATURE_FILESYSTEM_UNIXFILEMODE /// - public UnixFileMode UnixFileMode { get; set; } = (UnixFileMode)(-1); + public UnixFileMode UnixFileMode { get; set; } = UnixFileMode.OtherRead | + UnixFileMode.GroupRead | + UnixFileMode.UserWrite | + UnixFileMode.UserRead; #endif /// diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/UnixFileModeTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/UnixFileModeTests.cs index 190b6d3b5..ea2370ac3 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/UnixFileModeTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/UnixFileModeTests.cs @@ -8,6 +8,26 @@ public abstract partial class UnixFileModeTests : FileSystemTestBase where TFileSystem : IFileSystem { + [SkippableTheory] + [AutoData] + public void GetUnixFileMode_ShouldBeInitializedCorrectly( + string path) + { + Skip.If(Test.RunsOnWindows); + + FileSystem.File.WriteAllText(path, ""); + UnixFileMode expected = UnixFileMode.OtherRead | + UnixFileMode.GroupRead | + UnixFileMode.UserWrite | + UnixFileMode.UserRead; + + #pragma warning disable CA1416 + UnixFileMode result = FileSystem.File.GetUnixFileMode(path); + #pragma warning restore CA1416 + + result.Should().Be(expected); + } + [SkippableTheory] [AutoData] public void GetUnixFileMode_ShouldThrowPlatformNotSupportedException_OnWindows( diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemInfo/UnixFileModeTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemInfo/UnixFileModeTests.cs index 62766dbcf..1269bfa6e 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemInfo/UnixFileModeTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemInfo/UnixFileModeTests.cs @@ -40,12 +40,15 @@ public void UnixFileMode_SetterShouldThrowPlatformNotSupportedException_OnWindow [SkippableTheory] [AutoData] - public void UnixFileMode_ShouldBeInitializedToMinusOne( + public void UnixFileMode_ShouldBeInitializedCorrectly( string path) { - Skip.IfNot(Test.RunsOnWindows); + Skip.If(Test.RunsOnWindows); - UnixFileMode expected = (UnixFileMode)(-1); + UnixFileMode expected = UnixFileMode.OtherRead | + UnixFileMode.GroupRead | + UnixFileMode.UserWrite | + UnixFileMode.UserRead; FileSystem.File.WriteAllText(path, "some content"); IFileInfo fileSystemInfo = FileSystem.FileInfo.New(path);