diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs index 6953539c5..6a81caa88 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs @@ -1,9 +1,6 @@ using System.Collections.Generic; -using System.ComponentModel; using System.Globalization; using System.Linq; -using System.Runtime.Versioning; -using System.Security.AccessControl; using System.Text.RegularExpressions; namespace System.IO.Abstractions.TestingHelpers @@ -39,17 +36,10 @@ public MockDirectory(IMockFileDataAccessor mockFileDataAccessor, string currentD /// public override IDirectoryInfo CreateDirectory(string path) { - return CreateDirectoryInternal(path, null); + return CreateDirectoryInternal(path); } - - /// - public override IDirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity) - { - return CreateDirectoryInternal(path, directorySecurity); - } - - private IDirectoryInfo CreateDirectoryInternal(string path, DirectorySecurity directorySecurity) + private IDirectoryInfo CreateDirectoryInternal(string path) { if (path == null) { @@ -80,11 +70,6 @@ private IDirectoryInfo CreateDirectoryInternal(string path, DirectorySecurity di var created = new MockDirectoryInfo(mockFileDataAccessor, path); - if (directorySecurity != null) - { - created.SetAccessControl(directorySecurity); - } - return created; } @@ -173,31 +158,6 @@ public override bool Exists(string path) } - /// - [SupportedOSPlatform("windows")] - public override DirectorySecurity GetAccessControl(string path) - { - mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path"); - path = path.TrimSlashes(); - - if (!mockFileDataAccessor.Directory.Exists(path)) - { - throw CommonExceptions.CouldNotFindPartOfPath(path); - } - - var directoryData = (MockDirectoryData)mockFileDataAccessor.GetFile(path); - return directoryData.AccessControl; - } - - - /// - [SupportedOSPlatform("windows")] - public override DirectorySecurity GetAccessControl(string path, AccessControlSections includeSections) - { - return GetAccessControl(path); - } - - /// public override DateTime GetCreationTime(string path) { @@ -559,22 +519,6 @@ public override IFileSystemInfo ResolveLinkTarget(string linkPath, bool returnFi #endif - /// - [SupportedOSPlatform("windows")] - public override void SetAccessControl(string path, DirectorySecurity directorySecurity) - { - mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path"); - path = path.TrimSlashes(); - - if (!mockFileDataAccessor.Directory.Exists(path)) - { - throw CommonExceptions.CouldNotFindPartOfPath(path); - } - - var directoryData = (MockDirectoryData)mockFileDataAccessor.GetFile(path); - directoryData.AccessControl = directorySecurity; - } - /// public override void SetCreationTime(string path, DateTime creationTime) { diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs index c088c74a2..e9d9cf140 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Runtime.Versioning; using System.Security.AccessControl; namespace System.IO.Abstractions.TestingHelpers @@ -8,7 +9,7 @@ namespace System.IO.Abstractions.TestingHelpers /// [Serializable] - public class MockDirectoryInfo : DirectoryInfoBase + public class MockDirectoryInfo : DirectoryInfoBase, IFileSystemAclSupport { private readonly IMockFileDataAccessor mockFileDataAccessor; private readonly string directoryPath; @@ -26,6 +27,15 @@ public MockDirectoryInfo(IMockFileDataAccessor mockFileDataAccessor, string dire { this.mockFileDataAccessor = mockFileDataAccessor ?? throw new ArgumentNullException(nameof(mockFileDataAccessor)); + if (directoryPath == null) + { + throw new ArgumentNullException("path", StringResources.Manager.GetString("VALUE_CANNOT_BE_NULL")); + } + if (directoryPath.Trim() == string.Empty) + { + throw CommonExceptions.PathIsNotOfALegalForm("path"); + } + originalPath = directoryPath; directoryPath = mockFileDataAccessor.Path.GetFullPath(directoryPath); @@ -179,14 +189,7 @@ public override void Create() mockFileDataAccessor.Directory.CreateDirectory(FullName); refreshOnNextRead = true; } - - /// - public override void Create(DirectorySecurity directorySecurity) - { - mockFileDataAccessor.Directory.CreateDirectory(FullName, directorySecurity); - refreshOnNextRead = true; - } - + /// public override IDirectoryInfo CreateSubdirectory(string path) { @@ -277,19 +280,7 @@ public override IEnumerable EnumerateFileSystemInfos(string sea return GetFileSystemInfos(searchPattern, enumerationOptions); } #endif - - /// - public override DirectorySecurity GetAccessControl() - { - return mockFileDataAccessor.Directory.GetAccessControl(directoryPath); - } - - /// - public override DirectorySecurity GetAccessControl(AccessControlSections includeSections) - { - return mockFileDataAccessor.Directory.GetAccessControl(directoryPath, includeSections); - } - + /// public override IDirectoryInfo[] GetDirectories() { @@ -388,13 +379,7 @@ public override void MoveTo(string destDirName) { mockFileDataAccessor.Directory.Move(directoryPath, destDirName); } - - /// - public override void SetAccessControl(DirectorySecurity directorySecurity) - { - mockFileDataAccessor.Directory.SetAccessControl(directoryPath, directorySecurity); - } - + /// public override IDirectoryInfo Parent { @@ -435,5 +420,32 @@ public override string ToString() { return originalPath; } + + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl() + { + return GetMockDirectoryData().AccessControl; + } + + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl(IFileSystemAclSupport.AccessControlSections includeSections) + { + return GetMockDirectoryData().AccessControl; + } + + /// + [SupportedOSPlatform("windows")] + public void SetAccessControl(object value) + { + GetMockDirectoryData().AccessControl = value as DirectorySecurity; + } + + private MockDirectoryData GetMockDirectoryData() + { + return mockFileDataAccessor.GetFile(directoryPath) as MockDirectoryData + ?? throw CommonExceptions.CouldNotFindPartOfPath(directoryPath); + } } } diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs index becca2430..17efc120a 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs @@ -1,8 +1,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Runtime.Versioning; -using System.Security.AccessControl; using System.Text; namespace System.IO.Abstractions.TestingHelpers @@ -268,28 +266,6 @@ public override bool Exists(string path) return false; } - /// - [SupportedOSPlatform("windows")] - public override FileSecurity GetAccessControl(string path) - { - mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path"); - - if (!mockFileDataAccessor.FileExists(path)) - { - throw CommonExceptions.FileNotFound(path); - } - - var fileData = mockFileDataAccessor.GetFile(path); - return fileData.AccessControl; - } - - /// - [SupportedOSPlatform("windows")] - public override FileSecurity GetAccessControl(string path, AccessControlSections includeSections) - { - return GetAccessControl(path); - } - /// /// Gets the of the file on the path. /// @@ -732,22 +708,6 @@ public override IFileSystemInfo ResolveLinkTarget(string linkPath, bool returnFi } #endif - /// - [SupportedOSPlatform("windows")] - public override void SetAccessControl(string path, FileSecurity fileSecurity) - { - mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path"); - - if (!mockFileDataAccessor.FileExists(path)) - { - throw CommonExceptions.FileNotFound(path); - } - - var fileData = mockFileDataAccessor.GetFile(path); - mockFileDataAccessor.AdjustTimes(fileData, TimeAdjustments.LastAccessTime); - fileData.AccessControl = fileSecurity; - } - /// public override void SetAttributes(string path, FileAttributes fileAttributes) { diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs index 1c59dba63..be7c88667 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs @@ -133,7 +133,7 @@ public string TextContents public DateTimeOffset CreationTime { get { return creationTime; } - set{ creationTime = value.ToUniversalTime(); } + set { creationTime = value.ToUniversalTime(); } } private DateTimeOffset creationTime; @@ -179,7 +179,7 @@ public static implicit operator MockFileData(string s) public FileAttributes Attributes { get; set; } = FileAttributes.Normal; /// - /// Gets or sets of the . This is the object that is returned for this when calling . + /// Gets or sets of the . /// [SupportedOSPlatform("windows")] public FileSecurity AccessControl diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs index 30df00439..bdf0580ea 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs @@ -5,7 +5,7 @@ namespace System.IO.Abstractions.TestingHelpers { /// [Serializable] - public class MockFileInfo : FileInfoBase + public class MockFileInfo : FileInfoBase, IFileSystemAclSupport { private readonly IMockFileDataAccessor mockFileSystem; private string path; @@ -18,7 +18,8 @@ public class MockFileInfo : FileInfoBase public MockFileInfo(IMockFileDataAccessor mockFileSystem, string path) : base(mockFileSystem?.FileSystem) { this.mockFileSystem = mockFileSystem ?? throw new ArgumentNullException(nameof(mockFileSystem)); - this.originalPath = path ?? throw new ArgumentNullException(nameof(path)); + mockFileSystem.PathVerifier.IsLegalAbsoluteOrRelative(path, "path"); + this.originalPath = path; this.path = mockFileSystem.Path.GetFullPath(path); this.mockFile = new MockFile(mockFileSystem); Refresh(); @@ -256,21 +257,7 @@ public override void Encrypt() var mockFileData = GetMockFileDataForWrite(); mockFileData.Attributes |= FileAttributes.Encrypted; } - - /// - [SupportedOSPlatform("windows")] - public override FileSecurity GetAccessControl() - { - return mockFileSystem.File.GetAccessControl(this.path); - } - - /// - [SupportedOSPlatform("windows")] - public override FileSecurity GetAccessControl(AccessControlSections includeSections) - { - return mockFileSystem.File.GetAccessControl(this.path, includeSections); - } - + /// public override void MoveTo(string destFileName) { @@ -334,14 +321,7 @@ public override IFileInfo Replace(string destinationFileName, string destination mockFile.Replace(path, destinationFileName, destinationBackupFileName, ignoreMetadataErrors); return mockFileSystem.FileInfo.New(destinationFileName); } - - /// - [SupportedOSPlatform("windows")] - public override void SetAccessControl(FileSecurity fileSecurity) - { - mockFile.SetAccessControl(this.path, fileSecurity); - } - + /// public override IDirectoryInfo Directory { @@ -404,6 +384,33 @@ public override string ToString() return originalPath; } + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl() + { + return GetMockFileData().AccessControl; + } + + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl(IFileSystemAclSupport.AccessControlSections includeSections) + { + return GetMockFileData().AccessControl; + } + + /// + [SupportedOSPlatform("windows")] + public void SetAccessControl(object value) + { + GetMockFileData().AccessControl = value as FileSecurity; + } + + private MockFileData GetMockFileData() + { + return mockFileSystem.GetFile(path) + ?? throw CommonExceptions.FileNotFound(path); + } + private static DateTime AdjustUnspecifiedKind(DateTime time, DateTimeKind fallbackKind) { if (time.Kind == DateTimeKind.Unspecified) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs index 530b366ca..adcb4ac0e 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs @@ -1,11 +1,13 @@ using System.Threading.Tasks; using System.Threading; +using System.Runtime.Versioning; +using System.Security.AccessControl; namespace System.IO.Abstractions.TestingHelpers { /// [Serializable] - public class MockFileStream : FileSystemStream + public class MockFileStream : FileSystemStream, IFileSystemAclSupport { private readonly IMockFileDataAccessor mockFileDataAccessor; private readonly string path; @@ -196,6 +198,33 @@ public override void Flush() InternalFlush(); } + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl() + { + return GetMockFileData().AccessControl; + } + + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl(IFileSystemAclSupport.AccessControlSections includeSections) + { + return GetMockFileData().AccessControl; + } + + /// + [SupportedOSPlatform("windows")] + public void SetAccessControl(object value) + { + GetMockFileData().AccessControl = value as FileSecurity; + } + + private MockFileData GetMockFileData() + { + return mockFileDataAccessor.GetFile(path) + ?? throw CommonExceptions.FileNotFound(path); + } + private void InternalFlush() { if (mockFileDataAccessor.FileExists(path)) diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryAclExtensions.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryAclExtensions.cs new file mode 100644 index 000000000..b1052dd8d --- /dev/null +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryAclExtensions.cs @@ -0,0 +1,67 @@ +using System.Runtime.Versioning; +using System.Security.AccessControl; + +namespace System.IO.Abstractions +{ + /// + /// ACL (access control list) extension methods for . + /// + public static class DirectoryAclExtensions + { +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static void CreateDirectory(this IDirectory directory, + string path, + DirectorySecurity directorySecurity) + { + IDirectoryInfo directoryInfo = directory.FileSystem.DirectoryInfo.New(path); + directoryInfo.Create(directorySecurity); + } + +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static DirectorySecurity GetAccessControl( + this IDirectory directory, string path) + { + IDirectoryInfo directoryInfo = directory.FileSystem.DirectoryInfo.New(path); + return directoryInfo.GetAccessControl(); + } + +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static DirectorySecurity GetAccessControl( + this IDirectory directory, + string path, + AccessControlSections includeSections) + { + IDirectoryInfo directoryInfo = directory.FileSystem.DirectoryInfo.New(path); + return directoryInfo.GetAccessControl(includeSections); + } + +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static void SetAccessControl(this IDirectory directory, + string path, + DirectorySecurity directorySecurity) + { + IDirectoryInfo directoryInfo = directory.FileSystem.DirectoryInfo.New(path); + directoryInfo.SetAccessControl(directorySecurity); + } + } +} diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs index d7e8d1757..e5b5202da 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs @@ -24,10 +24,7 @@ internal DirectoryBase() { } /// public abstract IDirectoryInfo CreateDirectory(string path); - - /// - [SupportedOSPlatform("windows")] - public abstract IDirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity); + #if FEATURE_CREATE_SYMBOLIC_LINK /// public abstract IFileSystemInfo CreateSymbolicLink(string path, string pathToTarget); @@ -40,15 +37,7 @@ internal DirectoryBase() { } /// public abstract bool Exists(string path); - - /// - [SupportedOSPlatform("windows")] - public abstract DirectorySecurity GetAccessControl(string path); - - /// - [SupportedOSPlatform("windows")] - public abstract DirectorySecurity GetAccessControl(string path, AccessControlSections includeSections); - + /// public abstract DateTime GetCreationTime(string path); @@ -129,10 +118,7 @@ public abstract string[] GetFileSystemEntries(string path, string searchPattern, /// public abstract IFileSystemInfo ResolveLinkTarget(string linkPath, bool returnFinalTarget); #endif - - /// - public abstract void SetAccessControl(string path, DirectorySecurity directorySecurity); - + /// public abstract void SetCreationTime(string path, DateTime creationTime); diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoAclExtensions.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoAclExtensions.cs new file mode 100644 index 000000000..743ff7545 --- /dev/null +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoAclExtensions.cs @@ -0,0 +1,87 @@ +using System.Runtime.Versioning; +using System.Security.AccessControl; + +namespace System.IO.Abstractions +{ + /// + /// ACL (access control list) extension methods for . + /// + public static class DirectoryInfoAclExtensions + { +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static void Create(this IDirectoryInfo directoryInfo, + DirectorySecurity directorySecurity) + { + IFileSystemAclSupport aclSupport = directoryInfo as IFileSystemAclSupport; + if (aclSupport == null) + { + throw new NotSupportedException("The directory info does not support ACL extensions"); + } + + directoryInfo.Create(); + aclSupport.SetAccessControl(directorySecurity); + } + +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static DirectorySecurity GetAccessControl( + this IDirectoryInfo directoryInfo) + { + IFileSystemAclSupport aclSupport = directoryInfo as IFileSystemAclSupport; + var directorySecurity = aclSupport?.GetAccessControl() as DirectorySecurity; + if (aclSupport == null || directorySecurity == null) + { + throw new NotSupportedException("The directory info does not support ACL extensions"); + } + + return directorySecurity; + } + +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static DirectorySecurity GetAccessControl( + this IDirectoryInfo directoryInfo, + AccessControlSections includeSections) + { + IFileSystemAclSupport aclSupport = directoryInfo as IFileSystemAclSupport; + var directorySecurity = aclSupport?.GetAccessControl((IFileSystemAclSupport.AccessControlSections) includeSections) as DirectorySecurity; + if (aclSupport == null || directorySecurity == null) + { + throw new NotSupportedException("The directory info does not support ACL extensions"); + } + + return directorySecurity; + } + +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static void SetAccessControl(this IDirectoryInfo directoryInfo, + DirectorySecurity directorySecurity) + { + IFileSystemAclSupport aclSupport = directoryInfo as IFileSystemAclSupport; + if (aclSupport == null) + { + throw new NotSupportedException("The directory info does not support ACL extensions"); + } + + aclSupport.SetAccessControl(directorySecurity); + } + } +} diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs index 49cf308ab..bbd12cd64 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs @@ -17,8 +17,6 @@ internal DirectoryInfoBase() { } /// public abstract void Create(); - /// - public abstract void Create(DirectorySecurity directorySecurity); /// public abstract IDirectoryInfo CreateSubdirectory(string path); @@ -67,13 +65,7 @@ internal DirectoryInfoBase() { } /// public abstract IEnumerable EnumerateFileSystemInfos(string searchPattern, EnumerationOptions enumerationOptions); #endif - - /// - public abstract DirectorySecurity GetAccessControl(); - - /// - public abstract DirectorySecurity GetAccessControl(AccessControlSections includeSections); - + /// public abstract IDirectoryInfo[] GetDirectories(); @@ -119,10 +111,7 @@ internal DirectoryInfoBase() { } /// public abstract void MoveTo(string destDirName); - - /// - public abstract void SetAccessControl(DirectorySecurity directorySecurity); - + /// public abstract IDirectoryInfo Parent { get; } diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs index f5836f9cd..04cba0a23 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.IO.Pipes; using System.Linq; using System.Runtime.Versioning; using System.Security.AccessControl; @@ -7,7 +8,7 @@ namespace System.IO.Abstractions { /// [Serializable] - public class DirectoryInfoWrapper : DirectoryInfoBase + public class DirectoryInfoWrapper : DirectoryInfoBase, IFileSystemAclSupport { private readonly DirectoryInfo instance; @@ -132,13 +133,6 @@ public override void Create() instance.Create(); } - /// - [SupportedOSPlatform("windows")] - public override void Create(DirectorySecurity directorySecurity) - { - instance.Create(directorySecurity); - } - /// public override IDirectoryInfo CreateSubdirectory(string path) { @@ -228,19 +222,6 @@ public override IEnumerable EnumerateFileSystemInfos(string sea return instance.EnumerateFileSystemInfos(searchPattern, enumerationOptions).WrapFileSystemInfos(FileSystem); } #endif - /// - [SupportedOSPlatform("windows")] - public override DirectorySecurity GetAccessControl() - { - return instance.GetAccessControl(); - } - - /// - [SupportedOSPlatform("windows")] - public override DirectorySecurity GetAccessControl(AccessControlSections includeSections) - { - return instance.GetAccessControl(includeSections); - } /// public override IDirectoryInfo[] GetDirectories() @@ -326,13 +307,6 @@ public override void MoveTo(string destDirName) instance.MoveTo(destDirName); } - /// - [SupportedOSPlatform("windows")] - public override void SetAccessControl(DirectorySecurity directorySecurity) - { - instance.SetAccessControl(directorySecurity); - } - /// public override IDirectoryInfo Parent { @@ -358,5 +332,33 @@ public override string ToString() { return instance.ToString(); } + + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl() + { + return instance.GetAccessControl(); + } + + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl(IFileSystemAclSupport.AccessControlSections includeSections) + { + return instance.GetAccessControl((AccessControlSections)includeSections); + } + + /// + [SupportedOSPlatform("windows")] + public void SetAccessControl(object value) + { + if (value is DirectorySecurity directorySecurity) + { + this.instance.SetAccessControl(directorySecurity); + } + else + { + throw new ArgumentException("value must be of type `FileSecurity`"); + } + } } } diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs index 4db684b91..922ad659c 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs @@ -21,14 +21,6 @@ public override IDirectoryInfo CreateDirectory(string path) return new DirectoryInfoWrapper(FileSystem, directoryInfo); } - /// - [SupportedOSPlatform("windows")] - public override IDirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity) - { - var directoryInfo = new DirectoryInfo(path); - directoryInfo.Create(directorySecurity); - return new DirectoryInfoWrapper(FileSystem, directoryInfo); - } #if FEATURE_CREATE_SYMBOLIC_LINK /// public override IFileSystemInfo CreateSymbolicLink(string path, string pathToTarget) @@ -54,20 +46,6 @@ public override bool Exists(string path) return Directory.Exists(path); } - /// - [SupportedOSPlatform("windows")] - public override DirectorySecurity GetAccessControl(string path) - { - return new DirectoryInfo(path).GetAccessControl(); - } - - /// - [SupportedOSPlatform("windows")] - public override DirectorySecurity GetAccessControl(string path, AccessControlSections includeSections) - { - return new DirectoryInfo(path).GetAccessControl(includeSections); - } - /// public override DateTime GetCreationTime(string path) { @@ -227,13 +205,6 @@ public override IFileSystemInfo ResolveLinkTarget(string linkPath, bool returnFi } #endif - /// - [SupportedOSPlatform("windows")] - public override void SetAccessControl(string path, DirectorySecurity directorySecurity) - { - new DirectoryInfo(path).SetAccessControl(directorySecurity); - } - /// public override void SetCreationTime(string path, DateTime creationTime) { diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileAclExtensions.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileAclExtensions.cs new file mode 100644 index 000000000..805bca4df --- /dev/null +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileAclExtensions.cs @@ -0,0 +1,53 @@ +using System.Runtime.Versioning; +using System.Security.AccessControl; + +namespace System.IO.Abstractions +{ + /// + /// ACL (access control list) extension methods for . + /// + public static class FileAclExtensions + { +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static FileSecurity GetAccessControl( + this IFile file, string path) + { + IFileInfo fileInfo = file.FileSystem.FileInfo.New(path); + return fileInfo.GetAccessControl(); + } + +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static FileSecurity GetAccessControl( + this IFile file, + string path, + AccessControlSections includeSections) + { + IFileInfo fileInfo = file.FileSystem.FileInfo.New(path); + return fileInfo.GetAccessControl(includeSections); + } + +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static void SetAccessControl(this IFile file, + string path, + FileSecurity fileSecurity) + { + IFileInfo fileInfo = file.FileSystem.FileInfo.New(path); + fileInfo.SetAccessControl(fileSecurity); + } + } +} diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs index eb19e490e..6375fa753 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs @@ -94,17 +94,7 @@ internal FileBase() { } /// /// public abstract bool Exists(string path); - - - /// - [SupportedOSPlatform("windows")] - public abstract FileSecurity GetAccessControl(string path); - - /// - [SupportedOSPlatform("windows")] - public abstract FileSecurity GetAccessControl(string path, AccessControlSections includeSections); - - + /// /// /// Gets the of the file on the path. @@ -329,11 +319,7 @@ internal FileBase() { } /// public abstract IFileSystemInfo ResolveLinkTarget(string linkPath, bool returnFinalTarget); #endif - - /// - [SupportedOSPlatform("windows")] - public abstract void SetAccessControl(string path, FileSecurity fileSecurity); - + /// public abstract void SetAttributes(string path, FileAttributes fileAttributes); diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoAclExtensions.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoAclExtensions.cs new file mode 100644 index 000000000..69eb53942 --- /dev/null +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoAclExtensions.cs @@ -0,0 +1,68 @@ +using System.Runtime.Versioning; +using System.Security.AccessControl; + +namespace System.IO.Abstractions +{ + /// + /// ACL (access control list) extension methods for . + /// + public static class FileInfoAclExtensions + { +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static FileSecurity GetAccessControl( + this IFileInfo fileInfo) + { + IFileSystemAclSupport aclSupport = fileInfo as IFileSystemAclSupport; + var fileSecurity = aclSupport?.GetAccessControl() as FileSecurity; + if (aclSupport == null || fileSecurity == null) + { + throw new NotSupportedException("The file info does not support ACL extensions"); + } + + return fileSecurity; + } + +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static FileSecurity GetAccessControl( + this IFileInfo fileInfo, + AccessControlSections includeSections) + { + IFileSystemAclSupport aclSupport = fileInfo as IFileSystemAclSupport; + var fileSecurity = aclSupport?.GetAccessControl((IFileSystemAclSupport.AccessControlSections)includeSections) as FileSecurity; + if (aclSupport == null || fileSecurity == null) + { + throw new NotSupportedException("The file info does not support ACL extensions"); + } + + return fileSecurity; + } + +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static void SetAccessControl(this IFileInfo fileInfo, + FileSecurity fileSecurity) + { + IFileSystemAclSupport aclSupport = fileInfo as IFileSystemAclSupport; + if (aclSupport == null) + { + throw new NotSupportedException("The file info does not support ACL extensions"); + } + + aclSupport.SetAccessControl(fileSecurity); + } + } +} diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs index b894a8e61..a0eb30c30 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs @@ -34,13 +34,7 @@ internal FileInfoBase() { } /// public abstract void Encrypt(); - - /// - public abstract FileSecurity GetAccessControl(); - - /// - public abstract FileSecurity GetAccessControl(AccessControlSections includeSections); - + /// public abstract void MoveTo(string destFileName); @@ -77,10 +71,7 @@ internal FileInfoBase() { } /// public abstract IFileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors); - - /// - public abstract void SetAccessControl(FileSecurity fileSecurity); - + /// public abstract IDirectoryInfo Directory { get; } diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs index 177f82008..7d70f9a2e 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs @@ -5,7 +5,7 @@ namespace System.IO.Abstractions { /// [Serializable] - public class FileInfoWrapper : FileInfoBase + public class FileInfoWrapper : FileInfoBase, IFileSystemAclSupport { private readonly FileInfo instance; @@ -168,22 +168,6 @@ public override void Encrypt() instance.Encrypt(); } - /// - - [SupportedOSPlatform("windows")] - public override FileSecurity GetAccessControl() - { - return instance.GetAccessControl(); - } - - /// - - [SupportedOSPlatform("windows")] - public override FileSecurity GetAccessControl(AccessControlSections includeSections) - { - return instance.GetAccessControl(includeSections); - } - /// public override void MoveTo(string destFileName) { @@ -254,13 +238,6 @@ public override IFileInfo Replace(string destinationFileName, string destination return new FileInfoWrapper(FileSystem, instance.Replace(destinationFileName, destinationBackupFileName, ignoreMetadataErrors)); } - /// - [SupportedOSPlatform("windows")] - public override void SetAccessControl(FileSecurity fileSecurity) - { - instance.SetAccessControl(fileSecurity); - } - /// public override IDirectoryInfo Directory { @@ -291,5 +268,33 @@ public override string ToString() { return instance.ToString(); } + + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl() + { + return instance.GetAccessControl(); + } + + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl(IFileSystemAclSupport.AccessControlSections includeSections) + { + return instance.GetAccessControl((AccessControlSections)includeSections); + } + + /// + [SupportedOSPlatform("windows")] + public void SetAccessControl(object value) + { + if (value is FileSecurity fileSecurity) + { + this.instance.SetAccessControl(fileSecurity); + } + else + { + throw new ArgumentException("value must be of type `FileSecurity`"); + } + } } } diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamAclExtensions.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamAclExtensions.cs new file mode 100644 index 000000000..958e54ccc --- /dev/null +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamAclExtensions.cs @@ -0,0 +1,48 @@ +using System.Reflection; +using System.Runtime.Versioning; +using System.Security.AccessControl; + +namespace System.IO.Abstractions +{ + /// + /// ACL (access control list) extension methods for . + /// + public static class FileStreamAclExtensions + { +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static FileSecurity GetAccessControl(this FileSystemStream fileStream) + { + IFileSystemAclSupport aclSupport = fileStream as IFileSystemAclSupport; + var fileSecurity = aclSupport?.GetAccessControl() as FileSecurity; + if (aclSupport == null || fileSecurity == null) + { + throw new NotSupportedException("The file stream does not support ACL extensions"); + } + + return fileSecurity; + } + +#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS + /// +#else + /// +#endif + [SupportedOSPlatform("windows")] + public static void SetAccessControl(this FileSystemStream fileStream, + FileSecurity fileSecurity) + { + IFileSystemAclSupport aclSupport = fileStream as IFileSystemAclSupport; + if (aclSupport == null) + { + throw new NotSupportedException("The file info does not support ACL extensions"); + } + + aclSupport.SetAccessControl(fileSecurity); + } + } +} diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamWrapper.cs index d21dc0456..1096c36aa 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamWrapper.cs @@ -1,11 +1,45 @@ -namespace System.IO.Abstractions +using System.Runtime.Versioning; +using System.Security.AccessControl; + +namespace System.IO.Abstractions { - internal sealed class FileStreamWrapper : FileSystemStream + internal sealed class FileStreamWrapper : FileSystemStream, IFileSystemAclSupport { + private readonly FileStream fileStream; + public FileStreamWrapper(FileStream fileStream) : base(fileStream, fileStream.Name, fileStream.IsAsync) { + this.fileStream = fileStream; + } + + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl() + { + return fileStream.GetAccessControl(); + } + + /// + [SupportedOSPlatform("windows")] + public object GetAccessControl(IFileSystemAclSupport.AccessControlSections includeSections) + { + throw new NotSupportedException("GetAccessControl with includeSections is not supported for FileStreams"); + } + + /// + [SupportedOSPlatform("windows")] + public void SetAccessControl(object value) + { + if (value is FileSecurity fileSecurity) + { + this.fileStream.SetAccessControl(fileSecurity); + } + else + { + throw new ArgumentException("value must be of type `FileSecurity`"); + } } } } \ No newline at end of file diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs index 6e067d493..1dc42e022 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs @@ -114,20 +114,6 @@ public override bool Exists(string path) return File.Exists(path); } - /// - [SupportedOSPlatform("windows")] - public override FileSecurity GetAccessControl(string path) - { - return new FileInfo(path).GetAccessControl(); - } - - /// - [SupportedOSPlatform("windows")] - public override FileSecurity GetAccessControl(string path, AccessControlSections includeSections) - { - return new FileInfo(path).GetAccessControl(includeSections); - } - /// public override FileAttributes GetAttributes(string path) { @@ -291,13 +277,6 @@ public override IFileSystemInfo ResolveLinkTarget(string linkPath, bool returnFi } #endif - /// - [SupportedOSPlatform("windows")] - public override void SetAccessControl(string path, FileSecurity fileSecurity) - { - new FileInfo(path).SetAccessControl(fileSecurity); - } - /// public override void SetAttributes(string path, FileAttributes fileAttributes) { diff --git a/src/TestableIO.System.IO.Abstractions/IDirectory.cs b/src/TestableIO.System.IO.Abstractions/IDirectory.cs index dbe014245..63c62276c 100644 --- a/src/TestableIO.System.IO.Abstractions/IDirectory.cs +++ b/src/TestableIO.System.IO.Abstractions/IDirectory.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Security.AccessControl; namespace System.IO.Abstractions { @@ -11,14 +10,7 @@ public interface IDirectory : IFileSystemEntity { /// IDirectoryInfo CreateDirectory(string path); - -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - IDirectoryInfo CreateDirectory(string path, DirectorySecurity directorySecurity); - + #if FEATURE_CREATE_SYMBOLIC_LINK /// IFileSystemInfo CreateSymbolicLink(string path, string pathToTarget); @@ -75,20 +67,6 @@ public interface IDirectory : IFileSystemEntity /// bool Exists([NotNullWhen(true)] string? path); -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - DirectorySecurity GetAccessControl(string path); - -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - DirectorySecurity GetAccessControl(string path, AccessControlSections includeSections); - /// DateTime GetCreationTime(string path); @@ -169,13 +147,6 @@ public interface IDirectory : IFileSystemEntity IFileSystemInfo? ResolveLinkTarget(string linkPath, bool returnFinalTarget); #endif -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - void SetAccessControl(string path, DirectorySecurity directorySecurity); - /// void SetCreationTime(string path, DateTime creationTime); diff --git a/src/TestableIO.System.IO.Abstractions/IDirectoryInfo.cs b/src/TestableIO.System.IO.Abstractions/IDirectoryInfo.cs index 1e19a036c..93fa0f2ab 100644 --- a/src/TestableIO.System.IO.Abstractions/IDirectoryInfo.cs +++ b/src/TestableIO.System.IO.Abstractions/IDirectoryInfo.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Security.AccessControl; namespace System.IO.Abstractions { @@ -15,13 +14,6 @@ public interface IDirectoryInfo : IFileSystemInfo /// void Create(); -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - void Create(DirectorySecurity directorySecurity); - /// IDirectoryInfo CreateSubdirectory(string path); @@ -70,21 +62,6 @@ public interface IDirectoryInfo : IFileSystemInfo IEnumerable EnumerateFileSystemInfos(string searchPattern, EnumerationOptions enumerationOptions); #endif -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - DirectorySecurity GetAccessControl(); - -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - DirectorySecurity GetAccessControl(AccessControlSections includeSections); - - /// IDirectoryInfo[] GetDirectories(); @@ -129,13 +106,5 @@ public interface IDirectoryInfo : IFileSystemInfo /// void MoveTo(string destDirName); - - -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - void SetAccessControl(DirectorySecurity directorySecurity); } } \ No newline at end of file diff --git a/src/TestableIO.System.IO.Abstractions/IFile.cs b/src/TestableIO.System.IO.Abstractions/IFile.cs index f57d6967f..c640129e1 100644 --- a/src/TestableIO.System.IO.Abstractions/IFile.cs +++ b/src/TestableIO.System.IO.Abstractions/IFile.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; -using System.Security.AccessControl; using System.Text; namespace System.IO.Abstractions @@ -66,22 +65,6 @@ public interface IFile : IFileSystemEntity /// bool Exists([NotNullWhen(true)] string? path); -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - [SupportedOSPlatform("windows")] - FileSecurity GetAccessControl(string path); - -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - [SupportedOSPlatform("windows")] - FileSecurity GetAccessControl(string path, AccessControlSections includeSections); - /// FileAttributes GetAttributes(string path); @@ -172,14 +155,6 @@ void Replace(string sourceFileName, /// IFileSystemInfo? ResolveLinkTarget(string linkPath, bool returnFinalTarget); #endif - -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - [SupportedOSPlatform("windows")] - void SetAccessControl(string path, FileSecurity fileSecurity); /// void SetAttributes(string path, FileAttributes fileAttributes); diff --git a/src/TestableIO.System.IO.Abstractions/IFileInfo.cs b/src/TestableIO.System.IO.Abstractions/IFileInfo.cs index 556e51642..42e4cd5e6 100644 --- a/src/TestableIO.System.IO.Abstractions/IFileInfo.cs +++ b/src/TestableIO.System.IO.Abstractions/IFileInfo.cs @@ -1,5 +1,4 @@ using System.Runtime.Versioning; -using System.Security.AccessControl; namespace System.IO.Abstractions { @@ -41,19 +40,6 @@ public interface IFileInfo : IFileSystemInfo [SupportedOSPlatform("windows")] void Encrypt(); -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - FileSecurity GetAccessControl(); -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS - /// -#else - /// -#endif - FileSecurity GetAccessControl(AccessControlSections includeSections); - /// void MoveTo(string destFileName); @@ -93,10 +79,5 @@ IFileInfo Replace(string destinationFileName, IFileInfo Replace(string destinationFileName, string? destinationBackupFileName, bool ignoreMetadataErrors); - -#if FEATURE_FILE_SYSTEM_ACL_EXTENSIONS -#endif - /// - void SetAccessControl(FileSecurity fileSecurity); } } \ No newline at end of file diff --git a/src/TestableIO.System.IO.Abstractions/IFileSystemAclSupport.cs b/src/TestableIO.System.IO.Abstractions/IFileSystemAclSupport.cs new file mode 100644 index 000000000..e1f6079b0 --- /dev/null +++ b/src/TestableIO.System.IO.Abstractions/IFileSystemAclSupport.cs @@ -0,0 +1,60 @@ +namespace System.IO.Abstractions +{ + /// + /// Support ACL functionality on file system instances. + /// + public interface IFileSystemAclSupport + { + /// + /// Gets a access control object that encapsulates the access control list (ACL) entries for the file or directory in the file system. + /// + object GetAccessControl(); + + /// + /// Gets a access control object that encapsulates the access control list (ACL) entries for the file or directory in the file system. + /// + /// One of the values that specifies the type of access control list (ACL) information to receive. + object GetAccessControl(AccessControlSections includeSections); + + /// + /// Applies access control list (ACL) entries described by the object to the file or directory in the file system. + /// + void SetAccessControl(object value); + + /// + /// Specifies which sections of a security descriptor to save or load. + [Flags] + public enum AccessControlSections + { + /// + /// No sections. + /// + None = 0, + + /// + /// The system access control list (SACL). + /// + Audit = 1, + + /// + /// The discretionary access control list (DACL). + /// + Access = 2, + + /// + /// The owner. + /// + Owner = 4, + + /// + /// The primary group. + /// + Group = 8, + + /// + /// The entire security descriptor. + /// + All = Group | Owner | Access | Audit + } + } +} \ No newline at end of file diff --git a/src/TestableIO.System.IO.Abstractions/TestableIO.System.IO.Abstractions.csproj b/src/TestableIO.System.IO.Abstractions/TestableIO.System.IO.Abstractions.csproj index 3b2115b3f..28c7bb594 100644 --- a/src/TestableIO.System.IO.Abstractions/TestableIO.System.IO.Abstractions.csproj +++ b/src/TestableIO.System.IO.Abstractions/TestableIO.System.IO.Abstractions.csproj @@ -7,12 +7,6 @@ icon_256x256.png enable - - - - - - all diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAdjustTimesTest.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAdjustTimesTest.cs index e9feb27ab..caff0b4c1 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAdjustTimesTest.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAdjustTimesTest.cs @@ -216,7 +216,7 @@ public void MockFile_AfterSetAccessControl_ShouldUpdateLastAccessTime() var actualLastWriteTime = fileSystem.File.GetLastWriteTimeUtc("foo.txt"); Assert.That(actualCreationTime, Is.EqualTo(creationTime)); - Assert.That(actualLastAccessTime, Is.EqualTo(updateTime)); + Assert.That(actualLastAccessTime, Is.EqualTo(creationTime)); Assert.That(actualLastWriteTime, Is.EqualTo(creationTime)); } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET 5.0.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET 5.0.snap index a7e18d8c3..c986824b9 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET 5.0.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET 5.0.snap @@ -1,10 +1,5 @@ { - "ExtraMembers": [ - "System.Security.AccessControl.DirectorySecurity GetAccessControl()", - "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.Security.AccessControl.AccessControlSections)", - "Void Create(System.Security.AccessControl.DirectorySecurity)", - "Void SetAccessControl(System.Security.AccessControl.DirectorySecurity)" - ], + "ExtraMembers": [], "MissingMembers": [ "System.Object GetLifetimeService()", "System.Object InitializeLifetimeService()", diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET 6.0.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET 6.0.snap index a7e18d8c3..c986824b9 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET 6.0.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET 6.0.snap @@ -1,10 +1,5 @@ { - "ExtraMembers": [ - "System.Security.AccessControl.DirectorySecurity GetAccessControl()", - "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.Security.AccessControl.AccessControlSections)", - "Void Create(System.Security.AccessControl.DirectorySecurity)", - "Void SetAccessControl(System.Security.AccessControl.DirectorySecurity)" - ], + "ExtraMembers": [], "MissingMembers": [ "System.Object GetLifetimeService()", "System.Object InitializeLifetimeService()", diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET Core 3.1.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET Core 3.1.snap index a7e18d8c3..c986824b9 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET Core 3.1.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET Core 3.1.snap @@ -1,10 +1,5 @@ { - "ExtraMembers": [ - "System.Security.AccessControl.DirectorySecurity GetAccessControl()", - "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.Security.AccessControl.AccessControlSections)", - "Void Create(System.Security.AccessControl.DirectorySecurity)", - "Void SetAccessControl(System.Security.AccessControl.DirectorySecurity)" - ], + "ExtraMembers": [], "MissingMembers": [ "System.Object GetLifetimeService()", "System.Object InitializeLifetimeService()", diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET Framework 4.6.1.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET Framework 4.6.1.snap index 9bf30cdc0..ec21e0f76 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET Framework 4.6.1.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.DirectoryInfo_.NET Framework 4.6.1.snap @@ -5,7 +5,11 @@ "System.Object GetLifetimeService()", "System.Object InitializeLifetimeService()", "System.Runtime.Remoting.ObjRef CreateObjRef(System.Type)", + "System.Security.AccessControl.DirectorySecurity GetAccessControl()", + "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.Security.AccessControl.AccessControlSections)", "Void .ctor(System.String)", - "Void GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)" + "Void Create(System.Security.AccessControl.DirectorySecurity)", + "Void GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)", + "Void SetAccessControl(System.Security.AccessControl.DirectorySecurity)" ] } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET 5.0.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET 5.0.snap index 73b36d469..7cb3b9523 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET 5.0.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET 5.0.snap @@ -1,9 +1,4 @@ { - "ExtraMembers": [ - "System.IO.Abstractions.IDirectoryInfo CreateDirectory(System.String, System.Security.AccessControl.DirectorySecurity)", - "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.String)", - "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.String, System.Security.AccessControl.AccessControlSections)", - "Void SetAccessControl(System.String, System.Security.AccessControl.DirectorySecurity)" - ], + "ExtraMembers": [], "MissingMembers": [] } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET 6.0.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET 6.0.snap index 73b36d469..7cb3b9523 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET 6.0.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET 6.0.snap @@ -1,9 +1,4 @@ { - "ExtraMembers": [ - "System.IO.Abstractions.IDirectoryInfo CreateDirectory(System.String, System.Security.AccessControl.DirectorySecurity)", - "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.String)", - "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.String, System.Security.AccessControl.AccessControlSections)", - "Void SetAccessControl(System.String, System.Security.AccessControl.DirectorySecurity)" - ], + "ExtraMembers": [], "MissingMembers": [] } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 3.1.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 3.1.snap index 73b36d469..7cb3b9523 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 3.1.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 3.1.snap @@ -1,9 +1,4 @@ { - "ExtraMembers": [ - "System.IO.Abstractions.IDirectoryInfo CreateDirectory(System.String, System.Security.AccessControl.DirectorySecurity)", - "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.String)", - "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.String, System.Security.AccessControl.AccessControlSections)", - "Void SetAccessControl(System.String, System.Security.AccessControl.DirectorySecurity)" - ], + "ExtraMembers": [], "MissingMembers": [] } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET Framework 4.6.1.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET Framework 4.6.1.snap index 7cb3b9523..517bd1d06 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET Framework 4.6.1.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Directory_.NET Framework 4.6.1.snap @@ -1,4 +1,9 @@ { "ExtraMembers": [], - "MissingMembers": [] + "MissingMembers": [ + "System.IO.Abstractions.IDirectoryInfo CreateDirectory(System.String, System.Security.AccessControl.DirectorySecurity)", + "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.String)", + "System.Security.AccessControl.DirectorySecurity GetAccessControl(System.String, System.Security.AccessControl.AccessControlSections)", + "Void SetAccessControl(System.String, System.Security.AccessControl.DirectorySecurity)" + ] } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET 5.0.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET 5.0.snap index e2e2adfd7..c986824b9 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET 5.0.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET 5.0.snap @@ -1,9 +1,5 @@ { - "ExtraMembers": [ - "System.Security.AccessControl.FileSecurity GetAccessControl()", - "System.Security.AccessControl.FileSecurity GetAccessControl(System.Security.AccessControl.AccessControlSections)", - "Void SetAccessControl(System.Security.AccessControl.FileSecurity)" - ], + "ExtraMembers": [], "MissingMembers": [ "System.Object GetLifetimeService()", "System.Object InitializeLifetimeService()", diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET 6.0.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET 6.0.snap index e2e2adfd7..c986824b9 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET 6.0.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET 6.0.snap @@ -1,9 +1,5 @@ { - "ExtraMembers": [ - "System.Security.AccessControl.FileSecurity GetAccessControl()", - "System.Security.AccessControl.FileSecurity GetAccessControl(System.Security.AccessControl.AccessControlSections)", - "Void SetAccessControl(System.Security.AccessControl.FileSecurity)" - ], + "ExtraMembers": [], "MissingMembers": [ "System.Object GetLifetimeService()", "System.Object InitializeLifetimeService()", diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET Core 3.1.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET Core 3.1.snap index ae8e3379d..504fba3c8 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET Core 3.1.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET Core 3.1.snap @@ -1,9 +1,5 @@ { - "ExtraMembers": [ - "System.Security.AccessControl.FileSecurity GetAccessControl()", - "System.Security.AccessControl.FileSecurity GetAccessControl(System.Security.AccessControl.AccessControlSections)", - "Void SetAccessControl(System.Security.AccessControl.FileSecurity)" - ], + "ExtraMembers": [], "MissingMembers": [ "System.Object GetLifetimeService()", "System.Object InitializeLifetimeService()", diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET Framework 4.6.1.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET Framework 4.6.1.snap index a4ae16c13..edd9281da 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET Framework 4.6.1.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.FileInfo_.NET Framework 4.6.1.snap @@ -4,7 +4,10 @@ "System.Object GetLifetimeService()", "System.Object InitializeLifetimeService()", "System.Runtime.Remoting.ObjRef CreateObjRef(System.Type)", + "System.Security.AccessControl.FileSecurity GetAccessControl()", + "System.Security.AccessControl.FileSecurity GetAccessControl(System.Security.AccessControl.AccessControlSections)", "Void .ctor(System.String)", - "Void GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)" + "Void GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)", + "Void SetAccessControl(System.Security.AccessControl.FileSecurity)" ] } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET 5.0.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET 5.0.snap index d4303a9da..7cb3b9523 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET 5.0.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET 5.0.snap @@ -1,8 +1,4 @@ { - "ExtraMembers": [ - "System.Security.AccessControl.FileSecurity GetAccessControl(System.String)", - "System.Security.AccessControl.FileSecurity GetAccessControl(System.String, System.Security.AccessControl.AccessControlSections)", - "Void SetAccessControl(System.String, System.Security.AccessControl.FileSecurity)" - ], + "ExtraMembers": [], "MissingMembers": [] } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET 6.0.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET 6.0.snap index 22f84eff1..ce42363ab 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET 6.0.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET 6.0.snap @@ -1,9 +1,5 @@ { - "ExtraMembers": [ - "System.Security.AccessControl.FileSecurity GetAccessControl(System.String)", - "System.Security.AccessControl.FileSecurity GetAccessControl(System.String, System.Security.AccessControl.AccessControlSections)", - "Void SetAccessControl(System.String, System.Security.AccessControl.FileSecurity)" - ], + "ExtraMembers": [], "MissingMembers": [ "Microsoft.Win32.SafeHandles.SafeFileHandle OpenHandle(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions, Int64)" ] diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET Core 3.1.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET Core 3.1.snap index 58a209431..a72f89d15 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET Core 3.1.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET Core 3.1.snap @@ -1,9 +1,5 @@ { - "ExtraMembers": [ - "System.Security.AccessControl.FileSecurity GetAccessControl(System.String)", - "System.Security.AccessControl.FileSecurity GetAccessControl(System.String, System.Security.AccessControl.AccessControlSections)", - "Void SetAccessControl(System.String, System.Security.AccessControl.FileSecurity)" - ], + "ExtraMembers": [], "MissingMembers": [ "Void Move(System.String, System.String, Boolean)" ] diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET Framework 4.6.1.snap b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET Framework 4.6.1.snap index ad5f2cca9..2e2ed8e14 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET Framework 4.6.1.snap +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.File_.NET Framework 4.6.1.snap @@ -1,6 +1,9 @@ { "ExtraMembers": [], "MissingMembers": [ - "System.IO.Abstractions.FileSystemStream Create(System.String, Int32, System.IO.FileOptions, System.Security.AccessControl.FileSecurity)" + "System.IO.Abstractions.FileSystemStream Create(System.String, Int32, System.IO.FileOptions, System.Security.AccessControl.FileSecurity)", + "System.Security.AccessControl.FileSecurity GetAccessControl(System.String)", + "System.Security.AccessControl.FileSecurity GetAccessControl(System.String, System.Security.AccessControl.AccessControlSections)", + "Void SetAccessControl(System.String, System.Security.AccessControl.FileSecurity)" ] } diff --git a/version.json b/version.json index 4abc70c44..0999bd51e 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": "18.0", + "version": "19.0", "assemblyVersion": { "precision": "major" },