Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add statistics #474

Merged
merged 20 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
86 changes: 43 additions & 43 deletions Source/Testably.Abstractions.Interface/Helpers/PathSystemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,43 @@ protected PathSystemBase(IFileSystem fileSystem)
#region IPath Members

/// <inheritdoc cref="Path.AltDirectorySeparatorChar" />
public char AltDirectorySeparatorChar
public virtual char AltDirectorySeparatorChar
=> Path.AltDirectorySeparatorChar;

/// <inheritdoc cref="Path.DirectorySeparatorChar" />
public char DirectorySeparatorChar
public virtual char DirectorySeparatorChar
=> Path.DirectorySeparatorChar;

/// <inheritdoc cref="IFileSystemEntity.FileSystem" />
public IFileSystem FileSystem { get; }

/// <inheritdoc cref="Path.PathSeparator" />
public char PathSeparator
public virtual char PathSeparator
=> Path.PathSeparator;

/// <inheritdoc cref="Path.VolumeSeparatorChar" />
public char VolumeSeparatorChar
public virtual char VolumeSeparatorChar
=> Path.VolumeSeparatorChar;

/// <inheritdoc cref="Path.ChangeExtension(string, string)" />
[return: NotNullIfNotNull("path")]
public string? ChangeExtension(string? path, string? extension)
public virtual string? ChangeExtension(string? path, string? extension)
=> Path.ChangeExtension(path, extension);

/// <inheritdoc cref="Path.Combine(string, string)" />
public string Combine(string path1, string path2)
public virtual string Combine(string path1, string path2)
=> Path.Combine(path1, path2);

/// <inheritdoc cref="Path.Combine(string, string, string)" />
public string Combine(string path1, string path2, string path3)
public virtual string Combine(string path1, string path2, string path3)
=> Path.Combine(path1, path2, path3);

/// <inheritdoc cref="Path.Combine(string, string, string, string)" />
public string Combine(string path1, string path2, string path3, string path4)
public virtual string Combine(string path1, string path2, string path3, string path4)
=> Path.Combine(path1, path2, path3, path4);

/// <inheritdoc cref="Path.Combine(string[])" />
public string Combine(params string[] paths)
public virtual string Combine(params string[] paths)
=> Path.Combine(paths);

#if FEATURE_FILESYSTEM_NET7
Expand All @@ -71,45 +71,45 @@ public string Combine(params string[] paths)

#if FEATURE_SPAN
/// <inheritdoc cref="Path.GetDirectoryName(ReadOnlySpan{char})" />
public ReadOnlySpan<char> GetDirectoryName(ReadOnlySpan<char> path)
public virtual ReadOnlySpan<char> GetDirectoryName(ReadOnlySpan<char> path)
=> Path.GetDirectoryName(path);
#endif

/// <inheritdoc cref="Path.GetDirectoryName(string)" />
public string? GetDirectoryName(string? path)
public virtual string? GetDirectoryName(string? path)
=> Path.GetDirectoryName(path);

#if FEATURE_SPAN
/// <inheritdoc cref="Path.GetExtension(ReadOnlySpan{char})" />
public ReadOnlySpan<char> GetExtension(ReadOnlySpan<char> path)
public virtual ReadOnlySpan<char> GetExtension(ReadOnlySpan<char> path)
=> Path.GetExtension(path);
#endif

/// <inheritdoc cref="Path.GetExtension(string)" />
[return: NotNullIfNotNull("path")]
public string? GetExtension(string? path)
public virtual string? GetExtension(string? path)
=> Path.GetExtension(path);

#if FEATURE_SPAN
/// <inheritdoc cref="Path.GetFileName(ReadOnlySpan{char})" />
public ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
public virtual ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
=> Path.GetFileName(path);
#endif

/// <inheritdoc cref="Path.GetFileName(string)" />
[return: NotNullIfNotNull("path")]
public string? GetFileName(string? path)
public virtual string? GetFileName(string? path)
=> Path.GetFileName(path);

#if FEATURE_SPAN
/// <inheritdoc cref="Path.GetFileNameWithoutExtension(ReadOnlySpan{char})" />
public ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path)
public virtual ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path)
=> Path.GetFileNameWithoutExtension(path);
#endif

/// <inheritdoc cref="Path.GetFileNameWithoutExtension(string)" />
[return: NotNullIfNotNull("path")]
public string? GetFileNameWithoutExtension(string? path)
public virtual string? GetFileNameWithoutExtension(string? path)
=> Path.GetFileNameWithoutExtension(path);

/// <inheritdoc cref="Path.GetFullPath(string)" />
Expand All @@ -123,25 +123,25 @@ public virtual string GetFullPath(string path, string basePath)
#endif

