Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
<PackageVersion Include="AutoFixture" Version="4.18.1" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Testably.Abstractions.Interface" Version="[10.3.0,10.4.0)"/>
<PackageVersion Include="Testably.Abstractions" Version="[10.3.0,10.4.0)"/>
<PackageVersion Include="Testably.Abstractions.Interface" Version="[10.4.0-pre.1,10.5.0)"/>
<PackageVersion Include="Testably.Abstractions" Version="[10.4.0-pre.1,10.5.0)"/>
<PackageVersion Include="Testably.Abstractions.Testing" Version="6.6.0"/>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Pipeline/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ partial class Build : FalloutBuild
/// <para />
/// Afterward, you can update the package reference in `Directory.Packages.props` and reset this flag.
/// </summary>
readonly BuildScope BuildScope = BuildScope.CoreOnly;
readonly BuildScope BuildScope = BuildScope.Default;

[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
Expand Down
35 changes: 20 additions & 15 deletions Source/Testably.Abstractions.Testing/FileSystem/FileMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Text;
using Testably.Abstractions.Testing.Helpers;
using Testably.Abstractions.Testing.Storage;
#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
#if FEATURE_FILESYSTEM_SAFEFILEHANDLE || FEATURE_FILESYSTEM_RANDOMACCESS
using Microsoft.Win32.SafeHandles;
#endif
#if FEATURE_FILESYSTEM_ASYNC
Expand Down Expand Up @@ -827,6 +827,24 @@ public FileSystemStream Open(string path, FileStreamOptions options)
}
#endif

#if FEATURE_FILESYSTEM_RANDOMACCESS
/// <inheritdoc cref="IFile.OpenHandle(string, FileMode, FileAccess, FileShare, FileOptions, long)" />
public SafeFileHandle OpenHandle(string path,
FileMode mode = FileMode.Open,
FileAccess access = FileAccess.Read,
FileShare share = FileShare.Read,
FileOptions options = FileOptions.None,
long preallocationSize = 0)
{
using IDisposable registration = _fileSystem.StatisticsRegistration
.File.RegisterMethod(nameof(OpenHandle),
path, mode, access, share, options, preallocationSize);

return _fileSystem.SafeFileHandleRegistry
.Open(path, mode, access, share, options, preallocationSize);
}
#endif

/// <inheritdoc cref="IFile.OpenRead(string)" />
public FileSystemStream OpenRead(string path)
{
Expand Down Expand Up @@ -1671,20 +1689,7 @@ private IStorageContainer GetContainerFromPath(string path,

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
private IStorageContainer GetContainerFromSafeFileHandle(SafeFileHandle fileHandle)
{
SafeFileHandleMock safeFileHandleMock = _fileSystem
.SafeFileHandleStrategy.MapSafeFileHandle(fileHandle);
IStorageContainer container = _fileSystem.Storage
.GetContainer(_fileSystem.Storage.GetLocation(
safeFileHandleMock.Path)
.ThrowExceptionIfNotFound(_fileSystem));
if (container is NullContainer)
{
throw ExceptionFactory.FileNotFound("");
}

return container;
}
=> _fileSystem.SafeFileHandleRegistry.GetContainer(fileHandle).Container;
#endif

private void WriteText(string path, string? contents, Encoding? encoding, bool append = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ public FileSystemStream New(SafeFileHandle handle, FileAccess access)
.FileStream.RegisterMethod(nameof(New),
handle, access);

SafeFileHandleMock safeFileHandleMock = _fileSystem
.SafeFileHandleStrategy.MapSafeFileHandle(handle);
SafeFileHandleMock safeFileHandleMock = MapSafeFileHandle(handle);
return New(
safeFileHandleMock.Path,
safeFileHandleMock.Mode,
Expand All @@ -172,8 +171,7 @@ public FileSystemStream New(SafeFileHandle handle, FileAccess access, int buffer
.FileStream.RegisterMethod(nameof(New),
handle, access, bufferSize);

SafeFileHandleMock safeFileHandleMock = _fileSystem
.SafeFileHandleStrategy.MapSafeFileHandle(handle);
SafeFileHandleMock safeFileHandleMock = MapSafeFileHandle(handle);
return New(
safeFileHandleMock.Path,
safeFileHandleMock.Mode,
Expand All @@ -193,8 +191,7 @@ public FileSystemStream New(SafeFileHandle handle, FileAccess access, int buffer
.FileStream.RegisterMethod(nameof(New),
handle, access, bufferSize, isAsync);

SafeFileHandleMock safeFileHandleMock = _fileSystem
.SafeFileHandleStrategy.MapSafeFileHandle(handle);
SafeFileHandleMock safeFileHandleMock = MapSafeFileHandle(handle);
return New(
safeFileHandleMock.Path,
safeFileHandleMock.Mode,
Expand Down Expand Up @@ -234,4 +231,11 @@ public FileSystemStream Wrap(FileStream fileStream)
}

#endregion

private SafeFileHandleMock MapSafeFileHandle(SafeFileHandle handle)
#if FEATURE_FILESYSTEM_RANDOMACCESS
=> _fileSystem.SafeFileHandleRegistry.Map(handle);
#else
=> _fileSystem.SafeFileHandleStrategy.MapSafeFileHandle(handle);
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -901,25 +901,5 @@ private void ThrowIfDisposed()
}

private static void ThrowIfInvalidModeAccess(FileMode mode, FileAccess access)
Comment thread
vbreuss marked this conversation as resolved.
Outdated
{
if (mode == FileMode.Append)
{
if (access == FileAccess.Read)
{
throw ExceptionFactory.InvalidAccessCombination(mode, access);
}

if (access != FileAccess.Write)
{
throw ExceptionFactory.AppendAccessOnlyInWriteOnlyMode();
}
}

if (!access.HasFlag(FileAccess.Write) &&
(mode == FileMode.Truncate || mode == FileMode.CreateNew ||
mode == FileMode.Create || mode == FileMode.Append))
{
throw ExceptionFactory.InvalidAccessCombination(mode, access);
}
}
=> FileModeHelper.ThrowIfInvalidModeAccess(mode, access);
}
Loading
Loading