Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
using System;
using System.IO;
using Testably.Abstractions.Testing.Helpers;
#if NET6_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
#endif

namespace Testably.Abstractions.Testing.FileSystem;

Expand Down Expand Up @@ -144,9 +141,6 @@
#endif

/// <inheritdoc cref="IFileStreamFactory.New(SafeFileHandle, FileAccess)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public FileSystemStream New(SafeFileHandle handle, FileAccess access)
{
using IDisposable registration = _fileSystem.StatisticsRegistration
Expand All @@ -157,9 +151,6 @@
}

/// <inheritdoc cref="IFileStreamFactory.New(SafeFileHandle, FileAccess, int)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public FileSystemStream New(SafeFileHandle handle, FileAccess access, int bufferSize)
{
using IDisposable registration = _fileSystem.StatisticsRegistration
Expand All @@ -170,9 +161,6 @@
}

/// <inheritdoc cref="IFileStreamFactory.New(SafeFileHandle, FileAccess, int, bool)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public FileSystemStream New(SafeFileHandle handle, FileAccess access, int bufferSize,
bool isAsync)
{
Expand Down Expand Up @@ -216,9 +204,10 @@

/// <summary>
/// A handle from the <see cref="ISafeFileHandleStrategy" /> only carries a path and may wrap an operating system
/// handle that the caller still uses, so its file is opened by path and the handle is left open.
/// handle that the caller still uses, so its file is opened by path and the handle is left open. Like a real
/// <see cref="FileStream" />, the stream takes no share of its own, as the handle already holds the file open.
/// </summary>
private FileSystemStream NewFromHandle(SafeFileHandle handle, FileAccess access,

Check warning on line 210 in Source/Testably.Abstractions.Testing/FileSystem/FileStreamFactoryMock.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change return type of method 'NewFromHandle' from 'System.IO.Abstractions.FileSystemStream' to 'Testably.Abstractions.Testing.FileSystem.FileStreamMock' for improved performance

See more on https://sonarcloud.io/project/issues?id=Testably_Testably.Abstractions&issues=AaDjRsm6RgBRhcf6Eydh&open=AaDjRsm6RgBRhcf6Eydh&pullRequest=1109
int bufferSize, bool isAsync)
{
#if FEATURE_FILESYSTEM_RANDOMACCESS
Expand All @@ -233,12 +222,13 @@
SafeFileHandleMock safeFileHandleMock =
_fileSystem.SafeFileHandleStrategy.MapSafeFileHandle(handle);
#endif
return New(
return new FileStreamMock(_fileSystem,
safeFileHandleMock.Path,
safeFileHandleMock.Mode,
access,
safeFileHandleMock.Share,
bufferSize,
isAsync);
isAsync ? FileOptions.Asynchronous : FileOptions.None,
adoptHandle: true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ internal FileStreamMock(MockFileSystem fileSystem,
#if FEATURE_FILESYSTEM_UNIXFILEMODE
,UnixFileMode? unixFileMode = null
#endif
,bool adoptHandle = false
)
: this(new MemoryStream(),
fileSystem,
Expand All @@ -207,6 +208,7 @@ internal FileStreamMock(MockFileSystem fileSystem,
#if FEATURE_FILESYSTEM_UNIXFILEMODE
,unixFileMode
#endif
,adoptHandle
)
{
}
Expand All @@ -223,6 +225,7 @@ FileOptions options
#if FEATURE_FILESYSTEM_UNIXFILEMODE
,UnixFileMode? unixFileMode
#endif
,bool adoptHandle
)
: base(
stream,
Expand Down Expand Up @@ -254,7 +257,9 @@ FileOptions options
}
#endif

_accessLock = file.RequestAccess(access, share);
_accessLock = adoptHandle
? FileHandle.Ignore
: file.RequestAccess(access, share);

_container = file;

Expand Down
12 changes: 0 additions & 12 deletions Source/Testably.Abstractions/FileSystem/FileStreamFactory.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Microsoft.Win32.SafeHandles;
using System.IO;
#if NET6_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
#endif

namespace Testably.Abstractions.FileSystem;

Expand Down Expand Up @@ -60,23 +57,14 @@ public FileSystemStream New(string path,
=> Wrap(new FileStream(path, mode, access, share, bufferSize, options));

/// <inheritdoc cref="IFileStreamFactory.New(SafeFileHandle, FileAccess)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public FileSystemStream New(SafeFileHandle handle, FileAccess access)
=> Wrap(new FileStream(handle, access));

/// <inheritdoc cref="IFileStreamFactory.New(SafeFileHandle, FileAccess, int)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public FileSystemStream New(SafeFileHandle handle, FileAccess access, int bufferSize)
=> Wrap(new FileStream(handle, access, bufferSize));

/// <inheritdoc cref="IFileStreamFactory.New(SafeFileHandle, FileAccess, int, bool)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public FileSystemStream New(SafeFileHandle handle, FileAccess access, int bufferSize,
bool isAsync)
=> Wrap(new FileStream(handle, access, bufferSize, isAsync));
Expand Down
48 changes: 0 additions & 48 deletions Source/Testably.Abstractions/FileSystem/FileWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ public FileAttributes GetAttributes(string path)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.GetAttributes(SafeFileHandle)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public FileAttributes GetAttributes(SafeFileHandle fileHandle)
=> File.GetAttributes(fileHandle);
#endif
Expand All @@ -199,9 +196,6 @@ public DateTime GetCreationTime(string path)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.GetCreationTime(SafeFileHandle)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public DateTime GetCreationTime(SafeFileHandle fileHandle)
=> File.GetCreationTime(fileHandle);
#endif
Expand All @@ -212,9 +206,6 @@ public DateTime GetCreationTimeUtc(string path)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.GetCreationTimeUtc(SafeFileHandle)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public DateTime GetCreationTimeUtc(SafeFileHandle fileHandle)
=> File.GetCreationTimeUtc(fileHandle);
#endif
Expand All @@ -225,9 +216,6 @@ public DateTime GetLastAccessTime(string path)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.GetLastAccessTime(SafeFileHandle)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public DateTime GetLastAccessTime(SafeFileHandle fileHandle)
=> File.GetLastAccessTime(fileHandle);
#endif
Expand All @@ -238,9 +226,6 @@ public DateTime GetLastAccessTimeUtc(string path)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.GetLastAccessTimeUtc(SafeFileHandle)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public DateTime GetLastAccessTimeUtc(SafeFileHandle fileHandle)
=> File.GetLastAccessTimeUtc(fileHandle);
#endif
Expand All @@ -251,9 +236,6 @@ public DateTime GetLastWriteTime(string path)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.GetLastWriteTime(SafeFileHandle)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public DateTime GetLastWriteTime(SafeFileHandle fileHandle)
=> File.GetLastWriteTime(fileHandle);
#endif
Expand All @@ -264,9 +246,6 @@ public DateTime GetLastWriteTimeUtc(string path)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.GetLastWriteTimeUtc(SafeFileHandle)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public DateTime GetLastWriteTimeUtc(SafeFileHandle fileHandle)
=> File.GetLastWriteTimeUtc(fileHandle);
#endif
Expand All @@ -281,9 +260,6 @@ public UnixFileMode GetUnixFileMode(string path)
#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.GetUnixFileMode(SafeFileHandle)" />
[UnsupportedOSPlatform("windows")]
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public UnixFileMode GetUnixFileMode(SafeFileHandle fileHandle)
=> File.GetUnixFileMode(fileHandle);
#endif
Expand Down Expand Up @@ -451,9 +427,6 @@ public void SetAttributes(string path, FileAttributes fileAttributes)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.SetAttributes(SafeFileHandle, FileAttributes)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public void SetAttributes(SafeFileHandle fileHandle, FileAttributes fileAttributes)
=> File.SetAttributes(fileHandle, fileAttributes);
#endif
Expand All @@ -464,9 +437,6 @@ public void SetCreationTime(string path, DateTime creationTime)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.SetCreationTime(SafeFileHandle, DateTime)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public void SetCreationTime(SafeFileHandle fileHandle, DateTime creationTime)
=> File.SetCreationTime(fileHandle, creationTime);
#endif
Expand All @@ -477,9 +447,6 @@ public void SetCreationTimeUtc(string path, DateTime creationTimeUtc)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.SetCreationTimeUtc(SafeFileHandle, DateTime)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public void SetCreationTimeUtc(SafeFileHandle fileHandle, DateTime creationTimeUtc)
=> File.SetCreationTimeUtc(fileHandle, creationTimeUtc);
#endif
Expand All @@ -490,9 +457,6 @@ public void SetLastAccessTime(string path, DateTime lastAccessTime)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.SetLastAccessTime(SafeFileHandle, DateTime)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public void SetLastAccessTime(SafeFileHandle fileHandle, DateTime lastAccessTime)
=> File.SetLastAccessTime(fileHandle, lastAccessTime);
#endif
Expand All @@ -503,9 +467,6 @@ public void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.SetLastAccessTimeUtc(SafeFileHandle, DateTime)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public void SetLastAccessTimeUtc(SafeFileHandle fileHandle,
DateTime lastAccessTimeUtc)
=> File.SetLastAccessTimeUtc(fileHandle, lastAccessTimeUtc);
Expand All @@ -517,9 +478,6 @@ public void SetLastWriteTime(string path, DateTime lastWriteTime)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.SetLastWriteTime(SafeFileHandle, DateTime)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public void SetLastWriteTime(SafeFileHandle fileHandle, DateTime lastWriteTime)
=> File.SetLastWriteTime(fileHandle, lastWriteTime);
#endif
Expand All @@ -530,9 +488,6 @@ public void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)

#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.SetLastWriteTimeUtc(SafeFileHandle, DateTime)" />
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public void SetLastWriteTimeUtc(SafeFileHandle fileHandle, DateTime lastWriteTimeUtc)
=> File.SetLastWriteTimeUtc(fileHandle, lastWriteTimeUtc);
#endif
Expand All @@ -547,9 +502,6 @@ public void SetUnixFileMode(string path, UnixFileMode mode)
#if FEATURE_FILESYSTEM_SAFEFILEHANDLE
/// <inheritdoc cref="IFile.SetUnixFileMode(SafeFileHandle, UnixFileMode)" />
[UnsupportedOSPlatform("windows")]
#if NET6_0_OR_GREATER
[ExcludeFromCodeCoverage(Justification = "SafeFileHandle cannot be unit tested.")]
#endif
public void SetUnixFileMode(SafeFileHandle fileHandle, UnixFileMode mode)
=> File.SetUnixFileMode(fileHandle, mode);
#endif
Expand Down

This file was deleted.

Loading
Loading