/// <inheritdoc cref="Path.GetInvalidFileNameChars()" />
public char[] GetInvalidFileNameChars()
public virtual char[] GetInvalidFileNameChars()
=> Path.GetInvalidFileNameChars();

/// <inheritdoc cref="Path.GetInvalidPathChars()" />
public char[] GetInvalidPathChars()
public virtual char[] GetInvalidPathChars()
=> Path.GetInvalidPathChars();

#if FEATURE_SPAN
/// <inheritdoc cref="Path.GetPathRoot(ReadOnlySpan{char})" />
public ReadOnlySpan<char> GetPathRoot(ReadOnlySpan<char> path)
public virtual ReadOnlySpan<char> GetPathRoot(ReadOnlySpan<char> path)
=> Path.GetPathRoot(path);
#endif

/// <inheritdoc cref="Path.GetPathRoot(string?)" />
public string? GetPathRoot(string? path)
public virtual string? GetPathRoot(string? path)
=> Path.GetPathRoot(path);

/// <inheritdoc cref="Path.GetRandomFileName()" />
public string GetRandomFileName()
public virtual string GetRandomFileName()
=> Path.GetRandomFileName();

#if FEATURE_PATH_RELATIVE
Expand All @@ -155,114 +155,114 @@ public virtual string GetRelativePath(string relativeTo, string path)
[Obsolete(
"Insecure temporary file creation methods should not be used. Use `Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())` instead.")]
#endif
public string GetTempFileName()
public virtual string GetTempFileName()
=> Path.GetTempFileName();

/// <inheritdoc cref="Path.GetTempPath()" />
public string GetTempPath()
public virtual string GetTempPath()
=> Path.GetTempPath();

#if FEATURE_SPAN
/// <inheritdoc cref="Path.HasExtension(ReadOnlySpan{char})" />
public bool HasExtension(ReadOnlySpan<char> path)
public virtual bool HasExtension(ReadOnlySpan<char> path)
=> Path.HasExtension(path);
#endif

/// <inheritdoc cref="Path.HasExtension(string)" />
public bool HasExtension([NotNullWhen(true)] string? path)
public virtual bool HasExtension([NotNullWhen(true)] string? path)
=> Path.HasExtension(path);

#if FEATURE_SPAN
/// <inheritdoc cref="Path.IsPathFullyQualified(ReadOnlySpan{char})" />
public bool IsPathFullyQualified(ReadOnlySpan<char> path)
public virtual bool IsPathFullyQualified(ReadOnlySpan<char> path)
=> Path.IsPathFullyQualified(path);
#endif

#if FEATURE_PATH_RELATIVE
/// <inheritdoc cref="Path.IsPathFullyQualified(string)" />
public bool IsPathFullyQualified(string path)
public virtual bool IsPathFullyQualified(string path)
=> Path.IsPathFullyQualified(path);
#endif

#if FEATURE_SPAN
/// <inheritdoc cref="Path.IsPathRooted(ReadOnlySpan{char})" />
public bool IsPathRooted(ReadOnlySpan<char> path)
public virtual bool IsPathRooted(ReadOnlySpan<char> path)
=> Path.IsPathRooted(path);
#endif

/// <inheritdoc cref="Path.IsPathRooted(string)" />
public bool IsPathRooted(string? path)
public virtual bool IsPathRooted(string? path)
=> Path.IsPathRooted(path);

#endregion

#if FEATURE_PATH_ADVANCED
/// <inheritdoc cref="Path.EndsInDirectorySeparator(ReadOnlySpan{char})" />
public bool EndsInDirectorySeparator(ReadOnlySpan<char> path)
public virtual bool EndsInDirectorySeparator(ReadOnlySpan<char> path)
=> Path.EndsInDirectorySeparator(path);

/// <inheritdoc cref="Path.EndsInDirectorySeparator(string)" />
public bool EndsInDirectorySeparator(string path)
public virtual bool EndsInDirectorySeparator(string path)
=> Path.EndsInDirectorySeparator(path);
#endif

#if FEATURE_PATH_JOIN
/// <inheritdoc cref="Path.Join(ReadOnlySpan{char}, ReadOnlySpan{char})" />
public string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2)
public virtual string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2)
=> Path.Join(path1, path2);

