|
| 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 |
0 commit comments