From da679c04d23a72b433368d0bdbcbbde5735a30f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Fri, 25 Aug 2023 14:16:47 +0200 Subject: [PATCH 1/3] Disable serialization for .NET8 or greater --- .../MockDirectory.cs | 3 ++- .../MockDirectoryData.cs | 5 ++++- .../MockDirectoryInfo.cs | 2 ++ .../MockDirectoryInfoFactory.cs | 2 ++ .../MockDriveInfo.cs | 2 ++ .../MockDriveInfoFactory.cs | 2 ++ .../MockFile.cs | 2 ++ .../MockFileData.cs | 4 ++++ .../MockFileInfo.cs | 2 ++ .../MockFileInfoFactory.cs | 2 ++ .../MockFileStream.cs | 2 ++ .../MockFileStreamFactory.cs | 2 ++ .../MockFileSystem.cs | 8 +++++++- .../MockFileSystemWatcherFactory.cs | 2 ++ .../MockPath.cs | 2 ++ .../PathVerifier.cs | 2 ++ .../StringOperations.cs | 2 ++ .../DirectoryBase.cs | 2 ++ .../DirectoryInfoBase.cs | 2 ++ .../DirectoryInfoFactory.cs | 2 ++ .../DirectoryInfoWrapper.cs | 2 ++ .../DirectoryWrapper.cs | 2 ++ .../DriveInfoBase.cs | 2 ++ .../DriveInfoFactory.cs | 2 ++ .../DriveInfoWrapper.cs | 2 ++ .../FileBase.cs | 2 ++ .../FileInfoBase.cs | 2 ++ .../FileInfoFactory.cs | 2 ++ .../FileInfoWrapper.cs | 2 ++ .../FileStreamFactory.cs | 2 ++ .../FileSystem.cs | 2 ++ .../FileSystemBase.cs | 2 ++ .../FileSystemInfoBase.cs | 2 ++ .../FileSystemWatcherBase.cs | 2 ++ .../FileSystemWatcherFactory.cs | 2 ++ .../FileSystemWatcherWrapper.cs | 4 ++++ .../FileWrapper.cs | 2 ++ .../PathBase.cs | 2 ++ .../PathWrapper.cs | 2 ++ .../MockFileSystemSerializationTests.cs | 4 +++- .../MockFileSystemTests.cs | 2 ++ .../MockFileTests.cs | 2 ++ .../FileSystemTests.cs | 2 ++ 43 files changed, 98 insertions(+), 4 deletions(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs index 1902b859d..9195cd2a5 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs @@ -10,8 +10,9 @@ namespace System.IO.Abstractions.TestingHelpers /// - +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockDirectory : DirectoryBase { private readonly IMockFileDataAccessor mockFileDataAccessor; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryData.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryData.cs index 28d8925f1..124a2ab9b 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryData.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryData.cs @@ -4,11 +4,14 @@ namespace System.IO.Abstractions.TestingHelpers { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockDirectoryData : MockFileData { - +#if !NET8_0_OR_GREATER [NonSerialized] +#endif private DirectorySecurity accessControl; /// diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs index 29b82e7a1..124700c30 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs @@ -8,7 +8,9 @@ namespace System.IO.Abstractions.TestingHelpers using XFS = MockUnixSupport; /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockDirectoryInfo : DirectoryInfoBase, IFileSystemAclSupport { private readonly IMockFileDataAccessor mockFileDataAccessor; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfoFactory.cs index ba680b91b..96ba7c786 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfoFactory.cs @@ -1,7 +1,9 @@ namespace System.IO.Abstractions.TestingHelpers { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockDirectoryInfoFactory : IDirectoryInfoFactory { readonly IMockFileDataAccessor mockFileSystem; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfo.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfo.cs index 9b72b11ec..d8e1a00df 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfo.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfo.cs @@ -1,7 +1,9 @@ namespace System.IO.Abstractions.TestingHelpers { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockDriveInfo : DriveInfoBase { private readonly IMockFileDataAccessor mockFileDataAccessor; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs index b0a1d6046..56da4f00c 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs @@ -3,7 +3,9 @@ namespace System.IO.Abstractions.TestingHelpers { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockDriveInfoFactory : IDriveInfoFactory { private readonly IMockFileDataAccessor mockFileSystem; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs index 534e51f9d..fe0f64c57 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs @@ -9,7 +9,9 @@ namespace System.IO.Abstractions.TestingHelpers using XFS = MockUnixSupport; /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public partial class MockFile : FileBase { private readonly IMockFileDataAccessor mockFileDataAccessor; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs index be7c88667..6c1da1d85 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs @@ -8,7 +8,9 @@ namespace System.IO.Abstractions.TestingHelpers /// /// The class represents the associated data of a file. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockFileData { /// @@ -36,7 +38,9 @@ public class MockFileData /// /// The access control of the . /// +#if !NET8_0_OR_GREATER [NonSerialized] +#endif private FileSecurity accessControl; /// diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs index a057eeeed..86da71640 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs @@ -4,7 +4,9 @@ namespace System.IO.Abstractions.TestingHelpers { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockFileInfo : FileInfoBase, IFileSystemAclSupport { private readonly IMockFileDataAccessor mockFileSystem; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfoFactory.cs index 2d3129092..f9f6ef368 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfoFactory.cs @@ -1,7 +1,9 @@ namespace System.IO.Abstractions.TestingHelpers { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockFileInfoFactory : IFileInfoFactory { private readonly IMockFileDataAccessor mockFileSystem; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs index 197fffd43..7fe5cbd16 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs @@ -6,7 +6,9 @@ namespace System.IO.Abstractions.TestingHelpers { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockFileStream : FileSystemStream, IFileSystemAclSupport { /// diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStreamFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStreamFactory.cs index 887526f5a..84c383603 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStreamFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStreamFactory.cs @@ -4,7 +4,9 @@ namespace System.IO.Abstractions.TestingHelpers { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockFileStreamFactory : IFileStreamFactory { private readonly IMockFileDataAccessor mockFileSystem; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs index cbc9d81ba..8c35364c9 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs @@ -8,7 +8,9 @@ namespace System.IO.Abstractions.TestingHelpers using XFS = MockUnixSupport; /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockFileSystem : FileSystemBase, IMockFileDataAccessor { private const string DEFAULT_CURRENT_DIRECTORY = @"C:\"; @@ -16,7 +18,9 @@ public class MockFileSystem : FileSystemBase, IMockFileDataAccessor private readonly IDictionary files; private readonly PathVerifier pathVerifier; +#if !NET8_0_OR_GREATER [NonSerialized] +#endif private Func dateTimeProvider = defaultDateTimeProvider; private static Func defaultDateTimeProvider = () => DateTime.UtcNow; @@ -516,7 +520,9 @@ private bool FileIsReadOnly(string path) return (GetFile(path).Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; } - [Serializable] +#if !NET8_0_OR_GREATER + [Serializable] +#endif private class FileSystemEntry { public string Path { get; set; } diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs index 9a65d4b04..fc9d52673 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs @@ -1,7 +1,9 @@ namespace System.IO.Abstractions.TestingHelpers { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockFileSystemWatcherFactory : IFileSystemWatcherFactory { diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs index 1ed5c01ab..b0e9da5e2 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs @@ -7,7 +7,9 @@ namespace System.IO.Abstractions.TestingHelpers /// /// PathWrapper calls direct to Path but all this does is string manipulation so we can inherit directly from PathWrapper as no IO is done /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MockPath : PathWrapper { private readonly IMockFileDataAccessor mockFileDataAccessor; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs index 4f3dd7b51..4012a35c7 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs @@ -7,7 +7,9 @@ namespace System.IO.Abstractions.TestingHelpers /// /// Provides helper methods for verifying paths. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class PathVerifier { private static readonly char[] AdditionalInvalidPathChars = { '*', '?' }; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/StringOperations.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/StringOperations.cs index 1145da833..7445d89c6 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/StringOperations.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/StringOperations.cs @@ -4,7 +4,9 @@ /// /// Provides operations against path strings dependeing on the case-senstivity of the runtime platform. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class StringOperations { private readonly bool caseSensitive; diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs index 949d6c0d8..aa06d6198 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs @@ -5,7 +5,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public abstract class DirectoryBase : IDirectory { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs index bbd12cd64..b15c6cbf8 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs @@ -4,7 +4,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public abstract class DirectoryInfoBase : FileSystemInfoBase, IDirectoryInfo { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoFactory.cs index ed33f9eb3..7ef26d5f8 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoFactory.cs @@ -1,6 +1,8 @@ namespace System.IO.Abstractions { +#if !NET8_0_OR_GREATER [Serializable] +#endif internal class DirectoryInfoFactory : IDirectoryInfoFactory { private readonly IFileSystem fileSystem; diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs index 93444b86e..ecd21e29c 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs @@ -7,7 +7,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class DirectoryInfoWrapper : DirectoryInfoBase, IFileSystemAclSupport { private readonly DirectoryInfo instance; diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs index 6a0717459..7977e4a07 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs @@ -4,7 +4,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class DirectoryWrapper : DirectoryBase { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoBase.cs index b1e92e04a..5b9e0b442 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoBase.cs @@ -1,7 +1,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public abstract class DriveInfoBase : IDriveInfo { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs index f08453bd9..fa2872efe 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs @@ -1,6 +1,8 @@ namespace System.IO.Abstractions { +#if !NET8_0_OR_GREATER [Serializable] +#endif internal class DriveInfoFactory : IDriveInfoFactory { private readonly IFileSystem fileSystem; diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoWrapper.cs index 5b5c38fdf..8e4c4d5e9 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoWrapper.cs @@ -5,7 +5,9 @@ namespace System.IO.Abstractions /// /// The wrapper for a . /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class DriveInfoWrapper : DriveInfoBase { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs index 1b5714547..ba08fe4e5 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs @@ -5,7 +5,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public abstract partial class FileBase : IFile { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs index a0eb30c30..2281e246c 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs @@ -3,7 +3,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public abstract class FileInfoBase : FileSystemInfoBase, IFileInfo { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoFactory.cs index a2f79ecc9..1b57386d4 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoFactory.cs @@ -1,6 +1,8 @@ namespace System.IO.Abstractions { +#if !NET8_0_OR_GREATER [Serializable] +#endif internal class FileInfoFactory : IFileInfoFactory { private readonly IFileSystem fileSystem; diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs index 68721c328..a62fea27d 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs @@ -4,7 +4,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class FileInfoWrapper : FileInfoBase, IFileSystemAclSupport { private readonly FileInfo instance; diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamFactory.cs index 02e14b870..f87fbaada 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamFactory.cs @@ -2,7 +2,9 @@ namespace System.IO.Abstractions { +#if !NET8_0_OR_GREATER [Serializable] +#endif internal sealed class FileStreamFactory : IFileStreamFactory { public FileStreamFactory(IFileSystem fileSystem) diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystem.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystem.cs index 87c6a2ea6..51f0113e5 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystem.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystem.cs @@ -1,7 +1,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class FileSystem : FileSystemBase { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemBase.cs index 30ac14234..71820594b 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemBase.cs @@ -1,7 +1,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public abstract class FileSystemBase : IFileSystem { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemInfoBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemInfoBase.cs index 00e8ad716..6941e1e41 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemInfoBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemInfoBase.cs @@ -3,7 +3,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public abstract class FileSystemInfoBase : IFileSystemInfo { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherBase.cs index 5bf4a2bfd..61fd1a3fc 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherBase.cs @@ -3,7 +3,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public abstract class FileSystemWatcherBase : IFileSystemWatcher { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs index 2b62e5dbd..f8e82896c 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs @@ -1,7 +1,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class FileSystemWatcherFactory : IFileSystemWatcherFactory { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherWrapper.cs index acfe55b3f..6aa2494d5 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherWrapper.cs @@ -3,10 +3,14 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class FileSystemWatcherWrapper : FileSystemWatcherBase { +#if !NET8_0_OR_GREATER [NonSerialized] +#endif private readonly FileSystemWatcher watcher; /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs index 45d0cc016..dfbfc8e8c 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs @@ -6,7 +6,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public partial class FileWrapper : FileBase { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/PathBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/PathBase.cs index d3fbd0041..fbbc7e179 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/PathBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/PathBase.cs @@ -3,7 +3,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public abstract class PathBase : IPath { /// diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/PathWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/PathWrapper.cs index f749c9898..6fe48d41e 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/PathWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/PathWrapper.cs @@ -3,7 +3,9 @@ namespace System.IO.Abstractions { /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class PathWrapper : PathBase { /// diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs index b304b9256..60a7e7cd1 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs @@ -1,3 +1,4 @@ +#if !NET8_0_OR_GREATER namespace System.IO.Abstractions.TestingHelpers.Tests { using NUnit.Framework; @@ -41,4 +42,5 @@ public void SerializationBytes() fileSystem.File.ReadAllBytes(path)); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index 7f2343d4d..28bc53a88 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -163,6 +163,7 @@ public void MockFileSystem_AddDirectory_ShouldExist() Assert.That(path.Exists, Is.True); } +#if !NET8_0_OR_GREATER [Test] public void MockFileSystem_ByDefault_IsSerializable() { @@ -182,6 +183,7 @@ public void MockFileSystem_ByDefault_IsSerializable() Assert.That(memoryStream.Length > 0, "Length didn't increase after serialization task."); } +#endif [Test] public void MockFileSystem_AddDirectory_ShouldCreateDirectory() diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs index 3c2c6238f..33e515db7 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs @@ -534,6 +534,7 @@ public void MockFile_AppendText_CreatesNewFileForAppendToNonExistingFile() Assert.That(filesystem.FileExists(filepath)); } +#if !NET8_0_OR_GREATER [Test] public void Serializable_works() { @@ -574,6 +575,7 @@ public void Serializable_can_deserialize() //Assert Assert.That(deserialized.TextContents, Is.EqualTo(textContentStr)); } +#endif [Test] public void MockFile_Encrypt_ShouldSetEncryptedAttribute() diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemTests.cs index 4905cb453..f0c19e352 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemTests.cs @@ -6,6 +6,7 @@ namespace System.IO.Abstractions.Tests [TestFixture] public class FileSystemTests { +#if !NET8_0_OR_GREATER [Test] public void Is_Serializable() { @@ -20,6 +21,7 @@ public void Is_Serializable() Assert.That(memoryStream.Length > 0, "Length didn't increase after serialization task."); } +#endif [Test] public void Mock_File_Succeeds() From b662cc7557aa30cd4431c0d01e1f8bc56d069cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Mon, 11 Sep 2023 13:37:49 +0200 Subject: [PATCH 2/3] Keep Serialization attributes also on .NET8, but disable the tests --- Directory.Build.props | 1 + .../MockDirectory.cs | 2 +- .../MockDirectoryData.cs | 4 ++-- .../MockDirectoryInfo.cs | 2 +- .../MockDirectoryInfoFactory.cs | 2 +- .../MockDriveInfo.cs | 2 +- .../MockDriveInfoFactory.cs | 2 +- .../MockFile.cs | 2 +- .../MockFileData.cs | 4 ++-- .../MockFileInfo.cs | 2 +- .../MockFileInfoFactory.cs | 2 +- .../MockFileStream.cs | 2 +- .../MockFileStreamFactory.cs | 2 +- .../MockFileSystem.cs | 6 +++--- .../MockFileSystemWatcherFactory.cs | 2 +- .../MockPath.cs | 2 +- .../PathVerifier.cs | 2 +- .../StringOperations.cs | 2 +- .../DirectoryBase.cs | 2 +- .../DirectoryInfoBase.cs | 2 +- .../DirectoryInfoFactory.cs | 2 +- .../DirectoryInfoWrapper.cs | 2 +- .../DirectoryWrapper.cs | 2 +- .../DriveInfoBase.cs | 2 +- .../DriveInfoFactory.cs | 2 +- .../DriveInfoWrapper.cs | 2 +- src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs | 2 +- .../FileInfoBase.cs | 2 +- .../FileInfoFactory.cs | 2 +- .../FileInfoWrapper.cs | 2 +- .../FileStreamFactory.cs | 2 +- .../FileSystem.cs | 2 +- .../FileSystemBase.cs | 2 +- .../FileSystemInfoBase.cs | 2 +- .../FileSystemWatcherBase.cs | 2 +- .../FileSystemWatcherFactory.cs | 2 +- .../FileSystemWatcherWrapper.cs | 4 ++-- .../FileWrapper.cs | 2 +- src/TestableIO.System.IO.Abstractions.Wrappers/PathBase.cs | 2 +- .../PathWrapper.cs | 2 +- 40 files changed, 45 insertions(+), 44 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index a31e02d0d..02328b977 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -15,6 +15,7 @@ $(DefineConstants);FEATURE_FILE_MOVE_WITH_OVERWRITE;FEATURE_SUPPORTED_OS_ATTRIBUTE;FEATURE_FILE_SYSTEM_WATCHER_FILTERS;FEATURE_ENDS_IN_DIRECTORY_SEPARATOR;FEATURE_PATH_JOIN_WITH_PARAMS;FEATURE_PATH_JOIN_WITH_FOUR_PATHS $(DefineConstants);FEATURE_FILE_SYSTEM_INFO_LINK_TARGET;FEATURE_CREATE_SYMBOLIC_LINK;FEATURE_FILESTREAM_OPTIONS $(DefineConstants);FEATURE_PATH_EXISTS;FEATURE_FILE_SYSTEM_WATCHER_WAIT_WITH_TIMESPAN;FEATURE_FILE_ATTRIBUTES_VIA_HANDLE;FEATURE_CREATE_TEMP_SUBDIRECTORY;FEATURE_READ_LINES_ASYNC;FEATURE_UNIX_FILE_MODE + $(DefineConstants);FEATURE_SERIALIZABLE diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs index 9195cd2a5..525c78fa0 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs @@ -10,7 +10,7 @@ namespace System.IO.Abstractions.TestingHelpers /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockDirectory : DirectoryBase diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryData.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryData.cs index 124a2ab9b..d3c3d3cdf 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryData.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryData.cs @@ -4,12 +4,12 @@ namespace System.IO.Abstractions.TestingHelpers { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockDirectoryData : MockFileData { -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [NonSerialized] #endif private DirectorySecurity accessControl; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs index 124700c30..690c63ba7 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs @@ -8,7 +8,7 @@ namespace System.IO.Abstractions.TestingHelpers using XFS = MockUnixSupport; /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockDirectoryInfo : DirectoryInfoBase, IFileSystemAclSupport diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfoFactory.cs index 96ba7c786..14c3e655c 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfoFactory.cs @@ -1,7 +1,7 @@ namespace System.IO.Abstractions.TestingHelpers { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockDirectoryInfoFactory : IDirectoryInfoFactory diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfo.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfo.cs index d8e1a00df..60cc6dbe1 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfo.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfo.cs @@ -1,7 +1,7 @@ namespace System.IO.Abstractions.TestingHelpers { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockDriveInfo : DriveInfoBase diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs index 56da4f00c..0ebc24070 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDriveInfoFactory.cs @@ -3,7 +3,7 @@ namespace System.IO.Abstractions.TestingHelpers { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockDriveInfoFactory : IDriveInfoFactory diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs index fe0f64c57..5ec85d35f 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs @@ -9,7 +9,7 @@ namespace System.IO.Abstractions.TestingHelpers using XFS = MockUnixSupport; /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public partial class MockFile : FileBase diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs index 6c1da1d85..ac3e41a36 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileData.cs @@ -8,7 +8,7 @@ namespace System.IO.Abstractions.TestingHelpers /// /// The class represents the associated data of a file. /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockFileData @@ -38,7 +38,7 @@ public class MockFileData /// /// The access control of the . /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [NonSerialized] #endif private FileSecurity accessControl; diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs index 86da71640..5356260f1 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfo.cs @@ -4,7 +4,7 @@ namespace System.IO.Abstractions.TestingHelpers { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockFileInfo : FileInfoBase, IFileSystemAclSupport diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfoFactory.cs index f9f6ef368..d3bae8c9a 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileInfoFactory.cs @@ -1,7 +1,7 @@ namespace System.IO.Abstractions.TestingHelpers { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockFileInfoFactory : IFileInfoFactory diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs index 7fe5cbd16..68a316a28 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStream.cs @@ -6,7 +6,7 @@ namespace System.IO.Abstractions.TestingHelpers { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockFileStream : FileSystemStream, IFileSystemAclSupport diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStreamFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStreamFactory.cs index 84c383603..5a1c4bde5 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStreamFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileStreamFactory.cs @@ -4,7 +4,7 @@ namespace System.IO.Abstractions.TestingHelpers { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockFileStreamFactory : IFileStreamFactory diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs index 8c35364c9..1e977d517 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs @@ -8,7 +8,7 @@ namespace System.IO.Abstractions.TestingHelpers using XFS = MockUnixSupport; /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockFileSystem : FileSystemBase, IMockFileDataAccessor @@ -18,7 +18,7 @@ public class MockFileSystem : FileSystemBase, IMockFileDataAccessor private readonly IDictionary files; private readonly PathVerifier pathVerifier; -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [NonSerialized] #endif private Func dateTimeProvider = defaultDateTimeProvider; @@ -520,7 +520,7 @@ private bool FileIsReadOnly(string path) return (GetFile(path).Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; } -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif private class FileSystemEntry diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs index fc9d52673..3e851080b 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemWatcherFactory.cs @@ -1,7 +1,7 @@ namespace System.IO.Abstractions.TestingHelpers { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockFileSystemWatcherFactory : IFileSystemWatcherFactory diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs index 883815bd2..1de4e5885 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs @@ -7,7 +7,7 @@ namespace System.IO.Abstractions.TestingHelpers /// /// PathWrapper calls direct to Path but all this does is string manipulation so we can inherit directly from PathWrapper as no IO is done /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class MockPath : PathWrapper diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs index 4012a35c7..a635399b1 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs @@ -7,7 +7,7 @@ namespace System.IO.Abstractions.TestingHelpers /// /// Provides helper methods for verifying paths. /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class PathVerifier diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/StringOperations.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/StringOperations.cs index 7445d89c6..a815a00de 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/StringOperations.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/StringOperations.cs @@ -4,7 +4,7 @@ /// /// Provides operations against path strings dependeing on the case-senstivity of the runtime platform. /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class StringOperations diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs index aa06d6198..d88a3e432 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryBase.cs @@ -5,7 +5,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public abstract class DirectoryBase : IDirectory diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs index b15c6cbf8..b9d31459d 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoBase.cs @@ -4,7 +4,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public abstract class DirectoryInfoBase : FileSystemInfoBase, IDirectoryInfo diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoFactory.cs index 7ef26d5f8..8994614ce 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoFactory.cs @@ -1,6 +1,6 @@ namespace System.IO.Abstractions { -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif internal class DirectoryInfoFactory : IDirectoryInfoFactory diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs index ecd21e29c..5b933bba6 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryInfoWrapper.cs @@ -7,7 +7,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class DirectoryInfoWrapper : DirectoryInfoBase, IFileSystemAclSupport diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs index 7977e4a07..05ae91821 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DirectoryWrapper.cs @@ -4,7 +4,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class DirectoryWrapper : DirectoryBase diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoBase.cs index 5b9e0b442..15830733a 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoBase.cs @@ -1,7 +1,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public abstract class DriveInfoBase : IDriveInfo diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs index fa2872efe..5a340eb05 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoFactory.cs @@ -1,6 +1,6 @@ namespace System.IO.Abstractions { -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif internal class DriveInfoFactory : IDriveInfoFactory diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoWrapper.cs index 8e4c4d5e9..5d3976382 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/DriveInfoWrapper.cs @@ -5,7 +5,7 @@ namespace System.IO.Abstractions /// /// The wrapper for a . /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class DriveInfoWrapper : DriveInfoBase diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs index ba08fe4e5..a5d25c51d 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs @@ -5,7 +5,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public abstract partial class FileBase : IFile diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs index 2281e246c..1c8875fb0 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoBase.cs @@ -3,7 +3,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public abstract class FileInfoBase : FileSystemInfoBase, IFileInfo diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoFactory.cs index 1b57386d4..411c06db7 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoFactory.cs @@ -1,6 +1,6 @@ namespace System.IO.Abstractions { -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif internal class FileInfoFactory : IFileInfoFactory diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs index a62fea27d..2cc1231a7 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileInfoWrapper.cs @@ -4,7 +4,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class FileInfoWrapper : FileInfoBase, IFileSystemAclSupport diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamFactory.cs index f87fbaada..46c4deb31 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileStreamFactory.cs @@ -2,7 +2,7 @@ namespace System.IO.Abstractions { -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif internal sealed class FileStreamFactory : IFileStreamFactory diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystem.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystem.cs index 51f0113e5..80e7ae69e 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystem.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystem.cs @@ -1,7 +1,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class FileSystem : FileSystemBase diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemBase.cs index 71820594b..6fb508161 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemBase.cs @@ -1,7 +1,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public abstract class FileSystemBase : IFileSystem diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemInfoBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemInfoBase.cs index 6941e1e41..9ada81b2d 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemInfoBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemInfoBase.cs @@ -3,7 +3,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public abstract class FileSystemInfoBase : IFileSystemInfo diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherBase.cs index 61fd1a3fc..c59147dc1 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherBase.cs @@ -3,7 +3,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public abstract class FileSystemWatcherBase : IFileSystemWatcher diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs index f8e82896c..04057943d 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherFactory.cs @@ -1,7 +1,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class FileSystemWatcherFactory : IFileSystemWatcherFactory diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherWrapper.cs index 6aa2494d5..b7fac4af1 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemWatcherWrapper.cs @@ -3,12 +3,12 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class FileSystemWatcherWrapper : FileSystemWatcherBase { -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [NonSerialized] #endif private readonly FileSystemWatcher watcher; diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs index dfbfc8e8c..8f1f5512d 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/FileWrapper.cs @@ -6,7 +6,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public partial class FileWrapper : FileBase diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/PathBase.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/PathBase.cs index fbbc7e179..0540b8f49 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/PathBase.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/PathBase.cs @@ -3,7 +3,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public abstract class PathBase : IPath diff --git a/src/TestableIO.System.IO.Abstractions.Wrappers/PathWrapper.cs b/src/TestableIO.System.IO.Abstractions.Wrappers/PathWrapper.cs index 6fe48d41e..2b4972e35 100644 --- a/src/TestableIO.System.IO.Abstractions.Wrappers/PathWrapper.cs +++ b/src/TestableIO.System.IO.Abstractions.Wrappers/PathWrapper.cs @@ -3,7 +3,7 @@ namespace System.IO.Abstractions { /// -#if !NET8_0_OR_GREATER +#if FEATURE_SERIALIZABLE [Serializable] #endif public class PathWrapper : PathBase From dde6b20b7ec3ddac061cecec0359b86c7bea6f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Tue, 12 Sep 2023 08:01:35 +0200 Subject: [PATCH 3/3] Use `EnableUnsafeBinaryFormatterSerialization` --- .../MockFileSystemSerializationTests.cs | 2 -- .../MockFileSystemTests.cs | 2 -- .../MockFileTests.cs | 2 -- ...bleIO.System.IO.Abstractions.TestingHelpers.Tests.csproj | 6 ++++++ .../FileSystemTests.cs | 2 -- .../TestableIO.System.IO.Abstractions.Wrappers.Tests.csproj | 6 ++++++ 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs index 60a7e7cd1..2e258eb53 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs @@ -1,4 +1,3 @@ -#if !NET8_0_OR_GREATER namespace System.IO.Abstractions.TestingHelpers.Tests { using NUnit.Framework; @@ -43,4 +42,3 @@ public void SerializationBytes() } } } -#endif \ No newline at end of file diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index 28bc53a88..7f2343d4d 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -163,7 +163,6 @@ public void MockFileSystem_AddDirectory_ShouldExist() Assert.That(path.Exists, Is.True); } -#if !NET8_0_OR_GREATER [Test] public void MockFileSystem_ByDefault_IsSerializable() { @@ -183,7 +182,6 @@ public void MockFileSystem_ByDefault_IsSerializable() Assert.That(memoryStream.Length > 0, "Length didn't increase after serialization task."); } -#endif [Test] public void MockFileSystem_AddDirectory_ShouldCreateDirectory() diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs index 33e515db7..3c2c6238f 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs @@ -534,7 +534,6 @@ public void MockFile_AppendText_CreatesNewFileForAppendToNonExistingFile() Assert.That(filesystem.FileExists(filepath)); } -#if !NET8_0_OR_GREATER [Test] public void Serializable_works() { @@ -575,7 +574,6 @@ public void Serializable_can_deserialize() //Assert Assert.That(deserialized.TextContents, Is.EqualTo(textContentStr)); } -#endif [Test] public void MockFile_Encrypt_ShouldSetEncryptedAttribute() diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj index b4a2144ac..4fefd58d1 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj @@ -40,4 +40,10 @@ + + + true + diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemTests.cs index f0c19e352..4905cb453 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemTests.cs @@ -6,7 +6,6 @@ namespace System.IO.Abstractions.Tests [TestFixture] public class FileSystemTests { -#if !NET8_0_OR_GREATER [Test] public void Is_Serializable() { @@ -21,7 +20,6 @@ public void Is_Serializable() Assert.That(memoryStream.Length > 0, "Length didn't increase after serialization task."); } -#endif [Test] public void Mock_File_Succeeds() diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/TestableIO.System.IO.Abstractions.Wrappers.Tests.csproj b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/TestableIO.System.IO.Abstractions.Wrappers.Tests.csproj index e82396605..070f0dc92 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/TestableIO.System.IO.Abstractions.Wrappers.Tests.csproj +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/TestableIO.System.IO.Abstractions.Wrappers.Tests.csproj @@ -23,4 +23,10 @@ + + + true +