/// <inheritdoc cref="Path.Join(ReadOnlySpan{char}, ReadOnlySpan{char}, ReadOnlySpan{char})" />
public string Join(ReadOnlySpan<char> path1,
public virtual string Join(ReadOnlySpan<char> path1,
ReadOnlySpan<char> path2,
ReadOnlySpan<char> path3)
=> Path.Join(path1, path2, path3);
#endif

#if FEATURE_PATH_ADVANCED
/// <inheritdoc cref="Path.Join(ReadOnlySpan{char}, ReadOnlySpan{char}, ReadOnlySpan{char}, ReadOnlySpan{char})" />
public string Join(ReadOnlySpan<char> path1,
public virtual string Join(ReadOnlySpan<char> path1,
ReadOnlySpan<char> path2,
ReadOnlySpan<char> path3,
ReadOnlySpan<char> path4)
=> Path.Join(path1, path2, path3, path4);

/// <inheritdoc cref="Path.Join(string, string)" />
public string Join(string? path1, string? path2)
public virtual string Join(string? path1, string? path2)
=> Path.Join(path1, path2);

/// <inheritdoc cref="Path.Join(string, string, string)" />
public string Join(string? path1, string? path2, string? path3)
public virtual string Join(string? path1, string? path2, string? path3)
=> Path.Join(path1, path2, path3);

/// <inheritdoc cref="Path.Join(string, string, string, string)" />
public string Join(string? path1, string? path2, string? path3, string? path4)
public virtual string Join(string? path1, string? path2, string? path3, string? path4)
=> Path.Join(path1, path2, path3, path4);

/// <inheritdoc cref="Path.Join(string[])" />
public string Join(params string?[] paths)
public virtual string Join(params string?[] paths)
=> Path.Join(paths);
#endif

#if FEATURE_PATH_ADVANCED
/// <inheritdoc cref="Path.TrimEndingDirectorySeparator(ReadOnlySpan{char})" />
public ReadOnlySpan<char> TrimEndingDirectorySeparator(ReadOnlySpan<char> path)
public virtual ReadOnlySpan<char> TrimEndingDirectorySeparator(ReadOnlySpan<char> path)
=> Path.TrimEndingDirectorySeparator(path);

/// <inheritdoc cref="Path.TrimEndingDirectorySeparator(string)" />
public string TrimEndingDirectorySeparator(string path)
public virtual string TrimEndingDirectorySeparator(string path)
=> Path.TrimEndingDirectorySeparator(path);
#endif

#if FEATURE_PATH_JOIN
/// <inheritdoc cref="Path.TryJoin(ReadOnlySpan{char}, ReadOnlySpan{char}, Span{char}, out int)" />
public bool TryJoin(ReadOnlySpan<char> path1,
public virtual bool TryJoin(ReadOnlySpan<char> path1,
ReadOnlySpan<char> path2,
Span<char> destination,
out int charsWritten)
=> Path.TryJoin(path1, path2, destination, out charsWritten);

/// <inheritdoc cref="Path.TryJoin(ReadOnlySpan{char}, ReadOnlySpan{char}, ReadOnlySpan{char}, Span{char}, out int)" />
public bool TryJoin(ReadOnlySpan<char> path1,
public virtual bool TryJoin(ReadOnlySpan<char> path1,
ReadOnlySpan<char> path2,
ReadOnlySpan<char> path3,
Span<char> destination,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Testably.Abstractions.Testing.Helpers;
using Testably.Abstractions.Testing.Statistics;

namespace Testably.Abstractions.Testing.FileSystem;

Expand All @@ -23,11 +24,19 @@ public IFileSystem FileSystem
/// <inheritdoc cref="IDirectoryInfoFactory.FromDirectoryName(string)" />
[Obsolete("Use `IDirectoryInfoFactory.New(string)` instead")]
public IDirectoryInfo FromDirectoryName(string directoryName)
=> New(directoryName);
{
using IDisposable registration = Register(nameof(FromDirectoryName),
directoryName);

return New(directoryName);
}

/// <inheritdoc cref="IDirectoryInfoFactory.New(string)" />
public IDirectoryInfo New(string path)
{
using IDisposable registration = Register(nameof(New),
path);

return DirectoryInfoMock.New(
_fileSystem.Storage.GetLocation(path
.EnsureValidArgument(_fileSystem, nameof(path))),
Expand All @@ -37,11 +46,19 @@ public IDirectoryInfo New(string path)
/// <inheritdoc cref="IDirectoryInfoFactory.Wrap(DirectoryInfo)" />
[return: NotNullIfNotNull("directoryInfo")]
public IDirectoryInfo? Wrap(DirectoryInfo? directoryInfo)
=> DirectoryInfoMock.New(
{
using IDisposable registration = Register(nameof(Wrap),
directoryInfo);

return DirectoryInfoMock.New(
_fileSystem.Storage.GetLocation(
directoryInfo?.FullName,
directoryInfo?.ToString()),
_fileSystem);
}

#endregion

private IDisposable Register<T1>(string name, T1 parameter1)
=> _fileSystem.StatisticsRegistration.DirectoryInfo.Register(name, ParameterDescription.FromParameter(parameter1));
}
Loading
Loading