Skip to content

Commit 8446600

Browse files
authored
chore: bump Testably.Abstractions.FileSystem.Interface to v10.4.0 (#1542)
v10.4.0 adds `IFile.OpenHandle` and `IFileSystem.RandomAccess`. The wrappers forward to the real APIs; the mock throws `NotSupportedException`, since it cannot provide a `SafeFileHandle` for its in-memory files.
1 parent 4eebe7f commit 8446600

24 files changed

Lines changed: 377 additions & 18 deletions

‎Directory.Build.props‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<PackageReadmeFile>README.md</PackageReadmeFile>
1515
<DefineConstants Condition="'$(TargetFramework)' != 'net472'">$(DefineConstants);FEATURE_FILE_SYSTEM_ACL_EXTENSIONS</DefineConstants>
1616
<DefineConstants Condition="'$(TargetFramework)' == 'net10.0' OR '$(TargetFramework)' == 'net9.0' OR '$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS;FEATURE_ADVANCED_PATH_OPERATIONS;FEATURE_PATH_JOIN_WITH_SPAN;FEATURE_SPAN</DefineConstants>
17-
<DefineConstants Condition="'$(TargetFramework)' == 'net10.0' OR '$(TargetFramework)' == 'net9.0' OR '$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == 'net6.0'">$(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;FEATURE_FILE_SYSTEM_INFO_LINK_TARGET;FEATURE_CREATE_SYMBOLIC_LINK;FEATURE_FILESTREAM_OPTIONS</DefineConstants>
18-
<DefineConstants Condition="'$(TargetFramework)' == 'net10.0' OR '$(TargetFramework)' == 'net9.0' OR '$(TargetFramework)' == 'net8.0'">$(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>
17+
<DefineConstants Condition="'$(TargetFramework)' == 'net10.0' OR '$(TargetFramework)' == 'net9.0' OR '$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == 'net6.0'">$(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;FEATURE_FILE_SYSTEM_INFO_LINK_TARGET;FEATURE_CREATE_SYMBOLIC_LINK;FEATURE_FILESTREAM_OPTIONS;FEATURE_RANDOM_ACCESS</DefineConstants>
18+
<DefineConstants Condition="'$(TargetFramework)' == 'net10.0' OR '$(TargetFramework)' == 'net9.0' OR '$(TargetFramework)' == 'net8.0'">$(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;FEATURE_RANDOM_ACCESS_FLUSH_TO_DISK</DefineConstants>
1919
<DefineConstants Condition="'$(TargetFramework)' == 'net10.0' OR '$(TargetFramework)' == 'net9.0'">$(DefineConstants);FEATURE_PATH_SPAN;FEATURE_FILE_SPAN</DefineConstants>
2020
<DefineConstants>$(DefineConstants);FEATURE_SERIALIZABLE</DefineConstants>
2121
</PropertyGroup>

‎Directory.Packages.props‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageVersion Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
1616
<PackageVersion Include="IsExternalInit" Version="1.0.3" />
1717
<PackageVersion Include="Nullable" Version="1.3.1" />
18-
<PackageVersion Include="Testably.Abstractions.FileSystem.Interface" Version="10.3.0" />
18+
<PackageVersion Include="Testably.Abstractions.FileSystem.Interface" Version="10.4.0" />
1919
</ItemGroup>
2020
<ItemGroup>
2121
<PackageVersion Include="BenchmarkDotNet" Version="0.15.8" />

‎src/TestableIO.System.IO.Abstractions.TestingHelpers/CommonExceptions.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public static ArgumentException AppendAccessOnlyInWriteOnlyMode()
7777
public static NotImplementedException NotImplemented() =>
7878
new NotImplementedException(StringResources.Manager.GetString("NOT_IMPLEMENTED_EXCEPTION"));
7979

80+
public static NotSupportedException RandomAccessNotSupported() =>
81+
new NotSupportedException(StringResources.Manager.GetString("RANDOM_ACCESS_NOT_SUPPORTED_EXCEPTION"));
82+
8083
public static IOException CannotCreateBecauseSameNameAlreadyExists(string path) =>
8184
new IOException(
8285
string.Format(

‎src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,16 @@ public override FileSystemStream Open(string path, FileStreamOptions options)
637637
}
638638
#endif
639639

640+
#if FEATURE_RANDOM_ACCESS
641+
/// <inheritdoc />
642+
public override SafeFileHandle OpenHandle(string path, FileMode mode = FileMode.Open,
643+
FileAccess access = FileAccess.Read, FileShare share = FileShare.Read,
644+
FileOptions options = FileOptions.None, long preallocationSize = 0)
645+
{
646+
throw CommonExceptions.RandomAccessNotSupported();
647+
}
648+
#endif
649+
640650
private FileSystemStream OpenInternal(
641651
string path,
642652
FileMode mode,

‎src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public MockFileSystem(IDictionary<string, MockFileData> files, MockFileSystemOpt
7474
DirectoryInfo = new MockDirectoryInfoFactory(this);
7575
DriveInfo = new MockDriveInfoFactory(this);
7676
FileSystemWatcher = new MockFileSystemWatcherFactory(this);
77+
#if FEATURE_RANDOM_ACCESS
78+
RandomAccess = new MockRandomAccess(this);
79+
#endif
7780

7881
if (files != null)
7982
{
@@ -114,6 +117,10 @@ public MockFileSystem(IDictionary<string, MockFileData> files, MockFileSystemOpt
114117
public override IDriveInfoFactory DriveInfo { get; }
115118
/// <inheritdoc />
116119
public override IFileSystemWatcherFactory FileSystemWatcher { get; }
120+
#if FEATURE_RANDOM_ACCESS
121+
/// <inheritdoc />
122+
public override IRandomAccess RandomAccess { get; }
123+
#endif
117124
/// <inheritdoc />
118125
public IFileSystem FileSystem => this;
119126
/// <inheritdoc />
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#if FEATURE_RANDOM_ACCESS
2+
using System.Collections.Generic;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using Microsoft.Win32.SafeHandles;
6+
7+
namespace System.IO.Abstractions.TestingHelpers;
8+
9+
/// <summary>
10+
/// Placeholder for <see cref="IRandomAccess"/>: every member throws a <see cref="NotSupportedException"/>.
11+
/// </summary>
12+
#if FEATURE_SERIALIZABLE
13+
[Serializable]
14+
#endif
15+
public class MockRandomAccess : IRandomAccess
16+
{
17+
/// <inheritdoc />
18+
public MockRandomAccess(IFileSystem fileSystem)
19+
{
20+
FileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
21+
}
22+
23+
/// <inheritdoc />
24+
public IFileSystem FileSystem { get; }
25+
26+
#if FEATURE_RANDOM_ACCESS_FLUSH_TO_DISK
27+
/// <inheritdoc />
28+
public void FlushToDisk(SafeFileHandle handle)
29+
=> throw CommonExceptions.RandomAccessNotSupported();
30+
#endif
31+
32+
/// <inheritdoc />
33+
public long GetLength(SafeFileHandle handle)
34+
=> throw CommonExceptions.RandomAccessNotSupported();
35+
36+
/// <inheritdoc />
37+
public int Read(SafeFileHandle handle, Span<byte> buffer, long fileOffset)
38+
=> throw CommonExceptions.RandomAccessNotSupported();
39+
40+
/// <inheritdoc />
41+
public long Read(SafeFileHandle handle, IReadOnlyList<Memory<byte>> buffers, long fileOffset)
42+
=> throw CommonExceptions.RandomAccessNotSupported();
43+
44+
/// <inheritdoc />
45+
public ValueTask<int> ReadAsync(SafeFileHandle handle, Memory<byte> buffer, long fileOffset,
46+
CancellationToken cancellationToken = default)
47+
=> throw CommonExceptions.RandomAccessNotSupported();
48+
49+
/// <inheritdoc />
50+
public ValueTask<long> ReadAsync(SafeFileHandle handle, IReadOnlyList<Memory<byte>> buffers,
51+
long fileOffset, CancellationToken cancellationToken = default)
52+
=> throw CommonExceptions.RandomAccessNotSupported();
53+
54+
#if FEATURE_RANDOM_ACCESS_FLUSH_TO_DISK
55+
/// <inheritdoc />
56+
public void SetLength(SafeFileHandle handle, long length)
57+
=> throw CommonExceptions.RandomAccessNotSupported();
58+
#endif
59+
60+
/// <inheritdoc />
61+
public void Write(SafeFileHandle handle, ReadOnlySpan<byte> buffer, long fileOffset)
62+
=> throw CommonExceptions.RandomAccessNotSupported();
63+
64+
/// <inheritdoc />
65+
public void Write(SafeFileHandle handle, IReadOnlyList<ReadOnlyMemory<byte>> buffers,
66+
long fileOffset)
67+
=> throw CommonExceptions.RandomAccessNotSupported();
68+
69+
/// <inheritdoc />
70+
public ValueTask WriteAsync(SafeFileHandle handle, ReadOnlyMemory<byte> buffer,
71+
long fileOffset, CancellationToken cancellationToken = default)
72+
=> throw CommonExceptions.RandomAccessNotSupported();
73+
74+
/// <inheritdoc />
75+
public ValueTask WriteAsync(SafeFileHandle handle, IReadOnlyList<ReadOnlyMemory<byte>> buffers,
76+
long fileOffset, CancellationToken cancellationToken = default)
77+
=> throw CommonExceptions.RandomAccessNotSupported();
78+
}
79+
#endif

‎src/TestableIO.System.IO.Abstractions.TestingHelpers/Properties/Resources.resx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,7 @@
171171
<data name="PATH_DOES_NOT_EXIST_OR_COULD_NOT_BE_FOUND" xml:space="preserve">
172172
<value>'{0}' does not exist or could not be found.</value>
173173
</data>
174+
<data name="RANDOM_ACCESS_NOT_SUPPORTED_EXCEPTION" xml:space="preserve">
175+
<value>MockFileSystem does not support File.OpenHandle or RandomAccess, because it cannot provide a SafeFileHandle for its in-memory files.</value>
176+
</data>
174177
</root>

‎src/TestableIO.System.IO.Abstractions.Wrappers/FileBase.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ internal FileBase() { }
179179
public abstract FileSystemStream Open(string path, FileStreamOptions options);
180180
#endif
181181

182+
#if FEATURE_RANDOM_ACCESS
183+
/// <inheritdoc cref="IFile.OpenHandle(string,FileMode,FileAccess,FileShare,FileOptions,long)"/>
184+
public abstract SafeFileHandle OpenHandle(string path, FileMode mode = FileMode.Open,
185+
FileAccess access = FileAccess.Read, FileShare share = FileShare.Read,
186+
FileOptions options = FileOptions.None, long preallocationSize = 0);
187+
#endif
188+
182189
/// <inheritdoc cref="IFile.OpenRead"/>
183190
public abstract FileSystemStream OpenRead(string path);
184191

‎src/TestableIO.System.IO.Abstractions.Wrappers/FileSystem.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public FileSystem()
1818
Directory = new DirectoryWrapper(this);
1919
FileStream = new FileStreamFactory(this);
2020
FileSystemWatcher = new FileSystemWatcherFactory(this);
21+
#if FEATURE_RANDOM_ACCESS
22+
RandomAccess = new RandomAccessWrapper(this);
23+
#endif
2124
}
2225

2326
/// <inheritdoc />
@@ -46,4 +49,9 @@ public FileSystem()
4649

4750
/// <inheritdoc />
4851
public override IFileSystemWatcherFactory FileSystemWatcher { get; }
52+
53+
#if FEATURE_RANDOM_ACCESS
54+
/// <inheritdoc />
55+
public override IRandomAccess RandomAccess { get; }
56+
#endif
4957
}

‎src/TestableIO.System.IO.Abstractions.Wrappers/FileSystemBase.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ public abstract class FileSystemBase : IFileSystem
3232

3333
/// <inheritdoc />
3434
public abstract IFileSystemWatcherFactory FileSystemWatcher { get; }
35+
36+
#if FEATURE_RANDOM_ACCESS
37+
/// <inheritdoc />
38+
public abstract IRandomAccess RandomAccess { get; }
39+
#endif
3540
}

0 commit comments

Comments
 (0)