From bb23cccc4bd2ca0bfb7f6e16d807095c58f3a608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Thu, 14 Mar 2024 20:10:31 +0100 Subject: [PATCH 1/8] Initial commit --- .../FileSystem/DirectoryInfoFactoryMock.cs | 2 +- .../FileSystem/DirectoryInfoMock.cs | 82 +++--- .../FileSystem/DirectoryMock.cs | 116 ++++---- .../FileSystem/DriveInfoFactoryMock.cs | 4 +- .../FileSystem/DriveInfoMock.cs | 61 ++++- .../FileSystem/FileInfoFactoryMock.cs | 2 +- .../FileSystem/FileInfoMock.cs | 52 ++-- .../FileSystem/FileMock.cs | 196 +++++++------- .../FileSystem/FileStreamFactoryMock.cs | 46 ++-- .../FileSystem/FileStreamMock.cs | 76 +++--- .../FileSystem/FileSystemInfoMock.cs | 16 +- .../FileSystemWatcherFactoryMock.cs | 6 +- .../FileSystem/FileSystemWatcherMock.cs | 6 +- .../FileSystem/PathMock.cs | 22 +- .../Statistics/CallStatistics.cs | 31 ++- .../Statistics/FileSystemEntryStatistics.cs | 15 +- .../Statistics/IStatistics.cs | 9 +- .../Statistics/PropertyStatistic.cs | 51 ++++ .../DirectoryInfoStatisticsTests.cs | 248 ++++++++++++++++++ .../FileSystem/DriveInfoStatisticsTests.cs | 107 +++++++- .../Statistics/StatisticsTests.cs | 83 +++++- .../TestHelpers/StatisticsTestHelpers.cs | 14 + 22 files changed, 916 insertions(+), 329 deletions(-) create mode 100644 Source/Testably.Abstractions.Testing/Statistics/PropertyStatistic.cs diff --git a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoFactoryMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoFactoryMock.cs index 3072ba4d7..ad9e0fa8e 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoFactoryMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoFactoryMock.cs @@ -60,5 +60,5 @@ public IDirectoryInfo New(string path) #endregion private IDisposable Register(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.DirectoryInfo.Register(name, ParameterDescription.FromParameter(parameter1)); + => _fileSystem.StatisticsRegistration.DirectoryInfo.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs index c6a208497..6eefcc0c7 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs @@ -28,7 +28,14 @@ private DirectoryInfoMock(IStorageLocation location, /// public override bool Exists - => base.Exists && FileSystemType == FileSystemTypes.Directory; + { + get + { + using IDisposable registration = RegisterProperty(nameof(Exists), PropertyStatistic.AccessMode.Get); + + return base.Exists && FileSystemType == FileSystemTypes.Directory; + } + } /// public IDirectoryInfo? Parent @@ -42,7 +49,7 @@ public IDirectoryInfo Root /// public void Create() { - using IDisposable registration = Register(nameof(Create)); + using IDisposable registration = RegisterMethod(nameof(Create)); FullName.EnsureValidFormat(_fileSystem); @@ -61,7 +68,7 @@ public void Create() /// public IDirectoryInfo CreateSubdirectory(string path) { - using IDisposable registration = Register(nameof(CreateSubdirectory), + using IDisposable registration = RegisterMethod(nameof(CreateSubdirectory), path); DirectoryInfoMock directory = New( @@ -77,7 +84,7 @@ public IDirectoryInfo CreateSubdirectory(string path) /// public override void Delete() { - using IDisposable registration = Register(nameof(Delete)); + using IDisposable registration = RegisterMethod(nameof(Delete)); if (!_fileSystem.Storage.DeleteContainer(Location)) { @@ -90,7 +97,7 @@ public override void Delete() /// public void Delete(bool recursive) { - using IDisposable registration = Register(nameof(Delete), + using IDisposable registration = RegisterMethod(nameof(Delete), recursive); if (!_fileSystem.Storage.DeleteContainer( @@ -105,7 +112,7 @@ public void Delete(bool recursive) /// public IEnumerable EnumerateDirectories() { - using IDisposable registration = Register(nameof(EnumerateDirectories)); + using IDisposable registration = RegisterMethod(nameof(EnumerateDirectories)); return EnumerateDirectories( EnumerationOptionsHelper.DefaultSearchPattern, @@ -116,7 +123,7 @@ public IEnumerable EnumerateDirectories() public IEnumerable EnumerateDirectories(string searchPattern) { - using IDisposable registration = Register(nameof(EnumerateDirectories), + using IDisposable registration = RegisterMethod(nameof(EnumerateDirectories), searchPattern); return EnumerateDirectories(searchPattern, SearchOption.TopDirectoryOnly); @@ -126,7 +133,7 @@ public IEnumerable public IEnumerable EnumerateDirectories( string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(EnumerateDirectories), + using IDisposable registration = RegisterMethod(nameof(EnumerateDirectories), searchPattern, searchOption); return EnumerateInternal(FileSystemTypes.Directory, @@ -142,7 +149,7 @@ public IEnumerable EnumerateDirectories( string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(EnumerateDirectories), + using IDisposable registration = RegisterMethod(nameof(EnumerateDirectories), searchPattern, enumerationOptions); return EnumerateInternal(FileSystemTypes.Directory, @@ -156,7 +163,7 @@ public IEnumerable EnumerateDirectories( /// public IEnumerable EnumerateFiles() { - using IDisposable registration = Register(nameof(EnumerateFiles)); + using IDisposable registration = RegisterMethod(nameof(EnumerateFiles)); return EnumerateFiles( EnumerationOptionsHelper.DefaultSearchPattern, @@ -166,7 +173,7 @@ public IEnumerable EnumerateFiles() /// public IEnumerable EnumerateFiles(string searchPattern) { - using IDisposable registration = Register(nameof(EnumerateFiles), + using IDisposable registration = RegisterMethod(nameof(EnumerateFiles), searchPattern); return EnumerateFiles(searchPattern, SearchOption.TopDirectoryOnly); @@ -176,7 +183,7 @@ public IEnumerable EnumerateFiles(string searchPattern) public IEnumerable EnumerateFiles( string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(EnumerateFiles), + using IDisposable registration = RegisterMethod(nameof(EnumerateFiles), searchPattern, searchOption); return EnumerateInternal(FileSystemTypes.File, @@ -191,7 +198,7 @@ public IEnumerable EnumerateFiles( public IEnumerable EnumerateFiles( string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(EnumerateFiles), + using IDisposable registration = RegisterMethod(nameof(EnumerateFiles), searchPattern, enumerationOptions); return EnumerateInternal(FileSystemTypes.File, @@ -205,7 +212,7 @@ public IEnumerable EnumerateFiles( /// public IEnumerable EnumerateFileSystemInfos() { - using IDisposable registration = Register(nameof(EnumerateFileSystemInfos)); + using IDisposable registration = RegisterMethod(nameof(EnumerateFileSystemInfos)); return EnumerateFileSystemInfos( EnumerationOptionsHelper.DefaultSearchPattern, @@ -216,7 +223,7 @@ public IEnumerable EnumerateFileSystemInfos() public IEnumerable EnumerateFileSystemInfos(string searchPattern) { - using IDisposable registration = Register(nameof(EnumerateFileSystemInfos), + using IDisposable registration = RegisterMethod(nameof(EnumerateFileSystemInfos), searchPattern); return EnumerateFileSystemInfos(searchPattern, SearchOption.TopDirectoryOnly); @@ -226,7 +233,7 @@ public IEnumerable public IEnumerable EnumerateFileSystemInfos( string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(EnumerateFileSystemInfos), + using IDisposable registration = RegisterMethod(nameof(EnumerateFileSystemInfos), searchPattern, searchOption); return EnumerateInternal(FileSystemTypes.DirectoryOrFile, @@ -242,7 +249,7 @@ public IEnumerable EnumerateFileSystemInfos( string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(EnumerateFileSystemInfos), + using IDisposable registration = RegisterMethod(nameof(EnumerateFileSystemInfos), searchPattern, enumerationOptions); return EnumerateInternal(FileSystemTypes.DirectoryOrFile, @@ -256,7 +263,7 @@ public IEnumerable EnumerateFileSystemInfos( /// public IDirectoryInfo[] GetDirectories() { - using IDisposable registration = Register(nameof(GetDirectories)); + using IDisposable registration = RegisterMethod(nameof(GetDirectories)); return EnumerateDirectories().ToArray(); } @@ -264,7 +271,7 @@ public IDirectoryInfo[] GetDirectories() /// public IDirectoryInfo[] GetDirectories(string searchPattern) { - using IDisposable registration = Register(nameof(GetDirectories), + using IDisposable registration = RegisterMethod(nameof(GetDirectories), searchPattern); return EnumerateDirectories(searchPattern).ToArray(); @@ -274,7 +281,7 @@ public IDirectoryInfo[] GetDirectories(string searchPattern) public IDirectoryInfo[] GetDirectories( string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(GetDirectories), + using IDisposable registration = RegisterMethod(nameof(GetDirectories), searchPattern, searchOption); return EnumerateDirectories(searchPattern, searchOption).ToArray(); @@ -286,7 +293,7 @@ public IDirectoryInfo[] GetDirectories( string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(GetDirectories), + using IDisposable registration = RegisterMethod(nameof(GetDirectories), searchPattern, enumerationOptions); return EnumerateDirectories(searchPattern, enumerationOptions).ToArray(); @@ -296,7 +303,7 @@ public IDirectoryInfo[] GetDirectories( /// public IFileInfo[] GetFiles() { - using IDisposable registration = Register(nameof(GetFiles)); + using IDisposable registration = RegisterMethod(nameof(GetFiles)); return EnumerateFiles().ToArray(); } @@ -304,7 +311,7 @@ public IFileInfo[] GetFiles() /// public IFileInfo[] GetFiles(string searchPattern) { - using IDisposable registration = Register(nameof(GetFiles), + using IDisposable registration = RegisterMethod(nameof(GetFiles), searchPattern); return EnumerateFiles(searchPattern).ToArray(); @@ -314,7 +321,7 @@ public IFileInfo[] GetFiles(string searchPattern) public IFileInfo[] GetFiles(string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(GetFiles), + using IDisposable registration = RegisterMethod(nameof(GetFiles), searchPattern, searchOption); return EnumerateFiles(searchPattern, searchOption).ToArray(); @@ -325,7 +332,7 @@ public IFileInfo[] GetFiles(string searchPattern, public IFileInfo[] GetFiles(string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(GetFiles), + using IDisposable registration = RegisterMethod(nameof(GetFiles), searchPattern, enumerationOptions); return EnumerateFiles(searchPattern, enumerationOptions).ToArray(); @@ -335,7 +342,7 @@ public IFileInfo[] GetFiles(string searchPattern, /// public IFileSystemInfo[] GetFileSystemInfos() { - using IDisposable registration = Register(nameof(GetFileSystemInfos)); + using IDisposable registration = RegisterMethod(nameof(GetFileSystemInfos)); return EnumerateFileSystemInfos().ToArray(); } @@ -343,7 +350,7 @@ public IFileSystemInfo[] GetFileSystemInfos() /// public IFileSystemInfo[] GetFileSystemInfos(string searchPattern) { - using IDisposable registration = Register(nameof(GetFileSystemInfos), + using IDisposable registration = RegisterMethod(nameof(GetFileSystemInfos), searchPattern); return EnumerateFileSystemInfos(searchPattern).ToArray(); @@ -353,7 +360,7 @@ public IFileSystemInfo[] GetFileSystemInfos(string searchPattern) public IFileSystemInfo[] GetFileSystemInfos( string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(GetFileSystemInfos), + using IDisposable registration = RegisterMethod(nameof(GetFileSystemInfos), searchPattern, searchOption); return EnumerateFileSystemInfos(searchPattern, searchOption).ToArray(); @@ -365,7 +372,7 @@ public IFileSystemInfo[] GetFileSystemInfos( string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(GetFileSystemInfos), + using IDisposable registration = RegisterMethod(nameof(GetFileSystemInfos), searchPattern, enumerationOptions); return EnumerateFileSystemInfos(searchPattern, enumerationOptions).ToArray(); @@ -375,7 +382,7 @@ public IFileSystemInfo[] GetFileSystemInfos( /// public void MoveTo(string destDirName) { - using IDisposable registration = Register(nameof(MoveTo), + using IDisposable registration = RegisterMethod(nameof(MoveTo), destDirName); Location = _fileSystem.Storage.Move( @@ -417,15 +424,18 @@ private IEnumerable EnumerateInternal( enumerationOptions); } - protected override IDisposable Register(string name) - => _fileSystem.StatisticsRegistration.DirectoryInfo.Register(Location.FullPath, name); + protected override IDisposable RegisterProperty(string name, PropertyStatistic.AccessMode mode) + => _fileSystem.StatisticsRegistration.DirectoryInfo.RegisterProperty(Location.FullPath, name, mode); + + protected override IDisposable RegisterMethod(string name) + => _fileSystem.StatisticsRegistration.DirectoryInfo.RegisterMethod(Location.FullPath, name); - protected override IDisposable Register(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.DirectoryInfo.Register(Location.FullPath, name, + protected override IDisposable RegisterMethod(string name, T1 parameter1) + => _fileSystem.StatisticsRegistration.DirectoryInfo.RegisterMethod(Location.FullPath, name, ParameterDescription.FromParameter(parameter1)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2) - => _fileSystem.StatisticsRegistration.DirectoryInfo.Register(Location.FullPath, name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2) + => _fileSystem.StatisticsRegistration.DirectoryInfo.RegisterMethod(Location.FullPath, name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryMock.cs index e18e2bc46..cb49b8d6f 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryMock.cs @@ -27,7 +27,7 @@ public IFileSystem FileSystem /// public IDirectoryInfo CreateDirectory(string path) { - using IDisposable registration = Register(nameof(CreateDirectory), + using IDisposable registration = RegisterMethod(nameof(CreateDirectory), path); path.EnsureValidFormat(_fileSystem); @@ -44,7 +44,7 @@ public IDirectoryInfo CreateDirectory(string path) /// public IDirectoryInfo CreateDirectory(string path, UnixFileMode unixCreateMode) { - using IDisposable registration = Register(nameof(CreateDirectory), + using IDisposable registration = RegisterMethod(nameof(CreateDirectory), path, unixCreateMode); IDirectoryInfo directoryInfo = CreateDirectory(path); @@ -60,7 +60,7 @@ public IDirectoryInfo CreateDirectory(string path, UnixFileMode unixCreateMode) public IFileSystemInfo CreateSymbolicLink( string path, string pathToTarget) { - using IDisposable registration = Register(nameof(CreateSymbolicLink), + using IDisposable registration = RegisterMethod(nameof(CreateSymbolicLink), path, pathToTarget); path.EnsureValidFormat(_fileSystem); @@ -75,7 +75,7 @@ public IFileSystemInfo CreateSymbolicLink( /// public IDirectoryInfo CreateTempSubdirectory(string? prefix = null) { - using IDisposable registration = Register(nameof(CreateTempSubdirectory), + using IDisposable registration = RegisterMethod(nameof(CreateTempSubdirectory), prefix); string basePath; @@ -98,7 +98,7 @@ public IDirectoryInfo CreateTempSubdirectory(string? prefix = null) /// public void Delete(string path) { - using IDisposable registration = Register(nameof(Delete), + using IDisposable registration = RegisterMethod(nameof(Delete), path); _fileSystem.DirectoryInfo @@ -109,7 +109,7 @@ public void Delete(string path) /// public void Delete(string path, bool recursive) { - using IDisposable registration = Register(nameof(Delete), + using IDisposable registration = RegisterMethod(nameof(Delete), path, recursive); _fileSystem.DirectoryInfo @@ -120,7 +120,7 @@ public void Delete(string path, bool recursive) /// public IEnumerable EnumerateDirectories(string path) { - using IDisposable registration = Register(nameof(EnumerateDirectories), + using IDisposable registration = RegisterMethod(nameof(EnumerateDirectories), path); return EnumerateDirectories(path, @@ -131,7 +131,7 @@ public IEnumerable EnumerateDirectories(string path) /// public IEnumerable EnumerateDirectories(string path, string searchPattern) { - using IDisposable registration = Register(nameof(EnumerateDirectories), + using IDisposable registration = RegisterMethod(nameof(EnumerateDirectories), path, searchPattern); return EnumerateDirectories(path, searchPattern, SearchOption.TopDirectoryOnly); @@ -142,7 +142,7 @@ public IEnumerable EnumerateDirectories(string path, string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(EnumerateDirectories), + using IDisposable registration = RegisterMethod(nameof(EnumerateDirectories), path, searchPattern, searchOption); return EnumerateInternal(FileSystemTypes.Directory, @@ -157,7 +157,7 @@ public IEnumerable EnumerateDirectories(string path, string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(EnumerateDirectories), + using IDisposable registration = RegisterMethod(nameof(EnumerateDirectories), path, searchPattern, enumerationOptions); return EnumerateInternal(FileSystemTypes.Directory, @@ -170,7 +170,7 @@ public IEnumerable EnumerateDirectories(string path, /// public IEnumerable EnumerateFiles(string path) { - using IDisposable registration = Register(nameof(EnumerateFiles), + using IDisposable registration = RegisterMethod(nameof(EnumerateFiles), path); return EnumerateFiles(path, @@ -181,7 +181,7 @@ public IEnumerable EnumerateFiles(string path) /// public IEnumerable EnumerateFiles(string path, string searchPattern) { - using IDisposable registration = Register(nameof(EnumerateFiles), + using IDisposable registration = RegisterMethod(nameof(EnumerateFiles), path, searchPattern); return EnumerateFiles(path, searchPattern, SearchOption.TopDirectoryOnly); @@ -192,7 +192,7 @@ public IEnumerable EnumerateFiles(string path, string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(EnumerateFiles), + using IDisposable registration = RegisterMethod(nameof(EnumerateFiles), path, searchPattern, searchOption); return EnumerateInternal(FileSystemTypes.File, @@ -207,7 +207,7 @@ public IEnumerable EnumerateFiles(string path, string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(EnumerateFiles), + using IDisposable registration = RegisterMethod(nameof(EnumerateFiles), path, searchPattern, enumerationOptions); return EnumerateInternal(FileSystemTypes.File, @@ -220,7 +220,7 @@ public IEnumerable EnumerateFiles(string path, /// public IEnumerable EnumerateFileSystemEntries(string path) { - using IDisposable registration = Register(nameof(EnumerateFileSystemEntries), + using IDisposable registration = RegisterMethod(nameof(EnumerateFileSystemEntries), path); return EnumerateFileSystemEntries(path, @@ -232,7 +232,7 @@ public IEnumerable EnumerateFileSystemEntries(string path) public IEnumerable EnumerateFileSystemEntries( string path, string searchPattern) { - using IDisposable registration = Register(nameof(EnumerateFileSystemEntries), + using IDisposable registration = RegisterMethod(nameof(EnumerateFileSystemEntries), path, searchPattern); return EnumerateFileSystemEntries(path, @@ -245,7 +245,7 @@ public IEnumerable EnumerateFileSystemEntries(string path, string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(EnumerateFileSystemEntries), + using IDisposable registration = RegisterMethod(nameof(EnumerateFileSystemEntries), path, searchPattern, searchOption); return EnumerateInternal(FileSystemTypes.DirectoryOrFile, @@ -260,7 +260,7 @@ public IEnumerable EnumerateFileSystemEntries(string path, string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(EnumerateFileSystemEntries), + using IDisposable registration = RegisterMethod(nameof(EnumerateFileSystemEntries), path, searchPattern, enumerationOptions); return EnumerateInternal(FileSystemTypes.DirectoryOrFile, @@ -273,7 +273,7 @@ public IEnumerable EnumerateFileSystemEntries(string path, /// public bool Exists([NotNullWhen(true)] string? path) { - using IDisposable registration = Register(nameof(Exists), + using IDisposable registration = RegisterMethod(nameof(Exists), path); return DirectoryInfoMock.New( @@ -284,7 +284,7 @@ public bool Exists([NotNullWhen(true)] string? path) /// public DateTime GetCreationTime(string path) { - using IDisposable registration = Register(nameof(GetCreationTime), + using IDisposable registration = RegisterMethod(nameof(GetCreationTime), path); return _fileSystem.Storage.GetContainer( @@ -296,7 +296,7 @@ public DateTime GetCreationTime(string path) /// public DateTime GetCreationTimeUtc(string path) { - using IDisposable registration = Register(nameof(GetCreationTimeUtc), + using IDisposable registration = RegisterMethod(nameof(GetCreationTimeUtc), path); return _fileSystem.Storage.GetContainer( @@ -308,7 +308,7 @@ public DateTime GetCreationTimeUtc(string path) /// public string GetCurrentDirectory() { - using IDisposable registration = Register(nameof(GetCurrentDirectory)); + using IDisposable registration = RegisterMethod(nameof(GetCurrentDirectory)); return _fileSystem.Storage.CurrentDirectory; } @@ -316,7 +316,7 @@ public string GetCurrentDirectory() /// public string[] GetDirectories(string path) { - using IDisposable registration = Register(nameof(GetDirectories), + using IDisposable registration = RegisterMethod(nameof(GetDirectories), path); return EnumerateDirectories(path).ToArray(); @@ -325,7 +325,7 @@ public string[] GetDirectories(string path) /// public string[] GetDirectories(string path, string searchPattern) { - using IDisposable registration = Register(nameof(GetDirectories), + using IDisposable registration = RegisterMethod(nameof(GetDirectories), path, searchPattern); return EnumerateDirectories(path, searchPattern).ToArray(); @@ -336,7 +336,7 @@ public string[] GetDirectories(string path, string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(GetDirectories), + using IDisposable registration = RegisterMethod(nameof(GetDirectories), path, searchPattern, searchOption); return EnumerateDirectories(path, searchPattern, searchOption).ToArray(); @@ -348,7 +348,7 @@ public string[] GetDirectories(string path, string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(GetDirectories), + using IDisposable registration = RegisterMethod(nameof(GetDirectories), path, searchPattern, enumerationOptions); return EnumerateDirectories(path, searchPattern, enumerationOptions).ToArray(); @@ -358,7 +358,7 @@ public string[] GetDirectories(string path, /// public string GetDirectoryRoot(string path) { - using IDisposable registration = Register(nameof(GetDirectoryRoot), + using IDisposable registration = RegisterMethod(nameof(GetDirectoryRoot), path); return _fileSystem.Path.GetPathRoot( @@ -369,7 +369,7 @@ public string GetDirectoryRoot(string path) /// public string[] GetFiles(string path) { - using IDisposable registration = Register(nameof(GetFiles), + using IDisposable registration = RegisterMethod(nameof(GetFiles), path); return EnumerateFiles(path).ToArray(); @@ -378,7 +378,7 @@ public string[] GetFiles(string path) /// public string[] GetFiles(string path, string searchPattern) { - using IDisposable registration = Register(nameof(GetFiles), + using IDisposable registration = RegisterMethod(nameof(GetFiles), path, searchPattern); return EnumerateFiles(path, searchPattern).ToArray(); @@ -389,7 +389,7 @@ public string[] GetFiles(string path, string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(GetFiles), + using IDisposable registration = RegisterMethod(nameof(GetFiles), path, searchPattern, searchOption); return EnumerateFiles(path, searchPattern, searchOption).ToArray(); @@ -401,7 +401,7 @@ public string[] GetFiles(string path, string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(GetFiles), + using IDisposable registration = RegisterMethod(nameof(GetFiles), path, searchPattern, enumerationOptions); return EnumerateFiles(path, searchPattern, enumerationOptions).ToArray(); @@ -411,7 +411,7 @@ public string[] GetFiles(string path, /// public string[] GetFileSystemEntries(string path) { - using IDisposable registration = Register(nameof(GetFileSystemEntries), + using IDisposable registration = RegisterMethod(nameof(GetFileSystemEntries), path); return EnumerateFileSystemEntries(path).ToArray(); @@ -420,7 +420,7 @@ public string[] GetFileSystemEntries(string path) /// public string[] GetFileSystemEntries(string path, string searchPattern) { - using IDisposable registration = Register(nameof(GetFileSystemEntries), + using IDisposable registration = RegisterMethod(nameof(GetFileSystemEntries), path, searchPattern); return EnumerateFileSystemEntries(path, searchPattern).ToArray(); @@ -431,7 +431,7 @@ public string[] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption) { - using IDisposable registration = Register(nameof(GetFileSystemEntries), + using IDisposable registration = RegisterMethod(nameof(GetFileSystemEntries), path, searchPattern, searchOption); return EnumerateFileSystemEntries(path, searchPattern, searchOption).ToArray(); @@ -443,7 +443,7 @@ public string[] GetFileSystemEntries(string path, string searchPattern, EnumerationOptions enumerationOptions) { - using IDisposable registration = Register(nameof(GetFileSystemEntries), + using IDisposable registration = RegisterMethod(nameof(GetFileSystemEntries), path, searchPattern, enumerationOptions); return EnumerateFileSystemEntries(path, searchPattern, enumerationOptions) @@ -454,7 +454,7 @@ public string[] GetFileSystemEntries(string path, /// public DateTime GetLastAccessTime(string path) { - using IDisposable registration = Register(nameof(GetLastAccessTime), + using IDisposable registration = RegisterMethod(nameof(GetLastAccessTime), path); return _fileSystem.Storage.GetContainer( @@ -466,7 +466,7 @@ public DateTime GetLastAccessTime(string path) /// public DateTime GetLastAccessTimeUtc(string path) { - using IDisposable registration = Register(nameof(GetLastAccessTimeUtc), + using IDisposable registration = RegisterMethod(nameof(GetLastAccessTimeUtc), path); return _fileSystem.Storage.GetContainer( @@ -478,7 +478,7 @@ public DateTime GetLastAccessTimeUtc(string path) /// public DateTime GetLastWriteTime(string path) { - using IDisposable registration = Register(nameof(GetLastWriteTime), + using IDisposable registration = RegisterMethod(nameof(GetLastWriteTime), path); return _fileSystem.Storage.GetContainer( @@ -490,7 +490,7 @@ public DateTime GetLastWriteTime(string path) /// public DateTime GetLastWriteTimeUtc(string path) { - using IDisposable registration = Register(nameof(GetLastWriteTimeUtc), + using IDisposable registration = RegisterMethod(nameof(GetLastWriteTimeUtc), path); return _fileSystem.Storage.GetContainer( @@ -502,7 +502,7 @@ public DateTime GetLastWriteTimeUtc(string path) /// public string[] GetLogicalDrives() { - using IDisposable registration = Register(nameof(GetLogicalDrives)); + using IDisposable registration = RegisterMethod(nameof(GetLogicalDrives)); return _fileSystem.DriveInfo.GetDrives().Select(x => x.Name).ToArray(); } @@ -510,7 +510,7 @@ public string[] GetLogicalDrives() /// public IDirectoryInfo? GetParent(string path) { - using IDisposable registration = Register(nameof(GetParent), + using IDisposable registration = RegisterMethod(nameof(GetParent), path); return _fileSystem.DirectoryInfo @@ -521,7 +521,7 @@ public string[] GetLogicalDrives() /// public void Move(string sourceDirName, string destDirName) { - using IDisposable registration = Register(nameof(Move), + using IDisposable registration = RegisterMethod(nameof(Move), sourceDirName, destDirName); _fileSystem.DirectoryInfo.New(sourceDirName @@ -535,7 +535,7 @@ public void Move(string sourceDirName, string destDirName) public IFileSystemInfo? ResolveLinkTarget( string linkPath, bool returnFinalTarget) { - using IDisposable registration = Register(nameof(ResolveLinkTarget), + using IDisposable registration = RegisterMethod(nameof(ResolveLinkTarget), linkPath, returnFinalTarget); try @@ -556,7 +556,7 @@ public void Move(string sourceDirName, string destDirName) /// public void SetCreationTime(string path, DateTime creationTime) { - using IDisposable registration = Register(nameof(SetCreationTime), + using IDisposable registration = RegisterMethod(nameof(SetCreationTime), path, creationTime); LoadDirectoryInfoOrThrowNotFoundException(path, ThrowMissingFileCreatedTimeException) @@ -566,7 +566,7 @@ public void SetCreationTime(string path, DateTime creationTime) /// public void SetCreationTimeUtc(string path, DateTime creationTimeUtc) { - using IDisposable registration = Register(nameof(SetCreationTimeUtc), + using IDisposable registration = RegisterMethod(nameof(SetCreationTimeUtc), path, creationTimeUtc); LoadDirectoryInfoOrThrowNotFoundException(path, ThrowMissingFileCreatedTimeException) @@ -576,7 +576,7 @@ public void SetCreationTimeUtc(string path, DateTime creationTimeUtc) /// public void SetCurrentDirectory(string path) { - using IDisposable registration = Register(nameof(SetCurrentDirectory), + using IDisposable registration = RegisterMethod(nameof(SetCurrentDirectory), path); @@ -594,7 +594,7 @@ public void SetCurrentDirectory(string path) /// public void SetLastAccessTime(string path, DateTime lastAccessTime) { - using IDisposable registration = Register(nameof(SetLastAccessTime), + using IDisposable registration = RegisterMethod(nameof(SetLastAccessTime), path, lastAccessTime); LoadDirectoryInfoOrThrowNotFoundException(path, @@ -605,7 +605,7 @@ public void SetLastAccessTime(string path, DateTime lastAccessTime) /// public void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc) { - using IDisposable registration = Register(nameof(SetLastAccessTimeUtc), + using IDisposable registration = RegisterMethod(nameof(SetLastAccessTimeUtc), path, lastAccessTimeUtc); LoadDirectoryInfoOrThrowNotFoundException(path, @@ -616,7 +616,7 @@ public void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc) /// public void SetLastWriteTime(string path, DateTime lastWriteTime) { - using IDisposable registration = Register(nameof(SetLastWriteTime), + using IDisposable registration = RegisterMethod(nameof(SetLastWriteTime), path, lastWriteTime); LoadDirectoryInfoOrThrowNotFoundException(path, @@ -627,7 +627,7 @@ public void SetLastWriteTime(string path, DateTime lastWriteTime) /// public void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc) { - using IDisposable registration = Register(nameof(SetLastWriteTimeUtc), + using IDisposable registration = RegisterMethod(nameof(SetLastWriteTimeUtc), path, lastWriteTimeUtc); LoadDirectoryInfoOrThrowNotFoundException(path, @@ -706,20 +706,20 @@ private IEnumerable EnumerateInternal(FileSystemTypes fileSystemTypes, .GetSubdirectoryPath(x.FullPath, adjustedLocation.GivenPath)); } - private IDisposable Register(string name) - => _fileSystem.StatisticsRegistration.Directory.Register(name); + private IDisposable RegisterMethod(string name) + => _fileSystem.StatisticsRegistration.Directory.RegisterMethod(name); - private IDisposable Register(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.Directory.Register(name, + private IDisposable RegisterMethod(string name, T1 parameter1) + => _fileSystem.StatisticsRegistration.Directory.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2) - => _fileSystem.StatisticsRegistration.Directory.Register(name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2) + => _fileSystem.StatisticsRegistration.Directory.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2, T3 parameter3) - => _fileSystem.StatisticsRegistration.Directory.Register(name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3) + => _fileSystem.StatisticsRegistration.Directory.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3)); diff --git a/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoFactoryMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoFactoryMock.cs index 912ae35a0..d76c1bd26 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoFactoryMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoFactoryMock.cs @@ -78,9 +78,9 @@ public IDriveInfo New(string driveName) #endregion private IDisposable Register(string name) - => _fileSystem.StatisticsRegistration.DriveInfo.Register(name); + => _fileSystem.StatisticsRegistration.DriveInfo.RegisterMethod(name); private IDisposable Register(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.DriveInfo.Register(name, + => _fileSystem.StatisticsRegistration.DriveInfo.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs index 574b45b74..35f340329 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using Testably.Abstractions.Testing.Helpers; +using Testably.Abstractions.Testing.Statistics; using Testably.Abstractions.Testing.Storage; namespace Testably.Abstractions.Testing.FileSystem; @@ -32,6 +33,8 @@ internal sealed class DriveInfoMock : IStorageDrive private long _usedBytes; private string _volumeLabel = nameof(MockFileSystem); + private readonly string _name; + private long _totalSize; private DriveInfoMock(string driveName, MockFileSystem fileSystem) { @@ -48,8 +51,8 @@ private DriveInfoMock(string driveName, MockFileSystem fileSystem) driveName = ValidateDriveLetter(driveName, fileSystem); } - Name = driveName; - TotalSize = DefaultTotalSize; + _name = driveName; + _totalSize = DefaultTotalSize; DriveFormat = DefaultDriveFormat; DriveType = DefaultDriveType; IsReady = true; @@ -59,7 +62,14 @@ private DriveInfoMock(string driveName, MockFileSystem fileSystem) /// public long AvailableFreeSpace - => TotalFreeSpace; + { + get + { + using IDisposable registration = RegisterProperty(nameof(AvailableFreeSpace), PropertyStatistic.AccessMode.Get); + + return TotalFreeSpace; + } + } /// public string DriveFormat { get; private set; } @@ -80,7 +90,15 @@ public IFileSystem FileSystem public bool IsUncPath { get; } /// - public string Name { get; } + public string Name + { + get + { + //using IDisposable registration = RegisterProperty(nameof(Name), PropertyStatistic.AccessMode.Get); + + return _name; + } + } /// public IDirectoryInfo RootDirectory @@ -88,19 +106,41 @@ public IDirectoryInfo RootDirectory /// public long TotalFreeSpace - => TotalSize - _usedBytes; + { + get + { + using IDisposable registration = RegisterProperty(nameof(TotalFreeSpace), PropertyStatistic.AccessMode.Get); + + return _totalSize - _usedBytes; + } + } /// - public long TotalSize { get; private set; } + public long TotalSize + { + get + { + using IDisposable registration = RegisterProperty(nameof(TotalSize), PropertyStatistic.AccessMode.Get); + + return _totalSize; + } + } /// [AllowNull] public string VolumeLabel { - get => _volumeLabel; + get + { + using IDisposable registration = RegisterProperty(nameof(VolumeLabel), PropertyStatistic.AccessMode.Get); + + return _volumeLabel; + } [SupportedOSPlatform("windows")] set { + using IDisposable registration = RegisterProperty(nameof(VolumeLabel), PropertyStatistic.AccessMode.Set); + _volumeLabel = value ?? _volumeLabel; _fileSystem.Execute.NotOnWindows( () => throw ExceptionFactory.OperationNotSupportedOnThisPlatform()); @@ -112,7 +152,7 @@ public IStorageDrive ChangeUsedBytes(long usedBytesDelta) { long newUsedBytes = Math.Max(0, _usedBytes + usedBytesDelta); - if (newUsedBytes > TotalSize) + if (newUsedBytes > _totalSize) { throw ExceptionFactory.NotEnoughDiskSpace(Name); } @@ -149,7 +189,7 @@ public IStorageDrive SetIsReady(bool isReady = true) public IStorageDrive SetTotalSize( long totalSize = DefaultTotalSize) { - TotalSize = totalSize; + _totalSize = totalSize; return this; } @@ -208,4 +248,7 @@ private static string ValidateDriveLetter(string driveName, return new DriveInfoMock(driveName, fileSystem); } + + private IDisposable RegisterProperty(string name, PropertyStatistic.AccessMode mode) + => _fileSystem.StatisticsRegistration.DriveInfo.RegisterProperty(_name, name, mode); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileInfoFactoryMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileInfoFactoryMock.cs index a5e944edd..c5e464fe1 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileInfoFactoryMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileInfoFactoryMock.cs @@ -69,6 +69,6 @@ public IFileInfo New(string fileName) #endregion private IDisposable Register(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.FileInfo.Register(name, + => _fileSystem.StatisticsRegistration.FileInfo.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs index 695cf2c29..491ec91dd 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs @@ -89,7 +89,7 @@ public override string Name /// public StreamWriter AppendText() { - using IDisposable registration = Register(nameof(AppendText)); + using IDisposable registration = RegisterMethod(nameof(AppendText)); return new StreamWriter(Open(FileMode.Append, FileAccess.Write)); } @@ -97,7 +97,7 @@ public StreamWriter AppendText() /// public IFileInfo CopyTo(string destFileName) { - using IDisposable registration = Register(nameof(CopyTo), + using IDisposable registration = RegisterMethod(nameof(CopyTo), destFileName); destFileName.EnsureValidArgument(_fileSystem, nameof(destFileName)); @@ -112,7 +112,7 @@ public IFileInfo CopyTo(string destFileName) /// public IFileInfo CopyTo(string destFileName, bool overwrite) { - using IDisposable registration = Register(nameof(CopyTo), + using IDisposable registration = RegisterMethod(nameof(CopyTo), destFileName, overwrite); destFileName.EnsureValidArgument(_fileSystem, nameof(destFileName)); @@ -127,7 +127,7 @@ public IFileInfo CopyTo(string destFileName, bool overwrite) /// public FileSystemStream Create() { - using IDisposable registration = Register(nameof(Create)); + using IDisposable registration = RegisterMethod(nameof(Create)); _fileSystem.Execute.NotOnNetFramework(Refresh); return _fileSystem.File.Create(FullName); @@ -136,7 +136,7 @@ public FileSystemStream Create() /// public StreamWriter CreateText() { - using IDisposable registration = Register(nameof(CreateText)); + using IDisposable registration = RegisterMethod(nameof(CreateText)); StreamWriter streamWriter = new(_fileSystem.File.Create(FullName)); #if NET8_0_OR_GREATER @@ -149,7 +149,7 @@ public StreamWriter CreateText() [SupportedOSPlatform("windows")] public void Decrypt() { - using IDisposable registration = Register(nameof(Decrypt)); + using IDisposable registration = RegisterMethod(nameof(Decrypt)); Container.Decrypt(); } @@ -158,7 +158,7 @@ public void Decrypt() [SupportedOSPlatform("windows")] public void Encrypt() { - using IDisposable registration = Register(nameof(Encrypt)); + using IDisposable registration = RegisterMethod(nameof(Encrypt)); Container.Encrypt(); } @@ -166,7 +166,7 @@ public void Encrypt() /// public void MoveTo(string destFileName) { - using IDisposable registration = Register(nameof(MoveTo), + using IDisposable registration = RegisterMethod(nameof(MoveTo), destFileName); Location = _fileSystem.Storage.Move( @@ -180,7 +180,7 @@ public void MoveTo(string destFileName) /// public void MoveTo(string destFileName, bool overwrite) { - using IDisposable registration = Register(nameof(MoveTo), + using IDisposable registration = RegisterMethod(nameof(MoveTo), destFileName, overwrite); Location = _fileSystem.Storage.Move( @@ -195,7 +195,7 @@ public void MoveTo(string destFileName, bool overwrite) /// public FileSystemStream Open(FileMode mode) { - using IDisposable registration = Register(nameof(Open), + using IDisposable registration = RegisterMethod(nameof(Open), mode); _fileSystem.Execute.OnNetFrameworkIf(mode == FileMode.Append, @@ -212,7 +212,7 @@ public FileSystemStream Open(FileMode mode) /// public FileSystemStream Open(FileMode mode, FileAccess access) { - using IDisposable registration = Register(nameof(Open), + using IDisposable registration = RegisterMethod(nameof(Open), mode, access); return new FileStreamMock( @@ -226,7 +226,7 @@ public FileSystemStream Open(FileMode mode, FileAccess access) /// public FileSystemStream Open(FileMode mode, FileAccess access, FileShare share) { - using IDisposable registration = Register(nameof(Open), + using IDisposable registration = RegisterMethod(nameof(Open), mode, access, share); return new FileStreamMock( @@ -241,7 +241,7 @@ public FileSystemStream Open(FileMode mode, FileAccess access, FileShare share) /// public FileSystemStream Open(FileStreamOptions options) { - using IDisposable registration = Register(nameof(Open), + using IDisposable registration = RegisterMethod(nameof(Open), options); return _fileSystem.File.Open(FullName, options); @@ -251,7 +251,7 @@ public FileSystemStream Open(FileStreamOptions options) /// public FileSystemStream OpenRead() { - using IDisposable registration = Register(nameof(OpenRead)); + using IDisposable registration = RegisterMethod(nameof(OpenRead)); return new FileStreamMock( _fileSystem, @@ -263,7 +263,7 @@ public FileSystemStream OpenRead() /// public StreamReader OpenText() { - using IDisposable registration = Register(nameof(OpenText)); + using IDisposable registration = RegisterMethod(nameof(OpenText)); return new StreamReader(OpenRead()); } @@ -271,7 +271,7 @@ public StreamReader OpenText() /// public FileSystemStream OpenWrite() { - using IDisposable registration = Register(nameof(OpenWrite)); + using IDisposable registration = RegisterMethod(nameof(OpenWrite)); return new FileStreamMock( _fileSystem, @@ -285,7 +285,7 @@ public FileSystemStream OpenWrite() public IFileInfo Replace(string destinationFileName, string? destinationBackupFileName) { - using IDisposable registration = Register(nameof(Replace), + using IDisposable registration = RegisterMethod(nameof(Replace), destinationFileName, destinationBackupFileName); IStorageLocation location = @@ -340,7 +340,7 @@ public IFileInfo Replace(string destinationFileName, string? destinationBackupFileName, bool ignoreMetadataErrors) { - using IDisposable registration = Register(nameof(Replace), + using IDisposable registration = RegisterMethod(nameof(Replace), destinationFileName, destinationBackupFileName, ignoreMetadataErrors); IStorageLocation location = _fileSystem.Storage.Replace( @@ -370,20 +370,20 @@ public IFileInfo Replace(string destinationFileName, return new FileInfoMock(location, fileSystem); } - protected override IDisposable Register(string name) - => _fileSystem.StatisticsRegistration.FileInfo.Register(Location.FullPath, name); + protected override IDisposable RegisterMethod(string name) + => _fileSystem.StatisticsRegistration.FileInfo.RegisterMethod(Location.FullPath, name); - protected override IDisposable Register(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.FileInfo.Register(Location.FullPath, name, + protected override IDisposable RegisterMethod(string name, T1 parameter1) + => _fileSystem.StatisticsRegistration.FileInfo.RegisterMethod(Location.FullPath, name, ParameterDescription.FromParameter(parameter1)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2) - => _fileSystem.StatisticsRegistration.FileInfo.Register(Location.FullPath, name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2) + => _fileSystem.StatisticsRegistration.FileInfo.RegisterMethod(Location.FullPath, name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2, T3 parameter3) - => _fileSystem.StatisticsRegistration.FileInfo.Register(Location.FullPath, name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3) + => _fileSystem.StatisticsRegistration.FileInfo.RegisterMethod(Location.FullPath, name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3)); diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileMock.cs index dc5374db9..b112a767f 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileMock.cs @@ -36,7 +36,7 @@ public IFileSystem FileSystem /// public void AppendAllLines(string path, IEnumerable contents) { - using IDisposable registration = Register(nameof(AppendAllLines), + using IDisposable registration = RegisterMethod(nameof(AppendAllLines), path, contents); AppendAllLines(path, contents, Encoding.Default); @@ -48,7 +48,7 @@ public void AppendAllLines( IEnumerable contents, Encoding encoding) { - using IDisposable registration = Register(nameof(AppendAllLines), + using IDisposable registration = RegisterMethod(nameof(AppendAllLines), path, contents, encoding); _ = contents ?? throw new ArgumentNullException(nameof(contents)); @@ -64,7 +64,7 @@ public void AppendAllLines( public Task AppendAllLinesAsync(string path, IEnumerable contents, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(AppendAllLinesAsync), + using IDisposable registration = RegisterMethod(nameof(AppendAllLinesAsync), path, contents, cancellationToken); return AppendAllLinesAsync(path, contents, Encoding.Default, cancellationToken); @@ -75,7 +75,7 @@ public Task AppendAllLinesAsync(string path, IEnumerable contents, Encoding encoding, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(AppendAllLinesAsync), + using IDisposable registration = RegisterMethod(nameof(AppendAllLinesAsync), path, contents, encoding, cancellationToken); ThrowIfCancelled(cancellationToken); @@ -87,7 +87,7 @@ public Task AppendAllLinesAsync(string path, IEnumerable contents, /// public void AppendAllText(string path, string? contents) { - using IDisposable registration = Register(nameof(AppendAllText), + using IDisposable registration = RegisterMethod(nameof(AppendAllText), path, contents); AppendAllText(path, contents, Encoding.Default); @@ -96,7 +96,7 @@ public void AppendAllText(string path, string? contents) /// public void AppendAllText(string path, string? contents, Encoding encoding) { - using IDisposable registration = Register(nameof(AppendAllText), + using IDisposable registration = RegisterMethod(nameof(AppendAllText), path, contents, encoding); IStorageContainer container = @@ -131,7 +131,7 @@ public void AppendAllText(string path, string? contents, Encoding encoding) public Task AppendAllTextAsync(string path, string? contents, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(AppendAllTextAsync), + using IDisposable registration = RegisterMethod(nameof(AppendAllTextAsync), path, contents, cancellationToken); return AppendAllTextAsync(path, contents, Encoding.Default, cancellationToken); @@ -141,7 +141,7 @@ public Task AppendAllTextAsync(string path, string? contents, public Task AppendAllTextAsync(string path, string? contents, Encoding encoding, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(AppendAllTextAsync), + using IDisposable registration = RegisterMethod(nameof(AppendAllTextAsync), path, contents, encoding, cancellationToken); ThrowIfCancelled(cancellationToken); @@ -153,7 +153,7 @@ public Task AppendAllTextAsync(string path, string? contents, Encoding encoding, /// public StreamWriter AppendText(string path) { - using IDisposable registration = Register(nameof(AppendText), + using IDisposable registration = RegisterMethod(nameof(AppendText), path); return FileSystem.FileInfo @@ -164,7 +164,7 @@ public StreamWriter AppendText(string path) /// public void Copy(string sourceFileName, string destFileName) { - using IDisposable registration = Register(nameof(Copy), + using IDisposable registration = RegisterMethod(nameof(Copy), sourceFileName, destFileName); sourceFileName.EnsureValidFormat(_fileSystem, nameof(sourceFileName)); @@ -187,7 +187,7 @@ public void Copy(string sourceFileName, string destFileName) /// public void Copy(string sourceFileName, string destFileName, bool overwrite) { - using IDisposable registration = Register(nameof(Copy), + using IDisposable registration = RegisterMethod(nameof(Copy), sourceFileName, destFileName, overwrite); _fileSystem.Execute.OnNetFramework( @@ -218,7 +218,7 @@ public void Copy(string sourceFileName, string destFileName, bool overwrite) /// public FileSystemStream Create(string path) { - using IDisposable registration = Register(nameof(Create), + using IDisposable registration = RegisterMethod(nameof(Create), path); return new FileStreamMock( @@ -232,7 +232,7 @@ public FileSystemStream Create(string path) /// public FileSystemStream Create(string path, int bufferSize) { - using IDisposable registration = Register(nameof(Create), + using IDisposable registration = RegisterMethod(nameof(Create), path, bufferSize); return new FileStreamMock( @@ -247,7 +247,7 @@ public FileSystemStream Create(string path, int bufferSize) /// public FileSystemStream Create(string path, int bufferSize, FileOptions options) { - using IDisposable registration = Register(nameof(Create), + using IDisposable registration = RegisterMethod(nameof(Create), path, bufferSize, options); return new FileStreamMock( @@ -265,7 +265,7 @@ public FileSystemStream Create(string path, int bufferSize, FileOptions options) public IFileSystemInfo CreateSymbolicLink( string path, string pathToTarget) { - using IDisposable registration = Register(nameof(CreateSymbolicLink), + using IDisposable registration = RegisterMethod(nameof(CreateSymbolicLink), path, pathToTarget); path.EnsureValidFormat(_fileSystem); @@ -279,7 +279,7 @@ public IFileSystemInfo CreateSymbolicLink( /// public StreamWriter CreateText(string path) { - using IDisposable registration = Register(nameof(CreateText), + using IDisposable registration = RegisterMethod(nameof(CreateText), path); return FileSystem.FileInfo @@ -291,7 +291,7 @@ public StreamWriter CreateText(string path) [SupportedOSPlatform("windows")] public void Decrypt(string path) { - using IDisposable registration = Register(nameof(Decrypt), + using IDisposable registration = RegisterMethod(nameof(Decrypt), path); IStorageContainer container = GetContainerFromPath(path); @@ -301,7 +301,7 @@ public void Decrypt(string path) /// public void Delete(string path) { - using IDisposable registration = Register(nameof(Delete), + using IDisposable registration = RegisterMethod(nameof(Delete), path); _fileSystem.Storage.DeleteContainer( @@ -313,7 +313,7 @@ public void Delete(string path) [SupportedOSPlatform("windows")] public void Encrypt(string path) { - using IDisposable registration = Register(nameof(Encrypt), + using IDisposable registration = RegisterMethod(nameof(Encrypt), path); IStorageContainer container = GetContainerFromPath(path); @@ -323,7 +323,7 @@ public void Encrypt(string path) /// public bool Exists([NotNullWhen(true)] string? path) { - using IDisposable registration = Register(nameof(Exists), + using IDisposable registration = RegisterMethod(nameof(Exists), path); if (string.IsNullOrEmpty(path)) @@ -340,7 +340,7 @@ public bool Exists([NotNullWhen(true)] string? path) /// public FileAttributes GetAttributes(string path) { - using IDisposable registration = Register(nameof(GetAttributes), + using IDisposable registration = RegisterMethod(nameof(GetAttributes), path); IStorageContainer container = _fileSystem.Storage @@ -355,7 +355,7 @@ public FileAttributes GetAttributes(string path) /// public FileAttributes GetAttributes(SafeFileHandle fileHandle) { - using IDisposable registration = Register(nameof(GetAttributes), + using IDisposable registration = RegisterMethod(nameof(GetAttributes), fileHandle); IStorageContainer container = GetContainerFromSafeFileHandle(fileHandle); @@ -366,7 +366,7 @@ public FileAttributes GetAttributes(SafeFileHandle fileHandle) /// public DateTime GetCreationTime(string path) { - using IDisposable registration = Register(nameof(GetCreationTime), + using IDisposable registration = RegisterMethod(nameof(GetCreationTime), path); return _fileSystem.Storage.GetContainer( @@ -379,7 +379,7 @@ public DateTime GetCreationTime(string path) /// public DateTime GetCreationTime(SafeFileHandle fileHandle) { - using IDisposable registration = Register(nameof(GetCreationTime), + using IDisposable registration = RegisterMethod(nameof(GetCreationTime), fileHandle); return GetContainerFromSafeFileHandle(fileHandle) @@ -390,7 +390,7 @@ public DateTime GetCreationTime(SafeFileHandle fileHandle) /// public DateTime GetCreationTimeUtc(string path) { - using IDisposable registration = Register(nameof(GetCreationTimeUtc), + using IDisposable registration = RegisterMethod(nameof(GetCreationTimeUtc), path); return _fileSystem.Storage.GetContainer( @@ -403,7 +403,7 @@ public DateTime GetCreationTimeUtc(string path) /// public DateTime GetCreationTimeUtc(SafeFileHandle fileHandle) { - using IDisposable registration = Register(nameof(GetCreationTimeUtc), + using IDisposable registration = RegisterMethod(nameof(GetCreationTimeUtc), fileHandle); return GetContainerFromSafeFileHandle(fileHandle) @@ -414,7 +414,7 @@ public DateTime GetCreationTimeUtc(SafeFileHandle fileHandle) /// public DateTime GetLastAccessTime(string path) { - using IDisposable registration = Register(nameof(GetLastAccessTime), + using IDisposable registration = RegisterMethod(nameof(GetLastAccessTime), path); return _fileSystem.Storage.GetContainer( @@ -427,7 +427,7 @@ public DateTime GetLastAccessTime(string path) /// public DateTime GetLastAccessTime(SafeFileHandle fileHandle) { - using IDisposable registration = Register(nameof(GetLastAccessTime), + using IDisposable registration = RegisterMethod(nameof(GetLastAccessTime), fileHandle); return GetContainerFromSafeFileHandle(fileHandle) @@ -438,7 +438,7 @@ public DateTime GetLastAccessTime(SafeFileHandle fileHandle) /// public DateTime GetLastAccessTimeUtc(string path) { - using IDisposable registration = Register(nameof(GetLastAccessTimeUtc), + using IDisposable registration = RegisterMethod(nameof(GetLastAccessTimeUtc), path); return _fileSystem.Storage.GetContainer( @@ -451,7 +451,7 @@ public DateTime GetLastAccessTimeUtc(string path) /// public DateTime GetLastAccessTimeUtc(SafeFileHandle fileHandle) { - using IDisposable registration = Register(nameof(GetLastAccessTimeUtc), + using IDisposable registration = RegisterMethod(nameof(GetLastAccessTimeUtc), fileHandle); return GetContainerFromSafeFileHandle(fileHandle) @@ -462,7 +462,7 @@ public DateTime GetLastAccessTimeUtc(SafeFileHandle fileHandle) /// public DateTime GetLastWriteTime(string path) { - using IDisposable registration = Register(nameof(GetLastWriteTime), + using IDisposable registration = RegisterMethod(nameof(GetLastWriteTime), path); return _fileSystem.Storage.GetContainer( @@ -475,7 +475,7 @@ public DateTime GetLastWriteTime(string path) /// public DateTime GetLastWriteTime(SafeFileHandle fileHandle) { - using IDisposable registration = Register(nameof(GetLastWriteTime), + using IDisposable registration = RegisterMethod(nameof(GetLastWriteTime), fileHandle); return GetContainerFromSafeFileHandle(fileHandle) @@ -486,7 +486,7 @@ public DateTime GetLastWriteTime(SafeFileHandle fileHandle) /// public DateTime GetLastWriteTimeUtc(string path) { - using IDisposable registration = Register(nameof(GetLastWriteTimeUtc), + using IDisposable registration = RegisterMethod(nameof(GetLastWriteTimeUtc), path); return _fileSystem.Storage.GetContainer( @@ -499,7 +499,7 @@ public DateTime GetLastWriteTimeUtc(string path) /// public DateTime GetLastWriteTimeUtc(SafeFileHandle fileHandle) { - using IDisposable registration = Register(nameof(GetLastWriteTimeUtc), + using IDisposable registration = RegisterMethod(nameof(GetLastWriteTimeUtc), fileHandle); return GetContainerFromSafeFileHandle(fileHandle) @@ -512,7 +512,7 @@ public DateTime GetLastWriteTimeUtc(SafeFileHandle fileHandle) [UnsupportedOSPlatform("windows")] public UnixFileMode GetUnixFileMode(string path) { - using IDisposable registration = Register(nameof(GetUnixFileMode), + using IDisposable registration = RegisterMethod(nameof(GetUnixFileMode), path); return _fileSystem.Execute.OnWindows( @@ -530,7 +530,7 @@ public UnixFileMode GetUnixFileMode(string path) [UnsupportedOSPlatform("windows")] public UnixFileMode GetUnixFileMode(SafeFileHandle fileHandle) { - using IDisposable registration = Register(nameof(GetUnixFileMode), + using IDisposable registration = RegisterMethod(nameof(GetUnixFileMode), fileHandle); return _fileSystem.Execute.OnWindows( @@ -543,7 +543,7 @@ public UnixFileMode GetUnixFileMode(SafeFileHandle fileHandle) /// public void Move(string sourceFileName, string destFileName) { - using IDisposable registration = Register(nameof(Move), + using IDisposable registration = RegisterMethod(nameof(Move), sourceFileName, destFileName); _fileSystem.FileInfo.New(sourceFileName @@ -556,7 +556,7 @@ public void Move(string sourceFileName, string destFileName) /// public void Move(string sourceFileName, string destFileName, bool overwrite) { - using IDisposable registration = Register(nameof(Move), + using IDisposable registration = RegisterMethod(nameof(Move), sourceFileName, destFileName, overwrite); _fileSystem.FileInfo.New(sourceFileName @@ -569,7 +569,7 @@ public void Move(string sourceFileName, string destFileName, bool overwrite) /// public FileSystemStream Open(string path, FileMode mode) { - using IDisposable registration = Register(nameof(Open), + using IDisposable registration = RegisterMethod(nameof(Open), path, mode); return new FileStreamMock( @@ -583,7 +583,7 @@ public FileSystemStream Open(string path, FileMode mode) /// public FileSystemStream Open(string path, FileMode mode, FileAccess access) { - using IDisposable registration = Register(nameof(Open), + using IDisposable registration = RegisterMethod(nameof(Open), path, mode, access); return new FileStreamMock( @@ -601,7 +601,7 @@ public FileSystemStream Open( FileAccess access, FileShare share) { - using IDisposable registration = Register(nameof(Open), + using IDisposable registration = RegisterMethod(nameof(Open), path, mode, access, share); return new FileStreamMock( @@ -616,7 +616,7 @@ public FileSystemStream Open( /// public FileSystemStream Open(string path, FileStreamOptions options) { - using IDisposable registration = Register(nameof(Open), + using IDisposable registration = RegisterMethod(nameof(Open), path, options); return new FileStreamMock( @@ -633,7 +633,7 @@ public FileSystemStream Open(string path, FileStreamOptions options) /// public FileSystemStream OpenRead(string path) { - using IDisposable registration = Register(nameof(OpenRead), + using IDisposable registration = RegisterMethod(nameof(OpenRead), path); return new FileStreamMock( @@ -646,7 +646,7 @@ public FileSystemStream OpenRead(string path) /// public StreamReader OpenText(string path) { - using IDisposable registration = Register(nameof(OpenText), + using IDisposable registration = RegisterMethod(nameof(OpenText), path); return FileSystem.FileInfo @@ -657,7 +657,7 @@ public StreamReader OpenText(string path) /// public FileSystemStream OpenWrite(string path) { - using IDisposable registration = Register(nameof(OpenWrite), + using IDisposable registration = RegisterMethod(nameof(OpenWrite), path); return new FileStreamMock( @@ -671,7 +671,7 @@ public FileSystemStream OpenWrite(string path) /// public byte[] ReadAllBytes(string path) { - using IDisposable registration = Register(nameof(ReadAllBytes), + using IDisposable registration = RegisterMethod(nameof(ReadAllBytes), path); IStorageContainer container = GetContainerFromPath(path); @@ -691,7 +691,7 @@ public byte[] ReadAllBytes(string path) public Task ReadAllBytesAsync(string path, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(ReadAllBytesAsync), + using IDisposable registration = RegisterMethod(nameof(ReadAllBytesAsync), path, cancellationToken); ThrowIfCancelled(cancellationToken); @@ -702,7 +702,7 @@ public Task ReadAllBytesAsync(string path, /// public string[] ReadAllLines(string path) { - using IDisposable registration = Register(nameof(ReadAllLines), + using IDisposable registration = RegisterMethod(nameof(ReadAllLines), path); return ReadAllLines(path, Encoding.Default); @@ -711,7 +711,7 @@ public string[] ReadAllLines(string path) /// public string[] ReadAllLines(string path, Encoding encoding) { - using IDisposable registration = Register(nameof(ReadAllLines), + using IDisposable registration = RegisterMethod(nameof(ReadAllLines), path, encoding); return ReadLines(path, encoding).ToArray(); @@ -723,7 +723,7 @@ public Task ReadAllLinesAsync( string path, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(ReadAllLinesAsync), + using IDisposable registration = RegisterMethod(nameof(ReadAllLinesAsync), path, cancellationToken); return ReadAllLinesAsync(path, Encoding.Default, cancellationToken); @@ -735,7 +735,7 @@ public Task ReadAllLinesAsync( Encoding encoding, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(ReadAllLinesAsync), + using IDisposable registration = RegisterMethod(nameof(ReadAllLinesAsync), path, encoding, cancellationToken); ThrowIfCancelled(cancellationToken); @@ -746,7 +746,7 @@ public Task ReadAllLinesAsync( /// public string ReadAllText(string path) { - using IDisposable registration = Register(nameof(ReadAllText), + using IDisposable registration = RegisterMethod(nameof(ReadAllText), path); return ReadAllText(path, Encoding.Default); @@ -755,7 +755,7 @@ public string ReadAllText(string path) /// public string ReadAllText(string path, Encoding encoding) { - using IDisposable registration = Register(nameof(ReadAllText), + using IDisposable registration = RegisterMethod(nameof(ReadAllText), path, encoding); IStorageContainer container = GetContainerFromPath(path); @@ -780,7 +780,7 @@ public Task ReadAllTextAsync( string path, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(ReadAllTextAsync), + using IDisposable registration = RegisterMethod(nameof(ReadAllTextAsync), path, cancellationToken); return ReadAllTextAsync(path, Encoding.Default, cancellationToken); @@ -792,7 +792,7 @@ public Task ReadAllTextAsync( Encoding encoding, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(ReadAllTextAsync), + using IDisposable registration = RegisterMethod(nameof(ReadAllTextAsync), path, encoding, cancellationToken); ThrowIfCancelled(cancellationToken); @@ -803,7 +803,7 @@ public Task ReadAllTextAsync( /// public IEnumerable ReadLines(string path) { - using IDisposable registration = Register(nameof(ReadLines), + using IDisposable registration = RegisterMethod(nameof(ReadLines), path); return ReadLines(path, Encoding.Default); @@ -812,7 +812,7 @@ public IEnumerable ReadLines(string path) /// public IEnumerable ReadLines(string path, Encoding encoding) { - using IDisposable registration = Register(nameof(ReadLines), + using IDisposable registration = RegisterMethod(nameof(ReadLines), path, encoding); return EnumerateLines(ReadAllText(path, encoding)); @@ -823,7 +823,7 @@ public IEnumerable ReadLines(string path, Encoding encoding) public IAsyncEnumerable ReadLinesAsync(string path, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(ReadLinesAsync), + using IDisposable registration = RegisterMethod(nameof(ReadLinesAsync), path, cancellationToken); ThrowIfCancelled(cancellationToken); @@ -834,7 +834,7 @@ public IAsyncEnumerable ReadLinesAsync(string path, public IAsyncEnumerable ReadLinesAsync(string path, Encoding encoding, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(ReadLinesAsync), + using IDisposable registration = RegisterMethod(nameof(ReadLinesAsync), path, encoding, cancellationToken); ThrowIfCancelled(cancellationToken); @@ -847,7 +847,7 @@ public void Replace(string sourceFileName, string destinationFileName, string? destinationBackupFileName) { - using IDisposable registration = Register(nameof(Replace), + using IDisposable registration = RegisterMethod(nameof(Replace), sourceFileName, destinationFileName, destinationBackupFileName); _fileSystem.FileInfo.New(sourceFileName @@ -863,7 +863,7 @@ public void Replace(string sourceFileName, string? destinationBackupFileName, bool ignoreMetadataErrors) { - using IDisposable registration = Register(nameof(Replace), + using IDisposable registration = RegisterMethod(nameof(Replace), sourceFileName, destinationFileName, destinationBackupFileName, ignoreMetadataErrors); _fileSystem.FileInfo.New(sourceFileName @@ -879,7 +879,7 @@ public void Replace(string sourceFileName, public IFileSystemInfo? ResolveLinkTarget( string linkPath, bool returnFinalTarget) { - using IDisposable registration = Register(nameof(ResolveLinkTarget), + using IDisposable registration = RegisterMethod(nameof(ResolveLinkTarget), linkPath, returnFinalTarget); IStorageLocation location = @@ -912,7 +912,7 @@ public void Replace(string sourceFileName, /// public void SetAttributes(string path, FileAttributes fileAttributes) { - using IDisposable registration = Register(nameof(SetAttributes), + using IDisposable registration = RegisterMethod(nameof(SetAttributes), path, fileAttributes); IStorageContainer container = GetContainerFromPath(path); @@ -923,7 +923,7 @@ public void SetAttributes(string path, FileAttributes fileAttributes) /// public void SetAttributes(SafeFileHandle fileHandle, FileAttributes fileAttributes) { - using IDisposable registration = Register(nameof(SetAttributes), + using IDisposable registration = RegisterMethod(nameof(SetAttributes), fileHandle, fileAttributes); IStorageContainer container = GetContainerFromSafeFileHandle(fileHandle); @@ -934,7 +934,7 @@ public void SetAttributes(SafeFileHandle fileHandle, FileAttributes fileAttribut /// public void SetCreationTime(string path, DateTime creationTime) { - using IDisposable registration = Register(nameof(SetCreationTime), + using IDisposable registration = RegisterMethod(nameof(SetCreationTime), path, creationTime); IStorageContainer container = @@ -946,7 +946,7 @@ public void SetCreationTime(string path, DateTime creationTime) /// public void SetCreationTime(SafeFileHandle fileHandle, DateTime creationTime) { - using IDisposable registration = Register(nameof(SetCreationTime), + using IDisposable registration = RegisterMethod(nameof(SetCreationTime), fileHandle, creationTime); IStorageContainer container = GetContainerFromSafeFileHandle(fileHandle); @@ -957,7 +957,7 @@ public void SetCreationTime(SafeFileHandle fileHandle, DateTime creationTime) /// public void SetCreationTimeUtc(string path, DateTime creationTimeUtc) { - using IDisposable registration = Register(nameof(SetCreationTimeUtc), + using IDisposable registration = RegisterMethod(nameof(SetCreationTimeUtc), path, creationTimeUtc); IStorageContainer container = @@ -969,7 +969,7 @@ public void SetCreationTimeUtc(string path, DateTime creationTimeUtc) /// public void SetCreationTimeUtc(SafeFileHandle fileHandle, DateTime creationTimeUtc) { - using IDisposable registration = Register(nameof(SetCreationTimeUtc), + using IDisposable registration = RegisterMethod(nameof(SetCreationTimeUtc), fileHandle, creationTimeUtc); IStorageContainer container = GetContainerFromSafeFileHandle(fileHandle); @@ -980,7 +980,7 @@ public void SetCreationTimeUtc(SafeFileHandle fileHandle, DateTime creationTimeU /// public void SetLastAccessTime(string path, DateTime lastAccessTime) { - using IDisposable registration = Register(nameof(SetLastAccessTime), + using IDisposable registration = RegisterMethod(nameof(SetLastAccessTime), path, lastAccessTime); IStorageContainer container = @@ -992,7 +992,7 @@ public void SetLastAccessTime(string path, DateTime lastAccessTime) /// public void SetLastAccessTime(SafeFileHandle fileHandle, DateTime lastAccessTime) { - using IDisposable registration = Register(nameof(SetLastAccessTime), + using IDisposable registration = RegisterMethod(nameof(SetLastAccessTime), fileHandle, lastAccessTime); IStorageContainer container = GetContainerFromSafeFileHandle(fileHandle); @@ -1003,7 +1003,7 @@ public void SetLastAccessTime(SafeFileHandle fileHandle, DateTime lastAccessTime /// public void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc) { - using IDisposable registration = Register(nameof(SetLastAccessTimeUtc), + using IDisposable registration = RegisterMethod(nameof(SetLastAccessTimeUtc), path, lastAccessTimeUtc); IStorageContainer container = @@ -1015,7 +1015,7 @@ public void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc) /// public void SetLastAccessTimeUtc(SafeFileHandle fileHandle, DateTime lastAccessTimeUtc) { - using IDisposable registration = Register(nameof(SetLastAccessTimeUtc), + using IDisposable registration = RegisterMethod(nameof(SetLastAccessTimeUtc), fileHandle, lastAccessTimeUtc); IStorageContainer container = GetContainerFromSafeFileHandle(fileHandle); @@ -1026,7 +1026,7 @@ public void SetLastAccessTimeUtc(SafeFileHandle fileHandle, DateTime lastAccessT /// public void SetLastWriteTime(string path, DateTime lastWriteTime) { - using IDisposable registration = Register(nameof(SetLastWriteTime), + using IDisposable registration = RegisterMethod(nameof(SetLastWriteTime), path, lastWriteTime); IStorageContainer container = @@ -1038,7 +1038,7 @@ public void SetLastWriteTime(string path, DateTime lastWriteTime) /// public void SetLastWriteTime(SafeFileHandle fileHandle, DateTime lastWriteTime) { - using IDisposable registration = Register(nameof(SetLastWriteTime), + using IDisposable registration = RegisterMethod(nameof(SetLastWriteTime), fileHandle, lastWriteTime); IStorageContainer container = GetContainerFromSafeFileHandle(fileHandle); @@ -1049,7 +1049,7 @@ public void SetLastWriteTime(SafeFileHandle fileHandle, DateTime lastWriteTime) /// public void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc) { - using IDisposable registration = Register(nameof(SetLastWriteTimeUtc), + using IDisposable registration = RegisterMethod(nameof(SetLastWriteTimeUtc), path, lastWriteTimeUtc); IStorageContainer container = @@ -1061,7 +1061,7 @@ public void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc) /// public void SetLastWriteTimeUtc(SafeFileHandle fileHandle, DateTime lastWriteTimeUtc) { - using IDisposable registration = Register(nameof(SetLastWriteTimeUtc), + using IDisposable registration = RegisterMethod(nameof(SetLastWriteTimeUtc), fileHandle, lastWriteTimeUtc); IStorageContainer container = GetContainerFromSafeFileHandle(fileHandle); @@ -1074,7 +1074,7 @@ public void SetLastWriteTimeUtc(SafeFileHandle fileHandle, DateTime lastWriteTim [UnsupportedOSPlatform("windows")] public void SetUnixFileMode(string path, UnixFileMode mode) { - using IDisposable registration = Register(nameof(SetUnixFileMode), + using IDisposable registration = RegisterMethod(nameof(SetUnixFileMode), path, mode); _fileSystem.Execute.OnWindows( @@ -1090,7 +1090,7 @@ public void SetUnixFileMode(string path, UnixFileMode mode) [UnsupportedOSPlatform("windows")] public void SetUnixFileMode(SafeFileHandle fileHandle, UnixFileMode mode) { - using IDisposable registration = Register(nameof(SetUnixFileMode), + using IDisposable registration = RegisterMethod(nameof(SetUnixFileMode), fileHandle, mode); _fileSystem.Execute.OnWindows( @@ -1104,7 +1104,7 @@ public void SetUnixFileMode(SafeFileHandle fileHandle, UnixFileMode mode) /// public void WriteAllBytes(string path, byte[] bytes) { - using IDisposable registration = Register(nameof(WriteAllBytes), + using IDisposable registration = RegisterMethod(nameof(WriteAllBytes), path, bytes); _ = bytes ?? throw new ArgumentNullException(nameof(bytes)); @@ -1140,7 +1140,7 @@ public void WriteAllBytes(string path, byte[] bytes) public Task WriteAllBytesAsync(string path, byte[] bytes, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(WriteAllBytesAsync), + using IDisposable registration = RegisterMethod(nameof(WriteAllBytesAsync), path, bytes, cancellationToken); ThrowIfCancelled(cancellationToken); @@ -1152,7 +1152,7 @@ public Task WriteAllBytesAsync(string path, byte[] bytes, /// public void WriteAllLines(string path, string[] contents) { - using IDisposable registration = Register(nameof(WriteAllLines), + using IDisposable registration = RegisterMethod(nameof(WriteAllLines), path, contents); WriteAllLines(path, contents, Encoding.Default); @@ -1161,7 +1161,7 @@ public void WriteAllLines(string path, string[] contents) /// public void WriteAllLines(string path, IEnumerable contents) { - using IDisposable registration = Register(nameof(WriteAllLines), + using IDisposable registration = RegisterMethod(nameof(WriteAllLines), path, contents); WriteAllLines(path, contents, Encoding.Default); @@ -1173,7 +1173,7 @@ public void WriteAllLines( string[] contents, Encoding encoding) { - using IDisposable registration = Register(nameof(WriteAllLines), + using IDisposable registration = RegisterMethod(nameof(WriteAllLines), path, contents, encoding); WriteAllLines(path, contents.AsEnumerable(), encoding); @@ -1185,7 +1185,7 @@ public void WriteAllLines( IEnumerable contents, Encoding encoding) { - using IDisposable registration = Register(nameof(WriteAllLines), + using IDisposable registration = RegisterMethod(nameof(WriteAllLines), path, contents, encoding); WriteAllText( @@ -1201,7 +1201,7 @@ public Task WriteAllLinesAsync( IEnumerable contents, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(WriteAllLinesAsync), + using IDisposable registration = RegisterMethod(nameof(WriteAllLinesAsync), path, contents, cancellationToken); return WriteAllLinesAsync(path, contents, Encoding.Default, cancellationToken); @@ -1214,7 +1214,7 @@ public Task WriteAllLinesAsync( Encoding encoding, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(WriteAllLinesAsync), + using IDisposable registration = RegisterMethod(nameof(WriteAllLinesAsync), path, contents, encoding, cancellationToken); ThrowIfCancelled(cancellationToken); @@ -1226,7 +1226,7 @@ public Task WriteAllLinesAsync( /// public void WriteAllText(string path, string? contents) { - using IDisposable registration = Register(nameof(WriteAllText), + using IDisposable registration = RegisterMethod(nameof(WriteAllText), path, contents); WriteAllText(path, contents, Encoding.Default); @@ -1235,7 +1235,7 @@ public void WriteAllText(string path, string? contents) /// public void WriteAllText(string path, string? contents, Encoding encoding) { - using IDisposable registration = Register(nameof(WriteAllText), + using IDisposable registration = RegisterMethod(nameof(WriteAllText), path, contents, encoding); IStorageContainer container = @@ -1273,7 +1273,7 @@ public void WriteAllText(string path, string? contents, Encoding encoding) public Task WriteAllTextAsync(string path, string? contents, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(WriteAllTextAsync), + using IDisposable registration = RegisterMethod(nameof(WriteAllTextAsync), path, contents, cancellationToken); return WriteAllTextAsync(path, contents, Encoding.Default, cancellationToken); @@ -1283,7 +1283,7 @@ public Task WriteAllTextAsync(string path, string? contents, public Task WriteAllTextAsync(string path, string? contents, Encoding encoding, CancellationToken cancellationToken = default) { - using IDisposable registration = Register(nameof(WriteAllTextAsync), + using IDisposable registration = RegisterMethod(nameof(WriteAllTextAsync), path, contents, encoding, cancellationToken); ThrowIfCancelled(cancellationToken); @@ -1360,27 +1360,27 @@ private static void ThrowIfCancelled(CancellationToken cancellationToken) } #endif - private IDisposable Register(string name, + private IDisposable RegisterMethod(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.File.Register(name, + => _fileSystem.StatisticsRegistration.File.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); - private IDisposable Register(string name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2) - => _fileSystem.StatisticsRegistration.File.Register(name, + => _fileSystem.StatisticsRegistration.File.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); - private IDisposable Register(string name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3) - => _fileSystem.StatisticsRegistration.File.Register(name, + => _fileSystem.StatisticsRegistration.File.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3)); - private IDisposable Register(string name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) - => _fileSystem.StatisticsRegistration.File.Register(name, + => _fileSystem.StatisticsRegistration.File.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3), diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileStreamFactoryMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileStreamFactoryMock.cs index 0ad2a8608..c4fb5d9e7 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileStreamFactoryMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileStreamFactoryMock.cs @@ -107,7 +107,7 @@ public Stream Create(IntPtr handle, FileAccess access, bool ownsHandle, int buff /// public FileSystemStream New(string path, FileMode mode) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), path, mode); return New(path, @@ -121,7 +121,7 @@ public FileSystemStream New(string path, FileMode mode) /// public FileSystemStream New(string path, FileMode mode, FileAccess access) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), path, mode, access); return New(path, mode, access, DefaultShare, DefaultBufferSize, DefaultUseAsync); @@ -133,7 +133,7 @@ public FileSystemStream New(string path, FileAccess access, FileShare share) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), path, mode, access, share); return New(path, mode, access, share, DefaultBufferSize, DefaultUseAsync); @@ -146,7 +146,7 @@ public FileSystemStream New(string path, FileShare share, int bufferSize) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), path, mode, access, share, bufferSize); return New(path, mode, access, share, bufferSize, DefaultUseAsync); @@ -160,7 +160,7 @@ public FileSystemStream New(string path, int bufferSize, bool useAsync) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), path, mode, access, share, bufferSize, useAsync); return New(path, @@ -179,7 +179,7 @@ public FileSystemStream New(string path, int bufferSize, FileOptions options) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), path, mode, access, share, bufferSize, options); return new FileStreamMock(_fileSystem, @@ -197,7 +197,7 @@ public FileSystemStream New(string path, #endif public FileSystemStream New(SafeFileHandle handle, FileAccess access) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), handle, access); SafeFileHandleMock safeFileHandleMock = _fileSystem @@ -215,7 +215,7 @@ public FileSystemStream New(SafeFileHandle handle, FileAccess access) #endif public FileSystemStream New(SafeFileHandle handle, FileAccess access, int bufferSize) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), handle, access, bufferSize); SafeFileHandleMock safeFileHandleMock = _fileSystem @@ -235,7 +235,7 @@ public FileSystemStream New(SafeFileHandle handle, FileAccess access, int buffer public FileSystemStream New(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), handle, access, bufferSize, isAsync); SafeFileHandleMock safeFileHandleMock = _fileSystem @@ -253,7 +253,7 @@ public FileSystemStream New(SafeFileHandle handle, FileAccess access, int buffer /// public FileSystemStream New(string path, FileStreamOptions options) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), path, options); return New(path, @@ -268,44 +268,44 @@ public FileSystemStream New(string path, FileStreamOptions options) /// public FileSystemStream Wrap(FileStream fileStream) { - Register(nameof(Wrap), fileStream); + RegisterMethod(nameof(Wrap), fileStream); throw ExceptionFactory.NotSupportedFileStreamWrapping(); } #endregion - private void Register(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.FileStream.Register(name, + private void RegisterMethod(string name, T1 parameter1) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2) - => _fileSystem.StatisticsRegistration.FileStream.Register(name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2, T3 parameter3) - => _fileSystem.StatisticsRegistration.FileStream.Register(name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) - => _fileSystem.StatisticsRegistration.FileStream.Register(name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3), ParameterDescription.FromParameter(parameter4)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4, T5 parameter5) - => _fileSystem.StatisticsRegistration.FileStream.Register(name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4, T5 parameter5) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3), ParameterDescription.FromParameter(parameter4), ParameterDescription.FromParameter(parameter5)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4, T5 parameter5, T6 parameter6) - => _fileSystem.StatisticsRegistration.FileStream.Register(name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4, T5 parameter5, T6 parameter6) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3), diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs index bf20e4f3d..c19742b9f 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs @@ -129,7 +129,7 @@ public override IAsyncResult BeginRead(byte[] buffer, AsyncCallback? callback, object? state) { - using IDisposable registration = Register(nameof(BeginRead), + using IDisposable registration = RegisterMethod(nameof(BeginRead), buffer, offset, count, callback, state); ThrowIfDisposed(); @@ -148,7 +148,7 @@ public override IAsyncResult BeginWrite(byte[] buffer, AsyncCallback? callback, object? state) { - using IDisposable registration = Register(nameof(BeginWrite), + using IDisposable registration = RegisterMethod(nameof(BeginWrite), buffer, offset, count, callback, state); ThrowIfDisposed(); @@ -163,7 +163,7 @@ public override IAsyncResult BeginWrite(byte[] buffer, /// public override void CopyTo(Stream destination, int bufferSize) { - using IDisposable registration = Register(nameof(CopyTo), + using IDisposable registration = RegisterMethod(nameof(CopyTo), destination, bufferSize); _fileSystem.Execute.NotOnWindows(() => @@ -175,7 +175,7 @@ public override void CopyTo(Stream destination, int bufferSize) public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { - using IDisposable registration = Register(nameof(CopyToAsync), + using IDisposable registration = RegisterMethod(nameof(CopyToAsync), destination, bufferSize, cancellationToken); _container.AdjustTimes(TimeAdjustments.LastAccessTime); @@ -185,7 +185,7 @@ public override Task CopyToAsync(Stream destination, int bufferSize, /// public override int EndRead(IAsyncResult asyncResult) { - using IDisposable registration = Register(nameof(EndRead), + using IDisposable registration = RegisterMethod(nameof(EndRead), asyncResult); _container.AdjustTimes(TimeAdjustments.LastAccessTime); @@ -195,7 +195,7 @@ public override int EndRead(IAsyncResult asyncResult) /// public override void EndWrite(IAsyncResult asyncResult) { - using IDisposable registration = Register(nameof(EndWrite), + using IDisposable registration = RegisterMethod(nameof(EndWrite), asyncResult); _isContentChanged = true; @@ -205,7 +205,7 @@ public override void EndWrite(IAsyncResult asyncResult) /// public override void Flush() { - using IDisposable registration = Register(nameof(Flush)); + using IDisposable registration = RegisterMethod(nameof(Flush)); ThrowIfDisposed(); InternalFlush(); @@ -214,7 +214,7 @@ public override void Flush() /// public override void Flush(bool flushToDisk) { - using IDisposable registration = Register(nameof(Flush), + using IDisposable registration = RegisterMethod(nameof(Flush), flushToDisk); Flush(); @@ -223,7 +223,7 @@ public override void Flush(bool flushToDisk) /// public override Task FlushAsync(CancellationToken cancellationToken) { - using IDisposable registration = Register(nameof(FlushAsync), + using IDisposable registration = RegisterMethod(nameof(FlushAsync), cancellationToken); if (cancellationToken.IsCancellationRequested) @@ -238,7 +238,7 @@ public override Task FlushAsync(CancellationToken cancellationToken) /// public override int Read(byte[] buffer, int offset, int count) { - using IDisposable registration = Register(nameof(Read), + using IDisposable registration = RegisterMethod(nameof(Read), buffer, offset, count); if (!CanRead) @@ -255,7 +255,7 @@ public override int Read(byte[] buffer, int offset, int count) /// public override int Read(Span buffer) { - using IDisposable registration = Register(nameof(Read), + using IDisposable registration = RegisterMethod(nameof(Read), buffer); if (!CanRead) @@ -273,7 +273,7 @@ public override int Read(Span buffer) public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - using IDisposable registration = Register(nameof(ReadAsync), + using IDisposable registration = RegisterMethod(nameof(ReadAsync), buffer, offset, count, cancellationToken); if (!CanRead) @@ -291,7 +291,7 @@ public override Task ReadAsync(byte[] buffer, int offset, int count, public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = new()) { - using IDisposable registration = Register(nameof(ReadAsync), + using IDisposable registration = RegisterMethod(nameof(ReadAsync), buffer, cancellationToken); if (!CanRead) @@ -308,7 +308,7 @@ public override ValueTask ReadAsync(Memory buffer, /// public override int ReadByte() { - using IDisposable registration = Register(nameof(ReadByte)); + using IDisposable registration = RegisterMethod(nameof(ReadByte)); if (!CanRead) { @@ -323,7 +323,7 @@ public override int ReadByte() /// public override long Seek(long offset, SeekOrigin origin) { - using IDisposable registration = Register(nameof(Seek), + using IDisposable registration = RegisterMethod(nameof(Seek), offset, origin); if (_mode == FileMode.Append && offset <= _initialPosition) @@ -337,7 +337,7 @@ public override long Seek(long offset, SeekOrigin origin) /// public override void SetLength(long value) { - using IDisposable registration = Register(nameof(SetLength), + using IDisposable registration = RegisterMethod(nameof(SetLength), value); ThrowIfDisposed(); @@ -352,7 +352,7 @@ public override void SetLength(long value) /// public override void Write(byte[] buffer, int offset, int count) { - using IDisposable registration = Register(nameof(Write), + using IDisposable registration = RegisterMethod(nameof(Write), buffer, offset, count); if (!CanWrite) @@ -368,7 +368,7 @@ public override void Write(byte[] buffer, int offset, int count) /// public override void Write(ReadOnlySpan buffer) { - using IDisposable registration = Register(nameof(Write), + using IDisposable registration = RegisterMethod(nameof(Write), buffer); if (!CanWrite) @@ -385,7 +385,7 @@ public override void Write(ReadOnlySpan buffer) public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - using IDisposable registration = Register(nameof(WriteAsync), + using IDisposable registration = RegisterMethod(nameof(WriteAsync), buffer, offset, count, cancellationToken); if (!CanWrite) @@ -402,7 +402,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = new()) { - using IDisposable registration = Register(nameof(WriteAsync), + using IDisposable registration = RegisterMethod(nameof(WriteAsync), buffer, cancellationToken); if (!CanWrite) @@ -418,7 +418,7 @@ public override ValueTask WriteAsync(ReadOnlyMemory buffer, /// public override void WriteByte(byte value) { - using IDisposable registration = Register(nameof(WriteByte), + using IDisposable registration = RegisterMethod(nameof(WriteByte), value); if (!CanWrite) @@ -433,7 +433,7 @@ public override void WriteByte(byte value) /// public override string? ToString() { - using IDisposable registration = Register(nameof(ToString)); + using IDisposable registration = RegisterMethod(nameof(ToString)); return base.ToString(); } @@ -538,42 +538,42 @@ public void StoreMetadata(string key, T? value) public T? RetrieveMetadata(string key) => _container.Extensibility.RetrieveMetadata(key); - private IDisposable Register(string name) - => _fileSystem.StatisticsRegistration.FileStream.Register(_location.FullPath, name); + private IDisposable RegisterMethod(string name) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(_location.FullPath, name); - private IDisposable Register(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.FileStream.Register(_location.FullPath, name, + private IDisposable RegisterMethod(string name, T1 parameter1) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(_location.FullPath, name, ParameterDescription.FromParameter(parameter1)); #if FEATURE_SPAN - private IDisposable Register(string name, Span parameter1) - => _fileSystem.StatisticsRegistration.FileStream.Register(_location.FullPath, name, + private IDisposable RegisterMethod(string name, Span parameter1) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(_location.FullPath, name, ParameterDescription.FromParameter(parameter1)); - private IDisposable Register(string name, ReadOnlySpan parameter1) - => _fileSystem.StatisticsRegistration.FileStream.Register(_location.FullPath, name, + private IDisposable RegisterMethod(string name, ReadOnlySpan parameter1) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(_location.FullPath, name, ParameterDescription.FromParameter(parameter1)); #endif - private IDisposable Register(string name, T1 parameter1, T2 parameter2) - => _fileSystem.StatisticsRegistration.FileStream.Register(_location.FullPath, name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(_location.FullPath, name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2, T3 parameter3) - => _fileSystem.StatisticsRegistration.FileStream.Register(_location.FullPath, name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(_location.FullPath, name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) - => _fileSystem.StatisticsRegistration.FileStream.Register(_location.FullPath, name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(_location.FullPath, name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3), ParameterDescription.FromParameter(parameter4)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4, T5 parameter5) - => _fileSystem.StatisticsRegistration.FileStream.Register(_location.FullPath, name, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4, T5 parameter5) + => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(_location.FullPath, name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3), diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs index 34921a74c..bc4fed082 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs @@ -3,6 +3,7 @@ using System.IO; using Testably.Abstractions.Helpers; using Testably.Abstractions.Testing.Helpers; +using Testably.Abstractions.Testing.Statistics; using Testably.Abstractions.Testing.Storage; namespace Testably.Abstractions.Testing.FileSystem; @@ -55,7 +56,7 @@ public FileAttributes Attributes /// public void CreateAsSymbolicLink(string pathToTarget) { - using IDisposable registration = Register(nameof(CreateAsSymbolicLink), + using IDisposable registration = RegisterMethod(nameof(CreateAsSymbolicLink), pathToTarget); if (!_fileSystem.Execute.IsWindows && string.IsNullOrWhiteSpace(FullName)) @@ -97,7 +98,7 @@ public DateTime CreationTimeUtc /// public virtual void Delete() { - using IDisposable registration = Register(nameof(Delete)); + using IDisposable registration = RegisterMethod(nameof(Delete)); _fileSystem.Storage.DeleteContainer(Location); ResetCache(!_fileSystem.Execute.IsNetFramework); @@ -198,7 +199,7 @@ public UnixFileMode UnixFileMode /// public void Refresh() { - using IDisposable registration = Register(nameof(Refresh)); + using IDisposable registration = RegisterMethod(nameof(Refresh)); ResetCache(true); } @@ -207,7 +208,7 @@ public void Refresh() /// public IFileSystemInfo? ResolveLinkTarget(bool returnFinalTarget) { - using IDisposable registration = Register(nameof(ResolveLinkTarget), + using IDisposable registration = RegisterMethod(nameof(ResolveLinkTarget), returnFinalTarget); try @@ -292,9 +293,12 @@ private void RefreshInternal() _isInitialized = true; } - protected virtual IDisposable Register(string name) + protected virtual IDisposable RegisterProperty(string name, PropertyStatistic.AccessMode mode) => new NoOpDisposable(); - protected virtual IDisposable Register(string name, T1 parameter1) + protected virtual IDisposable RegisterMethod(string name) + => new NoOpDisposable(); + + protected virtual IDisposable RegisterMethod(string name, T1 parameter1) => new NoOpDisposable(); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherFactoryMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherFactoryMock.cs index 21ac70591..abeddb6c8 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherFactoryMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherFactoryMock.cs @@ -107,14 +107,14 @@ public IFileSystemWatcher New(string path, string filter) #endregion private IDisposable Register(string name) - => _fileSystem.StatisticsRegistration.FileSystemWatcher.Register(name); + => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(name); private IDisposable Register(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.FileSystemWatcher.Register(name, + => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); private IDisposable Register(string name, T1 parameter1, T2 parameter2) - => _fileSystem.StatisticsRegistration.FileSystemWatcher.Register(name, + => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs index 6dd66c333..4297a0960 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs @@ -528,14 +528,14 @@ public WaitForChangedResultMock( } private IDisposable Register(string name) - => _fileSystem.StatisticsRegistration.FileSystemWatcher.Register(_path, name); + => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(_path, name); private IDisposable Register(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.FileSystemWatcher.Register(_path, name, + => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(_path, name, ParameterDescription.FromParameter(parameter1)); private IDisposable Register(string name, T1 parameter1, T2 parameter2) - => _fileSystem.StatisticsRegistration.FileSystemWatcher.Register(_path, name, + => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(_path, name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs index eb859a479..78cad44bc 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs @@ -479,7 +479,7 @@ public override bool TryJoin(ReadOnlySpan path1, } finally { - _fileSystem.StatisticsRegistration.Path.Register(nameof(TryJoin), + _fileSystem.StatisticsRegistration.Path.RegisterMethod(nameof(TryJoin), ParameterDescription.FromParameter(path1), ParameterDescription.FromParameter(path2), ParameterDescription.FromParameter(destination), @@ -503,7 +503,7 @@ public override bool TryJoin(ReadOnlySpan path1, } finally { - _fileSystem.StatisticsRegistration.Path.Register(nameof(TryJoin), + _fileSystem.StatisticsRegistration.Path.RegisterMethod(nameof(TryJoin), ParameterDescription.FromParameter(path1), ParameterDescription.FromParameter(path2), ParameterDescription.FromParameter(path3), @@ -514,35 +514,35 @@ public override bool TryJoin(ReadOnlySpan path1, #endif private IDisposable Register(string name) - => _fileSystem.StatisticsRegistration.Path.Register(name); + => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name); private IDisposable Register(string name, T1 parameter1) - => _fileSystem.StatisticsRegistration.Path.Register(name, + => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); #if FEATURE_SPAN private IDisposable Register(string name, ReadOnlySpan parameter1) - => _fileSystem.StatisticsRegistration.Path.Register(name, + => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); #endif #if FEATURE_PATH_ADVANCED private IDisposable Register(string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2) - => _fileSystem.StatisticsRegistration.Path.Register(name, + => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); private IDisposable Register(string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2, ReadOnlySpan parameter3) - => _fileSystem.StatisticsRegistration.Path.Register(name, + => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3)); private IDisposable Register(string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2, ReadOnlySpan parameter3, ReadOnlySpan parameter4) - => _fileSystem.StatisticsRegistration.Path.Register(name, + => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3), @@ -550,20 +550,20 @@ private IDisposable Register(string name, ReadOnlySpan param #endif private IDisposable Register(string name, T1 parameter1, T2 parameter2) - => _fileSystem.StatisticsRegistration.Path.Register(name, + => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); private IDisposable Register(string name, T1 parameter1, T2 parameter2, T3 parameter3) - => _fileSystem.StatisticsRegistration.Path.Register(name, + => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3)); private IDisposable Register(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) - => _fileSystem.StatisticsRegistration.Path.Register(name, + => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3), diff --git a/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs b/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs index 5232e3d6c..b7148398c 100644 --- a/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs +++ b/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs @@ -6,8 +6,14 @@ namespace Testably.Abstractions.Testing.Statistics; internal class CallStatistics : IStatistics { private readonly IStatisticsGate _statisticsGate; - private readonly ConcurrentQueue _calls = new(); - public MethodStatistic[] Methods => _calls.ToArray(); + private readonly ConcurrentQueue _methods = new(); + private readonly ConcurrentQueue _properties = new(); + + /// + public MethodStatistic[] Methods => _methods.ToArray(); + + /// + public PropertyStatistic[] Properties => _properties.ToArray(); public CallStatistics(IStatisticsGate statisticsGate) { @@ -15,15 +21,30 @@ public CallStatistics(IStatisticsGate statisticsGate) } /// - /// Registers the callback with . + /// Registers the method with . + /// + /// A disposable which ignores all registrations, until it is disposed. + internal IDisposable RegisterMethod(string name, params ParameterDescription[] parameters) + { + if (_statisticsGate.TryGetLock(out IDisposable release)) + { + int counter = _statisticsGate.GetCounter(); + _methods.Enqueue(new MethodStatistic(counter, name, parameters)); + } + + return release; + } + + /// + /// Registers the property callback with access. /// /// A disposable which ignores all registrations, until it is disposed. - internal IDisposable Register(string name, params ParameterDescription[] parameters) + internal IDisposable RegisterProperty(string name, PropertyStatistic.AccessMode mode) { if (_statisticsGate.TryGetLock(out IDisposable release)) { int counter = _statisticsGate.GetCounter(); - _calls.Enqueue(new MethodStatistic(counter, name, parameters)); + _properties.Enqueue(new PropertyStatistic(counter, name, mode)); } return release; diff --git a/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs b/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs index 43243ecc8..a89044905 100644 --- a/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs +++ b/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs @@ -28,10 +28,21 @@ public IStatistics this[string path] /// Registers the callback with under . /// /// A disposable which ignores all registrations, until it is disposed. - internal IDisposable Register(string path, string name, params ParameterDescription[] parameters) + internal IDisposable RegisterMethod(string path, string name, params ParameterDescription[] parameters) { CallStatistics callStatistics = _statistics.GetOrAdd(_fileSystem.Path.GetFullPath(path), _ => new CallStatistics(_statisticsGate)); - return callStatistics.Register(name, parameters); + return callStatistics.RegisterMethod(name, parameters); + } + + /// + /// Registers the property callback with access under . + /// + /// A disposable which ignores all registrations, until it is disposed. + internal IDisposable RegisterProperty(string path, string name, PropertyStatistic.AccessMode mode) + { + CallStatistics callStatistics = _statistics.GetOrAdd(_fileSystem.Path.GetFullPath(path), + _ => new CallStatistics(_statisticsGate)); + return callStatistics.RegisterProperty(name, mode); } } diff --git a/Source/Testably.Abstractions.Testing/Statistics/IStatistics.cs b/Source/Testably.Abstractions.Testing/Statistics/IStatistics.cs index b0ca8e41f..a20ec50e0 100644 --- a/Source/Testably.Abstractions.Testing/Statistics/IStatistics.cs +++ b/Source/Testably.Abstractions.Testing/Statistics/IStatistics.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace Testably.Abstractions.Testing.Statistics; +namespace Testably.Abstractions.Testing.Statistics; /// /// Contains statistical information about the mock usage. @@ -11,4 +9,9 @@ public interface IStatistics /// Lists all called mocked methods. /// MethodStatistic[] Methods { get; } + + /// + /// Lists all accessed mocked properties. + /// + PropertyStatistic[] Properties { get; } } diff --git a/Source/Testably.Abstractions.Testing/Statistics/PropertyStatistic.cs b/Source/Testably.Abstractions.Testing/Statistics/PropertyStatistic.cs new file mode 100644 index 000000000..cb5b4d065 --- /dev/null +++ b/Source/Testably.Abstractions.Testing/Statistics/PropertyStatistic.cs @@ -0,0 +1,51 @@ +using System.Globalization; + +namespace Testably.Abstractions.Testing.Statistics; + +/// +/// Describes access to a mocked property. +/// +public sealed class PropertyStatistic +{ + /// + /// The global counter value to determine the order of calls. + /// + public int Counter { get; } + + /// + /// The name of the accessed property. + /// + public string Name { get; } + + /// + /// The mode of the accessed property (getter or setter). + /// + public AccessMode Mode { get; } + + internal PropertyStatistic(int counter, string name, AccessMode mode) + { + Counter = counter; + Name = name; + Mode = mode; + } + + /// + public override string ToString() + => $"{Name}{{{Mode.ToString().ToLower(CultureInfo.InvariantCulture)};}}"; + + /// + /// The mode of accessing a property (getter or setter). + /// + public enum AccessMode + { + /// + /// The property was read. + /// + Get, + + /// + /// The property was written to. + /// + Set + } +} diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs index 784ab83f0..0ba9ba0ca 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs @@ -5,6 +5,254 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public sealed class DirectoryInfoStatisticsTests { + [SkippableFact] + public void Attributes_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").Attributes; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Attributes)); + } + + [SkippableFact] + public void Attributes_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + FileAttributes value = new(); + + sut.DirectoryInfo.New("foo").Attributes = value; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Attributes)); + } + + [SkippableFact] + public void CreationTime_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").CreationTime; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTime)); + } + + [SkippableFact] + public void CreationTime_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.DirectoryInfo.New("foo").CreationTime = value; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTime)); + } + + [SkippableFact] + public void CreationTimeUtc_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").CreationTimeUtc; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTimeUtc)); + } + + [SkippableFact] + public void CreationTimeUtc_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.DirectoryInfo.New("foo").CreationTimeUtc = value; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTimeUtc)); + } + + [SkippableFact] + public void Exists_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").Exists; + + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Exists)); + } + + [SkippableFact] + public void Extension_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").Extension; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Extension)); + } + + [SkippableFact] + public void FullName_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").FullName; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.FullName)); + } + + [SkippableFact] + public void LastAccessTime_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").LastAccessTime; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTime)); + } + + [SkippableFact] + public void LastAccessTime_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.DirectoryInfo.New("foo").LastAccessTime = value; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTime)); + } + + [SkippableFact] + public void LastAccessTimeUtc_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").LastAccessTimeUtc; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTimeUtc)); + } + + [SkippableFact] + public void LastAccessTimeUtc_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.DirectoryInfo.New("foo").LastAccessTimeUtc = value; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTimeUtc)); + } + + [SkippableFact] + public void LastWriteTime_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").LastWriteTime; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTime)); + } + + [SkippableFact] + public void LastWriteTime_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.DirectoryInfo.New("foo").LastWriteTime = value; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTime)); + } + + [SkippableFact] + public void LastWriteTimeUtc_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").LastWriteTimeUtc; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTimeUtc)); + } + + [SkippableFact] + public void LastWriteTimeUtc_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.DirectoryInfo.New("foo").LastWriteTimeUtc = value; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTimeUtc)); + } + +#if FEATURE_FILESYSTEM_LINK + [SkippableFact] + public void LinkTarget_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").LinkTarget; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LinkTarget)); + } +#endif + + [SkippableFact] + public void Name_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").Name; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Name)); + } + + [SkippableFact] + public void Parent_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").Parent; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Parent)); + } + + [SkippableFact] + public void Root_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").Root; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Root)); + } + +#if FEATURE_FILESYSTEM_UNIXFILEMODE + [SkippableFact] + public void UnixFileMode_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DirectoryInfo.New("foo").UnixFileMode; + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.UnixFileMode)); + } + + [SkippableFact] + public void UnixFileMode_Set_ShouldRegisterPropertyAccess() + { + Skip.If(Test.RunsOnWindows); + + MockFileSystem sut = new(); + UnixFileMode value = new(); + + #pragma warning disable CA1416 + sut.DirectoryInfo.New("foo").UnixFileMode = value; + #pragma warning restore CA1416 + + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.UnixFileMode)); + } +#endif + + [SkippableFact] public void Create_ShouldRegisterCall() { diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs index c9aa95182..89e13ff71 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs @@ -1,8 +1,111 @@ -using System.IO; -using Testably.Abstractions.Testing.Tests.TestHelpers; +using Testably.Abstractions.Testing.Tests.TestHelpers; namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public sealed class DriveInfoStatisticsTests { + [SkippableFact] + public void AvailableFreeSpace_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DriveInfo.New("F:").AvailableFreeSpace; + + sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.AvailableFreeSpace)); + } + + [SkippableFact] + public void DriveFormat_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DriveInfo.New("F:").DriveFormat; + + sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.DriveFormat)); + } + + [SkippableFact] + public void DriveType_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DriveInfo.New("F:").DriveType; + + sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.DriveType)); + } + + [SkippableFact] + public void IsReady_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DriveInfo.New("F:").IsReady; + + sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.IsReady)); + } + + [SkippableFact] + public void Name_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DriveInfo.New("F:").Name; + + sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.Name)); + } + + [SkippableFact] + public void RootDirectory_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DriveInfo.New("F:").RootDirectory; + + sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.RootDirectory)); + } + + [SkippableFact] + public void TotalFreeSpace_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DriveInfo.New("F:").TotalFreeSpace; + + sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.TotalFreeSpace)); + } + + [SkippableFact] + public void TotalSize_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DriveInfo.New("F:").TotalSize; + + sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.TotalSize)); + } + + [SkippableFact] + public void VolumeLabel_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.DriveInfo.New("F:").VolumeLabel; + + sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.VolumeLabel)); + } + + [SkippableFact] + public void VolumeLabel_Set_ShouldRegisterPropertyAccess() + { + Skip.IfNot(Test.RunsOnWindows); + + MockFileSystem sut = new(); + string value = "F:"; + + #pragma warning disable CA1416 + sut.DriveInfo.New("F:").VolumeLabel = value; + #pragma warning restore CA1416 + + sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertySetAccess(nameof(IDriveInfo.VolumeLabel)); + } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.cs index d2a90cb5d..0af98d49d 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.cs @@ -166,12 +166,12 @@ public void FileSystem_Initialize_ShouldNotRegisterStatistics() public void ShouldHaveTestedAllFileSystemMethods(string className, bool requireInstance, Type mockType, Type testType) { - string result = CheckMethods(className, requireInstance, mockType, testType); + string result = CheckPropertiesAndMethods(className, requireInstance, mockType, testType); result.Should().BeEmpty(); } - private static string CheckMethods(string className, bool requireInstance, + private static string CheckPropertiesAndMethods(string className, bool requireInstance, Type mockType, Type testType) { StringBuilder builder = new(); @@ -325,6 +325,85 @@ string GetDefaultValue(Type type) return "new()"; } + void CheckPropertyGetAccess(string className, bool requireInstance, Type mockType, + Type testType, PropertyInfo propertyInfo, StringBuilder builder) + { + string expectedName = $"{propertyInfo.Name}_Get_ShouldRegisterPropertyAccess"; + if (testType.GetMethod(expectedName) != null) + { + return; + } + + builder.AppendLine("\t[SkippableFact]"); + builder.Append("\tpublic void "); + builder.Append(expectedName); + builder.AppendLine("()"); + builder.AppendLine("\t{"); + builder.AppendLine("\t\tMockFileSystem sut = new();"); + builder.AppendLine(); + builder.AppendLine( + $"\t\t_ = sut.{className}{(requireInstance ? ".New(\"foo\")" : "")}.{propertyInfo.Name};"); + builder.AppendLine(); + builder.AppendLine( + $"\t\tsut.Statistics.{className}{(requireInstance ? "[\"foo\"]" : "")}.ShouldOnlyContainPropertyGetAccess(nameof({mockType.Name}.{propertyInfo.Name}));"); + builder.AppendLine("\t}"); + builder.AppendLine(); + } + + void CheckPropertySetAccess(string className, bool requireInstance, Type mockType, + Type testType, PropertyInfo propertyInfo, StringBuilder builder) + { + string expectedName = $"{propertyInfo.Name}_Set_ShouldRegisterPropertyAccess"; + if (testType.GetMethod(expectedName) != null) + { + return; + } + + builder.AppendLine("\t[SkippableFact]"); + builder.Append("\tpublic void "); + builder.Append(expectedName); + builder.AppendLine("()"); + builder.AppendLine("\t{"); + builder.AppendLine("\t\tMockFileSystem sut = new();"); + builder.AppendLine( + $"\t\t{GetName(propertyInfo.PropertyType, false)} value = {GetDefaultValue(propertyInfo.PropertyType)};"); + builder.AppendLine(); + builder.AppendLine( + $"\t\tsut.{className}{(requireInstance ? ".New(\"foo\")" : "")}.{propertyInfo.Name} = value;"); + builder.AppendLine(); + builder.AppendLine( + $"\t\tsut.Statistics.{className}{(requireInstance ? "[\"foo\"]" : "")}.ShouldOnlyContainPropertySetAccess(nameof({mockType.Name}.{propertyInfo.Name}));"); + builder.AppendLine("\t}"); + builder.AppendLine(); + } + + foreach (PropertyInfo propertyInfo in + mockType.GetInterfaces() + .Where(i => i != typeof(IDisposable) && i != typeof(IAsyncDisposable)) + .SelectMany(i => i.GetProperties()) + .Concat(mockType.GetProperties(BindingFlags.DeclaredOnly | + BindingFlags.Public | + BindingFlags.Instance)) + .Where(p => p.IsSpecialName == false && (p.CanRead || p.CanWrite)) + .OrderBy(m => m.Name)) + { + if (propertyInfo.GetCustomAttribute() != null || + propertyInfo.Name == nameof(IFileSystemEntity.FileSystem)) + { + continue; + } + + if (propertyInfo.CanRead) + { + CheckPropertyGetAccess(className, requireInstance, mockType, testType, propertyInfo, builder); + } + + if (propertyInfo.CanWrite) + { + CheckPropertySetAccess(className, requireInstance, mockType, testType, propertyInfo, builder); + } + } + foreach (MethodInfo methodInfo in mockType.GetInterfaces() .Where(i => i != typeof(IDisposable) && i != typeof(IAsyncDisposable)) diff --git a/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs b/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs index ed1f8f913..341d9b597 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs @@ -5,6 +5,20 @@ namespace Testably.Abstractions.Testing.Tests.TestHelpers; public static class StatisticsTestHelpers { + public static void ShouldOnlyContainPropertyGetAccess(this IStatistics statistics, string name) + { + statistics.Properties.Length.Should().Be(1); + statistics.Properties.Should() + .ContainSingle(c => c.Name == name && c.Mode == PropertyStatistic.AccessMode.Get); + } + + public static void ShouldOnlyContainPropertySetAccess(this IStatistics statistics, string name) + { + statistics.Properties.Length.Should().Be(1); + statistics.Properties.Should() + .ContainSingle(c => c.Name == name && c.Mode == PropertyStatistic.AccessMode.Set); + } + public static void ShouldOnlyContain(this IStatistics statistics, string name, object?[] parameters, string because = "") { From dcad7e284471e5cf7dd6c1dccc3bf7e1fee719b0 Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 15 Mar 2024 12:21:19 +0100 Subject: [PATCH 2/8] Add missing tests --- .../FileSystem/DirectoryInfoFactoryMock.cs | 8 +- .../FileSystem/DriveInfoFactoryMock.cs | 12 +- .../FileSystem/FileInfoFactoryMock.cs | 8 +- .../FileSystemWatcherFactoryMock.cs | 14 +- .../FileSystem/FileSystemWatcherMock.cs | 16 +- .../FileSystem/PathMock.cs | 100 +-- .../DirectoryInfoFactoryStatisticsTests.cs | 8 +- .../DirectoryInfoStatisticsTests.cs | 588 +++++++++------- .../FileSystem/DirectoryStatisticsTests.cs | 375 +++++----- .../DriveInfoFactoryStatisticsTests.cs | 12 +- .../FileSystem/DriveInfoStatisticsTests.cs | 47 +- .../FileInfoFactoryStatisticsTests.cs | 8 +- .../FileSystem/FileInfoStatisticsTests.cs | 461 ++++++++++--- .../FileSystem/FileStatisticsTests.cs | 652 +++++++++--------- .../FileStreamFactoryStatisticsTests.cs | 143 ++-- .../FileSystem/FileStreamStatisticsTests.cs | 319 +++++++-- ...FileSystemWatcherFactoryStatisticsTests.cs | 20 +- .../FileSystemWatcherStatisticsTests.cs | 238 ++++++- .../FileSystem/PathStatisticsTests.cs | 273 +++++--- .../Statistics/StatisticsTests.Helpers.cs | 334 +++++++++ .../Statistics/StatisticsTests.cs | 308 +-------- .../TestHelpers/StatisticsTestHelpers.cs | 34 +- 22 files changed, 2413 insertions(+), 1565 deletions(-) create mode 100644 Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs diff --git a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoFactoryMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoFactoryMock.cs index ad9e0fa8e..c1493451f 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoFactoryMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoFactoryMock.cs @@ -25,7 +25,7 @@ public IFileSystem FileSystem [Obsolete("Use `IDirectoryInfoFactory.New(string)` instead")] public IDirectoryInfo FromDirectoryName(string directoryName) { - using IDisposable registration = Register(nameof(FromDirectoryName), + using IDisposable registration = RegisterMethod(nameof(FromDirectoryName), directoryName); return New(directoryName); @@ -34,7 +34,7 @@ public IDirectoryInfo FromDirectoryName(string directoryName) /// public IDirectoryInfo New(string path) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), path); return DirectoryInfoMock.New( @@ -47,7 +47,7 @@ public IDirectoryInfo New(string path) [return: NotNullIfNotNull("directoryInfo")] public IDirectoryInfo? Wrap(DirectoryInfo? directoryInfo) { - using IDisposable registration = Register(nameof(Wrap), + using IDisposable registration = RegisterMethod(nameof(Wrap), directoryInfo); return DirectoryInfoMock.New( @@ -59,6 +59,6 @@ public IDirectoryInfo New(string path) #endregion - private IDisposable Register(string name, T1 parameter1) + private IDisposable RegisterMethod(string name, T1 parameter1) => _fileSystem.StatisticsRegistration.DirectoryInfo.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoFactoryMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoFactoryMock.cs index d76c1bd26..98fdff58d 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoFactoryMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoFactoryMock.cs @@ -27,7 +27,7 @@ public IFileSystem FileSystem [Obsolete("Use `IDriveInfoFactory.New(string)` instead")] public IDriveInfo FromDriveName(string driveName) { - using IDisposable registration = Register(nameof(FromDriveName), + using IDisposable registration = RegisterMethod(nameof(FromDriveName), driveName); return New(driveName); @@ -36,7 +36,7 @@ public IDriveInfo FromDriveName(string driveName) /// public IDriveInfo[] GetDrives() { - using IDisposable registration = Register(nameof(GetDrives)); + using IDisposable registration = RegisterMethod(nameof(GetDrives)); return _fileSystem.Storage.GetDrives() .Where(x => !x.IsUncPath) @@ -47,7 +47,7 @@ public IDriveInfo[] GetDrives() /// public IDriveInfo New(string driveName) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), driveName); if (driveName == null) @@ -64,7 +64,7 @@ public IDriveInfo New(string driveName) [return: NotNullIfNotNull("driveInfo")] public IDriveInfo? Wrap(DriveInfo? driveInfo) { - using IDisposable registration = Register(nameof(Wrap), + using IDisposable registration = RegisterMethod(nameof(Wrap), driveInfo); if (driveInfo?.Name == null) @@ -77,10 +77,10 @@ public IDriveInfo New(string driveName) #endregion - private IDisposable Register(string name) + private IDisposable RegisterMethod(string name) => _fileSystem.StatisticsRegistration.DriveInfo.RegisterMethod(name); - private IDisposable Register(string name, T1 parameter1) + private IDisposable RegisterMethod(string name, T1 parameter1) => _fileSystem.StatisticsRegistration.DriveInfo.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileInfoFactoryMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileInfoFactoryMock.cs index c5e464fe1..f41dfc685 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileInfoFactoryMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileInfoFactoryMock.cs @@ -25,7 +25,7 @@ public IFileSystem FileSystem [Obsolete("Use `IFileInfoFactory.New(string)` instead")] public IFileInfo FromFileName(string fileName) { - using IDisposable registration = Register(nameof(FromFileName), + using IDisposable registration = RegisterMethod(nameof(FromFileName), fileName); return New(fileName); @@ -34,7 +34,7 @@ public IFileInfo FromFileName(string fileName) /// public IFileInfo New(string fileName) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), fileName); if (fileName == null) @@ -56,7 +56,7 @@ public IFileInfo New(string fileName) [return: NotNullIfNotNull("fileInfo")] public IFileInfo? Wrap(FileInfo? fileInfo) { - using IDisposable registration = Register(nameof(Wrap), + using IDisposable registration = RegisterMethod(nameof(Wrap), fileInfo); return FileInfoMock.New( @@ -68,7 +68,7 @@ public IFileInfo New(string fileName) #endregion - private IDisposable Register(string name, T1 parameter1) + private IDisposable RegisterMethod(string name, T1 parameter1) => _fileSystem.StatisticsRegistration.FileInfo.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherFactoryMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherFactoryMock.cs index abeddb6c8..e2c85bba8 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherFactoryMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherFactoryMock.cs @@ -40,7 +40,7 @@ public IFileSystemWatcher CreateNew(string path, string filter) /// public IFileSystemWatcher New() { - using IDisposable registration = Register(nameof(New)); + using IDisposable registration = RegisterMethod(nameof(New)); return FileSystemWatcherMock.New(_fileSystem); } @@ -48,7 +48,7 @@ public IFileSystemWatcher New() /// public IFileSystemWatcher New(string path) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), path); FileSystemWatcherMock fileSystemWatcherMock = @@ -60,7 +60,7 @@ public IFileSystemWatcher New(string path) /// public IFileSystemWatcher New(string path, string filter) { - using IDisposable registration = Register(nameof(New), + using IDisposable registration = RegisterMethod(nameof(New), path, filter); FileSystemWatcherMock fileSystemWatcherMock = @@ -75,7 +75,7 @@ public IFileSystemWatcher New(string path, string filter) // ReSharper disable once ReturnTypeCanBeNotNullable public IFileSystemWatcher? Wrap(FileSystemWatcher? fileSystemWatcher) { - using IDisposable registration = Register(nameof(Wrap), + using IDisposable registration = RegisterMethod(nameof(Wrap), fileSystemWatcher); if (fileSystemWatcher == null) @@ -106,14 +106,14 @@ public IFileSystemWatcher New(string path, string filter) #endregion - private IDisposable Register(string name) + private IDisposable RegisterMethod(string name) => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(name); - private IDisposable Register(string name, T1 parameter1) + private IDisposable RegisterMethod(string name, T1 parameter1) => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2) + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2) => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs index 4297a0960..da1c65982 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs @@ -136,7 +136,7 @@ public string Path /// public void BeginInit() { - using IDisposable registration = Register(nameof(BeginInit)); + using IDisposable registration = RegisterMethod(nameof(BeginInit)); _isInitializing = true; Stop(); @@ -154,7 +154,7 @@ public void BeginInit() /// public void EndInit() { - using IDisposable registration = Register(nameof(EndInit)); + using IDisposable registration = RegisterMethod(nameof(EndInit)); _isInitializing = false; Restart(); @@ -170,7 +170,7 @@ public void EndInit() public IWaitForChangedResult WaitForChanged( WatcherChangeTypes changeType) { - using IDisposable registration = Register(nameof(WaitForChanged), + using IDisposable registration = RegisterMethod(nameof(WaitForChanged), changeType); return WaitForChanged(changeType, Timeout.Infinite); @@ -180,7 +180,7 @@ public IWaitForChangedResult WaitForChanged( public IWaitForChangedResult WaitForChanged( WatcherChangeTypes changeType, int timeout) { - using IDisposable registration = Register(nameof(WaitForChanged), + using IDisposable registration = RegisterMethod(nameof(WaitForChanged), changeType, timeout); return WaitForChangedInternal(changeType, TimeSpan.FromMilliseconds(timeout)); @@ -191,7 +191,7 @@ public IWaitForChangedResult WaitForChanged( public IWaitForChangedResult WaitForChanged( WatcherChangeTypes changeType, TimeSpan timeout) { - using IDisposable registration = Register(nameof(WaitForChanged), + using IDisposable registration = RegisterMethod(nameof(WaitForChanged), changeType, timeout); return WaitForChangedInternal(changeType, timeout); @@ -527,14 +527,14 @@ public WaitForChangedResultMock( public bool TimedOut { get; } } - private IDisposable Register(string name) + private IDisposable RegisterMethod(string name) => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(_path, name); - private IDisposable Register(string name, T1 parameter1) + private IDisposable RegisterMethod(string name, T1 parameter1) => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(_path, name, ParameterDescription.FromParameter(parameter1)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2) + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2) => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(_path, name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); diff --git a/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs index 78cad44bc..54156ae1d 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs @@ -24,7 +24,7 @@ internal PathMock(MockFileSystem fileSystem) [return: NotNullIfNotNull("path")] public override string? ChangeExtension(string? path, string? extension) { - using IDisposable register = Register(nameof(ChangeExtension), + using IDisposable register = RegisterMethod(nameof(ChangeExtension), path, extension); return base.ChangeExtension(path, extension); @@ -33,7 +33,7 @@ internal PathMock(MockFileSystem fileSystem) /// public override string Combine(string path1, string path2) { - using IDisposable register = Register(nameof(Combine), + using IDisposable register = RegisterMethod(nameof(Combine), path1, path2); return base.Combine(path1, path2); @@ -42,7 +42,7 @@ public override string Combine(string path1, string path2) /// public override string Combine(string path1, string path2, string path3) { - using IDisposable register = Register(nameof(Combine), + using IDisposable register = RegisterMethod(nameof(Combine), path1, path2, path3); return base.Combine(path1, path2, path3); @@ -51,7 +51,7 @@ public override string Combine(string path1, string path2, string path3) /// public override string Combine(string path1, string path2, string path3, string path4) { - using IDisposable register = Register(nameof(Combine), + using IDisposable register = RegisterMethod(nameof(Combine), path1, path2, path3, path4); return base.Combine(path1, path2, path3, path4); @@ -60,7 +60,7 @@ public override string Combine(string path1, string path2, string path3, string /// public override string Combine(params string[] paths) { - using IDisposable register = Register(nameof(Combine), + using IDisposable register = RegisterMethod(nameof(Combine), paths); return base.Combine(paths); @@ -70,7 +70,7 @@ public override string Combine(params string[] paths) /// public override bool EndsInDirectorySeparator(ReadOnlySpan path) { - using IDisposable register = Register(nameof(EndsInDirectorySeparator), + using IDisposable register = RegisterMethod(nameof(EndsInDirectorySeparator), path); return base.EndsInDirectorySeparator(path); @@ -79,7 +79,7 @@ public override bool EndsInDirectorySeparator(ReadOnlySpan path) /// public override bool EndsInDirectorySeparator(string path) { - using IDisposable register = Register(nameof(EndsInDirectorySeparator), + using IDisposable register = RegisterMethod(nameof(EndsInDirectorySeparator), path); return base.EndsInDirectorySeparator(path); @@ -90,7 +90,7 @@ public override bool EndsInDirectorySeparator(string path) /// public override bool Exists([NotNullWhen(true)] string? path) { - using IDisposable register = Register(nameof(Exists), + using IDisposable register = RegisterMethod(nameof(Exists), path); if (string.IsNullOrEmpty(path)) @@ -107,7 +107,7 @@ public override bool Exists([NotNullWhen(true)] string? path) /// public override ReadOnlySpan GetDirectoryName(ReadOnlySpan path) { - using IDisposable register = Register(nameof(GetDirectoryName), + using IDisposable register = RegisterMethod(nameof(GetDirectoryName), path); return base.GetDirectoryName(path); @@ -117,7 +117,7 @@ public override ReadOnlySpan GetDirectoryName(ReadOnlySpan path) /// public override string? GetDirectoryName(string? path) { - using IDisposable register = Register(nameof(GetDirectoryName), + using IDisposable register = RegisterMethod(nameof(GetDirectoryName), path); return base.GetDirectoryName(path); @@ -127,7 +127,7 @@ public override ReadOnlySpan GetDirectoryName(ReadOnlySpan path) /// public override ReadOnlySpan GetExtension(ReadOnlySpan path) { - using IDisposable register = Register(nameof(GetExtension), + using IDisposable register = RegisterMethod(nameof(GetExtension), path); return base.GetExtension(path); @@ -138,7 +138,7 @@ public override ReadOnlySpan GetExtension(ReadOnlySpan path) [return: NotNullIfNotNull("path")] public override string? GetExtension(string? path) { - using IDisposable register = Register(nameof(GetExtension), + using IDisposable register = RegisterMethod(nameof(GetExtension), path); return base.GetExtension(path); @@ -148,7 +148,7 @@ public override ReadOnlySpan GetExtension(ReadOnlySpan path) /// public override ReadOnlySpan GetFileName(ReadOnlySpan path) { - using IDisposable register = Register(nameof(GetFileName), + using IDisposable register = RegisterMethod(nameof(GetFileName), path); return base.GetFileName(path); @@ -159,7 +159,7 @@ public override ReadOnlySpan GetFileName(ReadOnlySpan path) [return: NotNullIfNotNull("path")] public override string? GetFileName(string? path) { - using IDisposable register = Register(nameof(GetFileName), + using IDisposable register = RegisterMethod(nameof(GetFileName), path); return base.GetFileName(path); @@ -169,7 +169,7 @@ public override ReadOnlySpan GetFileName(ReadOnlySpan path) /// public override ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan path) { - using IDisposable register = Register(nameof(GetFileNameWithoutExtension), + using IDisposable register = RegisterMethod(nameof(GetFileNameWithoutExtension), path); return base.GetFileNameWithoutExtension(path); @@ -180,7 +180,7 @@ public override ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan public override string GetFullPath(string path) { - using IDisposable register = Register(nameof(GetFullPath), + using IDisposable register = RegisterMethod(nameof(GetFullPath), path); path.EnsureValidArgument(_fileSystem, nameof(path)); @@ -218,7 +218,7 @@ public override string GetFullPath(string path) /// public override string GetFullPath(string path, string basePath) { - using IDisposable register = Register(nameof(GetFullPath), + using IDisposable register = RegisterMethod(nameof(GetFullPath), path, basePath); return base.GetFullPath(path, basePath); @@ -228,7 +228,7 @@ public override string GetFullPath(string path, string basePath) /// public override char[] GetInvalidFileNameChars() { - using IDisposable register = Register(nameof(GetInvalidFileNameChars)); + using IDisposable register = RegisterMethod(nameof(GetInvalidFileNameChars)); return base.GetInvalidFileNameChars(); } @@ -236,7 +236,7 @@ public override char[] GetInvalidFileNameChars() /// public override char[] GetInvalidPathChars() { - using IDisposable register = Register(nameof(GetInvalidPathChars)); + using IDisposable register = RegisterMethod(nameof(GetInvalidPathChars)); return base.GetInvalidPathChars(); } @@ -245,7 +245,7 @@ public override char[] GetInvalidPathChars() /// public override ReadOnlySpan GetPathRoot(ReadOnlySpan path) { - using IDisposable register = Register(nameof(GetPathRoot), + using IDisposable register = RegisterMethod(nameof(GetPathRoot), path); return base.GetPathRoot(path); @@ -255,7 +255,7 @@ public override ReadOnlySpan GetPathRoot(ReadOnlySpan path) /// public override string? GetPathRoot(string? path) { - using IDisposable register = Register(nameof(GetPathRoot), + using IDisposable register = RegisterMethod(nameof(GetPathRoot), path); return base.GetPathRoot(path); @@ -264,7 +264,7 @@ public override ReadOnlySpan GetPathRoot(ReadOnlySpan path) /// public override string GetRandomFileName() { - using IDisposable register = Register(nameof(GetRandomFileName)); + using IDisposable register = RegisterMethod(nameof(GetRandomFileName)); return base.GetRandomFileName(); } @@ -273,7 +273,7 @@ public override string GetRandomFileName() /// public override string GetRelativePath(string relativeTo, string path) { - using IDisposable register = Register(nameof(GetRelativePath), + using IDisposable register = RegisterMethod(nameof(GetRelativePath), relativeTo, path); relativeTo.EnsureValidArgument(_fileSystem, nameof(relativeTo)); @@ -293,7 +293,7 @@ public override string GetRelativePath(string relativeTo, string path) #endif public override string GetTempFileName() { - using IDisposable register = Register(nameof(GetTempFileName)); + using IDisposable register = RegisterMethod(nameof(GetTempFileName)); return base.GetTempFileName(); } @@ -301,7 +301,7 @@ public override string GetTempFileName() /// public override string GetTempPath() { - using IDisposable register = Register(nameof(GetTempPath)); + using IDisposable register = RegisterMethod(nameof(GetTempPath)); return base.GetTempPath(); } @@ -310,7 +310,7 @@ public override string GetTempPath() /// public override bool HasExtension(ReadOnlySpan path) { - using IDisposable register = Register(nameof(HasExtension), + using IDisposable register = RegisterMethod(nameof(HasExtension), path); return base.HasExtension(path); @@ -320,7 +320,7 @@ public override bool HasExtension(ReadOnlySpan path) /// public override bool HasExtension([NotNullWhen(true)] string? path) { - using IDisposable register = Register(nameof(HasExtension), + using IDisposable register = RegisterMethod(nameof(HasExtension), path); return base.HasExtension(path); @@ -330,7 +330,7 @@ public override bool HasExtension([NotNullWhen(true)] string? path) /// public override bool IsPathFullyQualified(ReadOnlySpan path) { - using IDisposable register = Register(nameof(IsPathFullyQualified), + using IDisposable register = RegisterMethod(nameof(IsPathFullyQualified), path); return base.IsPathFullyQualified(path); @@ -341,7 +341,7 @@ public override bool IsPathFullyQualified(ReadOnlySpan path) /// public override bool IsPathFullyQualified(string path) { - using IDisposable register = Register(nameof(IsPathFullyQualified), + using IDisposable register = RegisterMethod(nameof(IsPathFullyQualified), path); return base.IsPathFullyQualified(path); @@ -352,7 +352,7 @@ public override bool IsPathFullyQualified(string path) /// public override bool IsPathRooted(ReadOnlySpan path) { - using IDisposable register = Register(nameof(IsPathRooted), + using IDisposable register = RegisterMethod(nameof(IsPathRooted), path); return base.IsPathRooted(path); @@ -362,7 +362,7 @@ public override bool IsPathRooted(ReadOnlySpan path) /// public override bool IsPathRooted(string? path) { - using IDisposable register = Register(nameof(IsPathRooted), + using IDisposable register = RegisterMethod(nameof(IsPathRooted), path); return base.IsPathRooted(path); @@ -372,7 +372,7 @@ public override bool IsPathRooted(string? path) /// public override string Join(ReadOnlySpan path1, ReadOnlySpan path2) { - using IDisposable register = Register(nameof(Join), + using IDisposable register = RegisterMethod(nameof(Join), path1, path2); return base.Join(path1, path2); @@ -383,7 +383,7 @@ public override string Join(ReadOnlySpan path1, ReadOnlySpan path2, ReadOnlySpan path3) { - using IDisposable register = Register(nameof(Join), + using IDisposable register = RegisterMethod(nameof(Join), path1, path2, path3); @@ -397,7 +397,7 @@ public override string Join(ReadOnlySpan path1, ReadOnlySpan path3, ReadOnlySpan path4) { - using IDisposable register = Register(nameof(Join), + using IDisposable register = RegisterMethod(nameof(Join), path1, path2, path3, @@ -409,7 +409,7 @@ public override string Join(ReadOnlySpan path1, /// public override string Join(string? path1, string? path2) { - using IDisposable register = Register(nameof(Join), + using IDisposable register = RegisterMethod(nameof(Join), path1, path2); return base.Join(path1, path2); @@ -418,7 +418,7 @@ public override string Join(string? path1, string? path2) /// public override string Join(string? path1, string? path2, string? path3) { - using IDisposable register = Register(nameof(Join), + using IDisposable register = RegisterMethod(nameof(Join), path1, path2, path3); return base.Join(path1, path2, path3); @@ -427,7 +427,7 @@ public override string Join(string? path1, string? path2, string? path3) /// public override string Join(string? path1, string? path2, string? path3, string? path4) { - using IDisposable register = Register(nameof(Join), + using IDisposable register = RegisterMethod(nameof(Join), path1, path2, path3, path4); return base.Join(path1, path2, path3, path4); @@ -436,7 +436,7 @@ public override string Join(string? path1, string? path2, string? path3, string? /// public override string Join(params string?[] paths) { - using IDisposable register = Register(nameof(Join), + using IDisposable register = RegisterMethod(nameof(Join), paths); return base.Join(paths); @@ -447,7 +447,7 @@ public override string Join(params string?[] paths) /// public override ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) { - using IDisposable register = Register(nameof(TrimEndingDirectorySeparator), + using IDisposable register = RegisterMethod(nameof(TrimEndingDirectorySeparator), path); return base.TrimEndingDirectorySeparator(path); @@ -456,7 +456,7 @@ public override ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan public override string TrimEndingDirectorySeparator(string path) { - using IDisposable register = Register(nameof(TrimEndingDirectorySeparator), + using IDisposable register = RegisterMethod(nameof(TrimEndingDirectorySeparator), path); return base.TrimEndingDirectorySeparator(path); @@ -513,34 +513,34 @@ public override bool TryJoin(ReadOnlySpan path1, } #endif - private IDisposable Register(string name) + private IDisposable RegisterMethod(string name) => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name); - private IDisposable Register(string name, T1 parameter1) + private IDisposable RegisterMethod(string name, T1 parameter1) => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); #if FEATURE_SPAN - private IDisposable Register(string name, ReadOnlySpan parameter1) + private IDisposable RegisterMethod(string name, ReadOnlySpan parameter1) => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1)); #endif #if FEATURE_PATH_ADVANCED - private IDisposable Register(string name, ReadOnlySpan parameter1, + private IDisposable RegisterMethod(string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2) => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); - private IDisposable Register(string name, ReadOnlySpan parameter1, + private IDisposable RegisterMethod(string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2, ReadOnlySpan parameter3) => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3)); - private IDisposable Register(string name, ReadOnlySpan parameter1, + private IDisposable RegisterMethod(string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2, ReadOnlySpan parameter3, ReadOnlySpan parameter4) => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), @@ -549,19 +549,19 @@ private IDisposable Register(string name, ReadOnlySpan param ParameterDescription.FromParameter(parameter4)); #endif - private IDisposable Register(string name, T1 parameter1, T2 parameter2) + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2) => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3) => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), ParameterDescription.FromParameter(parameter2), ParameterDescription.FromParameter(parameter3)); - private IDisposable Register(string name, T1 parameter1, T2 parameter2, + private IDisposable RegisterMethod(string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name, ParameterDescription.FromParameter(parameter1), diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoFactoryStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoFactoryStatisticsTests.cs index 5d735450a..2e0531a3a 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoFactoryStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoFactoryStatisticsTests.cs @@ -6,26 +6,26 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public sealed class DirectoryInfoFactoryStatisticsTests { [SkippableFact] - public void New_String_ShouldRegisterCall() + public void Method_New_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.DirectoryInfo.New(path); - sut.Statistics.DirectoryInfo.ShouldOnlyContain(nameof(IDirectoryInfoFactory.New), + sut.Statistics.DirectoryInfo.ShouldOnlyContainMethodCall(nameof(IDirectoryInfoFactory.New), path); } [SkippableFact] - public void Wrap_DirectoryInfo_ShouldRegisterCall() + public void Method_Wrap_DirectoryInfo_ShouldRegisterCall() { MockFileSystem sut = new(); DirectoryInfo directoryInfo = new("."); sut.DirectoryInfo.Wrap(directoryInfo); - sut.Statistics.DirectoryInfo.ShouldOnlyContain(nameof(IDirectoryInfoFactory.Wrap), + sut.Statistics.DirectoryInfo.ShouldOnlyContainMethodCall(nameof(IDirectoryInfoFactory.Wrap), directoryInfo); } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs index 0ba9ba0ca..6e12073b7 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs @@ -6,659 +6,711 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public sealed class DirectoryInfoStatisticsTests { [SkippableFact] - public void Attributes_Get_ShouldRegisterPropertyAccess() + public void Method_Create_ShouldRegisterCall() { MockFileSystem sut = new(); - _ = sut.DirectoryInfo.New("foo").Attributes; + sut.DirectoryInfo.New("foo").Create(); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Attributes)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.Create)); } +#if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void Attributes_Set_ShouldRegisterPropertyAccess() + public void Method_CreateAsSymbolicLink_String_ShouldRegisterCall() { MockFileSystem sut = new(); - FileAttributes value = new(); + string pathToTarget = "foo"; - sut.DirectoryInfo.New("foo").Attributes = value; + sut.DirectoryInfo.New("foo").CreateAsSymbolicLink(pathToTarget); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Attributes)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.CreateAsSymbolicLink), + pathToTarget); } +#endif [SkippableFact] - public void CreationTime_Get_ShouldRegisterPropertyAccess() + public void Method_CreateSubdirectory_String_ShouldRegisterCall() { MockFileSystem sut = new(); + string path = "foo"; - _ = sut.DirectoryInfo.New("foo").CreationTime; + sut.DirectoryInfo.New("foo").CreateSubdirectory(path); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTime)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.CreateSubdirectory), + path); } [SkippableFact] - public void CreationTime_Set_ShouldRegisterPropertyAccess() + public void Method_Delete_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); - DateTime value = new(); + sut.Initialize().WithSubdirectory("foo"); + bool recursive = true; - sut.DirectoryInfo.New("foo").CreationTime = value; + sut.DirectoryInfo.New("foo").Delete(recursive); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTime)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.Delete), + recursive); } [SkippableFact] - public void CreationTimeUtc_Get_ShouldRegisterPropertyAccess() + public void Method_Delete_ShouldRegisterCall() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); - _ = sut.DirectoryInfo.New("foo").CreationTimeUtc; + sut.DirectoryInfo.New("foo").Delete(); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTimeUtc)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.Delete)); } [SkippableFact] - public void CreationTimeUtc_Set_ShouldRegisterPropertyAccess() + public void Method_EnumerateDirectories_ShouldRegisterCall() { MockFileSystem sut = new(); - DateTime value = new(); - sut.DirectoryInfo.New("foo").CreationTimeUtc = value; + sut.DirectoryInfo.New("foo").EnumerateDirectories(); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTimeUtc)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateDirectories)); } +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void Exists_Get_ShouldRegisterPropertyAccess() + public void Method_EnumerateDirectories_String_EnumerationOptions_ShouldRegisterCall() { MockFileSystem sut = new(); + string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - _ = sut.DirectoryInfo.New("foo").Exists; + sut.DirectoryInfo.New("foo").EnumerateDirectories(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"] - .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Exists)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.EnumerateDirectories), + searchPattern, enumerationOptions); } +#endif [SkippableFact] - public void Extension_Get_ShouldRegisterPropertyAccess() + public void Method_EnumerateDirectories_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); + string searchPattern = "foo"; + SearchOption searchOption = SearchOption.AllDirectories; - _ = sut.DirectoryInfo.New("foo").Extension; + sut.DirectoryInfo.New("foo").EnumerateDirectories(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Extension)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.EnumerateDirectories), + searchPattern, searchOption); } [SkippableFact] - public void FullName_Get_ShouldRegisterPropertyAccess() + public void Method_EnumerateDirectories_String_ShouldRegisterCall() { MockFileSystem sut = new(); + string searchPattern = "foo"; - _ = sut.DirectoryInfo.New("foo").FullName; + sut.DirectoryInfo.New("foo").EnumerateDirectories(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.FullName)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.EnumerateDirectories), + searchPattern); } [SkippableFact] - public void LastAccessTime_Get_ShouldRegisterPropertyAccess() + public void Method_EnumerateFiles_ShouldRegisterCall() { MockFileSystem sut = new(); - _ = sut.DirectoryInfo.New("foo").LastAccessTime; + sut.DirectoryInfo.New("foo").EnumerateFiles(); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTime)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateFiles)); } +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void LastAccessTime_Set_ShouldRegisterPropertyAccess() + public void Method_EnumerateFiles_String_EnumerationOptions_ShouldRegisterCall() { MockFileSystem sut = new(); - DateTime value = new(); + string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - sut.DirectoryInfo.New("foo").LastAccessTime = value; + sut.DirectoryInfo.New("foo").EnumerateFiles(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTime)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.EnumerateFiles), + searchPattern, enumerationOptions); } +#endif [SkippableFact] - public void LastAccessTimeUtc_Get_ShouldRegisterPropertyAccess() + public void Method_EnumerateFiles_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); + string searchPattern = "foo"; + SearchOption searchOption = SearchOption.AllDirectories; - _ = sut.DirectoryInfo.New("foo").LastAccessTimeUtc; + sut.DirectoryInfo.New("foo").EnumerateFiles(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTimeUtc)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.EnumerateFiles), + searchPattern, searchOption); } [SkippableFact] - public void LastAccessTimeUtc_Set_ShouldRegisterPropertyAccess() + public void Method_EnumerateFiles_String_ShouldRegisterCall() { MockFileSystem sut = new(); - DateTime value = new(); + string searchPattern = "foo"; - sut.DirectoryInfo.New("foo").LastAccessTimeUtc = value; + sut.DirectoryInfo.New("foo").EnumerateFiles(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTimeUtc)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.EnumerateFiles), + searchPattern); } [SkippableFact] - public void LastWriteTime_Get_ShouldRegisterPropertyAccess() + public void Method_EnumerateFileSystemInfos_ShouldRegisterCall() { MockFileSystem sut = new(); - _ = sut.DirectoryInfo.New("foo").LastWriteTime; + sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTime)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateFileSystemInfos)); } +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void LastWriteTime_Set_ShouldRegisterPropertyAccess() + public void Method_EnumerateFileSystemInfos_String_EnumerationOptions_ShouldRegisterCall() { MockFileSystem sut = new(); - DateTime value = new(); + string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - sut.DirectoryInfo.New("foo").LastWriteTime = value; + sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTime)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.EnumerateFileSystemInfos), + searchPattern, enumerationOptions); } +#endif [SkippableFact] - public void LastWriteTimeUtc_Get_ShouldRegisterPropertyAccess() + public void Method_EnumerateFileSystemInfos_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); + string searchPattern = "foo"; + SearchOption searchOption = SearchOption.AllDirectories; - _ = sut.DirectoryInfo.New("foo").LastWriteTimeUtc; + sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTimeUtc)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.EnumerateFileSystemInfos), + searchPattern, searchOption); } [SkippableFact] - public void LastWriteTimeUtc_Set_ShouldRegisterPropertyAccess() + public void Method_EnumerateFileSystemInfos_String_ShouldRegisterCall() { MockFileSystem sut = new(); - DateTime value = new(); + string searchPattern = "foo"; - sut.DirectoryInfo.New("foo").LastWriteTimeUtc = value; + sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTimeUtc)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.EnumerateFileSystemInfos), + searchPattern); } -#if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void LinkTarget_Get_ShouldRegisterPropertyAccess() + public void Method_GetDirectories_ShouldRegisterCall() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); - _ = sut.DirectoryInfo.New("foo").LinkTarget; + sut.DirectoryInfo.New("foo").GetDirectories(); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LinkTarget)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetDirectories)); } -#endif +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void Name_Get_ShouldRegisterPropertyAccess() + public void Method_GetDirectories_String_EnumerationOptions_ShouldRegisterCall() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); + string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - _ = sut.DirectoryInfo.New("foo").Name; + sut.DirectoryInfo.New("foo").GetDirectories(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Name)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.GetDirectories), + searchPattern, enumerationOptions); } +#endif [SkippableFact] - public void Parent_Get_ShouldRegisterPropertyAccess() + public void Method_GetDirectories_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); + string searchPattern = "foo"; + SearchOption searchOption = SearchOption.AllDirectories; - _ = sut.DirectoryInfo.New("foo").Parent; + sut.DirectoryInfo.New("foo").GetDirectories(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Parent)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.GetDirectories), + searchPattern, searchOption); } [SkippableFact] - public void Root_Get_ShouldRegisterPropertyAccess() + public void Method_GetDirectories_String_ShouldRegisterCall() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); + string searchPattern = "foo"; - _ = sut.DirectoryInfo.New("foo").Root; + sut.DirectoryInfo.New("foo").GetDirectories(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Root)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.GetDirectories), + searchPattern); } -#if FEATURE_FILESYSTEM_UNIXFILEMODE [SkippableFact] - public void UnixFileMode_Get_ShouldRegisterPropertyAccess() + public void Method_GetFiles_ShouldRegisterCall() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); - _ = sut.DirectoryInfo.New("foo").UnixFileMode; + sut.DirectoryInfo.New("foo").GetFiles(); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.UnixFileMode)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetFiles)); } +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void UnixFileMode_Set_ShouldRegisterPropertyAccess() + public void Method_GetFiles_String_EnumerationOptions_ShouldRegisterCall() { - Skip.If(Test.RunsOnWindows); - MockFileSystem sut = new(); - UnixFileMode value = new(); + sut.Initialize().WithSubdirectory("foo"); + string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - #pragma warning disable CA1416 - sut.DirectoryInfo.New("foo").UnixFileMode = value; - #pragma warning restore CA1416 + sut.DirectoryInfo.New("foo").GetFiles(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.UnixFileMode)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.GetFiles), + searchPattern, enumerationOptions); } #endif - [SkippableFact] - public void Create_ShouldRegisterCall() + public void Method_GetFiles_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); + string searchPattern = "foo"; + SearchOption searchOption = SearchOption.AllDirectories; - sut.DirectoryInfo.New("foo").Create(); + sut.DirectoryInfo.New("foo").GetFiles(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.Create)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.GetFiles), + searchPattern, searchOption); } -#if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void CreateAsSymbolicLink_String_ShouldRegisterCall() + public void Method_GetFiles_String_ShouldRegisterCall() { MockFileSystem sut = new(); - string pathToTarget = "foo"; + sut.Initialize().WithSubdirectory("foo"); + string searchPattern = "foo"; - sut.DirectoryInfo.New("foo").CreateAsSymbolicLink(pathToTarget); + sut.DirectoryInfo.New("foo").GetFiles(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.CreateAsSymbolicLink), - pathToTarget); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.GetFiles), + searchPattern); } -#endif [SkippableFact] - public void CreateSubdirectory_String_ShouldRegisterCall() + public void Method_GetFileSystemInfos_ShouldRegisterCall() { MockFileSystem sut = new(); - string path = "foo"; + sut.Initialize().WithSubdirectory("foo"); - sut.DirectoryInfo.New("foo").CreateSubdirectory(path); + sut.DirectoryInfo.New("foo").GetFileSystemInfos(); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.CreateSubdirectory), - path); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetFileSystemInfos)); } +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void Delete_ShouldRegisterCall() + public void Method_GetFileSystemInfos_String_EnumerationOptions_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); + string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - sut.DirectoryInfo.New("foo").Delete(); + sut.DirectoryInfo.New("foo").GetFileSystemInfos(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.Delete)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.GetFileSystemInfos), + searchPattern, enumerationOptions); } +#endif [SkippableFact] - public void Delete_Bool_ShouldRegisterCall() + public void Method_GetFileSystemInfos_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); - bool recursive = true; + string searchPattern = "foo"; + SearchOption searchOption = SearchOption.AllDirectories; - sut.DirectoryInfo.New("foo").Delete(recursive); + sut.DirectoryInfo.New("foo").GetFileSystemInfos(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.Delete), - recursive); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.GetFileSystemInfos), + searchPattern, searchOption); } [SkippableFact] - public void EnumerateDirectories_ShouldRegisterCall() + public void Method_GetFileSystemInfos_String_ShouldRegisterCall() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); + string searchPattern = "foo"; - sut.DirectoryInfo.New("foo").EnumerateDirectories(); + sut.DirectoryInfo.New("foo").GetFileSystemInfos(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateDirectories)); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.GetFileSystemInfos), + searchPattern); } [SkippableFact] - public void EnumerateDirectories_String_ShouldRegisterCall() + public void Method_MoveTo_String_ShouldRegisterCall() { MockFileSystem sut = new(); - string searchPattern = "foo"; + sut.Initialize().WithSubdirectory("foo"); + string destDirName = "bar"; - sut.DirectoryInfo.New("foo").EnumerateDirectories(searchPattern); + sut.DirectoryInfo.New("foo").MoveTo(destDirName); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateDirectories), - searchPattern); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.MoveTo), + destDirName); } [SkippableFact] - public void EnumerateDirectories_String_SearchOption_ShouldRegisterCall() + public void Method_Refresh_ShouldRegisterCall() { MockFileSystem sut = new(); - string searchPattern = "foo"; - SearchOption searchOption = SearchOption.AllDirectories; - sut.DirectoryInfo.New("foo").EnumerateDirectories(searchPattern, searchOption); + sut.DirectoryInfo.New("foo").Refresh(); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateDirectories), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.Refresh)); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS +#if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void EnumerateDirectories_String_EnumerationOptions_ShouldRegisterCall() + public void Method_ResolveLinkTarget_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); - string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); + bool returnFinalTarget = true; - sut.DirectoryInfo.New("foo").EnumerateDirectories(searchPattern, enumerationOptions); + sut.DirectoryInfo.New("foo").ResolveLinkTarget(returnFinalTarget); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateDirectories), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IDirectoryInfo.ResolveLinkTarget), + returnFinalTarget); } #endif - [SkippableFact] - public void EnumerateFiles_ShouldRegisterCall() + public void Property_Attributes_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.DirectoryInfo.New("foo").EnumerateFiles(); + _ = sut.DirectoryInfo.New("foo").Attributes; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateFiles)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Attributes)); } [SkippableFact] - public void EnumerateFiles_String_ShouldRegisterCall() + public void Property_Attributes_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - string searchPattern = "foo"; + FileAttributes value = new(); - sut.DirectoryInfo.New("foo").EnumerateFiles(searchPattern); + sut.DirectoryInfo.New("foo").Attributes = value; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateFiles), - searchPattern); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Attributes)); } [SkippableFact] - public void EnumerateFiles_String_SearchOption_ShouldRegisterCall() + public void Property_CreationTime_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - string searchPattern = "foo"; - SearchOption searchOption = SearchOption.AllDirectories; - sut.DirectoryInfo.New("foo").EnumerateFiles(searchPattern, searchOption); + _ = sut.DirectoryInfo.New("foo").CreationTime; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateFiles), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTime)); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void EnumerateFiles_String_EnumerationOptions_ShouldRegisterCall() + public void Property_CreationTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); + DateTime value = new(); - sut.DirectoryInfo.New("foo").EnumerateFiles(searchPattern, enumerationOptions); + sut.DirectoryInfo.New("foo").CreationTime = value; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateFiles), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTime)); } -#endif [SkippableFact] - public void EnumerateFileSystemInfos_ShouldRegisterCall() + public void Property_CreationTimeUtc_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(); + _ = sut.DirectoryInfo.New("foo").CreationTimeUtc; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateFileSystemInfos)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTimeUtc)); } [SkippableFact] - public void EnumerateFileSystemInfos_String_ShouldRegisterCall() + public void Property_CreationTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - string searchPattern = "foo"; + DateTime value = new(); - sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(searchPattern); + sut.DirectoryInfo.New("foo").CreationTimeUtc = value; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateFileSystemInfos), - searchPattern); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTimeUtc)); } [SkippableFact] - public void EnumerateFileSystemInfos_String_SearchOption_ShouldRegisterCall() + public void Property_Exists_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - string searchPattern = "foo"; - SearchOption searchOption = SearchOption.AllDirectories; - sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(searchPattern, searchOption); + _ = sut.DirectoryInfo.New("foo").Exists; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateFileSystemInfos), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Exists)); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void EnumerateFileSystemInfos_String_EnumerationOptions_ShouldRegisterCall() + public void Property_Extension_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); - sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(searchPattern, enumerationOptions); + _ = sut.DirectoryInfo.New("foo").Extension; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.EnumerateFileSystemInfos), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Extension)); } -#endif [SkippableFact] - public void GetDirectories_ShouldRegisterCall() + public void Property_FullName_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); - sut.DirectoryInfo.New("foo").GetDirectories(); + _ = sut.DirectoryInfo.New("foo").FullName; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetDirectories)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.FullName)); } [SkippableFact] - public void GetDirectories_String_ShouldRegisterCall() + public void Property_LastAccessTime_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); - string searchPattern = "foo"; - sut.DirectoryInfo.New("foo").GetDirectories(searchPattern); + _ = sut.DirectoryInfo.New("foo").LastAccessTime; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetDirectories), - searchPattern); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTime)); } [SkippableFact] - public void GetDirectories_String_SearchOption_ShouldRegisterCall() + public void Property_LastAccessTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); - string searchPattern = "foo"; - SearchOption searchOption = SearchOption.AllDirectories; + DateTime value = new(); - sut.DirectoryInfo.New("foo").GetDirectories(searchPattern, searchOption); + sut.DirectoryInfo.New("foo").LastAccessTime = value; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetDirectories), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTime)); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void GetDirectories_String_EnumerationOptions_ShouldRegisterCall() + public void Property_LastAccessTimeUtc_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); - string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); - sut.DirectoryInfo.New("foo").GetDirectories(searchPattern, enumerationOptions); + _ = sut.DirectoryInfo.New("foo").LastAccessTimeUtc; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetDirectories), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTimeUtc)); } -#endif [SkippableFact] - public void GetFiles_ShouldRegisterCall() + public void Property_LastAccessTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); + DateTime value = new(); - sut.DirectoryInfo.New("foo").GetFiles(); + sut.DirectoryInfo.New("foo").LastAccessTimeUtc = value; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetFiles)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTimeUtc)); } [SkippableFact] - public void GetFiles_String_ShouldRegisterCall() + public void Property_LastWriteTime_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); - string searchPattern = "foo"; - sut.DirectoryInfo.New("foo").GetFiles(searchPattern); + _ = sut.DirectoryInfo.New("foo").LastWriteTime; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetFiles), - searchPattern); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTime)); } [SkippableFact] - public void GetFiles_String_SearchOption_ShouldRegisterCall() + public void Property_LastWriteTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); - string searchPattern = "foo"; - SearchOption searchOption = SearchOption.AllDirectories; + DateTime value = new(); - sut.DirectoryInfo.New("foo").GetFiles(searchPattern, searchOption); + sut.DirectoryInfo.New("foo").LastWriteTime = value; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetFiles), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTime)); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void GetFiles_String_EnumerationOptions_ShouldRegisterCall() + public void Property_LastWriteTimeUtc_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); - string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); - sut.DirectoryInfo.New("foo").GetFiles(searchPattern, enumerationOptions); + _ = sut.DirectoryInfo.New("foo").LastWriteTimeUtc; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetFiles), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTimeUtc)); } -#endif [SkippableFact] - public void GetFileSystemInfos_ShouldRegisterCall() + public void Property_LastWriteTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); + DateTime value = new(); - sut.DirectoryInfo.New("foo").GetFileSystemInfos(); + sut.DirectoryInfo.New("foo").LastWriteTimeUtc = value; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetFileSystemInfos)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTimeUtc)); } +#if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void GetFileSystemInfos_String_ShouldRegisterCall() + public void Property_LinkTarget_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); - string searchPattern = "foo"; - sut.DirectoryInfo.New("foo").GetFileSystemInfos(searchPattern); + _ = sut.DirectoryInfo.New("foo").LinkTarget; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetFileSystemInfos), - searchPattern); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LinkTarget)); } +#endif [SkippableFact] - public void GetFileSystemInfos_String_SearchOption_ShouldRegisterCall() + public void Property_Name_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); - string searchPattern = "foo"; - SearchOption searchOption = SearchOption.AllDirectories; - sut.DirectoryInfo.New("foo").GetFileSystemInfos(searchPattern, searchOption); + _ = sut.DirectoryInfo.New("foo").Name; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetFileSystemInfos), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Name)); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void GetFileSystemInfos_String_EnumerationOptions_ShouldRegisterCall() + public void Property_Parent_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); - string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); - sut.DirectoryInfo.New("foo").GetFileSystemInfos(searchPattern, enumerationOptions); + _ = sut.DirectoryInfo.New("foo").Parent; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.GetFileSystemInfos), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Parent)); } -#endif [SkippableFact] - public void MoveTo_String_ShouldRegisterCall() + public void Property_Root_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.Initialize().WithSubdirectory("foo"); - string destDirName = "bar"; - sut.DirectoryInfo.New("foo").MoveTo(destDirName); + _ = sut.DirectoryInfo.New("foo").Root; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.MoveTo), - destDirName); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Root)); } +#if FEATURE_FILESYSTEM_UNIXFILEMODE [SkippableFact] - public void Refresh_ShouldRegisterCall() + public void Property_UnixFileMode_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - sut.DirectoryInfo.New("foo").Refresh(); + _ = sut.DirectoryInfo.New("foo").UnixFileMode; - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.Refresh)); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.UnixFileMode)); } -#if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void ResolveLinkTarget_Bool_ShouldRegisterCall() + public void Property_UnixFileMode_Set_ShouldRegisterPropertyAccess() { + Skip.If(Test.RunsOnWindows); + MockFileSystem sut = new(); - bool returnFinalTarget = true; + UnixFileMode value = new(); - sut.DirectoryInfo.New("foo").ResolveLinkTarget(returnFinalTarget); + #pragma warning disable CA1416 + sut.DirectoryInfo.New("foo").UnixFileMode = value; + #pragma warning restore CA1416 - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContain(nameof(IDirectoryInfo.ResolveLinkTarget), - returnFinalTarget); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.UnixFileMode)); } #endif } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryStatisticsTests.cs index 3f31e681d..164d4b2a4 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryStatisticsTests.cs @@ -6,20 +6,20 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public sealed class DirectoryStatisticsTests { [Fact] - public void CreateDirectory_String_ShouldRegisterCall() + public void Method_CreateDirectory_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.CreateDirectory(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.CreateDirectory), + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.CreateDirectory), path); } #if FEATURE_FILESYSTEM_UNIXFILEMODE [SkippableFact] - public void CreateDirectory_String_UnixFileMode_ShouldRegisterCall() + public void Method_CreateDirectory_String_UnixFileMode_ShouldRegisterCall() { Skip.If(!Test.RunsOnLinux); @@ -29,14 +29,14 @@ public void CreateDirectory_String_UnixFileMode_ShouldRegisterCall() sut.Directory.CreateDirectory(path, unixCreateMode); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.CreateDirectory), + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.CreateDirectory), path, unixCreateMode); } #endif #if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void CreateSymbolicLink_String_String_ShouldRegisterCall() + public void Method_CreateSymbolicLink_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -44,79 +44,85 @@ public void CreateSymbolicLink_String_String_ShouldRegisterCall() sut.Directory.CreateSymbolicLink(path, pathToTarget); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.CreateSymbolicLink), - path, pathToTarget); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.CreateSymbolicLink), + path, pathToTarget); } #endif #if FEATURE_FILESYSTEM_NET7 [SkippableFact] - public void CreateTempSubdirectory_String_ShouldRegisterCall() + public void Method_CreateTempSubdirectory_String_ShouldRegisterCall() { MockFileSystem sut = new(); string prefix = "foo"; sut.Directory.CreateTempSubdirectory(prefix); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.CreateTempSubdirectory), - prefix); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.CreateTempSubdirectory), + prefix); } #endif [SkippableFact] - public void Delete_String_ShouldRegisterCall() + public void Method_Delete_String_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); string path = "foo"; + bool recursive = true; - sut.Directory.Delete(path); + sut.Directory.Delete(path, recursive); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.Delete), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.Delete), + path, recursive); } [SkippableFact] - public void Delete_String_Bool_ShouldRegisterCall() + public void Method_Delete_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); string path = "foo"; - bool recursive = true; - sut.Directory.Delete(path, recursive); + sut.Directory.Delete(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.Delete), - path, recursive); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.Delete), + path); } [SkippableFact] - public void EnumerateDirectories_String_ShouldRegisterCall() + public void Method_EnumerateDirectories_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.EnumerateDirectories(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateDirectories), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.EnumerateDirectories), + path); } +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void EnumerateDirectories_String_String_ShouldRegisterCall() + public void Method_EnumerateDirectories_String_String_EnumerationOptions_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - sut.Directory.EnumerateDirectories(path, searchPattern); + sut.Directory.EnumerateDirectories(path, searchPattern, enumerationOptions); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateDirectories), - path, searchPattern); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.EnumerateDirectories), + path, searchPattern, enumerationOptions); } +#endif [SkippableFact] - public void EnumerateDirectories_String_String_SearchOption_ShouldRegisterCall() + public void Method_EnumerateDirectories_String_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -125,53 +131,55 @@ public void EnumerateDirectories_String_String_SearchOption_ShouldRegisterCall() sut.Directory.EnumerateDirectories(path, searchPattern, searchOption); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateDirectories), - path, searchPattern, searchOption); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.EnumerateDirectories), + path, searchPattern, searchOption); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void EnumerateDirectories_String_String_EnumerationOptions_ShouldRegisterCall() + public void Method_EnumerateDirectories_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); - sut.Directory.EnumerateDirectories(path, searchPattern, enumerationOptions); + sut.Directory.EnumerateDirectories(path, searchPattern); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateDirectories), - path, searchPattern, enumerationOptions); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.EnumerateDirectories), + path, searchPattern); } -#endif [SkippableFact] - public void EnumerateFiles_String_ShouldRegisterCall() + public void Method_EnumerateFiles_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.EnumerateFiles(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateFiles), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.EnumerateFiles), + path); } +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void EnumerateFiles_String_String_ShouldRegisterCall() + public void Method_EnumerateFiles_String_String_EnumerationOptions_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - sut.Directory.EnumerateFiles(path, searchPattern); + sut.Directory.EnumerateFiles(path, searchPattern, enumerationOptions); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateFiles), - path, searchPattern); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.EnumerateFiles), + path, searchPattern, enumerationOptions); } +#endif [SkippableFact] - public void EnumerateFiles_String_String_SearchOption_ShouldRegisterCall() + public void Method_EnumerateFiles_String_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -180,53 +188,56 @@ public void EnumerateFiles_String_String_SearchOption_ShouldRegisterCall() sut.Directory.EnumerateFiles(path, searchPattern, searchOption); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateFiles), - path, searchPattern, searchOption); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.EnumerateFiles), + path, searchPattern, searchOption); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void EnumerateFiles_String_String_EnumerationOptions_ShouldRegisterCall() + public void Method_EnumerateFiles_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); - sut.Directory.EnumerateFiles(path, searchPattern, enumerationOptions); + sut.Directory.EnumerateFiles(path, searchPattern); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateFiles), - path, searchPattern, enumerationOptions); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.EnumerateFiles), + path, searchPattern); } -#endif [SkippableFact] - public void EnumerateFileSystemEntries_String_ShouldRegisterCall() + public void Method_EnumerateFileSystemEntries_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.EnumerateFileSystemEntries(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateFileSystemEntries), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.EnumerateFileSystemEntries), + path); } +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void EnumerateFileSystemEntries_String_String_ShouldRegisterCall() + public void + Method_EnumerateFileSystemEntries_String_String_EnumerationOptions_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - sut.Directory.EnumerateFileSystemEntries(path, searchPattern); + sut.Directory.EnumerateFileSystemEntries(path, searchPattern, enumerationOptions); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateFileSystemEntries), - path, searchPattern); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.EnumerateFileSystemEntries), + path, searchPattern, enumerationOptions); } +#endif [SkippableFact] - public void EnumerateFileSystemEntries_String_String_SearchOption_ShouldRegisterCall() + public void Method_EnumerateFileSystemEntries_String_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -235,74 +246,74 @@ public void EnumerateFileSystemEntries_String_String_SearchOption_ShouldRegister sut.Directory.EnumerateFileSystemEntries(path, searchPattern, searchOption); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateFileSystemEntries), - path, searchPattern, searchOption); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.EnumerateFileSystemEntries), + path, searchPattern, searchOption); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void EnumerateFileSystemEntries_String_String_EnumerationOptions_ShouldRegisterCall() + public void Method_EnumerateFileSystemEntries_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); - sut.Directory.EnumerateFileSystemEntries(path, searchPattern, enumerationOptions); + sut.Directory.EnumerateFileSystemEntries(path, searchPattern); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.EnumerateFileSystemEntries), - path, searchPattern, enumerationOptions); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.EnumerateFileSystemEntries), + path, searchPattern); } -#endif [SkippableFact] - public void Exists_String_ShouldRegisterCall() + public void Method_Exists_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.Exists(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.Exists), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.Exists), + path); } [SkippableFact] - public void GetCreationTime_String_ShouldRegisterCall() + public void Method_GetCreationTime_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.GetCreationTime(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetCreationTime), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetCreationTime), + path); } [SkippableFact] - public void GetCreationTimeUtc_String_ShouldRegisterCall() + public void Method_GetCreationTimeUtc_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.GetCreationTimeUtc(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetCreationTimeUtc), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetCreationTimeUtc), + path); } [SkippableFact] - public void GetCurrentDirectory_ShouldRegisterCall() + public void Method_GetCurrentDirectory_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Directory.GetCurrentDirectory(); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetCurrentDirectory)); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.GetCurrentDirectory)); } [SkippableFact] - public void GetDirectories_String_ShouldRegisterCall() + public void Method_GetDirectories_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -310,26 +321,29 @@ public void GetDirectories_String_ShouldRegisterCall() sut.Directory.GetDirectories(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetDirectories), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetDirectories), + path); } +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void GetDirectories_String_String_ShouldRegisterCall() + public void Method_GetDirectories_String_String_EnumerationOptions_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); string path = "foo"; string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - sut.Directory.GetDirectories(path, searchPattern); + sut.Directory.GetDirectories(path, searchPattern, enumerationOptions); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetDirectories), - path, searchPattern); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetDirectories), + path, searchPattern, enumerationOptions); } +#endif [SkippableFact] - public void GetDirectories_String_String_SearchOption_ShouldRegisterCall() + public void Method_GetDirectories_String_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -339,41 +353,38 @@ public void GetDirectories_String_String_SearchOption_ShouldRegisterCall() sut.Directory.GetDirectories(path, searchPattern, searchOption); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetDirectories), - path, searchPattern, searchOption); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetDirectories), + path, searchPattern, searchOption); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void GetDirectories_String_String_EnumerationOptions_ShouldRegisterCall() + public void Method_GetDirectories_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); string path = "foo"; string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); - sut.Directory.GetDirectories(path, searchPattern, enumerationOptions); + sut.Directory.GetDirectories(path, searchPattern); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetDirectories), - path, searchPattern, enumerationOptions); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetDirectories), + path, searchPattern); } -#endif [SkippableFact] - public void GetDirectoryRoot_String_ShouldRegisterCall() + public void Method_GetDirectoryRoot_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.GetDirectoryRoot(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetDirectoryRoot), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetDirectoryRoot), + path); } [SkippableFact] - public void GetFiles_String_ShouldRegisterCall() + public void Method_GetFiles_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -381,26 +392,29 @@ public void GetFiles_String_ShouldRegisterCall() sut.Directory.GetFiles(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetFiles), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetFiles), + path); } +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void GetFiles_String_String_ShouldRegisterCall() + public void Method_GetFiles_String_String_EnumerationOptions_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); string path = "foo"; string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - sut.Directory.GetFiles(path, searchPattern); + sut.Directory.GetFiles(path, searchPattern, enumerationOptions); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetFiles), - path, searchPattern); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetFiles), + path, searchPattern, enumerationOptions); } +#endif [SkippableFact] - public void GetFiles_String_String_SearchOption_ShouldRegisterCall() + public void Method_GetFiles_String_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -410,29 +424,26 @@ public void GetFiles_String_String_SearchOption_ShouldRegisterCall() sut.Directory.GetFiles(path, searchPattern, searchOption); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetFiles), - path, searchPattern, searchOption); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetFiles), + path, searchPattern, searchOption); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void GetFiles_String_String_EnumerationOptions_ShouldRegisterCall() + public void Method_GetFiles_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); string path = "foo"; string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); - sut.Directory.GetFiles(path, searchPattern, enumerationOptions); + sut.Directory.GetFiles(path, searchPattern); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetFiles), - path, searchPattern, enumerationOptions); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetFiles), + path, searchPattern); } -#endif [SkippableFact] - public void GetFileSystemEntries_String_ShouldRegisterCall() + public void Method_GetFileSystemEntries_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -440,26 +451,31 @@ public void GetFileSystemEntries_String_ShouldRegisterCall() sut.Directory.GetFileSystemEntries(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetFileSystemEntries), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.GetFileSystemEntries), + path); } +#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void GetFileSystemEntries_String_String_ShouldRegisterCall() + public void Method_GetFileSystemEntries_String_String_EnumerationOptions_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); string path = "foo"; string searchPattern = "foo"; + EnumerationOptions enumerationOptions = new(); - sut.Directory.GetFileSystemEntries(path, searchPattern); + sut.Directory.GetFileSystemEntries(path, searchPattern, enumerationOptions); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetFileSystemEntries), - path, searchPattern); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.GetFileSystemEntries), + path, searchPattern, enumerationOptions); } +#endif [SkippableFact] - public void GetFileSystemEntries_String_String_SearchOption_ShouldRegisterCall() + public void Method_GetFileSystemEntries_String_String_SearchOption_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -469,99 +485,99 @@ public void GetFileSystemEntries_String_String_SearchOption_ShouldRegisterCall() sut.Directory.GetFileSystemEntries(path, searchPattern, searchOption); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetFileSystemEntries), - path, searchPattern, searchOption); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.GetFileSystemEntries), + path, searchPattern, searchOption); } -#if FEATURE_FILESYSTEM_ENUMERATION_OPTIONS [SkippableFact] - public void GetFileSystemEntries_String_String_EnumerationOptions_ShouldRegisterCall() + public void Method_GetFileSystemEntries_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); string path = "foo"; string searchPattern = "foo"; - EnumerationOptions enumerationOptions = new(); - sut.Directory.GetFileSystemEntries(path, searchPattern, enumerationOptions); + sut.Directory.GetFileSystemEntries(path, searchPattern); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetFileSystemEntries), - path, searchPattern, enumerationOptions); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.GetFileSystemEntries), + path, searchPattern); } -#endif [SkippableFact] - public void GetLastAccessTime_String_ShouldRegisterCall() + public void Method_GetLastAccessTime_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.GetLastAccessTime(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetLastAccessTime), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetLastAccessTime), + path); } [SkippableFact] - public void GetLastAccessTimeUtc_String_ShouldRegisterCall() + public void Method_GetLastAccessTimeUtc_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.GetLastAccessTimeUtc(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetLastAccessTimeUtc), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.GetLastAccessTimeUtc), + path); } [SkippableFact] - public void GetLastWriteTime_String_ShouldRegisterCall() + public void Method_GetLastWriteTime_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.GetLastWriteTime(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetLastWriteTime), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetLastWriteTime), + path); } [SkippableFact] - public void GetLastWriteTimeUtc_String_ShouldRegisterCall() + public void Method_GetLastWriteTimeUtc_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.GetLastWriteTimeUtc(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetLastWriteTimeUtc), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetLastWriteTimeUtc), + path); } [SkippableFact] - public void GetLogicalDrives_ShouldRegisterCall() + public void Method_GetLogicalDrives_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Directory.GetLogicalDrives(); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetLogicalDrives)); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetLogicalDrives)); } [SkippableFact] - public void GetParent_String_ShouldRegisterCall() + public void Method_GetParent_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Directory.GetParent(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.GetParent), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.GetParent), + path); } [SkippableFact] - public void Move_String_String_ShouldRegisterCall() + public void Method_Move_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -570,13 +586,13 @@ public void Move_String_String_ShouldRegisterCall() sut.Directory.Move(sourceDirName, destDirName); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.Move), - sourceDirName, destDirName); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.Move), + sourceDirName, destDirName); } #if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void ResolveLinkTarget_String_Bool_ShouldRegisterCall() + public void Method_ResolveLinkTarget_String_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); string linkPath = "foo"; @@ -584,13 +600,13 @@ public void ResolveLinkTarget_String_Bool_ShouldRegisterCall() sut.Directory.ResolveLinkTarget(linkPath, returnFinalTarget); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.ResolveLinkTarget), - linkPath, returnFinalTarget); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.ResolveLinkTarget), + linkPath, returnFinalTarget); } #endif [SkippableFact] - public void SetCreationTime_String_DateTime_ShouldRegisterCall() + public void Method_SetCreationTime_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -599,12 +615,12 @@ public void SetCreationTime_String_DateTime_ShouldRegisterCall() sut.Directory.SetCreationTime(path, creationTime); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.SetCreationTime), - path, creationTime); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.SetCreationTime), + path, creationTime); } [SkippableFact] - public void SetCreationTimeUtc_String_DateTime_ShouldRegisterCall() + public void Method_SetCreationTimeUtc_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -613,12 +629,12 @@ public void SetCreationTimeUtc_String_DateTime_ShouldRegisterCall() sut.Directory.SetCreationTimeUtc(path, creationTimeUtc); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.SetCreationTimeUtc), - path, creationTimeUtc); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.SetCreationTimeUtc), + path, creationTimeUtc); } [SkippableFact] - public void SetCurrentDirectory_String_ShouldRegisterCall() + public void Method_SetCurrentDirectory_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -626,12 +642,12 @@ public void SetCurrentDirectory_String_ShouldRegisterCall() sut.Directory.SetCurrentDirectory(path); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.SetCurrentDirectory), - path); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.SetCurrentDirectory), + path); } [SkippableFact] - public void SetLastAccessTime_String_DateTime_ShouldRegisterCall() + public void Method_SetLastAccessTime_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -640,12 +656,12 @@ public void SetLastAccessTime_String_DateTime_ShouldRegisterCall() sut.Directory.SetLastAccessTime(path, lastAccessTime); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.SetLastAccessTime), - path, lastAccessTime); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.SetLastAccessTime), + path, lastAccessTime); } [SkippableFact] - public void SetLastAccessTimeUtc_String_DateTime_ShouldRegisterCall() + public void Method_SetLastAccessTimeUtc_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -654,12 +670,13 @@ public void SetLastAccessTimeUtc_String_DateTime_ShouldRegisterCall() sut.Directory.SetLastAccessTimeUtc(path, lastAccessTimeUtc); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.SetLastAccessTimeUtc), - path, lastAccessTimeUtc); + sut.Statistics.Directory.ShouldOnlyContainMethodCall( + nameof(IDirectory.SetLastAccessTimeUtc), + path, lastAccessTimeUtc); } [SkippableFact] - public void SetLastWriteTime_String_DateTime_ShouldRegisterCall() + public void Method_SetLastWriteTime_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -668,12 +685,12 @@ public void SetLastWriteTime_String_DateTime_ShouldRegisterCall() sut.Directory.SetLastWriteTime(path, lastWriteTime); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.SetLastWriteTime), - path, lastWriteTime); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.SetLastWriteTime), + path, lastWriteTime); } [SkippableFact] - public void SetLastWriteTimeUtc_String_DateTime_ShouldRegisterCall() + public void Method_SetLastWriteTimeUtc_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -682,7 +699,7 @@ public void SetLastWriteTimeUtc_String_DateTime_ShouldRegisterCall() sut.Directory.SetLastWriteTimeUtc(path, lastWriteTimeUtc); - sut.Statistics.Directory.ShouldOnlyContain(nameof(IDirectory.SetLastWriteTimeUtc), - path, lastWriteTimeUtc); + sut.Statistics.Directory.ShouldOnlyContainMethodCall(nameof(IDirectory.SetLastWriteTimeUtc), + path, lastWriteTimeUtc); } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoFactoryStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoFactoryStatisticsTests.cs index 5db723257..cda25b165 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoFactoryStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoFactoryStatisticsTests.cs @@ -7,36 +7,36 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public sealed class DriveInfoFactoryStatisticsTests { [SkippableFact] - public void GetDrives_ShouldRegisterCall() + public void Method_GetDrives_ShouldRegisterCall() { MockFileSystem sut = new(); sut.DriveInfo.GetDrives(); - sut.Statistics.DriveInfo.ShouldOnlyContain(nameof(IDriveInfoFactory.GetDrives)); + sut.Statistics.DriveInfo.ShouldOnlyContainMethodCall(nameof(IDriveInfoFactory.GetDrives)); } [SkippableFact] - public void New_String_ShouldRegisterCall() + public void Method_New_String_ShouldRegisterCall() { MockFileSystem sut = new(); string driveName = "X"; sut.DriveInfo.New(driveName); - sut.Statistics.DriveInfo.ShouldOnlyContain(nameof(IDriveInfoFactory.New), + sut.Statistics.DriveInfo.ShouldOnlyContainMethodCall(nameof(IDriveInfoFactory.New), driveName); } [SkippableFact] - public void Wrap_DriveInfo_ShouldRegisterCall() + public void Method_Wrap_DriveInfo_ShouldRegisterCall() { MockFileSystem sut = new(); DriveInfo driveInfo = DriveInfo.GetDrives().First(); sut.DriveInfo.Wrap(driveInfo); - sut.Statistics.DriveInfo.ShouldOnlyContain(nameof(IDriveInfoFactory.Wrap), + sut.Statistics.DriveInfo.ShouldOnlyContainMethodCall(nameof(IDriveInfoFactory.Wrap), driveInfo); } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs index 89e13ff71..1f27d9fe0 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs @@ -5,47 +5,51 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public sealed class DriveInfoStatisticsTests { [SkippableFact] - public void AvailableFreeSpace_Get_ShouldRegisterPropertyAccess() + public void Property_AvailableFreeSpace_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").AvailableFreeSpace; - sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.AvailableFreeSpace)); + sut.Statistics.DriveInfo["F:"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.AvailableFreeSpace)); } [SkippableFact] - public void DriveFormat_Get_ShouldRegisterPropertyAccess() + public void Property_DriveFormat_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").DriveFormat; - sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.DriveFormat)); + sut.Statistics.DriveInfo["F:"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.DriveFormat)); } [SkippableFact] - public void DriveType_Get_ShouldRegisterPropertyAccess() + public void Property_DriveType_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").DriveType; - sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.DriveType)); + sut.Statistics.DriveInfo["F:"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.DriveType)); } [SkippableFact] - public void IsReady_Get_ShouldRegisterPropertyAccess() + public void Property_IsReady_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").IsReady; - sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.IsReady)); + sut.Statistics.DriveInfo["F:"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.IsReady)); } [SkippableFact] - public void Name_Get_ShouldRegisterPropertyAccess() + public void Property_Name_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); @@ -55,47 +59,51 @@ public void Name_Get_ShouldRegisterPropertyAccess() } [SkippableFact] - public void RootDirectory_Get_ShouldRegisterPropertyAccess() + public void Property_RootDirectory_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").RootDirectory; - sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.RootDirectory)); + sut.Statistics.DriveInfo["F:"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.RootDirectory)); } [SkippableFact] - public void TotalFreeSpace_Get_ShouldRegisterPropertyAccess() + public void Property_TotalFreeSpace_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").TotalFreeSpace; - sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.TotalFreeSpace)); + sut.Statistics.DriveInfo["F:"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.TotalFreeSpace)); } [SkippableFact] - public void TotalSize_Get_ShouldRegisterPropertyAccess() + public void Property_TotalSize_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").TotalSize; - sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.TotalSize)); + sut.Statistics.DriveInfo["F:"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.TotalSize)); } [SkippableFact] - public void VolumeLabel_Get_ShouldRegisterPropertyAccess() + public void Property_VolumeLabel_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").VolumeLabel; - sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.VolumeLabel)); + sut.Statistics.DriveInfo["F:"] + .ShouldOnlyContainPropertyGetAccess(nameof(IDriveInfo.VolumeLabel)); } [SkippableFact] - public void VolumeLabel_Set_ShouldRegisterPropertyAccess() + public void Property_VolumeLabel_Set_ShouldRegisterPropertyAccess() { Skip.IfNot(Test.RunsOnWindows); @@ -106,6 +114,7 @@ public void VolumeLabel_Set_ShouldRegisterPropertyAccess() sut.DriveInfo.New("F:").VolumeLabel = value; #pragma warning restore CA1416 - sut.Statistics.DriveInfo["F:"].ShouldOnlyContainPropertySetAccess(nameof(IDriveInfo.VolumeLabel)); + sut.Statistics.DriveInfo["F:"] + .ShouldOnlyContainPropertySetAccess(nameof(IDriveInfo.VolumeLabel)); } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoFactoryStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoFactoryStatisticsTests.cs index 69803c025..29169202d 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoFactoryStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoFactoryStatisticsTests.cs @@ -6,26 +6,26 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public class FileInfoFactoryStatisticsTests { [SkippableFact] - public void New_String_ShouldRegisterCall() + public void Method_New_String_ShouldRegisterCall() { MockFileSystem sut = new(); string fileName = "foo"; sut.FileInfo.New(fileName); - sut.Statistics.FileInfo.ShouldOnlyContain(nameof(IFileInfoFactory.New), + sut.Statistics.FileInfo.ShouldOnlyContainMethodCall(nameof(IFileInfoFactory.New), fileName); } [SkippableFact] - public void Wrap_FileInfo_ShouldRegisterCall() + public void Method_Wrap_FileInfo_ShouldRegisterCall() { MockFileSystem sut = new(); FileInfo fileInfo = new("foo"); sut.FileInfo.Wrap(fileInfo); - sut.Statistics.FileInfo.ShouldOnlyContain(nameof(IFileInfoFactory.Wrap), + sut.Statistics.FileInfo.ShouldOnlyContainMethodCall(nameof(IFileInfoFactory.Wrap), fileInfo); } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs index 1f58a9f57..9d24b1fba 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs @@ -6,78 +6,79 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public class FileInfoStatisticsTests { [SkippableFact] - public void AppendText_ShouldRegisterCall() + public void Method_AppendText_ShouldRegisterCall() { MockFileSystem sut = new(); sut.FileInfo.New("foo").AppendText(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.AppendText)); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.AppendText)); } [SkippableFact] - public void CopyTo_String_ShouldRegisterCall() + public void Method_CopyTo_String_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); string destFileName = "bar"; + bool overwrite = true; - sut.FileInfo.New("foo").CopyTo(destFileName); + sut.FileInfo.New("foo").CopyTo(destFileName, overwrite); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.CopyTo), - destFileName); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.CopyTo), + destFileName, overwrite); } [SkippableFact] - public void CopyTo_String_Bool_ShouldRegisterCall() + public void Method_CopyTo_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); string destFileName = "bar"; - bool overwrite = true; - sut.FileInfo.New("foo").CopyTo(destFileName, overwrite); + sut.FileInfo.New("foo").CopyTo(destFileName); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.CopyTo), - destFileName, overwrite); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.CopyTo), + destFileName); } [SkippableFact] - public void Create_ShouldRegisterCall() + public void Method_Create_ShouldRegisterCall() { MockFileSystem sut = new(); sut.FileInfo.New("foo").Create(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.Create)); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Create)); } #if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void CreateAsSymbolicLink_String_ShouldRegisterCall() + public void Method_CreateAsSymbolicLink_String_ShouldRegisterCall() { MockFileSystem sut = new(); string pathToTarget = "foo"; sut.FileInfo.New("foo").CreateAsSymbolicLink(pathToTarget); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.CreateAsSymbolicLink), - pathToTarget); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IFileInfo.CreateAsSymbolicLink), + pathToTarget); } #endif [SkippableFact] - public void CreateText_ShouldRegisterCall() + public void Method_CreateText_ShouldRegisterCall() { MockFileSystem sut = new(); sut.FileInfo.New("foo").CreateText(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.CreateText)); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.CreateText)); } [SkippableFact] - public void Decrypt_ShouldRegisterCall() + public void Method_Decrypt_ShouldRegisterCall() { Skip.If(!Test.RunsOnWindows); @@ -87,22 +88,22 @@ public void Decrypt_ShouldRegisterCall() sut.FileInfo.New("foo").Decrypt(); #pragma warning restore CA1416 - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.Decrypt)); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Decrypt)); } [SkippableFact] - public void Delete_ShouldRegisterCall() + public void Method_Delete_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); sut.FileInfo.New("foo").Delete(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.Delete)); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Delete)); } [SkippableFact] - public void Encrypt_ShouldRegisterCall() + public void Method_Encrypt_ShouldRegisterCall() { Skip.If(!Test.RunsOnWindows); @@ -112,174 +113,476 @@ public void Encrypt_ShouldRegisterCall() sut.FileInfo.New("foo").Encrypt(); #pragma warning restore CA1416 - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.Encrypt)); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Encrypt)); } +#if FEATURE_FILE_MOVETO_OVERWRITE [SkippableFact] - public void MoveTo_String_ShouldRegisterCall() + public void Method_MoveTo_String_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); string destFileName = "bar"; + bool overwrite = true; - sut.FileInfo.New("foo").MoveTo(destFileName); + sut.FileInfo.New("foo").MoveTo(destFileName, overwrite); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.MoveTo), - destFileName); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.MoveTo), + destFileName, overwrite); } +#endif -#if FEATURE_FILE_MOVETO_OVERWRITE [SkippableFact] - public void MoveTo_String_Bool_ShouldRegisterCall() + public void Method_MoveTo_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); string destFileName = "bar"; - bool overwrite = true; - sut.FileInfo.New("foo").MoveTo(destFileName, overwrite); + sut.FileInfo.New("foo").MoveTo(destFileName); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.MoveTo), - destFileName, overwrite); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.MoveTo), + destFileName); } -#endif [SkippableFact] - public void Open_FileMode_ShouldRegisterCall() + public void Method_Open_FileMode_FileAccess_FileShare_ShouldRegisterCall() { MockFileSystem sut = new(); FileMode mode = new(); + FileAccess access = new(); + FileShare share = new(); - sut.FileInfo.New("foo").Open(mode); + sut.FileInfo.New("foo").Open(mode, access, share); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.Open), - mode); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), + mode, access, share); } -#if FEATURE_FILESYSTEM_STREAM_OPTIONS [SkippableFact] - public void Open_FileStreamOptions_ShouldRegisterCall() + public void Method_Open_FileMode_FileAccess_ShouldRegisterCall() { MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - FileStreamOptions options = new(); + FileMode mode = new(); + FileAccess access = new(); - sut.FileInfo.New("foo").Open(options); + sut.FileInfo.New("foo").Open(mode, access); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.Open), - options); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), + mode, access); } -#endif [SkippableFact] - public void Open_FileMode_FileAccess_ShouldRegisterCall() + public void Method_Open_FileMode_ShouldRegisterCall() { MockFileSystem sut = new(); FileMode mode = new(); - FileAccess access = new(); - sut.FileInfo.New("foo").Open(mode, access); + sut.FileInfo.New("foo").Open(mode); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.Open), - mode, access); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), + mode); } +#if FEATURE_FILESYSTEM_STREAM_OPTIONS [SkippableFact] - public void Open_FileMode_FileAccess_FileShare_ShouldRegisterCall() + public void Method_Open_FileStreamOptions_ShouldRegisterCall() { MockFileSystem sut = new(); - FileMode mode = new(); - FileAccess access = new(); - FileShare share = new(); + sut.Initialize().WithFile("foo"); + FileStreamOptions options = new(); - sut.FileInfo.New("foo").Open(mode, access, share); + sut.FileInfo.New("foo").Open(options); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.Open), - mode, access, share); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), + options); } +#endif [SkippableFact] - public void OpenRead_ShouldRegisterCall() + public void Method_OpenRead_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); sut.FileInfo.New("foo").OpenRead(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.OpenRead)); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.OpenRead)); } [SkippableFact] - public void OpenText_ShouldRegisterCall() + public void Method_OpenText_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); sut.FileInfo.New("foo").OpenText(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.OpenText)); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.OpenText)); } [SkippableFact] - public void OpenWrite_ShouldRegisterCall() + public void Method_OpenWrite_ShouldRegisterCall() { MockFileSystem sut = new(); sut.FileInfo.New("foo").OpenWrite(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.OpenWrite)); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.OpenWrite)); } [SkippableFact] - public void Refresh_ShouldRegisterCall() + public void Method_Refresh_ShouldRegisterCall() { MockFileSystem sut = new(); sut.FileInfo.New("foo").Refresh(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.Refresh)); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Refresh)); } [SkippableFact] - public void Replace_String_String_ShouldRegisterCall() + public void Method_Replace_String_String_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo").WithFile("bar"); string destinationFileName = "bar"; string destinationBackupFileName = "xyz"; + bool ignoreMetadataErrors = true; - sut.FileInfo.New("foo").Replace(destinationFileName, destinationBackupFileName); + sut.FileInfo.New("foo").Replace(destinationFileName, destinationBackupFileName, + ignoreMetadataErrors); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.Replace), - destinationFileName, destinationBackupFileName); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Replace), + destinationFileName, destinationBackupFileName, ignoreMetadataErrors); } [SkippableFact] - public void Replace_String_String_Bool_ShouldRegisterCall() + public void Method_Replace_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo").WithFile("bar"); string destinationFileName = "bar"; string destinationBackupFileName = "xyz"; - bool ignoreMetadataErrors = true; - sut.FileInfo.New("foo").Replace(destinationFileName, destinationBackupFileName, ignoreMetadataErrors); + sut.FileInfo.New("foo").Replace(destinationFileName, destinationBackupFileName); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.Replace), - destinationFileName, destinationBackupFileName, ignoreMetadataErrors); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Replace), + destinationFileName, destinationBackupFileName); } #if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void ResolveLinkTarget_Bool_ShouldRegisterCall() + public void Method_ResolveLinkTarget_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); bool returnFinalTarget = true; sut.FileInfo.New("foo").ResolveLinkTarget(returnFinalTarget); - sut.Statistics.FileInfo["foo"].ShouldOnlyContain(nameof(IFileInfo.ResolveLinkTarget), - returnFinalTarget); + sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall( + nameof(IFileInfo.ResolveLinkTarget), + returnFinalTarget); + } +#endif + + [SkippableFact] + public void Property_Attributes_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").Attributes; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.Attributes)); + } + + [SkippableFact] + public void Property_Attributes_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + FileAttributes value = new(); + + sut.FileInfo.New("foo").Attributes = value; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileInfo.Attributes)); + } + + [SkippableFact] + public void Property_CreationTime_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").CreationTime; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.CreationTime)); + } + + [SkippableFact] + public void Property_CreationTime_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.FileInfo.New("foo").CreationTime = value; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileInfo.CreationTime)); + } + + [SkippableFact] + public void Property_CreationTimeUtc_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").CreationTimeUtc; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.CreationTimeUtc)); + } + + [SkippableFact] + public void Property_CreationTimeUtc_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.FileInfo.New("foo").CreationTimeUtc = value; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileInfo.CreationTimeUtc)); + } + + [SkippableFact] + public void Property_Directory_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").Directory; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.Directory)); + } + + [SkippableFact] + public void Property_DirectoryName_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").DirectoryName; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.DirectoryName)); + } + + [SkippableFact] + public void Property_Exists_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").Exists; + + sut.Statistics.FileInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.Exists)); + } + + [SkippableFact] + public void Property_Extension_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").Extension; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.Extension)); + } + + [SkippableFact] + public void Property_FullName_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").FullName; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.FullName)); + } + + [SkippableFact] + public void Property_IsReadOnly_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").IsReadOnly; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.IsReadOnly)); + } + + [SkippableFact] + public void Property_IsReadOnly_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + bool value = true; + + sut.FileInfo.New("foo").IsReadOnly = value; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileInfo.IsReadOnly)); + } + + [SkippableFact] + public void Property_LastAccessTime_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").LastAccessTime; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.LastAccessTime)); + } + + [SkippableFact] + public void Property_LastAccessTime_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.FileInfo.New("foo").LastAccessTime = value; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileInfo.LastAccessTime)); + } + + [SkippableFact] + public void Property_LastAccessTimeUtc_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").LastAccessTimeUtc; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.LastAccessTimeUtc)); + } + + [SkippableFact] + public void Property_LastAccessTimeUtc_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.FileInfo.New("foo").LastAccessTimeUtc = value; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileInfo.LastAccessTimeUtc)); + } + + [SkippableFact] + public void Property_LastWriteTime_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").LastWriteTime; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.LastWriteTime)); + } + + [SkippableFact] + public void Property_LastWriteTime_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.FileInfo.New("foo").LastWriteTime = value; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileInfo.LastWriteTime)); + } + + [SkippableFact] + public void Property_LastWriteTimeUtc_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").LastWriteTimeUtc; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.LastWriteTimeUtc)); + } + + [SkippableFact] + public void Property_LastWriteTimeUtc_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + DateTime value = new(); + + sut.FileInfo.New("foo").LastWriteTimeUtc = value; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileInfo.LastWriteTimeUtc)); + } + + [SkippableFact] + public void Property_Length_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").Length; + + sut.Statistics.FileInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.Length)); + } + +#if FEATURE_FILESYSTEM_LINK + [SkippableFact] + public void Property_LinkTarget_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").LinkTarget; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.LinkTarget)); + } +#endif + + [SkippableFact] + public void Property_Name_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").Name; + + sut.Statistics.FileInfo["foo"].ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.Name)); + } + +#if FEATURE_FILESYSTEM_UNIXFILEMODE + [SkippableFact] + public void Property_UnixFileMode_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileInfo.New("foo").UnixFileMode; + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileInfo.UnixFileMode)); + } + + [SkippableFact] + public void Property_UnixFileMode_Set_ShouldRegisterPropertyAccess() + { + Skip.If(Test.RunsOnWindows); + + MockFileSystem sut = new(); + UnixFileMode value = new(); + + #pragma warning disable CA1416 + sut.FileInfo.New("foo").UnixFileMode = value; + #pragma warning restore CA1416 + + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileInfo.UnixFileMode)); } #endif } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStatisticsTests.cs index 0b1c393de..2b44f153c 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStatisticsTests.cs @@ -17,7 +17,7 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public sealed class FileStatisticsTests { [SkippableFact] - public void AppendAllLines_String_IEnumerableString_Encoding_ShouldRegisterCall() + public void Method_AppendAllLines_String_IEnumerableString_Encoding_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -26,12 +26,12 @@ public void AppendAllLines_String_IEnumerableString_Encoding_ShouldRegisterCall( sut.File.AppendAllLines(path, contents, encoding); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.AppendAllLines), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllLines), path, contents, encoding); } [SkippableFact] - public void AppendAllLines_String_IEnumerableString_ShouldRegisterCall() + public void Method_AppendAllLines_String_IEnumerableString_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -39,45 +39,12 @@ public void AppendAllLines_String_IEnumerableString_ShouldRegisterCall() sut.File.AppendAllLines(path, contents); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.AppendAllLines), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllLines), path, contents); } -#if FEATURE_FILESYSTEM_ASYNC [SkippableFact] - public async Task - AppendAllLinesAsync_String_IEnumerableString_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - string path = "foo"; - IEnumerable contents = ["foo", "bar"]; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.AppendAllLinesAsync(path, contents, cancellationToken); - - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.AppendAllLinesAsync), - path, contents, cancellationToken); - } - - [SkippableFact] - public async Task - AppendAllLinesAsync_String_IEnumerableString_Encoding_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - string path = "foo"; - IEnumerable contents = ["foo", "bar"]; - Encoding encoding = Encoding.UTF8; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.AppendAllLinesAsync(path, contents, encoding, cancellationToken); - - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.AppendAllLinesAsync), - path, contents, encoding, cancellationToken); - } -#endif - - [SkippableFact] - public void AppendAllText_String_String_Encoding_ShouldRegisterCall() + public void Method_AppendAllText_String_String_Encoding_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -86,12 +53,12 @@ public void AppendAllText_String_String_Encoding_ShouldRegisterCall() sut.File.AppendAllText(path, contents, encoding); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.AppendAllText), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllText), path, contents, encoding); } [SkippableFact] - public void AppendAllText_String_String_ShouldRegisterCall() + public void Method_AppendAllText_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -99,56 +66,24 @@ public void AppendAllText_String_String_ShouldRegisterCall() sut.File.AppendAllText(path, contents); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.AppendAllText), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllText), path, contents); } -#if FEATURE_FILESYSTEM_ASYNC [SkippableFact] - public async Task AppendAllTextAsync_String_String_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - string path = "foo"; - string contents = "foo"; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.AppendAllTextAsync(path, contents, cancellationToken); - - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.AppendAllTextAsync), - path, contents, cancellationToken); - } - - [SkippableFact] - public async Task - AppendAllTextAsync_String_String_Encoding_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - string path = "foo"; - string contents = "foo"; - Encoding encoding = Encoding.UTF8; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.AppendAllTextAsync(path, contents, encoding, cancellationToken); - - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.AppendAllTextAsync), - path, contents, encoding, cancellationToken); - } -#endif - - [SkippableFact] - public void AppendText_String_ShouldRegisterCall() + public void Method_AppendText_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.File.AppendText(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.AppendText), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendText), path); } [SkippableFact] - public void Copy_String_String_Bool_ShouldRegisterCall() + public void Method_Copy_String_String_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -158,12 +93,12 @@ public void Copy_String_String_Bool_ShouldRegisterCall() sut.File.Copy(sourceFileName, destFileName, overwrite); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Copy), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Copy), sourceFileName, destFileName, overwrite); } [SkippableFact] - public void Copy_String_String_ShouldRegisterCall() + public void Method_Copy_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -172,12 +107,12 @@ public void Copy_String_String_ShouldRegisterCall() sut.File.Copy(sourceFileName, destFileName); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Copy), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Copy), sourceFileName, destFileName); } [SkippableFact] - public void Create_String_Int_FileOptions_ShouldRegisterCall() + public void Method_Create_String_Int_FileOptions_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -186,12 +121,12 @@ public void Create_String_Int_FileOptions_ShouldRegisterCall() sut.File.Create(path, bufferSize, options); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Create), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Create), path, bufferSize, options); } [SkippableFact] - public void Create_String_Int_ShouldRegisterCall() + public void Method_Create_String_Int_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -199,25 +134,25 @@ public void Create_String_Int_ShouldRegisterCall() sut.File.Create(path, bufferSize); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Create), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Create), path, bufferSize); } [SkippableFact] - public void Create_String_ShouldRegisterCall() + public void Method_Create_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.File.Create(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Create), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Create), path); } #if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void CreateSymbolicLink_String_String_ShouldRegisterCall() + public void Method_CreateSymbolicLink_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -225,25 +160,25 @@ public void CreateSymbolicLink_String_String_ShouldRegisterCall() sut.File.CreateSymbolicLink(path, pathToTarget); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.CreateSymbolicLink), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.CreateSymbolicLink), path, pathToTarget); } #endif [SkippableFact] - public void CreateText_String_ShouldRegisterCall() + public void Method_CreateText_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.File.CreateText(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.CreateText), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.CreateText), path); } [SkippableFact] - public void Decrypt_String_ShouldRegisterCall() + public void Method_Decrypt_String_ShouldRegisterCall() { Skip.If(!Test.RunsOnWindows); @@ -255,12 +190,12 @@ public void Decrypt_String_ShouldRegisterCall() sut.File.Decrypt(path); #pragma warning restore CA1416 - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Decrypt), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Decrypt), path); } [SkippableFact] - public void Delete_String_ShouldRegisterCall() + public void Method_Delete_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -268,12 +203,12 @@ public void Delete_String_ShouldRegisterCall() sut.File.Delete(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Delete), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Delete), path); } [SkippableFact] - public void Encrypt_String_ShouldRegisterCall() + public void Method_Encrypt_String_ShouldRegisterCall() { Skip.If(!Test.RunsOnWindows); @@ -285,25 +220,25 @@ public void Encrypt_String_ShouldRegisterCall() sut.File.Encrypt(path); #pragma warning restore CA1416 - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Encrypt), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Encrypt), path); } [SkippableFact] - public void Exists_String_ShouldRegisterCall() + public void Method_Exists_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.File.Exists(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Exists), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Exists), path); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void GetAttributes_SafeFileHandle_ShouldRegisterCall() + public void Method_GetAttributes_SafeFileHandle_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -313,13 +248,13 @@ public void GetAttributes_SafeFileHandle_ShouldRegisterCall() sut.File.GetAttributes(fileHandle); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetAttributes), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetAttributes), fileHandle); } #endif [SkippableFact] - public void GetAttributes_String_ShouldRegisterCall() + public void Method_GetAttributes_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -327,13 +262,13 @@ public void GetAttributes_String_ShouldRegisterCall() sut.File.GetAttributes(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetAttributes), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetAttributes), path); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void GetCreationTime_SafeFileHandle_ShouldRegisterCall() + public void Method_GetCreationTime_SafeFileHandle_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -343,13 +278,13 @@ public void GetCreationTime_SafeFileHandle_ShouldRegisterCall() sut.File.GetCreationTime(fileHandle); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetCreationTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetCreationTime), fileHandle); } #endif [SkippableFact] - public void GetCreationTime_String_ShouldRegisterCall() + public void Method_GetCreationTime_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -357,13 +292,13 @@ public void GetCreationTime_String_ShouldRegisterCall() sut.File.GetCreationTime(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetCreationTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetCreationTime), path); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void GetCreationTimeUtc_SafeFileHandle_ShouldRegisterCall() + public void Method_GetCreationTimeUtc_SafeFileHandle_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -373,13 +308,13 @@ public void GetCreationTimeUtc_SafeFileHandle_ShouldRegisterCall() sut.File.GetCreationTimeUtc(fileHandle); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetCreationTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetCreationTimeUtc), fileHandle); } #endif [SkippableFact] - public void GetCreationTimeUtc_String_ShouldRegisterCall() + public void Method_GetCreationTimeUtc_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -387,13 +322,13 @@ public void GetCreationTimeUtc_String_ShouldRegisterCall() sut.File.GetCreationTimeUtc(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetCreationTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetCreationTimeUtc), path); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void GetLastAccessTime_SafeFileHandle_ShouldRegisterCall() + public void Method_GetLastAccessTime_SafeFileHandle_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -403,13 +338,13 @@ public void GetLastAccessTime_SafeFileHandle_ShouldRegisterCall() sut.File.GetLastAccessTime(fileHandle); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetLastAccessTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetLastAccessTime), fileHandle); } #endif [SkippableFact] - public void GetLastAccessTime_String_ShouldRegisterCall() + public void Method_GetLastAccessTime_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -417,13 +352,13 @@ public void GetLastAccessTime_String_ShouldRegisterCall() sut.File.GetLastAccessTime(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetLastAccessTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetLastAccessTime), path); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void GetLastAccessTimeUtc_SafeFileHandle_ShouldRegisterCall() + public void Method_GetLastAccessTimeUtc_SafeFileHandle_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -433,13 +368,13 @@ public void GetLastAccessTimeUtc_SafeFileHandle_ShouldRegisterCall() sut.File.GetLastAccessTimeUtc(fileHandle); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetLastAccessTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetLastAccessTimeUtc), fileHandle); } #endif [SkippableFact] - public void GetLastAccessTimeUtc_String_ShouldRegisterCall() + public void Method_GetLastAccessTimeUtc_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -447,13 +382,13 @@ public void GetLastAccessTimeUtc_String_ShouldRegisterCall() sut.File.GetLastAccessTimeUtc(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetLastAccessTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetLastAccessTimeUtc), path); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void GetLastWriteTime_SafeFileHandle_ShouldRegisterCall() + public void Method_GetLastWriteTime_SafeFileHandle_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -463,13 +398,13 @@ public void GetLastWriteTime_SafeFileHandle_ShouldRegisterCall() sut.File.GetLastWriteTime(fileHandle); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetLastWriteTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetLastWriteTime), fileHandle); } #endif [SkippableFact] - public void GetLastWriteTime_String_ShouldRegisterCall() + public void Method_GetLastWriteTime_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -477,13 +412,13 @@ public void GetLastWriteTime_String_ShouldRegisterCall() sut.File.GetLastWriteTime(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetLastWriteTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetLastWriteTime), path); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void GetLastWriteTimeUtc_SafeFileHandle_ShouldRegisterCall() + public void Method_GetLastWriteTimeUtc_SafeFileHandle_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -493,13 +428,13 @@ public void GetLastWriteTimeUtc_SafeFileHandle_ShouldRegisterCall() sut.File.GetLastWriteTimeUtc(fileHandle); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetLastWriteTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetLastWriteTimeUtc), fileHandle); } #endif [SkippableFact] - public void GetLastWriteTimeUtc_String_ShouldRegisterCall() + public void Method_GetLastWriteTimeUtc_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -507,13 +442,13 @@ public void GetLastWriteTimeUtc_String_ShouldRegisterCall() sut.File.GetLastWriteTimeUtc(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetLastWriteTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetLastWriteTimeUtc), path); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void GetUnixFileMode_SafeFileHandle_ShouldRegisterCall() + public void Method_GetUnixFileMode_SafeFileHandle_ShouldRegisterCall() { Skip.If(!Test.RunsOnLinux); @@ -527,14 +462,14 @@ public void GetUnixFileMode_SafeFileHandle_ShouldRegisterCall() sut.File.GetUnixFileMode(fileHandle); #pragma warning restore CA1416 - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetUnixFileMode), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetUnixFileMode), fileHandle); } #endif #if FEATURE_FILESYSTEM_UNIXFILEMODE [SkippableFact] - public void GetUnixFileMode_String_ShouldRegisterCall() + public void Method_GetUnixFileMode_String_ShouldRegisterCall() { Skip.If(!Test.RunsOnLinux); @@ -546,14 +481,14 @@ public void GetUnixFileMode_String_ShouldRegisterCall() sut.File.GetUnixFileMode(path); #pragma warning restore CA1416 - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.GetUnixFileMode), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.GetUnixFileMode), path); } #endif #if FEATURE_FILE_MOVETO_OVERWRITE [SkippableFact] - public void Move_String_String_Bool_ShouldRegisterCall() + public void Method_Move_String_String_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -563,13 +498,13 @@ public void Move_String_String_Bool_ShouldRegisterCall() sut.File.Move(sourceFileName, destFileName, overwrite); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Move), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Move), sourceFileName, destFileName, overwrite); } #endif [SkippableFact] - public void Move_String_String_ShouldRegisterCall() + public void Method_Move_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -578,12 +513,12 @@ public void Move_String_String_ShouldRegisterCall() sut.File.Move(sourceFileName, destFileName); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Move), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Move), sourceFileName, destFileName); } [SkippableFact] - public void Open_String_FileMode_FileAccess_FileShare_ShouldRegisterCall() + public void Method_Open_String_FileMode_FileAccess_FileShare_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -593,12 +528,12 @@ public void Open_String_FileMode_FileAccess_FileShare_ShouldRegisterCall() sut.File.Open(path, mode, access, share); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Open), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Open), path, mode, access, share); } [SkippableFact] - public void Open_String_FileMode_FileAccess_ShouldRegisterCall() + public void Method_Open_String_FileMode_FileAccess_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -607,12 +542,12 @@ public void Open_String_FileMode_FileAccess_ShouldRegisterCall() sut.File.Open(path, mode, access); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Open), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Open), path, mode, access); } [SkippableFact] - public void Open_String_FileMode_ShouldRegisterCall() + public void Method_Open_String_FileMode_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -620,13 +555,13 @@ public void Open_String_FileMode_ShouldRegisterCall() sut.File.Open(path, mode); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Open), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Open), path, mode); } #if FEATURE_FILESYSTEM_STREAM_OPTIONS [SkippableFact] - public void Open_String_FileStreamOptions_ShouldRegisterCall() + public void Method_Open_String_FileStreamOptions_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -635,13 +570,13 @@ public void Open_String_FileStreamOptions_ShouldRegisterCall() sut.File.Open(path, options); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Open), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Open), path, options); } #endif [SkippableFact] - public void OpenRead_String_ShouldRegisterCall() + public void Method_OpenRead_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -649,12 +584,12 @@ public void OpenRead_String_ShouldRegisterCall() sut.File.OpenRead(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.OpenRead), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.OpenRead), path); } [SkippableFact] - public void OpenText_String_ShouldRegisterCall() + public void Method_OpenText_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -662,24 +597,24 @@ public void OpenText_String_ShouldRegisterCall() sut.File.OpenText(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.OpenText), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.OpenText), path); } [SkippableFact] - public void OpenWrite_String_ShouldRegisterCall() + public void Method_OpenWrite_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.File.OpenWrite(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.OpenWrite), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.OpenWrite), path); } [SkippableFact] - public void ReadAllBytes_String_ShouldRegisterCall() + public void Method_ReadAllBytes_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -687,13 +622,13 @@ public void ReadAllBytes_String_ShouldRegisterCall() sut.File.ReadAllBytes(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadAllBytes), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllBytes), path); } #if FEATURE_FILESYSTEM_ASYNC [SkippableFact] - public async Task ReadAllBytesAsync_String_CancellationToken_ShouldRegisterCall() + public async Task Method_ReadAllBytesAsync_String_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -702,13 +637,13 @@ public async Task ReadAllBytesAsync_String_CancellationToken_ShouldRegisterCall( await sut.File.ReadAllBytesAsync(path, cancellationToken); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadAllBytesAsync), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllBytesAsync), path, cancellationToken); } #endif [SkippableFact] - public void ReadAllLines_String_Encoding_ShouldRegisterCall() + public void Method_ReadAllLines_String_Encoding_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -717,12 +652,12 @@ public void ReadAllLines_String_Encoding_ShouldRegisterCall() sut.File.ReadAllLines(path, encoding); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadAllLines), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllLines), path, encoding); } [SkippableFact] - public void ReadAllLines_String_ShouldRegisterCall() + public void Method_ReadAllLines_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -730,43 +665,12 @@ public void ReadAllLines_String_ShouldRegisterCall() sut.File.ReadAllLines(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadAllLines), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllLines), path); } -#if FEATURE_FILESYSTEM_ASYNC - [SkippableFact] - public async Task ReadAllLinesAsync_String_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.ReadAllLinesAsync(path, cancellationToken); - - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadAllLinesAsync), - path, cancellationToken); - } - - [SkippableFact] - public async Task ReadAllLinesAsync_String_Encoding_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - Encoding encoding = Encoding.UTF8; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.ReadAllLinesAsync(path, encoding, cancellationToken); - - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadAllLinesAsync), - path, encoding, cancellationToken); - } -#endif - [SkippableFact] - public void ReadAllText_String_Encoding_ShouldRegisterCall() + public void Method_ReadAllText_String_Encoding_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -775,12 +679,12 @@ public void ReadAllText_String_Encoding_ShouldRegisterCall() sut.File.ReadAllText(path, encoding); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadAllText), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllText), path, encoding); } [SkippableFact] - public void ReadAllText_String_ShouldRegisterCall() + public void Method_ReadAllText_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -788,43 +692,12 @@ public void ReadAllText_String_ShouldRegisterCall() sut.File.ReadAllText(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadAllText), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllText), path); } -#if FEATURE_FILESYSTEM_ASYNC [SkippableFact] - public async Task ReadAllTextAsync_String_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.ReadAllTextAsync(path, cancellationToken); - - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadAllTextAsync), - path, cancellationToken); - } - - [SkippableFact] - public async Task ReadAllTextAsync_String_Encoding_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - Encoding encoding = Encoding.UTF8; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.ReadAllTextAsync(path, encoding, cancellationToken); - - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadAllTextAsync), - path, encoding, cancellationToken); - } -#endif - - [SkippableFact] - public void ReadLines_String_Encoding_ShouldRegisterCall() + public void Method_ReadLines_String_Encoding_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -833,12 +706,12 @@ public void ReadLines_String_Encoding_ShouldRegisterCall() sut.File.ReadLines(path, encoding); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadLines), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadLines), path, encoding); } [SkippableFact] - public void ReadLines_String_ShouldRegisterCall() + public void Method_ReadLines_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -846,43 +719,12 @@ public void ReadLines_String_ShouldRegisterCall() sut.File.ReadLines(path); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadLines), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadLines), path); } -#if FEATURE_FILESYSTEM_NET7 - [SkippableFact] - public void ReadLinesAsync_String_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - CancellationToken cancellationToken = CancellationToken.None; - - sut.File.ReadLinesAsync(path, cancellationToken); - - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadLinesAsync), - path, cancellationToken); - } - - [SkippableFact] - public void ReadLinesAsync_String_Encoding_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - Encoding encoding = Encoding.UTF8; - CancellationToken cancellationToken = CancellationToken.None; - - sut.File.ReadLinesAsync(path, encoding, cancellationToken); - - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ReadLinesAsync), - path, encoding, cancellationToken); - } -#endif - [SkippableFact] - public void Replace_String_String_String_Bool_ShouldRegisterCall() + public void Method_Replace_String_String_String_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo").WithFile("bar"); @@ -894,12 +736,12 @@ public void Replace_String_String_String_Bool_ShouldRegisterCall() sut.File.Replace(sourceFileName, destinationFileName, destinationBackupFileName, ignoreMetadataErrors); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Replace), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Replace), sourceFileName, destinationFileName, destinationBackupFileName, ignoreMetadataErrors); } [SkippableFact] - public void Replace_String_String_String_ShouldRegisterCall() + public void Method_Replace_String_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo").WithFile("bar"); @@ -909,13 +751,13 @@ public void Replace_String_String_String_ShouldRegisterCall() sut.File.Replace(sourceFileName, destinationFileName, destinationBackupFileName); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.Replace), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.Replace), sourceFileName, destinationFileName, destinationBackupFileName); } #if FEATURE_FILESYSTEM_LINK [SkippableFact] - public void ResolveLinkTarget_String_Bool_ShouldRegisterCall() + public void Method_ResolveLinkTarget_String_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -924,14 +766,14 @@ public void ResolveLinkTarget_String_Bool_ShouldRegisterCall() sut.File.ResolveLinkTarget(linkPath, returnFinalTarget); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.ResolveLinkTarget), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ResolveLinkTarget), linkPath, returnFinalTarget); } #endif #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void SetAttributes_SafeFileHandle_FileAttributes_ShouldRegisterCall() + public void Method_SetAttributes_SafeFileHandle_FileAttributes_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -942,13 +784,13 @@ public void SetAttributes_SafeFileHandle_FileAttributes_ShouldRegisterCall() sut.File.SetAttributes(fileHandle, fileAttributes); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetAttributes), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetAttributes), fileHandle, fileAttributes); } #endif [SkippableFact] - public void SetAttributes_String_FileAttributes_ShouldRegisterCall() + public void Method_SetAttributes_String_FileAttributes_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -957,13 +799,13 @@ public void SetAttributes_String_FileAttributes_ShouldRegisterCall() sut.File.SetAttributes(path, fileAttributes); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetAttributes), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetAttributes), path, fileAttributes); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void SetCreationTime_SafeFileHandle_DateTime_ShouldRegisterCall() + public void Method_SetCreationTime_SafeFileHandle_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -974,13 +816,13 @@ public void SetCreationTime_SafeFileHandle_DateTime_ShouldRegisterCall() sut.File.SetCreationTime(fileHandle, creationTime); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetCreationTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetCreationTime), fileHandle, creationTime); } #endif [SkippableFact] - public void SetCreationTime_String_DateTime_ShouldRegisterCall() + public void Method_SetCreationTime_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -989,13 +831,13 @@ public void SetCreationTime_String_DateTime_ShouldRegisterCall() sut.File.SetCreationTime(path, creationTime); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetCreationTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetCreationTime), path, creationTime); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void SetCreationTimeUtc_SafeFileHandle_DateTime_ShouldRegisterCall() + public void Method_SetCreationTimeUtc_SafeFileHandle_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -1006,13 +848,13 @@ public void SetCreationTimeUtc_SafeFileHandle_DateTime_ShouldRegisterCall() sut.File.SetCreationTimeUtc(fileHandle, creationTimeUtc); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetCreationTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetCreationTimeUtc), fileHandle, creationTimeUtc); } #endif [SkippableFact] - public void SetCreationTimeUtc_String_DateTime_ShouldRegisterCall() + public void Method_SetCreationTimeUtc_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -1021,13 +863,13 @@ public void SetCreationTimeUtc_String_DateTime_ShouldRegisterCall() sut.File.SetCreationTimeUtc(path, creationTimeUtc); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetCreationTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetCreationTimeUtc), path, creationTimeUtc); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void SetLastAccessTime_SafeFileHandle_DateTime_ShouldRegisterCall() + public void Method_SetLastAccessTime_SafeFileHandle_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -1038,13 +880,13 @@ public void SetLastAccessTime_SafeFileHandle_DateTime_ShouldRegisterCall() sut.File.SetLastAccessTime(fileHandle, lastAccessTime); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetLastAccessTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetLastAccessTime), fileHandle, lastAccessTime); } #endif [SkippableFact] - public void SetLastAccessTime_String_DateTime_ShouldRegisterCall() + public void Method_SetLastAccessTime_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -1053,13 +895,13 @@ public void SetLastAccessTime_String_DateTime_ShouldRegisterCall() sut.File.SetLastAccessTime(path, lastAccessTime); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetLastAccessTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetLastAccessTime), path, lastAccessTime); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void SetLastAccessTimeUtc_SafeFileHandle_DateTime_ShouldRegisterCall() + public void Method_SetLastAccessTimeUtc_SafeFileHandle_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -1070,13 +912,13 @@ public void SetLastAccessTimeUtc_SafeFileHandle_DateTime_ShouldRegisterCall() sut.File.SetLastAccessTimeUtc(fileHandle, lastAccessTimeUtc); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetLastAccessTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetLastAccessTimeUtc), fileHandle, lastAccessTimeUtc); } #endif [SkippableFact] - public void SetLastAccessTimeUtc_String_DateTime_ShouldRegisterCall() + public void Method_SetLastAccessTimeUtc_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -1085,13 +927,13 @@ public void SetLastAccessTimeUtc_String_DateTime_ShouldRegisterCall() sut.File.SetLastAccessTimeUtc(path, lastAccessTimeUtc); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetLastAccessTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetLastAccessTimeUtc), path, lastAccessTimeUtc); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void SetLastWriteTime_SafeFileHandle_DateTime_ShouldRegisterCall() + public void Method_SetLastWriteTime_SafeFileHandle_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -1102,13 +944,13 @@ public void SetLastWriteTime_SafeFileHandle_DateTime_ShouldRegisterCall() sut.File.SetLastWriteTime(fileHandle, lastWriteTime); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetLastWriteTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetLastWriteTime), fileHandle, lastWriteTime); } #endif [SkippableFact] - public void SetLastWriteTime_String_DateTime_ShouldRegisterCall() + public void Method_SetLastWriteTime_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -1117,13 +959,13 @@ public void SetLastWriteTime_String_DateTime_ShouldRegisterCall() sut.File.SetLastWriteTime(path, lastWriteTime); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetLastWriteTime), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetLastWriteTime), path, lastWriteTime); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void SetLastWriteTimeUtc_SafeFileHandle_DateTime_ShouldRegisterCall() + public void Method_SetLastWriteTimeUtc_SafeFileHandle_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -1134,13 +976,13 @@ public void SetLastWriteTimeUtc_SafeFileHandle_DateTime_ShouldRegisterCall() sut.File.SetLastWriteTimeUtc(fileHandle, lastWriteTimeUtc); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetLastWriteTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetLastWriteTimeUtc), fileHandle, lastWriteTimeUtc); } #endif [SkippableFact] - public void SetLastWriteTimeUtc_String_DateTime_ShouldRegisterCall() + public void Method_SetLastWriteTimeUtc_String_DateTime_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -1149,13 +991,13 @@ public void SetLastWriteTimeUtc_String_DateTime_ShouldRegisterCall() sut.File.SetLastWriteTimeUtc(path, lastWriteTimeUtc); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetLastWriteTimeUtc), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetLastWriteTimeUtc), path, lastWriteTimeUtc); } #if FEATURE_FILESYSTEM_SAFEFILEHANDLE [SkippableFact] - public void SetUnixFileMode_SafeFileHandle_UnixFileMode_ShouldRegisterCall() + public void Method_SetUnixFileMode_SafeFileHandle_UnixFileMode_ShouldRegisterCall() { Skip.If(!Test.RunsOnLinux); @@ -1170,14 +1012,14 @@ public void SetUnixFileMode_SafeFileHandle_UnixFileMode_ShouldRegisterCall() sut.File.SetUnixFileMode(fileHandle, mode); #pragma warning restore CA1416 - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetUnixFileMode), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetUnixFileMode), fileHandle, mode); } #endif #if FEATURE_FILESYSTEM_UNIXFILEMODE [SkippableFact] - public void SetUnixFileMode_String_UnixFileMode_ShouldRegisterCall() + public void Method_SetUnixFileMode_String_UnixFileMode_ShouldRegisterCall() { Skip.If(!Test.RunsOnLinux); @@ -1190,13 +1032,13 @@ public void SetUnixFileMode_String_UnixFileMode_ShouldRegisterCall() sut.File.SetUnixFileMode(path, mode); #pragma warning restore CA1416 - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.SetUnixFileMode), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.SetUnixFileMode), path, mode); } #endif [SkippableFact] - public void WriteAllBytes_String_ByteArray_ShouldRegisterCall() + public void Method_WriteAllBytes_String_ByteArray_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -1204,13 +1046,14 @@ public void WriteAllBytes_String_ByteArray_ShouldRegisterCall() sut.File.WriteAllBytes(path, bytes); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllBytes), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllBytes), path, bytes); } #if FEATURE_FILESYSTEM_ASYNC [SkippableFact] - public async Task WriteAllBytesAsync_String_ByteArray_CancellationToken_ShouldRegisterCall() + public async Task + Method_WriteAllBytesAsync_String_ByteArray_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -1219,13 +1062,13 @@ public async Task WriteAllBytesAsync_String_ByteArray_CancellationToken_ShouldRe await sut.File.WriteAllBytesAsync(path, bytes, cancellationToken); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllBytesAsync), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllBytesAsync), path, bytes, cancellationToken); } #endif [SkippableFact] - public void WriteAllLines_String_IEnumerableString_Encoding_ShouldRegisterCall() + public void Method_WriteAllLines_String_IEnumerableString_Encoding_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -1234,12 +1077,12 @@ public void WriteAllLines_String_IEnumerableString_Encoding_ShouldRegisterCall() sut.File.WriteAllLines(path, contents, encoding); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllLines), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllLines), path, contents, encoding); } [SkippableFact] - public void WriteAllLines_String_IEnumerableString_ShouldRegisterCall() + public void Method_WriteAllLines_String_IEnumerableString_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -1247,12 +1090,12 @@ public void WriteAllLines_String_IEnumerableString_ShouldRegisterCall() sut.File.WriteAllLines(path, contents); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllLines), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllLines), path, contents); } [SkippableFact] - public void WriteAllLines_String_StringArray_Encoding_ShouldRegisterCall() + public void Method_WriteAllLines_String_StringArray_Encoding_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -1261,12 +1104,12 @@ public void WriteAllLines_String_StringArray_Encoding_ShouldRegisterCall() sut.File.WriteAllLines(path, contents, encoding); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllLines), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllLines), path, contents, encoding); } [SkippableFact] - public void WriteAllLines_String_StringArray_ShouldRegisterCall() + public void Method_WriteAllLines_String_StringArray_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -1274,29 +1117,56 @@ public void WriteAllLines_String_StringArray_ShouldRegisterCall() sut.File.WriteAllLines(path, contents); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllLines), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllLines), + path, contents); + } + + [SkippableFact] + public void Method_WriteAllText_String_String_Encoding_ShouldRegisterCall() + { + MockFileSystem sut = new(); + string path = "foo"; + string contents = "foo"; + Encoding encoding = Encoding.UTF8; + + sut.File.WriteAllText(path, contents, encoding); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllText), + path, contents, encoding); + } + + [SkippableFact] + public void Method_WriteAllText_String_String_ShouldRegisterCall() + { + MockFileSystem sut = new(); + string path = "foo"; + string contents = "foo"; + + sut.File.WriteAllText(path, contents); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllText), path, contents); } #if FEATURE_FILESYSTEM_ASYNC [SkippableFact] public async Task - WriteAllLinesAsync_String_IEnumerableString_CancellationToken_ShouldRegisterCall() + Method_AppendAllLinesAsync_String_IEnumerableString_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; IEnumerable contents = ["foo", "bar"]; CancellationToken cancellationToken = CancellationToken.None; - await sut.File.WriteAllLinesAsync(path, contents, cancellationToken); + await sut.File.AppendAllLinesAsync(path, contents, cancellationToken); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllLinesAsync), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllLinesAsync), path, contents, cancellationToken); } [SkippableFact] public async Task - WriteAllLinesAsync_String_IEnumerableString_Encoding_CancellationToken_ShouldRegisterCall() + Method_AppendAllLinesAsync_String_IEnumerableString_Encoding_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -1304,43 +1174,175 @@ public async Task Encoding encoding = Encoding.UTF8; CancellationToken cancellationToken = CancellationToken.None; - await sut.File.WriteAllLinesAsync(path, contents, encoding, cancellationToken); + await sut.File.AppendAllLinesAsync(path, contents, encoding, cancellationToken); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllLinesAsync), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllLinesAsync), path, contents, encoding, cancellationToken); } #endif +#if FEATURE_FILESYSTEM_ASYNC [SkippableFact] - public void WriteAllText_String_String_Encoding_ShouldRegisterCall() + public async Task Method_AppendAllTextAsync_String_String_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; string contents = "foo"; - Encoding encoding = Encoding.UTF8; + CancellationToken cancellationToken = CancellationToken.None; - sut.File.WriteAllText(path, contents, encoding); + await sut.File.AppendAllTextAsync(path, contents, cancellationToken); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllText), - path, contents, encoding); + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllTextAsync), + path, contents, cancellationToken); } [SkippableFact] - public void WriteAllText_String_String_ShouldRegisterCall() + public async Task + Method_AppendAllTextAsync_String_String_Encoding_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; string contents = "foo"; + Encoding encoding = Encoding.UTF8; + CancellationToken cancellationToken = CancellationToken.None; - sut.File.WriteAllText(path, contents); + await sut.File.AppendAllTextAsync(path, contents, encoding, cancellationToken); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllText), - path, contents); + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllTextAsync), + path, contents, encoding, cancellationToken); + } +#endif + +#if FEATURE_FILESYSTEM_ASYNC + [SkippableFact] + public async Task Method_ReadAllLinesAsync_String_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.ReadAllLinesAsync(path, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllLinesAsync), + path, cancellationToken); + } + + [SkippableFact] + public async Task + Method_ReadAllLinesAsync_String_Encoding_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + Encoding encoding = Encoding.UTF8; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.ReadAllLinesAsync(path, encoding, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllLinesAsync), + path, encoding, cancellationToken); + } +#endif + +#if FEATURE_FILESYSTEM_ASYNC + [SkippableFact] + public async Task Method_ReadAllTextAsync_String_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.ReadAllTextAsync(path, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllTextAsync), + path, cancellationToken); } + [SkippableFact] + public async Task Method_ReadAllTextAsync_String_Encoding_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + Encoding encoding = Encoding.UTF8; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.ReadAllTextAsync(path, encoding, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllTextAsync), + path, encoding, cancellationToken); + } +#endif + +#if FEATURE_FILESYSTEM_NET7 + [SkippableFact] + public void Method_ReadLinesAsync_String_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + CancellationToken cancellationToken = CancellationToken.None; + + sut.File.ReadLinesAsync(path, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadLinesAsync), + path, cancellationToken); + } + + [SkippableFact] + public void Method_ReadLinesAsync_String_Encoding_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + Encoding encoding = Encoding.UTF8; + CancellationToken cancellationToken = CancellationToken.None; + + sut.File.ReadLinesAsync(path, encoding, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadLinesAsync), + path, encoding, cancellationToken); + } +#endif + +#if FEATURE_FILESYSTEM_ASYNC + [SkippableFact] + public async Task + Method_WriteAllLinesAsync_String_IEnumerableString_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + string path = "foo"; + IEnumerable contents = ["foo", "bar"]; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.WriteAllLinesAsync(path, contents, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllLinesAsync), + path, contents, cancellationToken); + } + + [SkippableFact] + public async Task + Method_WriteAllLinesAsync_String_IEnumerableString_Encoding_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + string path = "foo"; + IEnumerable contents = ["foo", "bar"]; + Encoding encoding = Encoding.UTF8; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.WriteAllLinesAsync(path, contents, encoding, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllLinesAsync), + path, contents, encoding, cancellationToken); + } +#endif + #if FEATURE_FILESYSTEM_ASYNC [SkippableFact] - public async Task WriteAllTextAsync_String_String_CancellationToken_ShouldRegisterCall() + public async Task Method_WriteAllTextAsync_String_String_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -1349,13 +1351,13 @@ public async Task WriteAllTextAsync_String_String_CancellationToken_ShouldRegist await sut.File.WriteAllTextAsync(path, contents, cancellationToken); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllTextAsync), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllTextAsync), path, contents, cancellationToken); } [SkippableFact] public async Task - WriteAllTextAsync_String_String_Encoding_CancellationToken_ShouldRegisterCall() + Method_WriteAllTextAsync_String_String_Encoding_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -1365,7 +1367,7 @@ public async Task await sut.File.WriteAllTextAsync(path, contents, encoding, cancellationToken); - sut.Statistics.File.ShouldOnlyContain(nameof(IFile.WriteAllTextAsync), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllTextAsync), path, contents, encoding, cancellationToken); } #endif diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamFactoryStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamFactoryStatisticsTests.cs index 69a77ce08..323c02507 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamFactoryStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamFactoryStatisticsTests.cs @@ -11,7 +11,7 @@ public class FileStreamFactoryStatisticsTests { #if NET6_0_OR_GREATER [SkippableFact] - public void New_SafeFileHandle_FileAccess_ShouldRegisterCall() + public void Method_New_SafeFileHandle_FileAccess_Int_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); sut.WithSafeFileHandleStrategy( @@ -19,98 +19,106 @@ public void New_SafeFileHandle_FileAccess_ShouldRegisterCall() .Initialize().WithFile("foo"); SafeFileHandle handle = new(); FileAccess access = FileAccess.ReadWrite; + int bufferSize = 42; + bool isAsync = true; - using FileSystemStream result = sut.FileStream.New(handle, access); + using FileSystemStream result = sut.FileStream.New(handle, access, bufferSize, isAsync); - sut.Statistics.FileStream.ShouldOnlyContain(nameof(IFileStreamFactory.New), - handle, access); + sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.New), + handle, access, bufferSize, isAsync); } #endif +#if NET6_0_OR_GREATER [SkippableFact] - public void New_String_FileMode_ShouldRegisterCall() + public void Method_New_SafeFileHandle_FileAccess_Int_ShouldRegisterCall() { MockFileSystem sut = new(); - string path = "foo"; - FileMode mode = FileMode.OpenOrCreate; + sut.WithSafeFileHandleStrategy( + new DefaultSafeFileHandleStrategy(_ => new SafeFileHandleMock("foo"))) + .Initialize().WithFile("foo"); + SafeFileHandle handle = new(); + FileAccess access = FileAccess.ReadWrite; + int bufferSize = 42; - using FileSystemStream result = sut.FileStream.New(path, mode); + using FileSystemStream result = sut.FileStream.New(handle, access, bufferSize); - sut.Statistics.FileStream.ShouldOnlyContain(nameof(IFileStreamFactory.New), - path, mode); + sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.New), + handle, access, bufferSize); } - -#if FEATURE_FILESYSTEM_STREAM_OPTIONS +#endif +#if NET6_0_OR_GREATER [SkippableFact] - public void New_String_FileStreamOptions_ShouldRegisterCall() + public void Method_New_SafeFileHandle_FileAccess_ShouldRegisterCall() { MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - FileStreamOptions options = new(); + sut.WithSafeFileHandleStrategy( + new DefaultSafeFileHandleStrategy(_ => new SafeFileHandleMock("foo"))) + .Initialize().WithFile("foo"); + SafeFileHandle handle = new(); + FileAccess access = FileAccess.ReadWrite; - using FileSystemStream result = sut.FileStream.New(path, options); + using FileSystemStream result = sut.FileStream.New(handle, access); - sut.Statistics.FileStream.ShouldOnlyContain(nameof(IFileStreamFactory.New), - path, options); + sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.New), + handle, access); } #endif -#if NET6_0_OR_GREATER [SkippableFact] - public void New_SafeFileHandle_FileAccess_Int_ShouldRegisterCall() + public void Method_New_String_FileMode_FileAccess_FileShare_Int_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); - sut.WithSafeFileHandleStrategy( - new DefaultSafeFileHandleStrategy(_ => new SafeFileHandleMock("foo"))) - .Initialize().WithFile("foo"); - SafeFileHandle handle = new(); + string path = "foo"; + FileMode mode = FileMode.OpenOrCreate; FileAccess access = FileAccess.ReadWrite; + FileShare share = FileShare.ReadWrite; int bufferSize = 42; + bool useAsync = true; - using FileSystemStream result = sut.FileStream.New(handle, access, bufferSize); + using FileSystemStream result = + sut.FileStream.New(path, mode, access, share, bufferSize, useAsync); - sut.Statistics.FileStream.ShouldOnlyContain(nameof(IFileStreamFactory.New), - handle, access, bufferSize); + sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.New), + path, mode, access, share, bufferSize, useAsync); } -#endif [SkippableFact] - public void New_String_FileMode_FileAccess_ShouldRegisterCall() + public void Method_New_String_FileMode_FileAccess_FileShare_Int_FileOptions_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; FileMode mode = FileMode.OpenOrCreate; FileAccess access = FileAccess.ReadWrite; + FileShare share = FileShare.ReadWrite; + int bufferSize = 42; + FileOptions options = new(); - using FileSystemStream result = sut.FileStream.New(path, mode, access); + using FileSystemStream result = + sut.FileStream.New(path, mode, access, share, bufferSize, options); - sut.Statistics.FileStream.ShouldOnlyContain(nameof(IFileStreamFactory.New), - path, mode, access); + sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.New), + path, mode, access, share, bufferSize, options); } -#if NET6_0_OR_GREATER [SkippableFact] - public void New_SafeFileHandle_FileAccess_Int_Bool_ShouldRegisterCall() + public void Method_New_String_FileMode_FileAccess_FileShare_Int_ShouldRegisterCall() { MockFileSystem sut = new(); - sut.WithSafeFileHandleStrategy( - new DefaultSafeFileHandleStrategy(_ => new SafeFileHandleMock("foo"))) - .Initialize().WithFile("foo"); - SafeFileHandle handle = new(); + string path = "foo"; + FileMode mode = FileMode.OpenOrCreate; FileAccess access = FileAccess.ReadWrite; + FileShare share = FileShare.ReadWrite; int bufferSize = 42; - bool isAsync = true; - using FileSystemStream result = sut.FileStream.New(handle, access, bufferSize, isAsync); + using FileSystemStream result = sut.FileStream.New(path, mode, access, share, bufferSize); - sut.Statistics.FileStream.ShouldOnlyContain(nameof(IFileStreamFactory.New), - handle, access, bufferSize, isAsync); + sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.New), + path, mode, access, share, bufferSize); } -#endif [SkippableFact] - public void New_String_FileMode_FileAccess_FileShare_ShouldRegisterCall() + public void Method_New_String_FileMode_FileAccess_FileShare_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -120,62 +128,55 @@ public void New_String_FileMode_FileAccess_FileShare_ShouldRegisterCall() using FileSystemStream result = sut.FileStream.New(path, mode, access, share); - sut.Statistics.FileStream.ShouldOnlyContain(nameof(IFileStreamFactory.New), + sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.New), path, mode, access, share); } [SkippableFact] - public void New_String_FileMode_FileAccess_FileShare_Int_ShouldRegisterCall() + public void Method_New_String_FileMode_FileAccess_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; FileMode mode = FileMode.OpenOrCreate; FileAccess access = FileAccess.ReadWrite; - FileShare share = FileShare.ReadWrite; - int bufferSize = 42; - using FileSystemStream result = sut.FileStream.New(path, mode, access, share, bufferSize); + using FileSystemStream result = sut.FileStream.New(path, mode, access); - sut.Statistics.FileStream.ShouldOnlyContain(nameof(IFileStreamFactory.New), - path, mode, access, share, bufferSize); + sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.New), + path, mode, access); } [SkippableFact] - public void New_String_FileMode_FileAccess_FileShare_Int_Bool_ShouldRegisterCall() + public void Method_New_String_FileMode_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; FileMode mode = FileMode.OpenOrCreate; - FileAccess access = FileAccess.ReadWrite; - FileShare share = FileShare.ReadWrite; - int bufferSize = 42; - bool useAsync = true; - using FileSystemStream result = sut.FileStream.New(path, mode, access, share, bufferSize, useAsync); + using FileSystemStream result = sut.FileStream.New(path, mode); - sut.Statistics.FileStream.ShouldOnlyContain(nameof(IFileStreamFactory.New), - path, mode, access, share, bufferSize, useAsync); + sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.New), + path, mode); } +#if FEATURE_FILESYSTEM_STREAM_OPTIONS [SkippableFact] - public void New_String_FileMode_FileAccess_FileShare_Int_FileOptions_ShouldRegisterCall() + public void Method_New_String_FileStreamOptions_ShouldRegisterCall() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); string path = "foo"; - FileMode mode = FileMode.OpenOrCreate; - FileAccess access = FileAccess.ReadWrite; - FileShare share = FileShare.ReadWrite; - int bufferSize = 42; - FileOptions options = new(); + FileStreamOptions options = new(); - using FileSystemStream result = sut.FileStream.New(path, mode, access, share, bufferSize, options); + using FileSystemStream result = sut.FileStream.New(path, options); - sut.Statistics.FileStream.ShouldOnlyContain(nameof(IFileStreamFactory.New), - path, mode, access, share, bufferSize, options); + sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.New), + path, options); } +#endif [SkippableFact] - public void Wrap_FileStream_ShouldRegisterCall() + public void Method_Wrap_FileStream_ShouldRegisterCall() { MockFileSystem sut = new(); FileStream fileStream = new("foo", FileMode.OpenOrCreate); @@ -189,7 +190,7 @@ public void Wrap_FileStream_ShouldRegisterCall() // Wrap is not possible on the MockFileSystem, but should still be registered! } - sut.Statistics.FileStream.ShouldOnlyContain(nameof(IFileStreamFactory.Wrap), + sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.Wrap), fileStream); } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs index daa4dc766..e524491cf 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs @@ -9,7 +9,7 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public class FileStreamStatisticsTests { [SkippableFact] - public void BeginRead_ByteArray_Int_Int_AsyncCallback_Object_ShouldRegisterCall() + public void Method_BeginRead_ByteArray_Int_Int_AsyncCallback_Object_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); @@ -21,12 +21,13 @@ public void BeginRead_ByteArray_Int_Int_AsyncCallback_Object_ShouldRegisterCall( fileStream.BeginRead(buffer, offset, count, callback, state); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.BeginRead), + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( + nameof(FileSystemStream.BeginRead), buffer, offset, count, callback, state); } [SkippableFact] - public void BeginWrite_ByteArray_Int_Int_AsyncCallback_Object_ShouldRegisterCall() + public void Method_BeginWrite_ByteArray_Int_Int_AsyncCallback_Object_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); @@ -38,12 +39,13 @@ public void BeginWrite_ByteArray_Int_Int_AsyncCallback_Object_ShouldRegisterCall fileStream.BeginWrite(buffer, offset, count, callback, state); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.BeginWrite), + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( + nameof(FileSystemStream.BeginWrite), buffer, offset, count, callback, state); } [SkippableFact] - public void CopyTo_Stream_Int_ShouldRegisterCall() + public void Method_CopyTo_Stream_Int_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); @@ -52,12 +54,13 @@ public void CopyTo_Stream_Int_ShouldRegisterCall() fileStream.CopyTo(destination, bufferSize); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.CopyTo), + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( + nameof(FileSystemStream.CopyTo), destination, bufferSize); } [SkippableFact] - public async Task CopyToAsync_Stream_Int_CancellationToken_ShouldRegisterCall() + public async Task Method_CopyToAsync_Stream_Int_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); @@ -67,12 +70,13 @@ public async Task CopyToAsync_Stream_Int_CancellationToken_ShouldRegisterCall() await fileStream.CopyToAsync(destination, bufferSize, cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.CopyToAsync), + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( + nameof(FileSystemStream.CopyToAsync), destination, bufferSize, cancellationToken); } [SkippableFact] - public void EndRead_IAsyncResult_ShouldRegisterCall() + public void Method_EndRead_IAsyncResult_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -89,7 +93,7 @@ public void EndRead_IAsyncResult_ShouldRegisterCall() } [SkippableFact] - public void EndWrite_IAsyncResult_ShouldRegisterCall() + public void Method_EndWrite_IAsyncResult_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); @@ -106,31 +110,32 @@ public void EndWrite_IAsyncResult_ShouldRegisterCall() } [SkippableFact] - public void Flush_ShouldRegisterCall() + public void Method_Flush_Bool_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + bool flushToDisk = true; - fileStream.Flush(); + fileStream.Flush(flushToDisk); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.Flush)); + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Flush), + flushToDisk); } [SkippableFact] - public void Flush_Bool_ShouldRegisterCall() + public void Method_Flush_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); - bool flushToDisk = true; - fileStream.Flush(flushToDisk); + fileStream.Flush(); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.Flush), - flushToDisk); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.Flush)); } [SkippableFact] - public async Task FlushAsync_CancellationToken_ShouldRegisterCall() + public async Task Method_FlushAsync_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); @@ -138,13 +143,29 @@ public async Task FlushAsync_CancellationToken_ShouldRegisterCall() await fileStream.FlushAsync(cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.FlushAsync), + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( + nameof(FileSystemStream.FlushAsync), cancellationToken); } + [SkippableFact] + public void Method_Read_ByteArray_Int_Int_ShouldRegisterCall() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + byte[] buffer = Encoding.UTF8.GetBytes("foo"); + int offset = 0; + int count = 2; + + _ = fileStream.Read(buffer, offset, count); + + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Read), + buffer, offset, count); + } + #if FEATURE_SPAN [SkippableFact] - public void Read_SpanByte_ShouldRegisterCall() + public void Method_Read_SpanByte_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); @@ -152,29 +173,31 @@ public void Read_SpanByte_ShouldRegisterCall() _ = fileStream.Read(buffer); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.Read), + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Read), buffer); } #endif [SkippableFact] - public void Read_ByteArray_Int_Int_ShouldRegisterCall() + public async Task Method_ReadAsync_ByteArray_Int_Int_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); byte[] buffer = Encoding.UTF8.GetBytes("foo"); int offset = 0; int count = 2; + CancellationToken cancellationToken = CancellationToken.None; - _ = fileStream.Read(buffer, offset, count); + _ = await fileStream.ReadAsync(buffer, offset, count, cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.Read), - buffer, offset, count); + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( + nameof(FileSystemStream.ReadAsync), + buffer, offset, count, cancellationToken); } #if FEATURE_SPAN [SkippableFact] - public async Task ReadAsync_MemoryByte_CancellationToken_ShouldRegisterCall() + public async Task Method_ReadAsync_MemoryByte_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); await using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); @@ -183,40 +206,26 @@ public async Task ReadAsync_MemoryByte_CancellationToken_ShouldRegisterCall() _ = await fileStream.ReadAsync(buffer, cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.ReadAsync), + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( + nameof(FileSystemStream.ReadAsync), buffer, cancellationToken); } #endif [SkippableFact] - public async Task ReadAsync_ByteArray_Int_Int_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); - byte[] buffer = Encoding.UTF8.GetBytes("foo"); - int offset = 0; - int count = 2; - CancellationToken cancellationToken = CancellationToken.None; - - _ = await fileStream.ReadAsync(buffer, offset, count, cancellationToken); - - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.ReadAsync), - buffer, offset, count, cancellationToken); - } - - [SkippableFact] - public void ReadByte_ShouldRegisterCall() + public void Method_ReadByte_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); fileStream.ReadByte(); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.ReadByte)); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.ReadByte)); } [SkippableFact] - public void Seek_Int64_SeekOrigin_ShouldRegisterCall() + public void Method_Seek_Int64_SeekOrigin_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); @@ -225,12 +234,12 @@ public void Seek_Int64_SeekOrigin_ShouldRegisterCall() fileStream.Seek(offset, origin); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.Seek), + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Seek), offset, origin); } [SkippableFact] - public void SetLength_Int64_ShouldRegisterCall() + public void Method_SetLength_Int64_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); @@ -238,24 +247,41 @@ public void SetLength_Int64_ShouldRegisterCall() fileStream.SetLength(value); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.SetLength), + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( + nameof(FileSystemStream.SetLength), value); } [SkippableFact] - public void ToString_ShouldRegisterCall() + public void Method_ToString_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); _ = fileStream.ToString(); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.ToString)); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.ToString)); + } + + [SkippableFact] + public void Method_Write_ByteArray_Int_Int_ShouldRegisterCall() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + byte[] buffer = Encoding.UTF8.GetBytes("foo"); + int offset = 0; + int count = 2; + + fileStream.Write(buffer, offset, count); + + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Write), + buffer, offset, count); } #if FEATURE_SPAN [SkippableFact] - public void Write_ReadOnlySpanByte_ShouldRegisterCall() + public void Method_Write_ReadOnlySpanByte_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); @@ -263,29 +289,31 @@ public void Write_ReadOnlySpanByte_ShouldRegisterCall() fileStream.Write(buffer); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.Write), + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Write), buffer); } #endif [SkippableFact] - public void Write_ByteArray_Int_Int_ShouldRegisterCall() + public async Task Method_WriteAsync_ByteArray_Int_Int_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); byte[] buffer = Encoding.UTF8.GetBytes("foo"); int offset = 0; int count = 2; + CancellationToken cancellationToken = CancellationToken.None; - fileStream.Write(buffer, offset, count); + await fileStream.WriteAsync(buffer, offset, count, cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.Write), - buffer, offset, count); + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( + nameof(FileSystemStream.WriteAsync), + buffer, offset, count, cancellationToken); } #if FEATURE_SPAN [SkippableFact] - public async Task WriteAsync_ReadOnlyMemoryByte_CancellationToken_ShouldRegisterCall() + public async Task Method_WriteAsync_ReadOnlyMemoryByte_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); await using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); @@ -294,37 +322,182 @@ public async Task WriteAsync_ReadOnlyMemoryByte_CancellationToken_ShouldRegister await fileStream.WriteAsync(buffer, cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.WriteAsync), + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( + nameof(FileSystemStream.WriteAsync), buffer, cancellationToken); } #endif [SkippableFact] - public async Task WriteAsync_ByteArray_Int_Int_CancellationToken_ShouldRegisterCall() + public void Method_WriteByte_Byte_ShouldRegisterCall() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); - byte[] buffer = Encoding.UTF8.GetBytes("foo"); - int offset = 0; - int count = 2; - CancellationToken cancellationToken = CancellationToken.None; + byte value = new(); - await fileStream.WriteAsync(buffer, offset, count, cancellationToken); + fileStream.WriteByte(value); - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.WriteAsync), - buffer, offset, count, cancellationToken); + sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( + nameof(FileSystemStream.WriteByte), + value); } [SkippableFact] - public void WriteByte_Byte_ShouldRegisterCall() + public void Property_CanRead_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); - byte value = new(); - fileStream.WriteByte(value); + _ = fileStream.CanRead; - sut.Statistics.FileStream["foo"].ShouldOnlyContain(nameof(FileSystemStream.WriteByte), - value); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.CanRead)); + } + + [SkippableFact] + public void Property_CanSeek_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + + _ = fileStream.CanSeek; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.CanSeek)); + } + + [SkippableFact] + public void Property_CanTimeout_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + + _ = fileStream.CanTimeout; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.CanTimeout)); + } + + [SkippableFact] + public void Property_CanWrite_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + + _ = fileStream.CanWrite; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.CanWrite)); + } + + [SkippableFact] + public void Property_IsAsync_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + + _ = fileStream.IsAsync; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.IsAsync)); + } + + [SkippableFact] + public void Property_Length_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + + _ = fileStream.Length; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.Length)); + } + + [SkippableFact] + public void Property_Name_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + + _ = fileStream.Name; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.Name)); + } + + [SkippableFact] + public void Property_Position_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + + _ = fileStream.Position; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.Position)); + } + + [SkippableFact] + public void Property_Position_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + long value = new(); + + fileStream.Position = value; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(FileSystemStream.Position)); + } + + [SkippableFact] + public void Property_ReadTimeout_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + + _ = fileStream.ReadTimeout; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.ReadTimeout)); + } + + [SkippableFact] + public void Property_ReadTimeout_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + int value = 42; + + fileStream.ReadTimeout = value; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(FileSystemStream.ReadTimeout)); + } + + [SkippableFact] + public void Property_WriteTimeout_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + + _ = fileStream.WriteTimeout; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.WriteTimeout)); + } + + [SkippableFact] + public void Property_WriteTimeout_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); + int value = 42; + + fileStream.WriteTimeout = value; + + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(FileSystemStream.WriteTimeout)); } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherFactoryStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherFactoryStatisticsTests.cs index 774a90024..73744b4d3 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherFactoryStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherFactoryStatisticsTests.cs @@ -6,17 +6,18 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public class FileSystemWatcherFactoryStatisticsTests { [SkippableFact] - public void New_ShouldRegisterCall() + public void Method_New_ShouldRegisterCall() { MockFileSystem sut = new(); using IFileSystemWatcher result = sut.FileSystemWatcher.New(); - sut.Statistics.FileSystemWatcher.ShouldOnlyContain(nameof(IFileSystemWatcherFactory.New)); + sut.Statistics.FileSystemWatcher.ShouldOnlyContainMethodCall( + nameof(IFileSystemWatcherFactory.New)); } [SkippableFact] - public void New_String_ShouldRegisterCall() + public void Method_New_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -24,12 +25,13 @@ public void New_String_ShouldRegisterCall() using IFileSystemWatcher result = sut.FileSystemWatcher.New(path); - sut.Statistics.FileSystemWatcher.ShouldOnlyContain(nameof(IFileSystemWatcherFactory.New), + sut.Statistics.FileSystemWatcher.ShouldOnlyContainMethodCall( + nameof(IFileSystemWatcherFactory.New), path); } [SkippableFact] - public void New_String_String_ShouldRegisterCall() + public void Method_New_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -38,19 +40,21 @@ public void New_String_String_ShouldRegisterCall() using IFileSystemWatcher result = sut.FileSystemWatcher.New(path, filter); - sut.Statistics.FileSystemWatcher.ShouldOnlyContain(nameof(IFileSystemWatcherFactory.New), + sut.Statistics.FileSystemWatcher.ShouldOnlyContainMethodCall( + nameof(IFileSystemWatcherFactory.New), path, filter); } [SkippableFact] - public void Wrap_FileSystemWatcher_ShouldRegisterCall() + public void Method_Wrap_FileSystemWatcher_ShouldRegisterCall() { MockFileSystem sut = new(); FileSystemWatcher fileSystemWatcher = new(); using IFileSystemWatcher result = sut.FileSystemWatcher.Wrap(fileSystemWatcher); - sut.Statistics.FileSystemWatcher.ShouldOnlyContain(nameof(IFileSystemWatcherFactory.Wrap), + sut.Statistics.FileSystemWatcher.ShouldOnlyContainMethodCall( + nameof(IFileSystemWatcherFactory.Wrap), fileSystemWatcher); } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherStatisticsTests.cs index f068cc94a..f39dd8923 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherStatisticsTests.cs @@ -1,4 +1,5 @@ -using System.IO; +using System.ComponentModel; +using System.IO; using System.Threading; using System.Threading.Tasks; using Testably.Abstractions.Testing.Tests.TestHelpers; @@ -8,7 +9,7 @@ namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public class FileSystemWatcherStatisticsTests { [SkippableFact] - public void BeginInit_ShouldRegisterCall() + public void Method_BeginInit_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -17,11 +18,11 @@ public void BeginInit_ShouldRegisterCall() fileSystemWatcher.BeginInit(); sut.Statistics.FileSystemWatcher["foo"] - .ShouldOnlyContain(nameof(IFileSystemWatcher.BeginInit)); + .ShouldOnlyContainMethodCall(nameof(IFileSystemWatcher.BeginInit)); } [SkippableFact] - public void EndInit_ShouldRegisterCall() + public void Method_EndInit_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -30,11 +31,11 @@ public void EndInit_ShouldRegisterCall() fileSystemWatcher.EndInit(); sut.Statistics.FileSystemWatcher["foo"] - .ShouldOnlyContain(nameof(IFileSystemWatcher.EndInit)); + .ShouldOnlyContainMethodCall(nameof(IFileSystemWatcher.EndInit)); } [SkippableFact] - public void WaitForChanged_WatcherChangeTypes_ShouldRegisterCall() + public void Method_WaitForChanged_WatcherChangeTypes_Int_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -51,15 +52,17 @@ public void WaitForChanged_WatcherChangeTypes_ShouldRegisterCall() } }, cts.Token); WatcherChangeTypes changeType = WatcherChangeTypes.Created; + int timeout = 42; - fileSystemWatcher.WaitForChanged(changeType); + fileSystemWatcher.WaitForChanged(changeType, timeout); sut.Statistics.FileSystemWatcher["foo"] - .ShouldOnlyContain(nameof(IFileSystemWatcher.WaitForChanged), changeType); + .ShouldOnlyContainMethodCall(nameof(IFileSystemWatcher.WaitForChanged), changeType, + timeout); } [SkippableFact] - public void WaitForChanged_WatcherChangeTypes_Int_ShouldRegisterCall() + public void Method_WaitForChanged_WatcherChangeTypes_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -76,17 +79,16 @@ public void WaitForChanged_WatcherChangeTypes_Int_ShouldRegisterCall() } }, cts.Token); WatcherChangeTypes changeType = WatcherChangeTypes.Created; - int timeout = 42; - fileSystemWatcher.WaitForChanged(changeType, timeout); + fileSystemWatcher.WaitForChanged(changeType); sut.Statistics.FileSystemWatcher["foo"] - .ShouldOnlyContain(nameof(IFileSystemWatcher.WaitForChanged), changeType, timeout); + .ShouldOnlyContainMethodCall(nameof(IFileSystemWatcher.WaitForChanged), changeType); } #if FEATURE_FILESYSTEM_NET7 [SkippableFact] - public void WaitForChanged_WatcherChangeTypes_TimeSpan_ShouldRegisterCall() + public void Method_WaitForChanged_WatcherChangeTypes_TimeSpan_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); @@ -108,7 +110,215 @@ public void WaitForChanged_WatcherChangeTypes_TimeSpan_ShouldRegisterCall() fileSystemWatcher.WaitForChanged(changeType, timeout); sut.Statistics.FileSystemWatcher["foo"] - .ShouldOnlyContain(nameof(IFileSystemWatcher.WaitForChanged), changeType, timeout); + .ShouldOnlyContainMethodCall(nameof(IFileSystemWatcher.WaitForChanged), changeType, + timeout); } #endif + [SkippableFact] + public void Property_Container_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileSystemWatcher.New("foo").Container; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileSystemWatcher.Container)); + } + + [SkippableFact] + public void Property_EnableRaisingEvents_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileSystemWatcher.New("foo").EnableRaisingEvents; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileSystemWatcher.EnableRaisingEvents)); + } + + [SkippableFact] + public void Property_EnableRaisingEvents_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + bool value = true; + + sut.FileSystemWatcher.New("foo").EnableRaisingEvents = value; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileSystemWatcher.EnableRaisingEvents)); + } + + [SkippableFact] + public void Property_Filter_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileSystemWatcher.New("foo").Filter; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileSystemWatcher.Filter)); + } + + [SkippableFact] + public void Property_Filter_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + string value = "foo"; + + sut.FileSystemWatcher.New("foo").Filter = value; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileSystemWatcher.Filter)); + } + +#if FEATURE_FILESYSTEMWATCHER_ADVANCED + [SkippableFact] + public void Property_Filters_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileSystemWatcher.New("foo").Filters; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileSystemWatcher.Filters)); + } +#endif + + [SkippableFact] + public void Property_IncludeSubdirectories_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileSystemWatcher.New("foo").IncludeSubdirectories; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileSystemWatcher.IncludeSubdirectories)); + } + + [SkippableFact] + public void Property_IncludeSubdirectories_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + bool value = true; + + sut.FileSystemWatcher.New("foo").IncludeSubdirectories = value; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileSystemWatcher.IncludeSubdirectories)); + } + + [SkippableFact] + public void Property_InternalBufferSize_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileSystemWatcher.New("foo").InternalBufferSize; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileSystemWatcher.InternalBufferSize)); + } + + [SkippableFact] + public void Property_InternalBufferSize_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + int value = 42; + + sut.FileSystemWatcher.New("foo").InternalBufferSize = value; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileSystemWatcher.InternalBufferSize)); + } + + [SkippableFact] + public void Property_NotifyFilter_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileSystemWatcher.New("foo").NotifyFilter; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileSystemWatcher.NotifyFilter)); + } + + [SkippableFact] + public void Property_NotifyFilter_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + NotifyFilters value = new(); + + sut.FileSystemWatcher.New("foo").NotifyFilter = value; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileSystemWatcher.NotifyFilter)); + } + + [SkippableFact] + public void Property_Path_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileSystemWatcher.New("foo").Path; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileSystemWatcher.Path)); + } + + [SkippableFact] + public void Property_Path_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + string value = "foo"; + + sut.FileSystemWatcher.New("foo").Path = value; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileSystemWatcher.Path)); + } + + [SkippableFact] + public void Property_Site_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileSystemWatcher.New("foo").Site; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileSystemWatcher.Site)); + } + + [SkippableFact] + public void Property_Site_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + ISite value = null!; + + sut.FileSystemWatcher.New("foo").Site = value; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileSystemWatcher.Site)); + } + + [SkippableFact] + public void Property_SynchronizingObject_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.FileSystemWatcher.New("foo").SynchronizingObject; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertyGetAccess(nameof(IFileSystemWatcher.SynchronizingObject)); + } + + [SkippableFact] + public void Property_SynchronizingObject_Set_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + ISynchronizeInvoke value = null!; + + sut.FileSystemWatcher.New("foo").SynchronizingObject = value; + + sut.Statistics.FileSystemWatcher["foo"] + .ShouldOnlyContainPropertySetAccess(nameof(IFileSystemWatcher.SynchronizingObject)); + } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/PathStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/PathStatisticsTests.cs index 33a3831ac..48deea5ae 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/PathStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/PathStatisticsTests.cs @@ -1,11 +1,12 @@ -using Testably.Abstractions.Testing.Tests.TestHelpers; +using System.IO; +using Testably.Abstractions.Testing.Tests.TestHelpers; namespace Testably.Abstractions.Testing.Tests.Statistics.FileSystem; public class PathStatisticsTests { [SkippableFact] - public void ChangeExtension_String_String_ShouldRegisterCall() + public void Method_ChangeExtension_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; @@ -13,24 +14,12 @@ public void ChangeExtension_String_String_ShouldRegisterCall() sut.Path.ChangeExtension(path, extension); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.ChangeExtension), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.ChangeExtension), path, extension); } [SkippableFact] - public void Combine_StringArray_ShouldRegisterCall() - { - MockFileSystem sut = new(); - string[] paths = ["foo", "bar"]; - - sut.Path.Combine(paths); - - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Combine), - paths); - } - - [SkippableFact] - public void Combine_String_String_ShouldRegisterCall() + public void Method_Combine_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path1 = "foo"; @@ -38,12 +27,12 @@ public void Combine_String_String_ShouldRegisterCall() sut.Path.Combine(path1, path2); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Combine), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Combine), path1, path2); } [SkippableFact] - public void Combine_String_String_String_ShouldRegisterCall() + public void Method_Combine_String_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path1 = "foo"; @@ -52,12 +41,12 @@ public void Combine_String_String_String_ShouldRegisterCall() sut.Path.Combine(path1, path2, path3); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Combine), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Combine), path1, path2, path3); } [SkippableFact] - public void Combine_String_String_String_String_ShouldRegisterCall() + public void Method_Combine_String_String_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path1 = "foo"; @@ -67,240 +56,226 @@ public void Combine_String_String_String_String_ShouldRegisterCall() sut.Path.Combine(path1, path2, path3, path4); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Combine), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Combine), path1, path2, path3, path4); } -#if FEATURE_PATH_ADVANCED - [SkippableFact] - public void EndsInDirectorySeparator_ReadOnlySpanChar_ShouldRegisterCall() - { - MockFileSystem sut = new(); - ReadOnlySpan path = new(); - - sut.Path.EndsInDirectorySeparator(path); - - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.EndsInDirectorySeparator), - path); - } - [SkippableFact] - public void EndsInDirectorySeparator_String_ShouldRegisterCall() + public void Method_Combine_StringArray_ShouldRegisterCall() { MockFileSystem sut = new(); - string path = "foo"; + string[] paths = ["foo", "bar"]; - sut.Path.EndsInDirectorySeparator(path); + sut.Path.Combine(paths); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.EndsInDirectorySeparator), - path); + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Combine), + paths); } -#endif #if FEATURE_FILESYSTEM_NET7 [SkippableFact] - public void Exists_String_ShouldRegisterCall() + public void Method_Exists_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Path.Exists(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Exists), - path); + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Exists), + path); } #endif #if FEATURE_SPAN [SkippableFact] - public void GetDirectoryName_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_GetDirectoryName_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path = new(); sut.Path.GetDirectoryName(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetDirectoryName), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetDirectoryName), path); } #endif [SkippableFact] - public void GetDirectoryName_String_ShouldRegisterCall() + public void Method_GetDirectoryName_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Path.GetDirectoryName(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetDirectoryName), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetDirectoryName), path); } #if FEATURE_SPAN [SkippableFact] - public void GetExtension_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_GetExtension_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path = new(); sut.Path.GetExtension(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetExtension), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetExtension), path); } #endif [SkippableFact] - public void GetExtension_String_ShouldRegisterCall() + public void Method_GetExtension_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Path.GetExtension(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetExtension), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetExtension), path); } #if FEATURE_SPAN [SkippableFact] - public void GetFileName_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_GetFileName_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path = new(); sut.Path.GetFileName(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetFileName), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetFileName), path); } #endif [SkippableFact] - public void GetFileName_String_ShouldRegisterCall() + public void Method_GetFileName_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Path.GetFileName(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetFileName), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetFileName), path); } #if FEATURE_SPAN [SkippableFact] - public void GetFileNameWithoutExtension_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_GetFileNameWithoutExtension_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path = new(); sut.Path.GetFileNameWithoutExtension(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetFileNameWithoutExtension), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetFileNameWithoutExtension), path); } #endif [SkippableFact] - public void GetFileNameWithoutExtension_String_ShouldRegisterCall() + public void Method_GetFileNameWithoutExtension_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Path.GetFileNameWithoutExtension(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetFileNameWithoutExtension), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetFileNameWithoutExtension), path); } [SkippableFact] - public void GetFullPath_String_ShouldRegisterCall() + public void Method_GetFullPath_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Path.GetFullPath(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetFullPath), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetFullPath), path); } #if FEATURE_PATH_RELATIVE [SkippableFact] - public void GetFullPath_String_String_ShouldRegisterCall() + public void Method_GetFullPath_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; - string basePath = System.IO.Path.GetFullPath("bar"); + string basePath = Path.GetFullPath("bar"); sut.Path.GetFullPath(path, basePath); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetFullPath), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetFullPath), path, basePath); } #endif [SkippableFact] - public void GetInvalidFileNameChars_ShouldRegisterCall() + public void Method_GetInvalidFileNameChars_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Path.GetInvalidFileNameChars(); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetInvalidFileNameChars)); + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetInvalidFileNameChars)); } [SkippableFact] - public void GetInvalidPathChars_ShouldRegisterCall() + public void Method_GetInvalidPathChars_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Path.GetInvalidPathChars(); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetInvalidPathChars)); + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetInvalidPathChars)); } #if FEATURE_SPAN [SkippableFact] - public void GetPathRoot_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_GetPathRoot_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path = new(); sut.Path.GetPathRoot(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetPathRoot), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetPathRoot), path); } #endif [SkippableFact] - public void GetPathRoot_String_ShouldRegisterCall() + public void Method_GetPathRoot_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Path.GetPathRoot(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetPathRoot), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetPathRoot), path); } [SkippableFact] - public void GetRandomFileName_ShouldRegisterCall() + public void Method_GetRandomFileName_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Path.GetRandomFileName(); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetRandomFileName)); + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetRandomFileName)); } #if FEATURE_PATH_RELATIVE [SkippableFact] - public void GetRelativePath_String_String_ShouldRegisterCall() + public void Method_GetRelativePath_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string relativeTo = "foo"; @@ -308,126 +283,194 @@ public void GetRelativePath_String_String_ShouldRegisterCall() sut.Path.GetRelativePath(relativeTo, path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetRelativePath), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetRelativePath), relativeTo, path); } #endif [SkippableFact] - public void GetTempFileName_ShouldRegisterCall() + public void Method_GetTempFileName_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Path.GetTempFileName(); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetTempFileName)); + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetTempFileName)); } [SkippableFact] - public void GetTempPath_ShouldRegisterCall() + public void Method_GetTempPath_ShouldRegisterCall() { MockFileSystem sut = new(); sut.Path.GetTempPath(); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.GetTempPath)); + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.GetTempPath)); } #if FEATURE_SPAN [SkippableFact] - public void HasExtension_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_HasExtension_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path = new(); sut.Path.HasExtension(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.HasExtension), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.HasExtension), path); } #endif [SkippableFact] - public void HasExtension_String_ShouldRegisterCall() + public void Method_HasExtension_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Path.HasExtension(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.HasExtension), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.HasExtension), path); } #if FEATURE_SPAN [SkippableFact] - public void IsPathFullyQualified_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_IsPathFullyQualified_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path = new(); sut.Path.IsPathFullyQualified(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.IsPathFullyQualified), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.IsPathFullyQualified), path); } #endif #if FEATURE_PATH_RELATIVE [SkippableFact] - public void IsPathFullyQualified_String_ShouldRegisterCall() + public void Method_IsPathFullyQualified_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Path.IsPathFullyQualified(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.IsPathFullyQualified), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.IsPathFullyQualified), path); } #endif #if FEATURE_SPAN [SkippableFact] - public void IsPathRooted_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_IsPathRooted_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path = new(); sut.Path.IsPathRooted(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.IsPathRooted), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.IsPathRooted), path); } #endif [SkippableFact] - public void IsPathRooted_String_ShouldRegisterCall() + public void Method_IsPathRooted_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Path.IsPathRooted(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.IsPathRooted), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.IsPathRooted), path); } + [SkippableFact] + public void Property_AltDirectorySeparatorChar_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.Path.AltDirectorySeparatorChar; + + sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess( + nameof(IPath.AltDirectorySeparatorChar)); + } + + [SkippableFact] + public void Property_DirectorySeparatorChar_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.Path.DirectorySeparatorChar; + + sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess( + nameof(IPath.DirectorySeparatorChar)); + } + + [SkippableFact] + public void Property_PathSeparator_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.Path.PathSeparator; + + sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess(nameof(IPath.PathSeparator)); + } + + [SkippableFact] + public void Property_VolumeSeparatorChar_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.Path.VolumeSeparatorChar; + + sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess(nameof(IPath.VolumeSeparatorChar)); + } + +#if FEATURE_PATH_ADVANCED + [SkippableFact] + public void Method_EndsInDirectorySeparator_ReadOnlySpanChar_ShouldRegisterCall() + { + MockFileSystem sut = new(); + ReadOnlySpan path = new(); + + sut.Path.EndsInDirectorySeparator(path); + + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.EndsInDirectorySeparator), + path); + } + + [SkippableFact] + public void Method_EndsInDirectorySeparator_String_ShouldRegisterCall() + { + MockFileSystem sut = new(); + string path = "foo"; + + sut.Path.EndsInDirectorySeparator(path); + + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.EndsInDirectorySeparator), + path); + } +#endif + #if FEATURE_PATH_JOIN [SkippableFact] - public void Join_StringArray_ShouldRegisterCall() + public void Method_Join_StringArray_ShouldRegisterCall() { MockFileSystem sut = new(); string[] paths = ["foo", "bar"]; sut.Path.Join(paths); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Join), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), paths); } [SkippableFact] - public void Join_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_Join_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path1 = new(); @@ -435,12 +478,12 @@ public void Join_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() sut.Path.Join(path1, path2); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Join), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), path1, path2); } [SkippableFact] - public void Join_String_String_ShouldRegisterCall() + public void Method_Join_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path1 = "foo"; @@ -448,12 +491,12 @@ public void Join_String_String_ShouldRegisterCall() sut.Path.Join(path1, path2); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Join), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), path1, path2); } [SkippableFact] - public void Join_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_Join_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path1 = new(); @@ -462,12 +505,12 @@ public void Join_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegist sut.Path.Join(path1, path2, path3); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Join), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), path1, path2, path3); } [SkippableFact] - public void Join_String_String_String_ShouldRegisterCall() + public void Method_Join_String_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path1 = "foo"; @@ -476,13 +519,13 @@ public void Join_String_String_String_ShouldRegisterCall() sut.Path.Join(path1, path2, path3); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Join), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), path1, path2, path3); } [SkippableFact] public void - Join_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() + Method_Join_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path1 = new(); @@ -492,12 +535,12 @@ public void sut.Path.Join(path1, path2, path3, path4); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Join), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), path1, path2, path3, path4); } [SkippableFact] - public void Join_String_String_String_String_ShouldRegisterCall() + public void Method_Join_String_String_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path1 = "foo"; @@ -507,40 +550,41 @@ public void Join_String_String_String_String_ShouldRegisterCall() sut.Path.Join(path1, path2, path3, path4); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.Join), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), path1, path2, path3, path4); } #endif #if FEATURE_PATH_ADVANCED [SkippableFact] - public void TrimEndingDirectorySeparator_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_TrimEndingDirectorySeparator_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path = new(); sut.Path.TrimEndingDirectorySeparator(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.TrimEndingDirectorySeparator), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.TrimEndingDirectorySeparator), path); } [SkippableFact] - public void TrimEndingDirectorySeparator_String_ShouldRegisterCall() + public void Method_TrimEndingDirectorySeparator_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; sut.Path.TrimEndingDirectorySeparator(path); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.TrimEndingDirectorySeparator), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.TrimEndingDirectorySeparator), path); } #endif #if FEATURE_PATH_JOIN [SkippableFact] - public void TryJoin_ReadOnlySpanChar_ReadOnlySpanChar_SpanChar_OutInt_ShouldRegisterCall() + public void + Method_TryJoin_ReadOnlySpanChar_ReadOnlySpanChar_SpanChar_OutInt_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path1 = new(); @@ -549,12 +593,13 @@ public void TryJoin_ReadOnlySpanChar_ReadOnlySpanChar_SpanChar_OutInt_ShouldRegi sut.Path.TryJoin(path1, path2, destination, out int charsWritten); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.TryJoin), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.TryJoin), path1, path2, destination, charsWritten); } [SkippableFact] - public void TryJoin_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_SpanChar_OutInt_ShouldRegisterCall() + public void + Method_TryJoin_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_SpanChar_OutInt_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path1 = new(); @@ -564,7 +609,7 @@ public void TryJoin_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_SpanChar_ sut.Path.TryJoin(path1, path2, path3, destination, out int charsWritten); - sut.Statistics.Path.ShouldOnlyContain(nameof(IPath.TryJoin), + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.TryJoin), path1, path2, path3, destination, charsWritten); } #endif diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs new file mode 100644 index 000000000..547bcfbdf --- /dev/null +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs @@ -0,0 +1,334 @@ +using Microsoft.Win32.SafeHandles; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Testably.Abstractions.Testing.Tests.TestHelpers; + +namespace Testably.Abstractions.Testing.Tests.Statistics; + +public sealed partial class StatisticsTests +{ + private static class Helper + { + public static string CheckPropertiesAndMethods(string className, bool requireInstance, + Type mockType, Type testType) + { + StringBuilder builder = new(); + + foreach (PropertyInfo propertyInfo in + mockType.GetInterfaces() + .Where(i => i != typeof(IDisposable) && i != typeof(IAsyncDisposable)) + .SelectMany(i => i.GetProperties()) + .Concat(mockType.GetProperties(BindingFlags.DeclaredOnly | + BindingFlags.Public | + BindingFlags.Instance)) + .Where(p => p.IsSpecialName == false && (p.CanRead || p.CanWrite)) + .OrderBy(m => m.Name)) + { + if (propertyInfo.GetCustomAttribute() != null || + propertyInfo.Name == nameof(IFileSystemEntity.FileSystem)) + { + continue; + } + + if (propertyInfo.CanRead) + { + CheckPropertyGetAccess(builder, propertyInfo, className, requireInstance, mockType, testType); + } + + if (propertyInfo.CanWrite) + { + CheckPropertySetAccess(builder, propertyInfo, className, requireInstance, mockType, testType); + } + } + + foreach (MethodInfo methodInfo in + mockType.GetInterfaces() + .Where(i => i != typeof(IDisposable) && i != typeof(IAsyncDisposable)) + .SelectMany(i => i.GetMethods()) + .Concat(mockType.GetMethods(BindingFlags.DeclaredOnly | + BindingFlags.Public | + BindingFlags.Instance)) + .Where(m => m is { IsPublic: true, IsSpecialName: false }) + .OrderBy(m => m.Name) + .ThenBy(m => m.GetParameters().Length)) + { + if (methodInfo.GetCustomAttribute() != null) + { + continue; + } + + ParameterInfo[] parameters = methodInfo.GetParameters(); + + if (Test.IsNetFramework && + parameters.Any(p => p.ParameterType == typeof(SafeFileHandle))) + { + // SafeFileHandle cannot be instantiated on .NET Framework + continue; + } + + CheckMethodCall(builder, methodInfo, parameters, className, requireInstance, mockType, testType); + } + + return builder.ToString(); + } + + private static void CheckMethodCall(StringBuilder builder, + MethodInfo methodInfo, + ParameterInfo[] parameters, + string className, + bool requireInstance, + Type mockType, + Type testType) + { + string expectedName = $"Method_{methodInfo.Name}_{string.Join("_", methodInfo + .GetParameters() + .Select(x => FirstCharToUpperAsSpan(GetName(x.ParameterType, true) + .Replace("<", "") + .Replace(">", "") + .Replace("IEnumerablestring", "IEnumerableString") + .Replace("[]", "Array"))))}{(parameters.Length > 0 ? "_" : "")}ShouldRegisterCall"; + if (testType.GetMethod(expectedName) != null) + { + return; + } + + bool isAsync = typeof(Task).IsAssignableFrom(methodInfo.ReturnType); + builder.AppendLine("\t[SkippableFact]"); + builder.Append(isAsync ? "\tpublic async Task " : "\tpublic void "); + builder.Append(expectedName); + builder.AppendLine("()"); + builder.AppendLine("\t{"); + builder.AppendLine("\t\tMockFileSystem sut = new();"); + foreach (ParameterInfo parameterInfo in methodInfo.GetParameters()) + { + builder.AppendLine( + $"\t\t{GetName(parameterInfo.ParameterType, false)} {parameterInfo.Name} = {GetDefaultValue(parameterInfo.ParameterType)};"); + } + + builder.AppendLine(); + builder.AppendLine( + $"\t\t{(isAsync ? "await " : "")}sut.{className}{(requireInstance ? ".New(\"foo\")" : "")}.{methodInfo.Name}({string.Join(", ", methodInfo.GetParameters().Select(p => p.Name))});"); + builder.AppendLine(); + builder.AppendLine( + $"\t\tsut.Statistics.{className}{(requireInstance ? "[\"foo\"]" : "")}.ShouldOnlyContainMethodCall(nameof({mockType.Name}.{methodInfo.Name}){(parameters.Length > 0 ? ",\n\t\t\t" : "")}{string.Join(", ", methodInfo.GetParameters().Select(p => p.Name))});"); + builder.AppendLine("\t}"); + builder.AppendLine(); + } + + private static void CheckPropertyGetAccess(StringBuilder builder, + PropertyInfo propertyInfo, + string className, + bool requireInstance, + Type mockType, + Type testType) + { + string expectedName = $"Property_{propertyInfo.Name}_Get_ShouldRegisterPropertyAccess"; + if (testType.GetMethod(expectedName) != null) + { + return; + } + + builder.AppendLine("\t[SkippableFact]"); + builder.Append("\tpublic void "); + builder.Append(expectedName); + builder.AppendLine("()"); + builder.AppendLine("\t{"); + builder.AppendLine("\t\tMockFileSystem sut = new();"); + builder.AppendLine(); + builder.AppendLine( + $"\t\t_ = sut.{className}{(requireInstance ? ".New(\"foo\")" : "")}.{propertyInfo.Name};"); + builder.AppendLine(); + builder.AppendLine( + $"\t\tsut.Statistics.{className}{(requireInstance ? "[\"foo\"]" : "")}.ShouldOnlyContainPropertyGetAccess(nameof({mockType.Name}.{propertyInfo.Name}));"); + builder.AppendLine("\t}"); + builder.AppendLine(); + } + + private static void CheckPropertySetAccess(StringBuilder builder, + PropertyInfo propertyInfo, + string className, + bool requireInstance, + Type mockType, + Type testType) + { + string expectedName = $"Property_{propertyInfo.Name}_Set_ShouldRegisterPropertyAccess"; + if (testType.GetMethod(expectedName) != null) + { + return; + } + + builder.AppendLine("\t[SkippableFact]"); + builder.Append("\tpublic void "); + builder.Append(expectedName); + builder.AppendLine("()"); + builder.AppendLine("\t{"); + builder.AppendLine("\t\tMockFileSystem sut = new();"); + builder.AppendLine( + $"\t\t{GetName(propertyInfo.PropertyType, false)} value = {GetDefaultValue(propertyInfo.PropertyType)};"); + builder.AppendLine(); + builder.AppendLine( + $"\t\tsut.{className}{(requireInstance ? ".New(\"foo\")" : "")}.{propertyInfo.Name} = value;"); + builder.AppendLine(); + builder.AppendLine( + $"\t\tsut.Statistics.{className}{(requireInstance ? "[\"foo\"]" : "")}.ShouldOnlyContainPropertySetAccess(nameof({mockType.Name}.{propertyInfo.Name}));"); + builder.AppendLine("\t}"); + builder.AppendLine(); + } + + + private static string FirstCharToUpperAsSpan(string input) + { + if (string.IsNullOrEmpty(input)) + { + return string.Empty; + } + + return + $"{input[0].ToString().ToUpper(CultureInfo.InvariantCulture)}{input.Substring(1)}"; + } + + private static string GetDefaultValue(Type type) + { + if (type == typeof(string)) + { + return "\"foo\""; + } + + if (type == typeof(int)) + { + return "42"; + } + + if (type == typeof(bool)) + { + return "true"; + } + + if (type == typeof(SearchOption)) + { + return "SearchOption.AllDirectories"; + } + + if (type == typeof(FileMode)) + { + return "FileMode.OpenOrCreate"; + } + + if (type == typeof(FileAccess)) + { + return "FileAccess.ReadWrite"; + } + + if (type == typeof(FileShare)) + { + return "FileShare.ReadWrite"; + } + + if (type == typeof(SearchOption)) + { + return "SearchOption.AllDirectories"; + } + + if (type == typeof(IEnumerable) || + type == typeof(string[])) + { + return "[\"foo\", \"bar\"]"; + } + + if (type == typeof(byte[])) + { + return "\"foo\"u8.ToArray()"; + } + + if (type == typeof(Encoding)) + { + return "Encoding.UTF8"; + } + + if (type == typeof(Stream)) + { + return "new MemoryStream()"; + } + + if (type == typeof(CancellationToken)) + { + return "CancellationToken.None"; + } + + return "new()"; + } + + private static string GetName(Type type, bool firstCharUpperCase) + { + if (type.Name == "Int32&") + { + return "OutInt"; + } + + if (type.IsGenericType) + { + int idx = type.Name.IndexOf('`', StringComparison.Ordinal); + if (idx > 0) + { + return + $"{type.Name.Substring(0, idx)}<{string.Join(",", type.GenericTypeArguments.Select(x => GetName(x, firstCharUpperCase)))}>"; + } + + return type.ToString(); + } + + if (firstCharUpperCase) + { + if (type == typeof(int)) + { + return "Int"; + } + + if (type == typeof(bool)) + { + return "Bool"; + } + } + else + { + if (type == typeof(int)) + { + return "int"; + } + + if (type == typeof(bool)) + { + return "bool"; + } + + if (type == typeof(byte)) + { + return "byte"; + } + + if (type == typeof(string)) + { + return "string"; + } + + if (type == typeof(byte[])) + { + return "byte[]"; + } + + if (type == typeof(string[])) + { + return "string[]"; + } + } + + return type.Name; + } + } +} diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.cs index 0af98d49d..f1d62a334 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.cs @@ -1,19 +1,13 @@ -using Microsoft.Win32.SafeHandles; -using System.Collections.Generic; -using System.Globalization; -using System.IO; +using System.IO; using System.Linq; -using System.Reflection; using System.Text; -using System.Threading; using System.Threading.Tasks; using Testably.Abstractions.Testing.Statistics; using Testably.Abstractions.Testing.Tests.Statistics.FileSystem; -using Testably.Abstractions.Testing.Tests.TestHelpers; namespace Testably.Abstractions.Testing.Tests.Statistics; -public sealed class StatisticsTests +public sealed partial class StatisticsTests { [Fact] public async Task Statistics_ShouldSupportParallelCalls() @@ -166,304 +160,8 @@ public void FileSystem_Initialize_ShouldNotRegisterStatistics() public void ShouldHaveTestedAllFileSystemMethods(string className, bool requireInstance, Type mockType, Type testType) { - string result = CheckPropertiesAndMethods(className, requireInstance, mockType, testType); + string result = Helper.CheckPropertiesAndMethods(className, requireInstance, mockType, testType); result.Should().BeEmpty(); } - - private static string CheckPropertiesAndMethods(string className, bool requireInstance, - Type mockType, Type testType) - { - StringBuilder builder = new(); - - string FirstCharToUpperAsSpan(string input) - { - if (string.IsNullOrEmpty(input)) - { - return string.Empty; - } - - return - $"{input[0].ToString().ToUpper(CultureInfo.InvariantCulture)}{input.Substring(1)}"; - } - - string GetName(Type type, bool firstCharUpperCase) - { - if (type.Name == "Int32&") - { - return "OutInt"; - } - - if (type.IsGenericType) - { - int idx = type.Name.IndexOf('`', StringComparison.Ordinal); - if (idx > 0) - { - return - $"{type.Name.Substring(0, idx)}<{string.Join(",", type.GenericTypeArguments.Select(x => GetName(x, firstCharUpperCase)))}>"; - } - - return type.ToString(); - } - - if (firstCharUpperCase) - { - if (type == typeof(int)) - { - return "Int"; - } - - if (type == typeof(bool)) - { - return "Bool"; - } - } - else - { - if (type == typeof(int)) - { - return "int"; - } - - if (type == typeof(bool)) - { - return "bool"; - } - - if (type == typeof(byte)) - { - return "byte"; - } - - if (type == typeof(string)) - { - return "string"; - } - - if (type == typeof(byte[])) - { - return "byte[]"; - } - - if (type == typeof(string[])) - { - return "string[]"; - } - } - - return type.Name; - } - - string GetDefaultValue(Type type) - { - if (type == typeof(string)) - { - return "\"foo\""; - } - - if (type == typeof(int)) - { - return "42"; - } - - if (type == typeof(bool)) - { - return "true"; - } - - if (type == typeof(SearchOption)) - { - return "SearchOption.AllDirectories"; - } - - if (type == typeof(FileMode)) - { - return "FileMode.OpenOrCreate"; - } - - if (type == typeof(FileAccess)) - { - return "FileAccess.ReadWrite"; - } - - if (type == typeof(FileShare)) - { - return "FileShare.ReadWrite"; - } - - if (type == typeof(SearchOption)) - { - return "SearchOption.AllDirectories"; - } - - if (type == typeof(IEnumerable) || - type == typeof(string[])) - { - return "[\"foo\", \"bar\"]"; - } - - if (type == typeof(byte[])) - { - return "\"foo\"u8.ToArray()"; - } - - if (type == typeof(Encoding)) - { - return "Encoding.UTF8"; - } - - if (type == typeof(Stream)) - { - return "new MemoryStream()"; - } - - if (type == typeof(CancellationToken)) - { - return "CancellationToken.None"; - } - - return "new()"; - } - - void CheckPropertyGetAccess(string className, bool requireInstance, Type mockType, - Type testType, PropertyInfo propertyInfo, StringBuilder builder) - { - string expectedName = $"{propertyInfo.Name}_Get_ShouldRegisterPropertyAccess"; - if (testType.GetMethod(expectedName) != null) - { - return; - } - - builder.AppendLine("\t[SkippableFact]"); - builder.Append("\tpublic void "); - builder.Append(expectedName); - builder.AppendLine("()"); - builder.AppendLine("\t{"); - builder.AppendLine("\t\tMockFileSystem sut = new();"); - builder.AppendLine(); - builder.AppendLine( - $"\t\t_ = sut.{className}{(requireInstance ? ".New(\"foo\")" : "")}.{propertyInfo.Name};"); - builder.AppendLine(); - builder.AppendLine( - $"\t\tsut.Statistics.{className}{(requireInstance ? "[\"foo\"]" : "")}.ShouldOnlyContainPropertyGetAccess(nameof({mockType.Name}.{propertyInfo.Name}));"); - builder.AppendLine("\t}"); - builder.AppendLine(); - } - - void CheckPropertySetAccess(string className, bool requireInstance, Type mockType, - Type testType, PropertyInfo propertyInfo, StringBuilder builder) - { - string expectedName = $"{propertyInfo.Name}_Set_ShouldRegisterPropertyAccess"; - if (testType.GetMethod(expectedName) != null) - { - return; - } - - builder.AppendLine("\t[SkippableFact]"); - builder.Append("\tpublic void "); - builder.Append(expectedName); - builder.AppendLine("()"); - builder.AppendLine("\t{"); - builder.AppendLine("\t\tMockFileSystem sut = new();"); - builder.AppendLine( - $"\t\t{GetName(propertyInfo.PropertyType, false)} value = {GetDefaultValue(propertyInfo.PropertyType)};"); - builder.AppendLine(); - builder.AppendLine( - $"\t\tsut.{className}{(requireInstance ? ".New(\"foo\")" : "")}.{propertyInfo.Name} = value;"); - builder.AppendLine(); - builder.AppendLine( - $"\t\tsut.Statistics.{className}{(requireInstance ? "[\"foo\"]" : "")}.ShouldOnlyContainPropertySetAccess(nameof({mockType.Name}.{propertyInfo.Name}));"); - builder.AppendLine("\t}"); - builder.AppendLine(); - } - - foreach (PropertyInfo propertyInfo in - mockType.GetInterfaces() - .Where(i => i != typeof(IDisposable) && i != typeof(IAsyncDisposable)) - .SelectMany(i => i.GetProperties()) - .Concat(mockType.GetProperties(BindingFlags.DeclaredOnly | - BindingFlags.Public | - BindingFlags.Instance)) - .Where(p => p.IsSpecialName == false && (p.CanRead || p.CanWrite)) - .OrderBy(m => m.Name)) - { - if (propertyInfo.GetCustomAttribute() != null || - propertyInfo.Name == nameof(IFileSystemEntity.FileSystem)) - { - continue; - } - - if (propertyInfo.CanRead) - { - CheckPropertyGetAccess(className, requireInstance, mockType, testType, propertyInfo, builder); - } - - if (propertyInfo.CanWrite) - { - CheckPropertySetAccess(className, requireInstance, mockType, testType, propertyInfo, builder); - } - } - - foreach (MethodInfo methodInfo in - mockType.GetInterfaces() - .Where(i => i != typeof(IDisposable) && i != typeof(IAsyncDisposable)) - .SelectMany(i => i.GetMethods()) - .Concat(mockType.GetMethods(BindingFlags.DeclaredOnly | - BindingFlags.Public | - BindingFlags.Instance)) - .Where(m => m is { IsPublic: true, IsSpecialName: false }) - .OrderBy(m => m.Name) - .ThenBy(m => m.GetParameters().Length)) - { - if (methodInfo.GetCustomAttribute() != null) - { - continue; - } - - ParameterInfo[] parameters = methodInfo.GetParameters(); - - if (Test.IsNetFramework && - parameters.Any(p => p.ParameterType == typeof(SafeFileHandle))) - { - // SafeFileHandle cannot be instantiated on .NET Framework - continue; - } - - string expectedName = $"{methodInfo.Name}_{string.Join("_", methodInfo - .GetParameters() - .Select(x => FirstCharToUpperAsSpan(GetName(x.ParameterType, true) - .Replace("<", "") - .Replace(">", "") - .Replace("IEnumerablestring", "IEnumerableString") - .Replace("[]", "Array"))))}{(parameters.Length > 0 ? "_" : "")}ShouldRegisterCall"; - if (testType.GetMethod(expectedName) != null) - { - continue; - } - - bool isAsync = typeof(Task).IsAssignableFrom(methodInfo.ReturnType); - builder.AppendLine("\t[SkippableFact]"); - builder.Append(isAsync ? "\tpublic async Task " : "\tpublic void "); - builder.Append(expectedName); - builder.AppendLine("()"); - builder.AppendLine("\t{"); - builder.AppendLine("\t\tMockFileSystem sut = new();"); - foreach (ParameterInfo parameterInfo in methodInfo.GetParameters()) - { - builder.AppendLine( - $"\t\t{GetName(parameterInfo.ParameterType, false)} {parameterInfo.Name} = {GetDefaultValue(parameterInfo.ParameterType)};"); - } - - builder.AppendLine(); - builder.AppendLine( - $"\t\t{(isAsync ? "await " : "")}sut.{className}{(requireInstance ? ".New(\"foo\")" : "")}.{methodInfo.Name}({string.Join(", ", methodInfo.GetParameters().Select(p => p.Name))});"); - builder.AppendLine(); - builder.AppendLine( - $"\t\tsut.Statistics.{className}{(requireInstance ? "[\"foo\"]" : "")}.ShouldOnlyContain(nameof({mockType.Name}.{methodInfo.Name}){(parameters.Length > 0 ? ",\n\t\t" : "")}{string.Join(", ", methodInfo.GetParameters().Select(p => p.Name))});"); - builder.AppendLine("\t}"); - builder.AppendLine(); - } - - return builder.ToString(); - } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs b/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs index 341d9b597..b5dd568cf 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs @@ -19,7 +19,7 @@ public static void ShouldOnlyContainPropertySetAccess(this IStatistics statistic .ContainSingle(c => c.Name == name && c.Mode == PropertyStatistic.AccessMode.Set); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, object?[] parameters, string because = "") { statistics.Methods.Length.Should().Be(1, because); @@ -29,7 +29,7 @@ public static void ShouldOnlyContain(this IStatistics statistics, string name, because); } - public static void ShouldOnlyContain(this IStatistics statistics, string name) + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name) { statistics.Methods.Length.Should().Be(1); statistics.Methods.Should() @@ -37,7 +37,7 @@ public static void ShouldOnlyContain(this IStatistics statistics, string name) c.Parameters.Length == 0); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, T1 parameter1) { statistics.Methods.Length.Should().Be(1); @@ -47,7 +47,7 @@ public static void ShouldOnlyContain(this IStatistics statistics, string nam c.Parameters[0].Is(parameter1)); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, T1[] parameter1) { statistics.Methods.Length.Should().Be(1); @@ -58,7 +58,7 @@ public static void ShouldOnlyContain(this IStatistics statistics, string nam } #if FEATURE_SPAN - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, ReadOnlySpan parameter1) { statistics.Methods.Length.Should().Be(1); @@ -68,7 +68,7 @@ public static void ShouldOnlyContain(this IStatistics statistics, string nam parameter.Is(parameter1).Should().BeTrue(); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2) { statistics.Methods.Length.Should().Be(1); @@ -79,7 +79,7 @@ public static void ShouldOnlyContain(this IStatistics statistics, string statistic.Parameters[1].Is(parameter2).Should().BeTrue(); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2, ReadOnlySpan parameter3) { statistics.Methods.Length.Should().Be(1); @@ -91,7 +91,7 @@ public static void ShouldOnlyContain(this IStatistics statistics, st statistic.Parameters[2].Is(parameter3).Should().BeTrue(); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2, ReadOnlySpan parameter3, ReadOnlySpan parameter4) { statistics.Methods.Length.Should().Be(1); @@ -104,7 +104,7 @@ public static void ShouldOnlyContain(this IStatistics statistics statistic.Parameters[3].Is(parameter4).Should().BeTrue(); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2, T3 parameter3, T4 parameter4) { statistics.Methods.Length.Should().Be(1); @@ -117,7 +117,7 @@ public static void ShouldOnlyContain(this IStatistics statistics statistic.Parameters[3].Is(parameter4).Should().BeTrue(); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2, Span parameter3, T4 parameter4) { statistics.Methods.Length.Should().Be(1); @@ -130,7 +130,7 @@ public static void ShouldOnlyContain(this IStatistics statistics statistic.Parameters[3].Is(parameter4).Should().BeTrue(); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, ReadOnlySpan parameter1, ReadOnlySpan parameter2, ReadOnlySpan parameter3, Span parameter4, T5 parameter5) { statistics.Methods.Length.Should().Be(1); @@ -144,7 +144,7 @@ public static void ShouldOnlyContain(this IStatistics statis statistic.Parameters[4].Is(parameter5).Should().BeTrue(); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, Span parameter1) { statistics.Methods.Length.Should().Be(1); @@ -155,7 +155,7 @@ public static void ShouldOnlyContain(this IStatistics statistics, string nam } #endif - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, T1 parameter1, T2 parameter2) { statistics.Methods.Length.Should().Be(1); @@ -166,7 +166,7 @@ public static void ShouldOnlyContain(this IStatistics statistics, string c.Parameters[1].Is(parameter2)); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, T1 parameter1, T2 parameter2, T3 parameter3) { statistics.Methods.Length.Should().Be(1); @@ -178,7 +178,7 @@ public static void ShouldOnlyContain(this IStatistics statistics, st c.Parameters[2].Is(parameter3)); } - public static void ShouldOnlyContain(this IStatistics statistics, string name, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4) { statistics.Methods.Length.Should().Be(1); @@ -191,7 +191,7 @@ public static void ShouldOnlyContain(this IStatistics statistics c.Parameters[3].Is(parameter4)); } - public static void ShouldOnlyContain(this IStatistics statistics, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4, T5 parameter5) { statistics.Methods.Length.Should().Be(1); @@ -205,7 +205,7 @@ public static void ShouldOnlyContain(this IStatistics statis c.Parameters[4].Is(parameter5)); } - public static void ShouldOnlyContain(this IStatistics statistics, + public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, T1 parameter1, T2 parameter2, T3 parameter3, T4 parameter4, T5 parameter5, T6 parameter6) { From e16cc888e4b5e7db6e4cd33a181477d043c6ecaf Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 15 Mar 2024 12:31:37 +0100 Subject: [PATCH 3/8] Implement property statistics for DriveInfoMock --- .../FileSystem/DriveInfoMock.cs | 60 +++++++++++++++---- .../Storage/InMemoryStorage.cs | 5 +- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs index 35f340329..f6a87ab14 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs @@ -35,6 +35,9 @@ internal sealed class DriveInfoMock : IStorageDrive private string _volumeLabel = nameof(MockFileSystem); private readonly string _name; private long _totalSize; + private string _driveFormat; + private DriveType _driveType; + private bool _isReady; private DriveInfoMock(string driveName, MockFileSystem fileSystem) { @@ -53,9 +56,9 @@ private DriveInfoMock(string driveName, MockFileSystem fileSystem) _name = driveName; _totalSize = DefaultTotalSize; - DriveFormat = DefaultDriveFormat; - DriveType = DefaultDriveType; - IsReady = true; + _driveFormat = DefaultDriveFormat; + _driveType = DefaultDriveType; + _isReady = true; } #region IStorageDrive Members @@ -72,17 +75,41 @@ public long AvailableFreeSpace } /// - public string DriveFormat { get; private set; } + public string DriveFormat + { + get + { + using IDisposable registration = RegisterProperty(nameof(DriveFormat), PropertyStatistic.AccessMode.Get); + + return _driveFormat; + } + } /// - public DriveType DriveType { get; private set; } + public DriveType DriveType + { + get + { + using IDisposable registration = RegisterProperty(nameof(DriveType), PropertyStatistic.AccessMode.Get); + + return _driveType; + } + } /// public IFileSystem FileSystem => _fileSystem; /// - public bool IsReady { get; private set; } + public bool IsReady + { + get + { + using IDisposable registration = RegisterProperty(nameof(IsReady), PropertyStatistic.AccessMode.Get); + + return _isReady; + } + } /// /// Flag indicating if the drive is a UNC drive @@ -94,7 +121,7 @@ public string Name { get { - //using IDisposable registration = RegisterProperty(nameof(Name), PropertyStatistic.AccessMode.Get); + using IDisposable registration = RegisterProperty(nameof(Name), PropertyStatistic.AccessMode.Get); return _name; } @@ -102,7 +129,14 @@ public string Name /// public IDirectoryInfo RootDirectory - => DirectoryInfoMock.New(_fileSystem.Storage.GetLocation(Name), _fileSystem); + { + get + { + using IDisposable registration = RegisterProperty(nameof(RootDirectory), PropertyStatistic.AccessMode.Get); + + return DirectoryInfoMock.New(_fileSystem.Storage.GetLocation(Name), _fileSystem); + } + } /// public long TotalFreeSpace @@ -166,7 +200,7 @@ public IStorageDrive ChangeUsedBytes(long usedBytesDelta) public IStorageDrive SetDriveFormat( string driveFormat = DefaultDriveFormat) { - DriveFormat = driveFormat; + _driveFormat = driveFormat; return this; } @@ -174,14 +208,14 @@ public IStorageDrive SetDriveFormat( public IStorageDrive SetDriveType( DriveType driveType = DefaultDriveType) { - DriveType = driveType; + _driveType = driveType; return this; } /// public IStorageDrive SetIsReady(bool isReady = true) { - IsReady = isReady; + _isReady = isReady; return this; } @@ -197,7 +231,9 @@ public IStorageDrive SetTotalSize( /// public override string ToString() - => Name; + => _name; + + internal string GetName() => _name; private string GetTopmostParentDirectory(string path) { diff --git a/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs b/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs index b01af88e4..7450db04e 100644 --- a/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs +++ b/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs @@ -27,8 +27,9 @@ public InMemoryStorage(MockFileSystem fileSystem) { _fileSystem = fileSystem; CurrentDirectory = string.Empty.PrefixRoot(_fileSystem); - MainDrive = DriveInfoMock.New(CurrentDirectory, _fileSystem); - _drives.TryAdd(MainDrive.Name, MainDrive); + DriveInfoMock mainDrive = DriveInfoMock.New(CurrentDirectory, _fileSystem); + _drives.TryAdd(mainDrive.GetName(), mainDrive); + MainDrive = mainDrive; } #region IStorage Members From c205a3d70a23aa209c717876ff8eeb60a3debe1c Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 15 Mar 2024 12:35:45 +0100 Subject: [PATCH 4/8] Implement property statistics for PathMock --- .../FileSystem/PathMock.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs index 54156ae1d..478786629 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs @@ -20,6 +20,50 @@ internal PathMock(MockFileSystem fileSystem) _fileSystem = fileSystem; } + /// + public override char AltDirectorySeparatorChar + { + get + { + using IDisposable register = RegisterProperty(nameof(AltDirectorySeparatorChar)); + + return base.AltDirectorySeparatorChar; + } + } + + /// + public override char DirectorySeparatorChar + { + get + { + using IDisposable register = RegisterProperty(nameof(DirectorySeparatorChar)); + + return base.DirectorySeparatorChar; + } + } + + /// + public override char PathSeparator + { + get + { + using IDisposable register = RegisterProperty(nameof(PathSeparator)); + + return base.PathSeparator; + } + } + + /// + public override char VolumeSeparatorChar + { + get + { + using IDisposable register = RegisterProperty(nameof(VolumeSeparatorChar)); + + return base.VolumeSeparatorChar; + } + } + /// [return: NotNullIfNotNull("path")] public override string? ChangeExtension(string? path, string? extension) @@ -513,6 +557,9 @@ public override bool TryJoin(ReadOnlySpan path1, } #endif + private IDisposable RegisterProperty(string name, PropertyStatistic.AccessMode mode = PropertyStatistic.AccessMode.Get) + => _fileSystem.StatisticsRegistration.Path.RegisterProperty(name, mode); + private IDisposable RegisterMethod(string name) => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name); From f2d80a0cf7f246c5eb890b7a53510f75d4402478 Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 15 Mar 2024 12:39:19 +0100 Subject: [PATCH 5/8] Rename enum to PropertyAccess --- .../FileSystem/DirectoryInfoMock.cs | 6 ++--- .../FileSystem/DriveInfoMock.cs | 24 +++++++++---------- .../FileSystem/FileSystemInfoMock.cs | 2 +- .../FileSystem/PathMock.cs | 4 ++-- .../Statistics/CallStatistics.cs | 6 ++--- .../Statistics/FileSystemEntryStatistics.cs | 6 ++--- .../Statistics/PropertyAccess.cs | 17 +++++++++++++ .../Statistics/PropertyStatistic.cs | 24 ++++--------------- .../TestHelpers/StatisticsTestHelpers.cs | 4 ++-- 9 files changed, 47 insertions(+), 46 deletions(-) create mode 100644 Source/Testably.Abstractions.Testing/Statistics/PropertyAccess.cs diff --git a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs index 6eefcc0c7..857da100c 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs @@ -31,7 +31,7 @@ public override bool Exists { get { - using IDisposable registration = RegisterProperty(nameof(Exists), PropertyStatistic.AccessMode.Get); + using IDisposable registration = RegisterProperty(nameof(Exists), PropertyAccess.Get); return base.Exists && FileSystemType == FileSystemTypes.Directory; } @@ -424,8 +424,8 @@ private IEnumerable EnumerateInternal( enumerationOptions); } - protected override IDisposable RegisterProperty(string name, PropertyStatistic.AccessMode mode) - => _fileSystem.StatisticsRegistration.DirectoryInfo.RegisterProperty(Location.FullPath, name, mode); + protected override IDisposable RegisterProperty(string name, PropertyAccess access) + => _fileSystem.StatisticsRegistration.DirectoryInfo.RegisterProperty(Location.FullPath, name, access); protected override IDisposable RegisterMethod(string name) => _fileSystem.StatisticsRegistration.DirectoryInfo.RegisterMethod(Location.FullPath, name); diff --git a/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs index f6a87ab14..8605d82b4 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/DriveInfoMock.cs @@ -68,7 +68,7 @@ public long AvailableFreeSpace { get { - using IDisposable registration = RegisterProperty(nameof(AvailableFreeSpace), PropertyStatistic.AccessMode.Get); + using IDisposable registration = RegisterProperty(nameof(AvailableFreeSpace), PropertyAccess.Get); return TotalFreeSpace; } @@ -79,7 +79,7 @@ public string DriveFormat { get { - using IDisposable registration = RegisterProperty(nameof(DriveFormat), PropertyStatistic.AccessMode.Get); + using IDisposable registration = RegisterProperty(nameof(DriveFormat), PropertyAccess.Get); return _driveFormat; } @@ -90,7 +90,7 @@ public DriveType DriveType { get { - using IDisposable registration = RegisterProperty(nameof(DriveType), PropertyStatistic.AccessMode.Get); + using IDisposable registration = RegisterProperty(nameof(DriveType), PropertyAccess.Get); return _driveType; } @@ -105,7 +105,7 @@ public bool IsReady { get { - using IDisposable registration = RegisterProperty(nameof(IsReady), PropertyStatistic.AccessMode.Get); + using IDisposable registration = RegisterProperty(nameof(IsReady), PropertyAccess.Get); return _isReady; } @@ -121,7 +121,7 @@ public string Name { get { - using IDisposable registration = RegisterProperty(nameof(Name), PropertyStatistic.AccessMode.Get); + using IDisposable registration = RegisterProperty(nameof(Name), PropertyAccess.Get); return _name; } @@ -132,7 +132,7 @@ public IDirectoryInfo RootDirectory { get { - using IDisposable registration = RegisterProperty(nameof(RootDirectory), PropertyStatistic.AccessMode.Get); + using IDisposable registration = RegisterProperty(nameof(RootDirectory), PropertyAccess.Get); return DirectoryInfoMock.New(_fileSystem.Storage.GetLocation(Name), _fileSystem); } @@ -143,7 +143,7 @@ public long TotalFreeSpace { get { - using IDisposable registration = RegisterProperty(nameof(TotalFreeSpace), PropertyStatistic.AccessMode.Get); + using IDisposable registration = RegisterProperty(nameof(TotalFreeSpace), PropertyAccess.Get); return _totalSize - _usedBytes; } @@ -154,7 +154,7 @@ public long TotalSize { get { - using IDisposable registration = RegisterProperty(nameof(TotalSize), PropertyStatistic.AccessMode.Get); + using IDisposable registration = RegisterProperty(nameof(TotalSize), PropertyAccess.Get); return _totalSize; } @@ -166,14 +166,14 @@ public string VolumeLabel { get { - using IDisposable registration = RegisterProperty(nameof(VolumeLabel), PropertyStatistic.AccessMode.Get); + using IDisposable registration = RegisterProperty(nameof(VolumeLabel), PropertyAccess.Get); return _volumeLabel; } [SupportedOSPlatform("windows")] set { - using IDisposable registration = RegisterProperty(nameof(VolumeLabel), PropertyStatistic.AccessMode.Set); + using IDisposable registration = RegisterProperty(nameof(VolumeLabel), PropertyAccess.Set); _volumeLabel = value ?? _volumeLabel; _fileSystem.Execute.NotOnWindows( @@ -285,6 +285,6 @@ private static string ValidateDriveLetter(string driveName, return new DriveInfoMock(driveName, fileSystem); } - private IDisposable RegisterProperty(string name, PropertyStatistic.AccessMode mode) - => _fileSystem.StatisticsRegistration.DriveInfo.RegisterProperty(_name, name, mode); + private IDisposable RegisterProperty(string name, PropertyAccess access) + => _fileSystem.StatisticsRegistration.DriveInfo.RegisterProperty(_name, name, access); } diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs index bc4fed082..ce551db9b 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs @@ -293,7 +293,7 @@ private void RefreshInternal() _isInitialized = true; } - protected virtual IDisposable RegisterProperty(string name, PropertyStatistic.AccessMode mode) + protected virtual IDisposable RegisterProperty(string name, PropertyAccess access) => new NoOpDisposable(); protected virtual IDisposable RegisterMethod(string name) diff --git a/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs index 478786629..2f30467da 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs @@ -557,8 +557,8 @@ public override bool TryJoin(ReadOnlySpan path1, } #endif - private IDisposable RegisterProperty(string name, PropertyStatistic.AccessMode mode = PropertyStatistic.AccessMode.Get) - => _fileSystem.StatisticsRegistration.Path.RegisterProperty(name, mode); + private IDisposable RegisterProperty(string name, PropertyAccess access = PropertyAccess.Get) + => _fileSystem.StatisticsRegistration.Path.RegisterProperty(name, access); private IDisposable RegisterMethod(string name) => _fileSystem.StatisticsRegistration.Path.RegisterMethod(name); diff --git a/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs b/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs index b7148398c..742c5e6be 100644 --- a/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs +++ b/Source/Testably.Abstractions.Testing/Statistics/CallStatistics.cs @@ -36,15 +36,15 @@ internal IDisposable RegisterMethod(string name, params ParameterDescription[] p } /// - /// Registers the property callback with access. + /// Registers the property callback with access. /// /// A disposable which ignores all registrations, until it is disposed. - internal IDisposable RegisterProperty(string name, PropertyStatistic.AccessMode mode) + internal IDisposable RegisterProperty(string name, PropertyAccess access) { if (_statisticsGate.TryGetLock(out IDisposable release)) { int counter = _statisticsGate.GetCounter(); - _properties.Enqueue(new PropertyStatistic(counter, name, mode)); + _properties.Enqueue(new PropertyStatistic(counter, name, access)); } return release; diff --git a/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs b/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs index a89044905..0ca97efaa 100644 --- a/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs +++ b/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs @@ -36,13 +36,13 @@ internal IDisposable RegisterMethod(string path, string name, params ParameterDe } /// - /// Registers the property callback with access under . + /// Registers the property callback with access under . /// /// A disposable which ignores all registrations, until it is disposed. - internal IDisposable RegisterProperty(string path, string name, PropertyStatistic.AccessMode mode) + internal IDisposable RegisterProperty(string path, string name, PropertyAccess access) { CallStatistics callStatistics = _statistics.GetOrAdd(_fileSystem.Path.GetFullPath(path), _ => new CallStatistics(_statisticsGate)); - return callStatistics.RegisterProperty(name, mode); + return callStatistics.RegisterProperty(name, access); } } diff --git a/Source/Testably.Abstractions.Testing/Statistics/PropertyAccess.cs b/Source/Testably.Abstractions.Testing/Statistics/PropertyAccess.cs new file mode 100644 index 000000000..9e9aaf33f --- /dev/null +++ b/Source/Testably.Abstractions.Testing/Statistics/PropertyAccess.cs @@ -0,0 +1,17 @@ +namespace Testably.Abstractions.Testing.Statistics; + +/// +/// The mode of accessing a property (getter or setter). +/// +public enum PropertyAccess +{ + /// + /// The property was read. + /// + Get, + + /// + /// The property was written to. + /// + Set +} diff --git a/Source/Testably.Abstractions.Testing/Statistics/PropertyStatistic.cs b/Source/Testably.Abstractions.Testing/Statistics/PropertyStatistic.cs index cb5b4d065..955fb4b6b 100644 --- a/Source/Testably.Abstractions.Testing/Statistics/PropertyStatistic.cs +++ b/Source/Testably.Abstractions.Testing/Statistics/PropertyStatistic.cs @@ -20,32 +20,16 @@ public sealed class PropertyStatistic /// /// The mode of the accessed property (getter or setter). /// - public AccessMode Mode { get; } + public PropertyAccess Access { get; } - internal PropertyStatistic(int counter, string name, AccessMode mode) + internal PropertyStatistic(int counter, string name, PropertyAccess access) { Counter = counter; Name = name; - Mode = mode; + Access = access; } /// public override string ToString() - => $"{Name}{{{Mode.ToString().ToLower(CultureInfo.InvariantCulture)};}}"; - - /// - /// The mode of accessing a property (getter or setter). - /// - public enum AccessMode - { - /// - /// The property was read. - /// - Get, - - /// - /// The property was written to. - /// - Set - } + => $"{Name}{{{Access.ToString().ToLower(CultureInfo.InvariantCulture)};}}"; } diff --git a/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs b/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs index b5dd568cf..b2e72955d 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/StatisticsTestHelpers.cs @@ -9,14 +9,14 @@ public static void ShouldOnlyContainPropertyGetAccess(this IStatistics statistic { statistics.Properties.Length.Should().Be(1); statistics.Properties.Should() - .ContainSingle(c => c.Name == name && c.Mode == PropertyStatistic.AccessMode.Get); + .ContainSingle(c => c.Name == name && c.Access == PropertyAccess.Get); } public static void ShouldOnlyContainPropertySetAccess(this IStatistics statistics, string name) { statistics.Properties.Length.Should().Be(1); statistics.Properties.Should() - .ContainSingle(c => c.Name == name && c.Mode == PropertyStatistic.AccessMode.Set); + .ContainSingle(c => c.Name == name && c.Access == PropertyAccess.Set); } public static void ShouldOnlyContainMethodCall(this IStatistics statistics, string name, From d038671769bc9276c1b6c0413edf1abdc3631c59 Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 15 Mar 2024 13:04:07 +0100 Subject: [PATCH 6/8] Adapt failing tests --- Directory.Packages.props | 2 +- .../FileSystem/DirectoryInfoMock.cs | 20 ++- .../FileSystem/FileInfoMock.cs | 46 +++++- .../FileSystem/FileStreamMock.cs | 149 ++++++++++++++++-- .../FileSystem/FileSystemInfoMock.cs | 145 ++++++++++++++--- .../FileSystem/FileSystemWatcherMock.cs | 117 ++++++++++++-- .../Statistics/FileSystemEntryStatistics.cs | 35 +++- .../Storage/InMemoryStorage.cs | 4 +- .../Testably.Abstractions.Testing_net6.0.txt | 13 ++ .../Testably.Abstractions.Testing_net7.0.txt | 13 ++ .../Testably.Abstractions.Testing_net8.0.txt | 13 ++ ...ly.Abstractions.Testing_netstandard2.0.txt | 13 ++ ...ly.Abstractions.Testing_netstandard2.1.txt | 13 ++ .../Testably.Abstractions.Api.Tests/Helper.cs | 2 +- .../DirectoryInfoStatisticsTests.cs | 39 ++++- .../FileSystem/FileInfoStatisticsTests.cs | 26 +++ .../FileSystem/FileStreamStatisticsTests.cs | 36 ++++- ...FileSystemWatcherFactoryStatisticsTests.cs | 3 +- .../FileSystemWatcherStatisticsTests.cs | 29 ++-- .../Statistics/StatisticsTests.Helpers.cs | 7 + 20 files changed, 636 insertions(+), 89 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 6d316a09f..7b8d8a613 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,7 +7,7 @@ - + diff --git a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs index 857da100c..d3ab96e53 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/DirectoryInfoMock.cs @@ -39,12 +39,26 @@ public override bool Exists /// public IDirectoryInfo? Parent - => New(Location.GetParent(), _fileSystem); + { + get + { + using IDisposable registration = RegisterProperty(nameof(Parent), PropertyAccess.Get); + + return New(Location.GetParent(), _fileSystem); + } + } /// public IDirectoryInfo Root - => New(_fileSystem.Storage.GetLocation(string.Empty.PrefixRoot(_fileSystem)), - _fileSystem); + { + get + { + using IDisposable registration = RegisterProperty(nameof(Root), PropertyAccess.Get); + + return New(_fileSystem.Storage.GetLocation(string.Empty.PrefixRoot(_fileSystem)), + _fileSystem); + } + } /// public void Create() diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs index 491ec91dd..8b440c9f8 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.IO; +using System.Xml.Linq; using Testably.Abstractions.Testing.Helpers; using Testably.Abstractions.Testing.Statistics; using Testably.Abstractions.Testing.Storage; @@ -26,23 +27,51 @@ private FileInfoMock(IStorageLocation location, /// public IDirectoryInfo? Directory - => DirectoryInfoMock.New(Location.GetParent(), - _fileSystem); + { + get + { + using IDisposable registration = RegisterProperty(nameof(Directory), PropertyAccess.Get); + + return DirectoryInfoMock.New(Location.GetParent(), + _fileSystem); + } + } /// public string? DirectoryName - => Directory?.FullName; + { + get + { + using IDisposable registration = RegisterProperty(nameof(DirectoryName), PropertyAccess.Get); + + return Directory?.FullName; + } + } /// public override bool Exists - => base.Exists && FileSystemType == FileSystemTypes.File; + { + get + { + using IDisposable registration = RegisterProperty(nameof(Exists), PropertyAccess.Get); + + return base.Exists && FileSystemType == FileSystemTypes.File; + } + } /// public bool IsReadOnly { - get => (Attributes & FileAttributes.ReadOnly) != 0; + get + { + using IDisposable registration = RegisterProperty(nameof(IsReadOnly), PropertyAccess.Get); + + return (Attributes & FileAttributes.ReadOnly) != 0; + } set { + using IDisposable registration = RegisterProperty(nameof(IsReadOnly), PropertyAccess.Set); + if (value) { Attributes |= FileAttributes.ReadOnly; @@ -59,6 +88,8 @@ public long Length { get { + using IDisposable registration = RegisterProperty(nameof(Length), PropertyAccess.Get); + if (Container is NullContainer || Container.Type != FileSystemTypes.File) { @@ -77,6 +108,8 @@ public override string Name { get { + using IDisposable registration = RegisterProperty(nameof(Name), PropertyAccess.Get); + if (Location.FullPath.EndsWith(FileSystem.Path.DirectorySeparatorChar)) { return string.Empty; @@ -370,6 +403,9 @@ public IFileInfo Replace(string destinationFileName, return new FileInfoMock(location, fileSystem); } + protected override IDisposable RegisterProperty(string name, PropertyAccess access) + => _fileSystem.StatisticsRegistration.FileInfo.RegisterProperty(Location.FullPath, name, access); + protected override IDisposable RegisterMethod(string name) => _fileSystem.StatisticsRegistration.FileInfo.RegisterMethod(Location.FullPath, name); diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs index c19742b9f..b85b7e64a 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileStreamMock.cs @@ -15,14 +15,6 @@ namespace Testably.Abstractions.Testing.FileSystem; /// internal sealed class FileStreamMock : FileSystemStream, IFileSystemExtensibility { - /// - public override bool CanRead - => _access.HasFlag(FileAccess.Read); - - /// - public override bool CanWrite - => _access.HasFlag(FileAccess.Write); - private readonly FileAccess _access; private readonly IDisposable _accessLock; private readonly IStorageContainer _container; @@ -74,9 +66,9 @@ private FileStreamMock(MemoryStream stream, _access = access; _ = bufferSize; _options = options; - _initialPosition = Position; + _initialPosition = base.Position; - _location = _fileSystem.Storage.GetLocation(Name); + _location = _fileSystem.Storage.GetLocation(base.Name); _location.ThrowExceptionIfNotFound(_fileSystem, true); IStorageContainer file = _fileSystem.Storage.GetContainer(_location); if (file is NullContainer) @@ -85,7 +77,7 @@ private FileStreamMock(MemoryStream stream, _mode.Equals(FileMode.Truncate)) { throw ExceptionFactory.FileNotFound( - _fileSystem.Path.GetFullPath(Name)); + _fileSystem.Path.GetFullPath(base.Name)); } file = _fileSystem.Storage.GetOrCreateContainer(_location, @@ -97,10 +89,10 @@ private FileStreamMock(MemoryStream stream, _fileSystem.Execute.OnWindows( () => throw ExceptionFactory.AccessToPathDenied( - _fileSystem.Path.GetFullPath(Name)), + _fileSystem.Path.GetFullPath(base.Name)), () => throw ExceptionFactory.FileAlreadyExists( - _fileSystem.Path.GetFullPath(Name), 17)); + _fileSystem.Path.GetFullPath(base.Name), 17)); } else if (_mode.Equals(FileMode.CreateNew)) { @@ -122,6 +114,134 @@ private FileStreamMock(MemoryStream stream, InitializeStream(); } + /// + public override bool CanRead + { + get + { + using IDisposable registration = RegisterProperty(nameof(CanRead), PropertyAccess.Get); + + return _access.HasFlag(FileAccess.Read); + } + } + + /// + public override bool CanSeek + { + get + { + using IDisposable registration = RegisterProperty(nameof(CanSeek), PropertyAccess.Get); + + return base.CanSeek; + } + } + + /// + public override bool CanTimeout + { + get + { + using IDisposable registration = RegisterProperty(nameof(CanTimeout), PropertyAccess.Get); + + return base.CanTimeout; + } + } + + /// + public override bool CanWrite + { + get + { + using IDisposable registration = RegisterProperty(nameof(CanWrite), PropertyAccess.Get); + + return _access.HasFlag(FileAccess.Write); + } + } + + /// + public override bool IsAsync + { + get + { + using IDisposable registration = RegisterProperty(nameof(IsAsync), PropertyAccess.Get); + + return base.IsAsync; + } + } + + /// + public override long Length + { + get + { + using IDisposable registration = RegisterProperty(nameof(Length), PropertyAccess.Get); + + return base.Length; + } + } + + /// + public override string Name + { + get + { + using IDisposable registration = RegisterProperty(nameof(Name), PropertyAccess.Get); + + return base.Name; + } + } + + /// + public override long Position + { + get + { + using IDisposable registration = RegisterProperty(nameof(Position), PropertyAccess.Get); + + return base.Position; + } + set + { + using IDisposable registration = RegisterProperty(nameof(Position), PropertyAccess.Set); + + base.Position = value; + } + } + + /// + public override int ReadTimeout + { + get + { + using IDisposable registration = RegisterProperty(nameof(ReadTimeout), PropertyAccess.Get); + + return base.ReadTimeout; + } + set + { + using IDisposable registration = RegisterProperty(nameof(ReadTimeout), PropertyAccess.Set); + + base.ReadTimeout = value; + } + } + + /// + public override int WriteTimeout + { + get + { + using IDisposable registration = RegisterProperty(nameof(WriteTimeout), PropertyAccess.Get); + + return base.WriteTimeout; + } + set + { + using IDisposable registration = RegisterProperty(nameof(WriteTimeout), PropertyAccess.Set); + + base.WriteTimeout = value; + } + } + /// public override IAsyncResult BeginRead(byte[] buffer, int offset, @@ -538,6 +658,9 @@ public void StoreMetadata(string key, T? value) public T? RetrieveMetadata(string key) => _container.Extensibility.RetrieveMetadata(key); + private IDisposable RegisterProperty(string name, PropertyAccess access) + => _fileSystem.StatisticsRegistration.FileStream.RegisterProperty(_location.FullPath, name, access); + private IDisposable RegisterMethod(string name) => _fileSystem.StatisticsRegistration.FileStream.RegisterMethod(_location.FullPath, name); diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs index ce551db9b..33076b434 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs @@ -48,8 +48,18 @@ protected FileSystemInfoMock(MockFileSystem fileSystem, IStorageLocation locatio /// public FileAttributes Attributes { - get => Container.Attributes; - set => Container.Attributes = value; + get + { + using IDisposable registration = RegisterProperty(nameof(Attributes), PropertyAccess.Get); + + return Container.Attributes; + } + set + { + using IDisposable registration = RegisterProperty(nameof(Attributes), PropertyAccess.Set); + + Container.Attributes = value; + } } #if FEATURE_FILESYSTEM_LINK @@ -84,15 +94,35 @@ public void CreateAsSymbolicLink(string pathToTarget) /// public DateTime CreationTime { - get => Container.CreationTime.Get(DateTimeKind.Local); - set => Container.CreationTime.Set(value, DateTimeKind.Local); + get + { + using IDisposable registration = RegisterProperty(nameof(CreationTime), PropertyAccess.Get); + + return Container.CreationTime.Get(DateTimeKind.Local); + } + set + { + using IDisposable registration = RegisterProperty(nameof(CreationTime), PropertyAccess.Set); + + Container.CreationTime.Set(value, DateTimeKind.Local); + } } /// public DateTime CreationTimeUtc { - get => Container.CreationTime.Get(DateTimeKind.Utc); - set => Container.CreationTime.Set(value, DateTimeKind.Utc); + get + { + using IDisposable registration = RegisterProperty(nameof(CreationTimeUtc), PropertyAccess.Get); + + return Container.CreationTime.Get(DateTimeKind.Utc); + } + set + { + using IDisposable registration = RegisterProperty(nameof(CreationTimeUtc), PropertyAccess.Set); + + Container.CreationTime.Set(value, DateTimeKind.Utc); + } } /// @@ -121,6 +151,8 @@ public string Extension { get { + using IDisposable registration = RegisterProperty(nameof(Extension), PropertyAccess.Get); + if (Location.FullPath.EndsWith('.') && !_fileSystem.Execute.IsWindows) { @@ -136,58 +168,127 @@ public IFileSystem FileSystem => _fileSystem; /// - public string FullName => Location.FullPath; + public string FullName + { + get + { + using IDisposable registration = RegisterProperty(nameof(FullName), PropertyAccess.Get); + + return Location.FullPath; + } + } /// public DateTime LastAccessTime { - get => Container.LastAccessTime.Get(DateTimeKind.Local); - set => Container.LastAccessTime.Set(value, DateTimeKind.Local); + get + { + using IDisposable registration = RegisterProperty(nameof(LastAccessTime), PropertyAccess.Get); + + return Container.LastAccessTime.Get(DateTimeKind.Local); + } + set + { + using IDisposable registration = RegisterProperty(nameof(LastAccessTime), PropertyAccess.Set); + + Container.LastAccessTime.Set(value, DateTimeKind.Local); + } } /// public DateTime LastAccessTimeUtc { - get => Container.LastAccessTime.Get(DateTimeKind.Utc); - set => Container.LastAccessTime.Set(value, DateTimeKind.Utc); + get + { + using IDisposable registration = RegisterProperty(nameof(LastAccessTimeUtc), PropertyAccess.Get); + + return Container.LastAccessTime.Get(DateTimeKind.Utc); + } + set + { + using IDisposable registration = RegisterProperty(nameof(LastAccessTimeUtc), PropertyAccess.Set); + + Container.LastAccessTime.Set(value, DateTimeKind.Utc); + } } /// public DateTime LastWriteTime { - get => Container.LastWriteTime.Get(DateTimeKind.Local); - set => Container.LastWriteTime.Set(value, DateTimeKind.Local); + get + { + using IDisposable registration = RegisterProperty(nameof(LastWriteTime), PropertyAccess.Get); + + return Container.LastWriteTime.Get(DateTimeKind.Local); + } + set + { + using IDisposable registration = RegisterProperty(nameof(LastWriteTime), PropertyAccess.Set); + + Container.LastWriteTime.Set(value, DateTimeKind.Local); + } } /// public DateTime LastWriteTimeUtc { - get => Container.LastWriteTime.Get(DateTimeKind.Utc); - set => Container.LastWriteTime.Set(value, DateTimeKind.Utc); + get + { + using IDisposable registration = RegisterProperty(nameof(LastWriteTimeUtc), PropertyAccess.Get); + + return Container.LastWriteTime.Get(DateTimeKind.Utc); + } + set + { + using IDisposable registration = RegisterProperty(nameof(LastWriteTimeUtc), PropertyAccess.Set); + + Container.LastWriteTime.Set(value, DateTimeKind.Utc); + } } #if FEATURE_FILESYSTEM_LINK /// public string? LinkTarget - => Container.LinkTarget; + { + get + { + using IDisposable registration = RegisterProperty(nameof(LinkTarget), PropertyAccess.Get); + + return Container.LinkTarget; + } + } #endif /// public virtual string Name - => _fileSystem.Path.GetPathRoot(Location.FullPath) == Location.FullPath - ? Location.FullPath - : _fileSystem.Path.GetFileName(Location.FullPath.TrimEnd( - _fileSystem.Path.DirectorySeparatorChar, - _fileSystem.Path.AltDirectorySeparatorChar)); + { + get + { + using IDisposable registration = RegisterProperty(nameof(Name), PropertyAccess.Get); + + return _fileSystem.Path.GetPathRoot(Location.FullPath) == Location.FullPath + ? Location.FullPath + : _fileSystem.Path.GetFileName(Location.FullPath.TrimEnd( + _fileSystem.Path.DirectorySeparatorChar, + _fileSystem.Path.AltDirectorySeparatorChar)); + } + } #if FEATURE_FILESYSTEM_UNIXFILEMODE /// public UnixFileMode UnixFileMode { - get => Container.UnixFileMode; + get + { + using IDisposable registration = RegisterProperty(nameof(UnixFileMode), PropertyAccess.Get); + + return Container.UnixFileMode; + } [UnsupportedOSPlatform("windows")] set { + using IDisposable registration = RegisterProperty(nameof(UnixFileMode), PropertyAccess.Set); + _fileSystem.Execute.OnWindows( () => throw ExceptionFactory.UnixFileModeNotSupportedOnThisPlatform()); diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs index da1c65982..c188f8402 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs @@ -31,6 +31,12 @@ internal sealed class FileSystemWatcherMock : Component, IFileSystemWatcher private int _internalBufferSize = 8192; private bool _isInitializing; private string _path = string.Empty; + private bool _includeSubdirectories; + private NotifyFilters _notifyFilter = NotifyFilters.FileName | + NotifyFilters.DirectoryName | + NotifyFilters.LastWrite; + + private ISynchronizeInvoke? _synchronizingObject; private FileSystemWatcherMock(MockFileSystem fileSystem) { @@ -44,9 +50,16 @@ private FileSystemWatcherMock(MockFileSystem fileSystem) /// public bool EnableRaisingEvents { - get => _enableRaisingEvents; + get + { + using IDisposable registration = RegisterProperty(nameof(EnableRaisingEvents), PropertyAccess.Get); + + return _enableRaisingEvents; + } set { + using IDisposable registration = RegisterProperty(nameof(EnableRaisingEvents), PropertyAccess.Set); + _enableRaisingEvents = value; if (_enableRaisingEvents) { @@ -68,6 +81,8 @@ public string Filter { get { + using IDisposable registration = RegisterProperty(nameof(Filter), PropertyAccess.Get); + if (_filters.Count == 0) { return _fileSystem.Execute.IsNetFramework ? "*.*" : "*"; @@ -76,6 +91,8 @@ public string Filter } set { + using IDisposable registration = RegisterProperty(nameof(Filter), PropertyAccess.Set); + _filters.Clear(); _filters.Add(value); } @@ -84,22 +101,46 @@ public string Filter #if FEATURE_FILESYSTEMWATCHER_ADVANCED /// public Collection Filters - => _filters; + { + get + { + using IDisposable registration = RegisterProperty(nameof(Filters), PropertyAccess.Get); + + return _filters; + } + } #endif /// public bool IncludeSubdirectories { - get; - set; + get + { + using IDisposable registration = RegisterProperty(nameof(IncludeSubdirectories), PropertyAccess.Get); + + return _includeSubdirectories; + } + set + { + using IDisposable registration = RegisterProperty(nameof(IncludeSubdirectories), PropertyAccess.Set); + + _includeSubdirectories = value; + } } /// public int InternalBufferSize { - get => _internalBufferSize; + get + { + using IDisposable registration = RegisterProperty(nameof(InternalBufferSize), PropertyAccess.Get); + + return _internalBufferSize; + } set { + using IDisposable registration = RegisterProperty(nameof(InternalBufferSize), PropertyAccess.Set); + _internalBufferSize = Math.Max(value, 4096); Restart(); } @@ -108,18 +149,33 @@ public int InternalBufferSize /// public NotifyFilters NotifyFilter { - get; - set; - } = NotifyFilters.FileName | - NotifyFilters.DirectoryName | - NotifyFilters.LastWrite; + get + { + using IDisposable registration = RegisterProperty(nameof(NotifyFilter), PropertyAccess.Get); + + return _notifyFilter; + } + set + { + using IDisposable registration = RegisterProperty(nameof(NotifyFilter), PropertyAccess.Set); + + _notifyFilter = value; + } + } /// public string Path { - get => _path; + get + { + using IDisposable registration = RegisterProperty(nameof(Path), PropertyAccess.Get); + + return _path; + } set { + using IDisposable registration = RegisterProperty(value, nameof(Path), PropertyAccess.Set); + if (!string.IsNullOrEmpty(value) && !_fileSystem.Directory.Exists(value)) { @@ -130,8 +186,39 @@ public string Path } } + /// + public override ISite? Site + { + get + { + using IDisposable registration = RegisterProperty(nameof(Site), PropertyAccess.Get); + + return base.Site; + } + set + { + using IDisposable registration = RegisterProperty(nameof(Site), PropertyAccess.Set); + + base.Site = value; + } + } + /// - public ISynchronizeInvoke? SynchronizingObject { get; set; } + public ISynchronizeInvoke? SynchronizingObject + { + get + { + using IDisposable registration = RegisterProperty(nameof(SynchronizingObject), PropertyAccess.Get); + + return _synchronizingObject; + } + set + { + using IDisposable registration = RegisterProperty(nameof(SynchronizingObject), PropertyAccess.Set); + + _synchronizingObject = value; + } + } /// public void BeginInit() @@ -527,6 +614,12 @@ public WaitForChangedResultMock( public bool TimedOut { get; } } + private IDisposable RegisterProperty(string name, PropertyAccess access) + => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterProperty(_path, name, access); + + private IDisposable RegisterProperty(string path, string name, PropertyAccess access) + => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterProperty(path, name, access); + private IDisposable RegisterMethod(string name) => _fileSystem.StatisticsRegistration.FileSystemWatcher.RegisterMethod(_path, name); diff --git a/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs b/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs index 0ca97efaa..ddb32632c 100644 --- a/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs +++ b/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Concurrent; +using System.IO; namespace Testably.Abstractions.Testing.Statistics; @@ -21,8 +22,13 @@ public FileSystemEntryStatistics( /// public IStatistics this[string path] - => _statistics.GetOrAdd(_fileSystem.Path.GetFullPath(path), - _ => new CallStatistics(_statisticsGate)); + { + get + { + string key = CreateKey(_fileSystem.Storage.CurrentDirectory, path); + return _statistics.GetOrAdd(key, _ => new CallStatistics(_statisticsGate)); + } + } /// /// Registers the callback with under . @@ -30,8 +36,8 @@ public IStatistics this[string path] /// A disposable which ignores all registrations, until it is disposed. internal IDisposable RegisterMethod(string path, string name, params ParameterDescription[] parameters) { - CallStatistics callStatistics = _statistics.GetOrAdd(_fileSystem.Path.GetFullPath(path), - _ => new CallStatistics(_statisticsGate)); + string key = CreateKey(_fileSystem.Storage.CurrentDirectory, path); + CallStatistics callStatistics = _statistics.GetOrAdd(key, _ => new CallStatistics(_statisticsGate)); return callStatistics.RegisterMethod(name, parameters); } @@ -41,8 +47,25 @@ internal IDisposable RegisterMethod(string path, string name, params ParameterDe /// A disposable which ignores all registrations, until it is disposed. internal IDisposable RegisterProperty(string path, string name, PropertyAccess access) { - CallStatistics callStatistics = _statistics.GetOrAdd(_fileSystem.Path.GetFullPath(path), - _ => new CallStatistics(_statisticsGate)); + string key = CreateKey(_fileSystem.Storage.CurrentDirectory, path); + CallStatistics callStatistics = _statistics.GetOrAdd(key, _ => new CallStatistics(_statisticsGate)); return callStatistics.RegisterProperty(name, access); } + + private string CreateKey(string currentDirectory, string path) + { + if (string.IsNullOrEmpty(path)) + { + return "(empty)"; + } + + if (Path.IsPathRooted(path)) + { + return path + .TrimEnd([Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar]); + } + + return Path.GetFullPath(Path.Combine(currentDirectory, path)) + .TrimEnd([Path.DirectorySeparatorChar , Path.AltDirectorySeparatorChar]); + } } diff --git a/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs b/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs index 7450db04e..ccccf3860 100644 --- a/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs +++ b/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs @@ -257,7 +257,7 @@ public IEnumerable EnumerateLocations( } DriveInfoMock drive = DriveInfoMock.New(driveName, _fileSystem); - if (_drives.TryGetValue(drive.Name, out IStorageDrive? d)) + if (_drives.TryGetValue(drive.GetName(), out IStorageDrive? d)) { return d; } @@ -292,7 +292,7 @@ public IEnumerable GetDrives() public IStorageDrive GetOrAddDrive(string driveName) { DriveInfoMock drive = DriveInfoMock.New(driveName, _fileSystem); - return _drives.GetOrAdd(drive.Name, _ => drive); + return _drives.GetOrAdd(drive.GetName(), _ => drive); } /// diff --git a/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net6.0.txt b/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net6.0.txt index 6f1ca6fc6..dc3a5d353 100644 --- a/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net6.0.txt +++ b/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net6.0.txt @@ -281,6 +281,7 @@ namespace Testably.Abstractions.Testing.Statistics public interface IStatistics { Testably.Abstractions.Testing.Statistics.MethodStatistic[] Methods { get; } + Testably.Abstractions.Testing.Statistics.PropertyStatistic[] Properties { get; } } public sealed class MethodStatistic { @@ -303,6 +304,18 @@ namespace Testably.Abstractions.Testing.Statistics public static Testably.Abstractions.Testing.Statistics.ParameterDescription FromParameter(System.Span value) { } public static Testably.Abstractions.Testing.Statistics.ParameterDescription FromParameter(T value) { } } + public enum PropertyAccess + { + Get = 0, + Set = 1, + } + public sealed class PropertyStatistic + { + public Testably.Abstractions.Testing.Statistics.PropertyAccess Access { get; } + public int Counter { get; } + public string Name { get; } + public override string ToString() { } + } } namespace Testably.Abstractions.Testing.Storage { diff --git a/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net7.0.txt b/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net7.0.txt index 78523af71..c79766b01 100644 --- a/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net7.0.txt +++ b/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net7.0.txt @@ -281,6 +281,7 @@ namespace Testably.Abstractions.Testing.Statistics public interface IStatistics { Testably.Abstractions.Testing.Statistics.MethodStatistic[] Methods { get; } + Testably.Abstractions.Testing.Statistics.PropertyStatistic[] Properties { get; } } public sealed class MethodStatistic { @@ -303,6 +304,18 @@ namespace Testably.Abstractions.Testing.Statistics public static Testably.Abstractions.Testing.Statistics.ParameterDescription FromParameter(System.Span value) { } public static Testably.Abstractions.Testing.Statistics.ParameterDescription FromParameter(T value) { } } + public enum PropertyAccess + { + Get = 0, + Set = 1, + } + public sealed class PropertyStatistic + { + public Testably.Abstractions.Testing.Statistics.PropertyAccess Access { get; } + public int Counter { get; } + public string Name { get; } + public override string ToString() { } + } } namespace Testably.Abstractions.Testing.Storage { diff --git a/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net8.0.txt b/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net8.0.txt index 14d174cdf..62e5c88dd 100644 --- a/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net8.0.txt +++ b/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_net8.0.txt @@ -279,6 +279,7 @@ namespace Testably.Abstractions.Testing.Statistics public interface IStatistics { Testably.Abstractions.Testing.Statistics.MethodStatistic[] Methods { get; } + Testably.Abstractions.Testing.Statistics.PropertyStatistic[] Properties { get; } } public sealed class MethodStatistic { @@ -301,6 +302,18 @@ namespace Testably.Abstractions.Testing.Statistics public static Testably.Abstractions.Testing.Statistics.ParameterDescription FromParameter(System.Span value) { } public static Testably.Abstractions.Testing.Statistics.ParameterDescription FromParameter(T value) { } } + public enum PropertyAccess + { + Get = 0, + Set = 1, + } + public sealed class PropertyStatistic + { + public Testably.Abstractions.Testing.Statistics.PropertyAccess Access { get; } + public int Counter { get; } + public string Name { get; } + public override string ToString() { } + } } namespace Testably.Abstractions.Testing.Storage { diff --git a/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_netstandard2.0.txt b/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_netstandard2.0.txt index b0364d804..19615591a 100644 --- a/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_netstandard2.0.txt +++ b/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_netstandard2.0.txt @@ -279,6 +279,7 @@ namespace Testably.Abstractions.Testing.Statistics public interface IStatistics { Testably.Abstractions.Testing.Statistics.MethodStatistic[] Methods { get; } + Testably.Abstractions.Testing.Statistics.PropertyStatistic[] Properties { get; } } public sealed class MethodStatistic { @@ -297,6 +298,18 @@ namespace Testably.Abstractions.Testing.Statistics public static Testably.Abstractions.Testing.Statistics.ParameterDescription FromOutParameter(T value) { } public static Testably.Abstractions.Testing.Statistics.ParameterDescription FromParameter(T value) { } } + public enum PropertyAccess + { + Get = 0, + Set = 1, + } + public sealed class PropertyStatistic + { + public Testably.Abstractions.Testing.Statistics.PropertyAccess Access { get; } + public int Counter { get; } + public string Name { get; } + public override string ToString() { } + } } namespace Testably.Abstractions.Testing.Storage { diff --git a/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_netstandard2.1.txt b/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_netstandard2.1.txt index 91a86c45c..a66e4db54 100644 --- a/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_netstandard2.1.txt +++ b/Tests/Api/Testably.Abstractions.Api.Tests/Expected/Testably.Abstractions.Testing_netstandard2.1.txt @@ -279,6 +279,7 @@ namespace Testably.Abstractions.Testing.Statistics public interface IStatistics { Testably.Abstractions.Testing.Statistics.MethodStatistic[] Methods { get; } + Testably.Abstractions.Testing.Statistics.PropertyStatistic[] Properties { get; } } public sealed class MethodStatistic { @@ -301,6 +302,18 @@ namespace Testably.Abstractions.Testing.Statistics public static Testably.Abstractions.Testing.Statistics.ParameterDescription FromParameter(System.Span value) { } public static Testably.Abstractions.Testing.Statistics.ParameterDescription FromParameter(T value) { } } + public enum PropertyAccess + { + Get = 0, + Set = 1, + } + public sealed class PropertyStatistic + { + public Testably.Abstractions.Testing.Statistics.PropertyAccess Access { get; } + public int Counter { get; } + public string Name { get; } + public override string ToString() { } + } } namespace Testably.Abstractions.Testing.Storage { diff --git a/Tests/Api/Testably.Abstractions.Api.Tests/Helper.cs b/Tests/Api/Testably.Abstractions.Api.Tests/Helper.cs index ddcb92cba..138773669 100644 --- a/Tests/Api/Testably.Abstractions.Api.Tests/Helper.cs +++ b/Tests/Api/Testably.Abstractions.Api.Tests/Helper.cs @@ -16,7 +16,7 @@ public static string CreatePublicApi(string framework, string assemblyName) string assemblyFile = CombinedPaths("Build", "Binaries", framework, $"{assemblyName}.dll"); Assembly assembly = Assembly.LoadFile(assemblyFile); string publicApi = assembly.GeneratePublicApi(options: null); - return publicApi.Replace("\r\n", "\n"); + return publicApi; } public static string GetExpectedApi(string framework, string assemblyName) diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs index 6e12073b7..b502e801f 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs @@ -449,6 +449,7 @@ public void Method_ResolveLinkTarget_Bool_ShouldRegisterCall() public void Property_Attributes_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").Attributes; @@ -460,18 +461,20 @@ public void Property_Attributes_Get_ShouldRegisterPropertyAccess() public void Property_Attributes_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); FileAttributes value = new(); sut.DirectoryInfo.New("foo").Attributes = value; sut.Statistics.DirectoryInfo["foo"] - .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.Attributes)); + .ShouldOnlyContainPropertySetAccess(nameof(IDirectoryInfo.Attributes)); } [SkippableFact] public void Property_CreationTime_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").CreationTime; @@ -483,18 +486,20 @@ public void Property_CreationTime_Get_ShouldRegisterPropertyAccess() public void Property_CreationTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); DateTime value = new(); sut.DirectoryInfo.New("foo").CreationTime = value; sut.Statistics.DirectoryInfo["foo"] - .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTime)); + .ShouldOnlyContainPropertySetAccess(nameof(IDirectoryInfo.CreationTime)); } [SkippableFact] public void Property_CreationTimeUtc_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").CreationTimeUtc; @@ -506,18 +511,20 @@ public void Property_CreationTimeUtc_Get_ShouldRegisterPropertyAccess() public void Property_CreationTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); DateTime value = new(); sut.DirectoryInfo.New("foo").CreationTimeUtc = value; sut.Statistics.DirectoryInfo["foo"] - .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.CreationTimeUtc)); + .ShouldOnlyContainPropertySetAccess(nameof(IDirectoryInfo.CreationTimeUtc)); } [SkippableFact] public void Property_Exists_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").Exists; @@ -529,6 +536,7 @@ public void Property_Exists_Get_ShouldRegisterPropertyAccess() public void Property_Extension_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").Extension; @@ -540,6 +548,7 @@ public void Property_Extension_Get_ShouldRegisterPropertyAccess() public void Property_FullName_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").FullName; @@ -551,6 +560,7 @@ public void Property_FullName_Get_ShouldRegisterPropertyAccess() public void Property_LastAccessTime_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").LastAccessTime; @@ -562,18 +572,20 @@ public void Property_LastAccessTime_Get_ShouldRegisterPropertyAccess() public void Property_LastAccessTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); DateTime value = new(); sut.DirectoryInfo.New("foo").LastAccessTime = value; sut.Statistics.DirectoryInfo["foo"] - .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTime)); + .ShouldOnlyContainPropertySetAccess(nameof(IDirectoryInfo.LastAccessTime)); } [SkippableFact] public void Property_LastAccessTimeUtc_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").LastAccessTimeUtc; @@ -585,18 +597,20 @@ public void Property_LastAccessTimeUtc_Get_ShouldRegisterPropertyAccess() public void Property_LastAccessTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); DateTime value = new(); sut.DirectoryInfo.New("foo").LastAccessTimeUtc = value; sut.Statistics.DirectoryInfo["foo"] - .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastAccessTimeUtc)); + .ShouldOnlyContainPropertySetAccess(nameof(IDirectoryInfo.LastAccessTimeUtc)); } [SkippableFact] public void Property_LastWriteTime_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").LastWriteTime; @@ -608,18 +622,20 @@ public void Property_LastWriteTime_Get_ShouldRegisterPropertyAccess() public void Property_LastWriteTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); DateTime value = new(); sut.DirectoryInfo.New("foo").LastWriteTime = value; sut.Statistics.DirectoryInfo["foo"] - .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTime)); + .ShouldOnlyContainPropertySetAccess(nameof(IDirectoryInfo.LastWriteTime)); } [SkippableFact] public void Property_LastWriteTimeUtc_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").LastWriteTimeUtc; @@ -631,12 +647,13 @@ public void Property_LastWriteTimeUtc_Get_ShouldRegisterPropertyAccess() public void Property_LastWriteTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); DateTime value = new(); sut.DirectoryInfo.New("foo").LastWriteTimeUtc = value; sut.Statistics.DirectoryInfo["foo"] - .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.LastWriteTimeUtc)); + .ShouldOnlyContainPropertySetAccess(nameof(IDirectoryInfo.LastWriteTimeUtc)); } #if FEATURE_FILESYSTEM_LINK @@ -644,6 +661,7 @@ public void Property_LastWriteTimeUtc_Set_ShouldRegisterPropertyAccess() public void Property_LinkTarget_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").LinkTarget; @@ -656,6 +674,7 @@ public void Property_LinkTarget_Get_ShouldRegisterPropertyAccess() public void Property_Name_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").Name; @@ -667,6 +686,7 @@ public void Property_Name_Get_ShouldRegisterPropertyAccess() public void Property_Parent_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").Parent; @@ -678,6 +698,7 @@ public void Property_Parent_Get_ShouldRegisterPropertyAccess() public void Property_Root_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").Root; @@ -690,6 +711,7 @@ public void Property_Root_Get_ShouldRegisterPropertyAccess() public void Property_UnixFileMode_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.DirectoryInfo.New("foo").UnixFileMode; @@ -703,6 +725,7 @@ public void Property_UnixFileMode_Set_ShouldRegisterPropertyAccess() Skip.If(Test.RunsOnWindows); MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); UnixFileMode value = new(); #pragma warning disable CA1416 @@ -710,7 +733,7 @@ public void Property_UnixFileMode_Set_ShouldRegisterPropertyAccess() #pragma warning restore CA1416 sut.Statistics.DirectoryInfo["foo"] - .ShouldOnlyContainPropertyGetAccess(nameof(IDirectoryInfo.UnixFileMode)); + .ShouldOnlyContainPropertySetAccess(nameof(IDirectoryInfo.UnixFileMode)); } #endif } diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs index 9d24b1fba..01dc0504e 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs @@ -290,6 +290,7 @@ public void Method_ResolveLinkTarget_Bool_ShouldRegisterCall() public void Property_Attributes_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").Attributes; @@ -301,6 +302,7 @@ public void Property_Attributes_Get_ShouldRegisterPropertyAccess() public void Property_Attributes_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); FileAttributes value = new(); sut.FileInfo.New("foo").Attributes = value; @@ -313,6 +315,7 @@ public void Property_Attributes_Set_ShouldRegisterPropertyAccess() public void Property_CreationTime_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").CreationTime; @@ -324,6 +327,7 @@ public void Property_CreationTime_Get_ShouldRegisterPropertyAccess() public void Property_CreationTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); DateTime value = new(); sut.FileInfo.New("foo").CreationTime = value; @@ -336,6 +340,7 @@ public void Property_CreationTime_Set_ShouldRegisterPropertyAccess() public void Property_CreationTimeUtc_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").CreationTimeUtc; @@ -347,6 +352,7 @@ public void Property_CreationTimeUtc_Get_ShouldRegisterPropertyAccess() public void Property_CreationTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); DateTime value = new(); sut.FileInfo.New("foo").CreationTimeUtc = value; @@ -359,6 +365,7 @@ public void Property_CreationTimeUtc_Set_ShouldRegisterPropertyAccess() public void Property_Directory_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").Directory; @@ -370,6 +377,7 @@ public void Property_Directory_Get_ShouldRegisterPropertyAccess() public void Property_DirectoryName_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").DirectoryName; @@ -381,6 +389,7 @@ public void Property_DirectoryName_Get_ShouldRegisterPropertyAccess() public void Property_Exists_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").Exists; @@ -391,6 +400,7 @@ public void Property_Exists_Get_ShouldRegisterPropertyAccess() public void Property_Extension_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").Extension; @@ -402,6 +412,7 @@ public void Property_Extension_Get_ShouldRegisterPropertyAccess() public void Property_FullName_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").FullName; @@ -413,6 +424,7 @@ public void Property_FullName_Get_ShouldRegisterPropertyAccess() public void Property_IsReadOnly_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").IsReadOnly; @@ -424,6 +436,7 @@ public void Property_IsReadOnly_Get_ShouldRegisterPropertyAccess() public void Property_IsReadOnly_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); bool value = true; sut.FileInfo.New("foo").IsReadOnly = value; @@ -436,6 +449,7 @@ public void Property_IsReadOnly_Set_ShouldRegisterPropertyAccess() public void Property_LastAccessTime_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").LastAccessTime; @@ -447,6 +461,7 @@ public void Property_LastAccessTime_Get_ShouldRegisterPropertyAccess() public void Property_LastAccessTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); DateTime value = new(); sut.FileInfo.New("foo").LastAccessTime = value; @@ -459,6 +474,7 @@ public void Property_LastAccessTime_Set_ShouldRegisterPropertyAccess() public void Property_LastAccessTimeUtc_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").LastAccessTimeUtc; @@ -470,6 +486,7 @@ public void Property_LastAccessTimeUtc_Get_ShouldRegisterPropertyAccess() public void Property_LastAccessTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); DateTime value = new(); sut.FileInfo.New("foo").LastAccessTimeUtc = value; @@ -482,6 +499,7 @@ public void Property_LastAccessTimeUtc_Set_ShouldRegisterPropertyAccess() public void Property_LastWriteTime_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").LastWriteTime; @@ -493,6 +511,7 @@ public void Property_LastWriteTime_Get_ShouldRegisterPropertyAccess() public void Property_LastWriteTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); DateTime value = new(); sut.FileInfo.New("foo").LastWriteTime = value; @@ -505,6 +524,7 @@ public void Property_LastWriteTime_Set_ShouldRegisterPropertyAccess() public void Property_LastWriteTimeUtc_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").LastWriteTimeUtc; @@ -516,6 +536,7 @@ public void Property_LastWriteTimeUtc_Get_ShouldRegisterPropertyAccess() public void Property_LastWriteTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); DateTime value = new(); sut.FileInfo.New("foo").LastWriteTimeUtc = value; @@ -528,6 +549,7 @@ public void Property_LastWriteTimeUtc_Set_ShouldRegisterPropertyAccess() public void Property_Length_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").Length; @@ -539,6 +561,7 @@ public void Property_Length_Get_ShouldRegisterPropertyAccess() public void Property_LinkTarget_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").LinkTarget; @@ -551,6 +574,7 @@ public void Property_LinkTarget_Get_ShouldRegisterPropertyAccess() public void Property_Name_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").Name; @@ -562,6 +586,7 @@ public void Property_Name_Get_ShouldRegisterPropertyAccess() public void Property_UnixFileMode_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); _ = sut.FileInfo.New("foo").UnixFileMode; @@ -575,6 +600,7 @@ public void Property_UnixFileMode_Set_ShouldRegisterPropertyAccess() Skip.If(Test.RunsOnWindows); MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); UnixFileMode value = new(); #pragma warning disable CA1416 diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs index e524491cf..9247086b8 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs @@ -457,7 +457,14 @@ public void Property_ReadTimeout_Get_ShouldRegisterPropertyAccess() MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); - _ = fileStream.ReadTimeout; + try + { + _ = fileStream.ReadTimeout; + } + catch (InvalidOperationException) + { + // Timeouts are not supported on this stream. + } sut.Statistics.FileStream["foo"] .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.ReadTimeout)); @@ -470,7 +477,14 @@ public void Property_ReadTimeout_Set_ShouldRegisterPropertyAccess() using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); int value = 42; - fileStream.ReadTimeout = value; + try + { + fileStream.ReadTimeout = value; + } + catch (InvalidOperationException) + { + // Timeouts are not supported on this stream. + } sut.Statistics.FileStream["foo"] .ShouldOnlyContainPropertySetAccess(nameof(FileSystemStream.ReadTimeout)); @@ -482,7 +496,14 @@ public void Property_WriteTimeout_Get_ShouldRegisterPropertyAccess() MockFileSystem sut = new(); using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); - _ = fileStream.WriteTimeout; + try + { + _ = fileStream.WriteTimeout; + } + catch (InvalidOperationException) + { + // Timeouts are not supported on this stream. + } sut.Statistics.FileStream["foo"] .ShouldOnlyContainPropertyGetAccess(nameof(FileSystemStream.WriteTimeout)); @@ -495,7 +516,14 @@ public void Property_WriteTimeout_Set_ShouldRegisterPropertyAccess() using FileSystemStream fileStream = sut.FileStream.New("foo", FileMode.OpenOrCreate); int value = 42; - fileStream.WriteTimeout = value; + try + { + fileStream.WriteTimeout = value; + } + catch (InvalidOperationException) + { + // Timeouts are not supported on this stream. + } sut.Statistics.FileStream["foo"] .ShouldOnlyContainPropertySetAccess(nameof(FileSystemStream.WriteTimeout)); diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherFactoryStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherFactoryStatisticsTests.cs index 73744b4d3..88a79887b 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherFactoryStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherFactoryStatisticsTests.cs @@ -49,7 +49,8 @@ public void Method_New_String_String_ShouldRegisterCall() public void Method_Wrap_FileSystemWatcher_ShouldRegisterCall() { MockFileSystem sut = new(); - FileSystemWatcher fileSystemWatcher = new(); + sut.Initialize(); + FileSystemWatcher fileSystemWatcher = new("."); //TODO: Check how empty path is treated! using IFileSystemWatcher result = sut.FileSystemWatcher.Wrap(fileSystemWatcher); diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherStatisticsTests.cs index f39dd8923..25b8e288e 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherStatisticsTests.cs @@ -114,21 +114,12 @@ public void Method_WaitForChanged_WatcherChangeTypes_TimeSpan_ShouldRegisterCall timeout); } #endif - [SkippableFact] - public void Property_Container_Get_ShouldRegisterPropertyAccess() - { - MockFileSystem sut = new(); - - _ = sut.FileSystemWatcher.New("foo").Container; - - sut.Statistics.FileSystemWatcher["foo"] - .ShouldOnlyContainPropertyGetAccess(nameof(IFileSystemWatcher.Container)); - } [SkippableFact] public void Property_EnableRaisingEvents_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.FileSystemWatcher.New("foo").EnableRaisingEvents; @@ -140,7 +131,8 @@ public void Property_EnableRaisingEvents_Get_ShouldRegisterPropertyAccess() public void Property_EnableRaisingEvents_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); - bool value = true; + sut.Initialize().WithSubdirectory("foo"); + bool value = false; sut.FileSystemWatcher.New("foo").EnableRaisingEvents = value; @@ -152,6 +144,7 @@ public void Property_EnableRaisingEvents_Set_ShouldRegisterPropertyAccess() public void Property_Filter_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.FileSystemWatcher.New("foo").Filter; @@ -163,6 +156,7 @@ public void Property_Filter_Get_ShouldRegisterPropertyAccess() public void Property_Filter_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); string value = "foo"; sut.FileSystemWatcher.New("foo").Filter = value; @@ -176,6 +170,7 @@ public void Property_Filter_Set_ShouldRegisterPropertyAccess() public void Property_Filters_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.FileSystemWatcher.New("foo").Filters; @@ -188,6 +183,7 @@ public void Property_Filters_Get_ShouldRegisterPropertyAccess() public void Property_IncludeSubdirectories_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.FileSystemWatcher.New("foo").IncludeSubdirectories; @@ -199,6 +195,7 @@ public void Property_IncludeSubdirectories_Get_ShouldRegisterPropertyAccess() public void Property_IncludeSubdirectories_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); bool value = true; sut.FileSystemWatcher.New("foo").IncludeSubdirectories = value; @@ -211,6 +208,7 @@ public void Property_IncludeSubdirectories_Set_ShouldRegisterPropertyAccess() public void Property_InternalBufferSize_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.FileSystemWatcher.New("foo").InternalBufferSize; @@ -222,6 +220,7 @@ public void Property_InternalBufferSize_Get_ShouldRegisterPropertyAccess() public void Property_InternalBufferSize_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); int value = 42; sut.FileSystemWatcher.New("foo").InternalBufferSize = value; @@ -234,6 +233,7 @@ public void Property_InternalBufferSize_Set_ShouldRegisterPropertyAccess() public void Property_NotifyFilter_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.FileSystemWatcher.New("foo").NotifyFilter; @@ -245,6 +245,7 @@ public void Property_NotifyFilter_Get_ShouldRegisterPropertyAccess() public void Property_NotifyFilter_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); NotifyFilters value = new(); sut.FileSystemWatcher.New("foo").NotifyFilter = value; @@ -257,6 +258,7 @@ public void Property_NotifyFilter_Set_ShouldRegisterPropertyAccess() public void Property_Path_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.FileSystemWatcher.New("foo").Path; @@ -268,6 +270,7 @@ public void Property_Path_Get_ShouldRegisterPropertyAccess() public void Property_Path_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); string value = "foo"; sut.FileSystemWatcher.New("foo").Path = value; @@ -280,6 +283,7 @@ public void Property_Path_Set_ShouldRegisterPropertyAccess() public void Property_Site_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.FileSystemWatcher.New("foo").Site; @@ -291,6 +295,7 @@ public void Property_Site_Get_ShouldRegisterPropertyAccess() public void Property_Site_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); ISite value = null!; sut.FileSystemWatcher.New("foo").Site = value; @@ -303,6 +308,7 @@ public void Property_Site_Set_ShouldRegisterPropertyAccess() public void Property_SynchronizingObject_Get_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); _ = sut.FileSystemWatcher.New("foo").SynchronizingObject; @@ -314,6 +320,7 @@ public void Property_SynchronizingObject_Get_ShouldRegisterPropertyAccess() public void Property_SynchronizingObject_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); + sut.Initialize().WithSubdirectory("foo"); ISynchronizeInvoke value = null!; sut.FileSystemWatcher.New("foo").SynchronizingObject = value; diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs index 547bcfbdf..dfd9979bc 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/StatisticsTests.Helpers.cs @@ -1,5 +1,6 @@ using Microsoft.Win32.SafeHandles; using System.Collections.Generic; +using System.ComponentModel; using System.Globalization; using System.IO; using System.Linq; @@ -36,6 +37,12 @@ public static string CheckPropertiesAndMethods(string className, bool requireIns continue; } + if (propertyInfo.PropertyType == typeof(IContainer)) + { + // Container cannot be overridden + continue; + } + if (propertyInfo.CanRead) { CheckPropertyGetAccess(builder, propertyInfo, className, requireInstance, mockType, testType); From f9c32e888f46af464a2a901a5499507aadf64b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Fri, 15 Mar 2024 16:49:02 +0100 Subject: [PATCH 7/8] Review --- .../FileSystem/FileInfoMock.cs | 1 - .../DirectoryInfoStatisticsTests.cs | 150 ++++---- .../FileSystem/FileInfoStatisticsTests.cs | 105 +++-- .../FileSystem/FileStatisticsTests.cs | 362 +++++++++--------- .../FileSystem/FileStreamStatisticsTests.cs | 96 ++--- .../FileSystem/PathStatisticsTests.cs | 214 ++++++----- 6 files changed, 493 insertions(+), 435 deletions(-) diff --git a/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs index 8b440c9f8..64e891f99 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/FileInfoMock.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; using System.IO; -using System.Xml.Linq; using Testably.Abstractions.Testing.Helpers; using Testably.Abstractions.Testing.Statistics; using Testably.Abstractions.Testing.Storage; diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs index b502e801f..437c7e2be 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs @@ -25,9 +25,9 @@ public void Method_CreateAsSymbolicLink_String_ShouldRegisterCall() sut.DirectoryInfo.New("foo").CreateAsSymbolicLink(pathToTarget); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.CreateAsSymbolicLink), - pathToTarget); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.CreateAsSymbolicLink), + pathToTarget); } #endif @@ -39,9 +39,9 @@ public void Method_CreateSubdirectory_String_ShouldRegisterCall() sut.DirectoryInfo.New("foo").CreateSubdirectory(path); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.CreateSubdirectory), - path); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.CreateSubdirectory), + path); } [SkippableFact] @@ -53,9 +53,9 @@ public void Method_Delete_Bool_ShouldRegisterCall() sut.DirectoryInfo.New("foo").Delete(recursive); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.Delete), - recursive); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.Delete), + recursive); } [SkippableFact] @@ -91,9 +91,9 @@ public void Method_EnumerateDirectories_String_EnumerationOptions_ShouldRegister sut.DirectoryInfo.New("foo").EnumerateDirectories(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.EnumerateDirectories), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateDirectories), + searchPattern, enumerationOptions); } #endif @@ -106,9 +106,9 @@ public void Method_EnumerateDirectories_String_SearchOption_ShouldRegisterCall() sut.DirectoryInfo.New("foo").EnumerateDirectories(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.EnumerateDirectories), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateDirectories), + searchPattern, searchOption); } [SkippableFact] @@ -119,9 +119,9 @@ public void Method_EnumerateDirectories_String_ShouldRegisterCall() sut.DirectoryInfo.New("foo").EnumerateDirectories(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.EnumerateDirectories), - searchPattern); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateDirectories), + searchPattern); } [SkippableFact] @@ -145,9 +145,9 @@ public void Method_EnumerateFiles_String_EnumerationOptions_ShouldRegisterCall() sut.DirectoryInfo.New("foo").EnumerateFiles(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.EnumerateFiles), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateFiles), + searchPattern, enumerationOptions); } #endif @@ -160,9 +160,9 @@ public void Method_EnumerateFiles_String_SearchOption_ShouldRegisterCall() sut.DirectoryInfo.New("foo").EnumerateFiles(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.EnumerateFiles), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateFiles), + searchPattern, searchOption); } [SkippableFact] @@ -173,9 +173,9 @@ public void Method_EnumerateFiles_String_ShouldRegisterCall() sut.DirectoryInfo.New("foo").EnumerateFiles(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.EnumerateFiles), - searchPattern); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateFiles), + searchPattern); } [SkippableFact] @@ -199,9 +199,9 @@ public void Method_EnumerateFileSystemInfos_String_EnumerationOptions_ShouldRegi sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.EnumerateFileSystemInfos), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateFileSystemInfos), + searchPattern, enumerationOptions); } #endif @@ -214,9 +214,9 @@ public void Method_EnumerateFileSystemInfos_String_SearchOption_ShouldRegisterCa sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.EnumerateFileSystemInfos), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateFileSystemInfos), + searchPattern, searchOption); } [SkippableFact] @@ -227,9 +227,9 @@ public void Method_EnumerateFileSystemInfos_String_ShouldRegisterCall() sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.EnumerateFileSystemInfos), - searchPattern); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.EnumerateFileSystemInfos), + searchPattern); } [SkippableFact] @@ -255,9 +255,9 @@ public void Method_GetDirectories_String_EnumerationOptions_ShouldRegisterCall() sut.DirectoryInfo.New("foo").GetDirectories(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.GetDirectories), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetDirectories), + searchPattern, enumerationOptions); } #endif @@ -271,9 +271,9 @@ public void Method_GetDirectories_String_SearchOption_ShouldRegisterCall() sut.DirectoryInfo.New("foo").GetDirectories(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.GetDirectories), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetDirectories), + searchPattern, searchOption); } [SkippableFact] @@ -285,9 +285,9 @@ public void Method_GetDirectories_String_ShouldRegisterCall() sut.DirectoryInfo.New("foo").GetDirectories(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.GetDirectories), - searchPattern); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetDirectories), + searchPattern); } [SkippableFact] @@ -313,9 +313,9 @@ public void Method_GetFiles_String_EnumerationOptions_ShouldRegisterCall() sut.DirectoryInfo.New("foo").GetFiles(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.GetFiles), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetFiles), + searchPattern, enumerationOptions); } #endif @@ -329,9 +329,9 @@ public void Method_GetFiles_String_SearchOption_ShouldRegisterCall() sut.DirectoryInfo.New("foo").GetFiles(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.GetFiles), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetFiles), + searchPattern, searchOption); } [SkippableFact] @@ -343,9 +343,9 @@ public void Method_GetFiles_String_ShouldRegisterCall() sut.DirectoryInfo.New("foo").GetFiles(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.GetFiles), - searchPattern); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetFiles), + searchPattern); } [SkippableFact] @@ -371,9 +371,9 @@ public void Method_GetFileSystemInfos_String_EnumerationOptions_ShouldRegisterCa sut.DirectoryInfo.New("foo").GetFileSystemInfos(searchPattern, enumerationOptions); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.GetFileSystemInfos), - searchPattern, enumerationOptions); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetFileSystemInfos), + searchPattern, enumerationOptions); } #endif @@ -387,9 +387,9 @@ public void Method_GetFileSystemInfos_String_SearchOption_ShouldRegisterCall() sut.DirectoryInfo.New("foo").GetFileSystemInfos(searchPattern, searchOption); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.GetFileSystemInfos), - searchPattern, searchOption); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetFileSystemInfos), + searchPattern, searchOption); } [SkippableFact] @@ -401,9 +401,9 @@ public void Method_GetFileSystemInfos_String_ShouldRegisterCall() sut.DirectoryInfo.New("foo").GetFileSystemInfos(searchPattern); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.GetFileSystemInfos), - searchPattern); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.GetFileSystemInfos), + searchPattern); } [SkippableFact] @@ -415,9 +415,9 @@ public void Method_MoveTo_String_ShouldRegisterCall() sut.DirectoryInfo.New("foo").MoveTo(destDirName); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.MoveTo), - destDirName); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.MoveTo), + destDirName); } [SkippableFact] @@ -440,9 +440,9 @@ public void Method_ResolveLinkTarget_Bool_ShouldRegisterCall() sut.DirectoryInfo.New("foo").ResolveLinkTarget(returnFinalTarget); - sut.Statistics.DirectoryInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IDirectoryInfo.ResolveLinkTarget), - returnFinalTarget); + sut.Statistics.DirectoryInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IDirectoryInfo.ResolveLinkTarget), + returnFinalTarget); } #endif [SkippableFact] @@ -487,7 +487,7 @@ public void Property_CreationTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); - DateTime value = new(); + DateTime value = DateTime.Now; sut.DirectoryInfo.New("foo").CreationTime = value; @@ -512,7 +512,7 @@ public void Property_CreationTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); - DateTime value = new(); + DateTime value = DateTime.UtcNow; sut.DirectoryInfo.New("foo").CreationTimeUtc = value; @@ -573,7 +573,7 @@ public void Property_LastAccessTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); - DateTime value = new(); + DateTime value = DateTime.Now; sut.DirectoryInfo.New("foo").LastAccessTime = value; @@ -598,7 +598,7 @@ public void Property_LastAccessTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); - DateTime value = new(); + DateTime value = DateTime.UtcNow; sut.DirectoryInfo.New("foo").LastAccessTimeUtc = value; @@ -623,7 +623,7 @@ public void Property_LastWriteTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); - DateTime value = new(); + DateTime value = DateTime.Now; sut.DirectoryInfo.New("foo").LastWriteTime = value; @@ -648,7 +648,7 @@ public void Property_LastWriteTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithSubdirectory("foo"); - DateTime value = new(); + DateTime value = DateTime.UtcNow; sut.DirectoryInfo.New("foo").LastWriteTimeUtc = value; diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs index 01dc0504e..4974c00ef 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileInfoStatisticsTests.cs @@ -12,7 +12,8 @@ public void Method_AppendText_ShouldRegisterCall() sut.FileInfo.New("foo").AppendText(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.AppendText)); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.AppendText)); } [SkippableFact] @@ -25,8 +26,9 @@ public void Method_CopyTo_String_Bool_ShouldRegisterCall() sut.FileInfo.New("foo").CopyTo(destFileName, overwrite); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.CopyTo), - destFileName, overwrite); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.CopyTo), + destFileName, overwrite); } [SkippableFact] @@ -38,8 +40,9 @@ public void Method_CopyTo_String_ShouldRegisterCall() sut.FileInfo.New("foo").CopyTo(destFileName); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.CopyTo), - destFileName); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.CopyTo), + destFileName); } [SkippableFact] @@ -49,7 +52,8 @@ public void Method_Create_ShouldRegisterCall() sut.FileInfo.New("foo").Create(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Create)); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.Create)); } #if FEATURE_FILESYSTEM_LINK @@ -61,9 +65,9 @@ public void Method_CreateAsSymbolicLink_String_ShouldRegisterCall() sut.FileInfo.New("foo").CreateAsSymbolicLink(pathToTarget); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IFileInfo.CreateAsSymbolicLink), - pathToTarget); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.CreateAsSymbolicLink), + pathToTarget); } #endif @@ -74,7 +78,8 @@ public void Method_CreateText_ShouldRegisterCall() sut.FileInfo.New("foo").CreateText(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.CreateText)); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.CreateText)); } [SkippableFact] @@ -88,7 +93,8 @@ public void Method_Decrypt_ShouldRegisterCall() sut.FileInfo.New("foo").Decrypt(); #pragma warning restore CA1416 - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Decrypt)); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.Decrypt)); } [SkippableFact] @@ -99,7 +105,8 @@ public void Method_Delete_ShouldRegisterCall() sut.FileInfo.New("foo").Delete(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Delete)); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.Delete)); } [SkippableFact] @@ -113,7 +120,8 @@ public void Method_Encrypt_ShouldRegisterCall() sut.FileInfo.New("foo").Encrypt(); #pragma warning restore CA1416 - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Encrypt)); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.Encrypt)); } #if FEATURE_FILE_MOVETO_OVERWRITE @@ -127,8 +135,9 @@ public void Method_MoveTo_String_Bool_ShouldRegisterCall() sut.FileInfo.New("foo").MoveTo(destFileName, overwrite); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.MoveTo), - destFileName, overwrite); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.MoveTo), + destFileName, overwrite); } #endif @@ -141,8 +150,9 @@ public void Method_MoveTo_String_ShouldRegisterCall() sut.FileInfo.New("foo").MoveTo(destFileName); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.MoveTo), - destFileName); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.MoveTo), + destFileName); } [SkippableFact] @@ -155,8 +165,9 @@ public void Method_Open_FileMode_FileAccess_FileShare_ShouldRegisterCall() sut.FileInfo.New("foo").Open(mode, access, share); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), - mode, access, share); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), + mode, access, share); } [SkippableFact] @@ -168,8 +179,9 @@ public void Method_Open_FileMode_FileAccess_ShouldRegisterCall() sut.FileInfo.New("foo").Open(mode, access); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), - mode, access); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), + mode, access); } [SkippableFact] @@ -180,8 +192,9 @@ public void Method_Open_FileMode_ShouldRegisterCall() sut.FileInfo.New("foo").Open(mode); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), - mode); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), + mode); } #if FEATURE_FILESYSTEM_STREAM_OPTIONS @@ -194,8 +207,9 @@ public void Method_Open_FileStreamOptions_ShouldRegisterCall() sut.FileInfo.New("foo").Open(options); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), - options); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.Open), + options); } #endif @@ -207,7 +221,8 @@ public void Method_OpenRead_ShouldRegisterCall() sut.FileInfo.New("foo").OpenRead(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.OpenRead)); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.OpenRead)); } [SkippableFact] @@ -218,7 +233,8 @@ public void Method_OpenText_ShouldRegisterCall() sut.FileInfo.New("foo").OpenText(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.OpenText)); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.OpenText)); } [SkippableFact] @@ -228,7 +244,8 @@ public void Method_OpenWrite_ShouldRegisterCall() sut.FileInfo.New("foo").OpenWrite(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.OpenWrite)); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.OpenWrite)); } [SkippableFact] @@ -238,7 +255,8 @@ public void Method_Refresh_ShouldRegisterCall() sut.FileInfo.New("foo").Refresh(); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Refresh)); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.Refresh)); } [SkippableFact] @@ -253,8 +271,9 @@ public void Method_Replace_String_String_Bool_ShouldRegisterCall() sut.FileInfo.New("foo").Replace(destinationFileName, destinationBackupFileName, ignoreMetadataErrors); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Replace), - destinationFileName, destinationBackupFileName, ignoreMetadataErrors); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.Replace), + destinationFileName, destinationBackupFileName, ignoreMetadataErrors); } [SkippableFact] @@ -267,8 +286,9 @@ public void Method_Replace_String_String_ShouldRegisterCall() sut.FileInfo.New("foo").Replace(destinationFileName, destinationBackupFileName); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall(nameof(IFileInfo.Replace), - destinationFileName, destinationBackupFileName); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall(nameof(IFileInfo.Replace), + destinationFileName, destinationBackupFileName); } #if FEATURE_FILESYSTEM_LINK @@ -280,9 +300,10 @@ public void Method_ResolveLinkTarget_Bool_ShouldRegisterCall() sut.FileInfo.New("foo").ResolveLinkTarget(returnFinalTarget); - sut.Statistics.FileInfo["foo"].ShouldOnlyContainMethodCall( - nameof(IFileInfo.ResolveLinkTarget), - returnFinalTarget); + sut.Statistics.FileInfo["foo"] + .ShouldOnlyContainMethodCall( + nameof(IFileInfo.ResolveLinkTarget), + returnFinalTarget); } #endif @@ -328,7 +349,7 @@ public void Property_CreationTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); - DateTime value = new(); + DateTime value = DateTime.Now; sut.FileInfo.New("foo").CreationTime = value; @@ -353,7 +374,7 @@ public void Property_CreationTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); - DateTime value = new(); + DateTime value = DateTime.UtcNow; sut.FileInfo.New("foo").CreationTimeUtc = value; @@ -462,7 +483,7 @@ public void Property_LastAccessTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); - DateTime value = new(); + DateTime value = DateTime.Now; sut.FileInfo.New("foo").LastAccessTime = value; @@ -487,7 +508,7 @@ public void Property_LastAccessTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); - DateTime value = new(); + DateTime value = DateTime.UtcNow; sut.FileInfo.New("foo").LastAccessTimeUtc = value; @@ -512,7 +533,7 @@ public void Property_LastWriteTime_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); - DateTime value = new(); + DateTime value = DateTime.Now; sut.FileInfo.New("foo").LastWriteTime = value; @@ -537,7 +558,7 @@ public void Property_LastWriteTimeUtc_Set_ShouldRegisterPropertyAccess() { MockFileSystem sut = new(); sut.Initialize().WithFile("foo"); - DateTime value = new(); + DateTime value = DateTime.UtcNow; sut.FileInfo.New("foo").LastWriteTimeUtc = value; diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStatisticsTests.cs index 2b44f153c..ea9819fe1 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStatisticsTests.cs @@ -43,6 +43,41 @@ public void Method_AppendAllLines_String_IEnumerableString_ShouldRegisterCall() path, contents); } +#if FEATURE_FILESYSTEM_ASYNC + [SkippableFact] + public async Task + Method_AppendAllLinesAsync_String_IEnumerableString_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + string path = "foo"; + IEnumerable contents = ["foo", "bar"]; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.AppendAllLinesAsync(path, contents, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllLinesAsync), + path, contents, cancellationToken); + } +#endif + +#if FEATURE_FILESYSTEM_ASYNC + [SkippableFact] + public async Task + Method_AppendAllLinesAsync_String_IEnumerableString_Encoding_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + string path = "foo"; + IEnumerable contents = ["foo", "bar"]; + Encoding encoding = Encoding.UTF8; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.AppendAllLinesAsync(path, contents, encoding, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllLinesAsync), + path, contents, encoding, cancellationToken); + } +#endif + [SkippableFact] public void Method_AppendAllText_String_String_Encoding_ShouldRegisterCall() { @@ -70,6 +105,40 @@ public void Method_AppendAllText_String_String_ShouldRegisterCall() path, contents); } +#if FEATURE_FILESYSTEM_ASYNC + [SkippableFact] + public async Task Method_AppendAllTextAsync_String_String_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + string path = "foo"; + string contents = "foo"; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.AppendAllTextAsync(path, contents, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllTextAsync), + path, contents, cancellationToken); + } +#endif + +#if FEATURE_FILESYSTEM_ASYNC + [SkippableFact] + public async Task + Method_AppendAllTextAsync_String_String_Encoding_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + string path = "foo"; + string contents = "foo"; + Encoding encoding = Encoding.UTF8; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.AppendAllTextAsync(path, contents, encoding, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllTextAsync), + path, contents, encoding, cancellationToken); + } +#endif + [SkippableFact] public void Method_AppendText_String_ShouldRegisterCall() { @@ -669,6 +738,40 @@ public void Method_ReadAllLines_String_ShouldRegisterCall() path); } +#if FEATURE_FILESYSTEM_ASYNC + [SkippableFact] + public async Task Method_ReadAllLinesAsync_String_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.ReadAllLinesAsync(path, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllLinesAsync), + path, cancellationToken); + } +#endif + +#if FEATURE_FILESYSTEM_ASYNC + [SkippableFact] + public async Task + Method_ReadAllLinesAsync_String_Encoding_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + Encoding encoding = Encoding.UTF8; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.ReadAllLinesAsync(path, encoding, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllLinesAsync), + path, encoding, cancellationToken); + } +#endif + [SkippableFact] public void Method_ReadAllText_String_Encoding_ShouldRegisterCall() { @@ -696,6 +799,39 @@ public void Method_ReadAllText_String_ShouldRegisterCall() path); } +#if FEATURE_FILESYSTEM_ASYNC + [SkippableFact] + public async Task Method_ReadAllTextAsync_String_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.ReadAllTextAsync(path, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllTextAsync), + path, cancellationToken); + } +#endif + +#if FEATURE_FILESYSTEM_ASYNC + [SkippableFact] + public async Task Method_ReadAllTextAsync_String_Encoding_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + Encoding encoding = Encoding.UTF8; + CancellationToken cancellationToken = CancellationToken.None; + + await sut.File.ReadAllTextAsync(path, encoding, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllTextAsync), + path, encoding, cancellationToken); + } +#endif + [SkippableFact] public void Method_ReadLines_String_Encoding_ShouldRegisterCall() { @@ -723,6 +859,39 @@ public void Method_ReadLines_String_ShouldRegisterCall() path); } +#if FEATURE_FILESYSTEM_NET7 + [SkippableFact] + public void Method_ReadLinesAsync_String_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + CancellationToken cancellationToken = CancellationToken.None; + + sut.File.ReadLinesAsync(path, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadLinesAsync), + path, cancellationToken); + } +#endif + +#if FEATURE_FILESYSTEM_NET7 + [SkippableFact] + public void Method_ReadLinesAsync_String_Encoding_CancellationToken_ShouldRegisterCall() + { + MockFileSystem sut = new(); + sut.Initialize().WithFile("foo"); + string path = "foo"; + Encoding encoding = Encoding.UTF8; + CancellationToken cancellationToken = CancellationToken.None; + + sut.File.ReadLinesAsync(path, encoding, cancellationToken); + + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadLinesAsync), + path, encoding, cancellationToken); + } +#endif + [SkippableFact] public void Method_Replace_String_String_String_Bool_ShouldRegisterCall() { @@ -1121,224 +1290,67 @@ public void Method_WriteAllLines_String_StringArray_ShouldRegisterCall() path, contents); } - [SkippableFact] - public void Method_WriteAllText_String_String_Encoding_ShouldRegisterCall() - { - MockFileSystem sut = new(); - string path = "foo"; - string contents = "foo"; - Encoding encoding = Encoding.UTF8; - - sut.File.WriteAllText(path, contents, encoding); - - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllText), - path, contents, encoding); - } - - [SkippableFact] - public void Method_WriteAllText_String_String_ShouldRegisterCall() - { - MockFileSystem sut = new(); - string path = "foo"; - string contents = "foo"; - - sut.File.WriteAllText(path, contents); - - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllText), - path, contents); - } - #if FEATURE_FILESYSTEM_ASYNC [SkippableFact] public async Task - Method_AppendAllLinesAsync_String_IEnumerableString_CancellationToken_ShouldRegisterCall() + Method_WriteAllLinesAsync_String_IEnumerableString_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; IEnumerable contents = ["foo", "bar"]; CancellationToken cancellationToken = CancellationToken.None; - await sut.File.AppendAllLinesAsync(path, contents, cancellationToken); + await sut.File.WriteAllLinesAsync(path, contents, cancellationToken); - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllLinesAsync), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllLinesAsync), path, contents, cancellationToken); } - - [SkippableFact] - public async Task - Method_AppendAllLinesAsync_String_IEnumerableString_Encoding_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - string path = "foo"; - IEnumerable contents = ["foo", "bar"]; - Encoding encoding = Encoding.UTF8; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.AppendAllLinesAsync(path, contents, encoding, cancellationToken); - - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllLinesAsync), - path, contents, encoding, cancellationToken); - } #endif #if FEATURE_FILESYSTEM_ASYNC - [SkippableFact] - public async Task Method_AppendAllTextAsync_String_String_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - string path = "foo"; - string contents = "foo"; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.AppendAllTextAsync(path, contents, cancellationToken); - - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllTextAsync), - path, contents, cancellationToken); - } - [SkippableFact] public async Task - Method_AppendAllTextAsync_String_String_Encoding_CancellationToken_ShouldRegisterCall() + Method_WriteAllLinesAsync_String_IEnumerableString_Encoding_CancellationToken_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; - string contents = "foo"; + IEnumerable contents = ["foo", "bar"]; Encoding encoding = Encoding.UTF8; CancellationToken cancellationToken = CancellationToken.None; - await sut.File.AppendAllTextAsync(path, contents, encoding, cancellationToken); + await sut.File.WriteAllLinesAsync(path, contents, encoding, cancellationToken); - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.AppendAllTextAsync), + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllLinesAsync), path, contents, encoding, cancellationToken); } #endif -#if FEATURE_FILESYSTEM_ASYNC [SkippableFact] - public async Task Method_ReadAllLinesAsync_String_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.ReadAllLinesAsync(path, cancellationToken); - - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllLinesAsync), - path, cancellationToken); - } - - [SkippableFact] - public async Task - Method_ReadAllLinesAsync_String_Encoding_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - Encoding encoding = Encoding.UTF8; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.ReadAllLinesAsync(path, encoding, cancellationToken); - - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllLinesAsync), - path, encoding, cancellationToken); - } -#endif - -#if FEATURE_FILESYSTEM_ASYNC - [SkippableFact] - public async Task Method_ReadAllTextAsync_String_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.ReadAllTextAsync(path, cancellationToken); - - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllTextAsync), - path, cancellationToken); - } - - [SkippableFact] - public async Task Method_ReadAllTextAsync_String_Encoding_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - Encoding encoding = Encoding.UTF8; - CancellationToken cancellationToken = CancellationToken.None; - - await sut.File.ReadAllTextAsync(path, encoding, cancellationToken); - - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadAllTextAsync), - path, encoding, cancellationToken); - } -#endif - -#if FEATURE_FILESYSTEM_NET7 - [SkippableFact] - public void Method_ReadLinesAsync_String_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); - string path = "foo"; - CancellationToken cancellationToken = CancellationToken.None; - - sut.File.ReadLinesAsync(path, cancellationToken); - - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadLinesAsync), - path, cancellationToken); - } - - [SkippableFact] - public void Method_ReadLinesAsync_String_Encoding_CancellationToken_ShouldRegisterCall() + public void Method_WriteAllText_String_String_Encoding_ShouldRegisterCall() { MockFileSystem sut = new(); - sut.Initialize().WithFile("foo"); string path = "foo"; + string contents = "foo"; Encoding encoding = Encoding.UTF8; - CancellationToken cancellationToken = CancellationToken.None; - - sut.File.ReadLinesAsync(path, encoding, cancellationToken); - - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.ReadLinesAsync), - path, encoding, cancellationToken); - } -#endif - -#if FEATURE_FILESYSTEM_ASYNC - [SkippableFact] - public async Task - Method_WriteAllLinesAsync_String_IEnumerableString_CancellationToken_ShouldRegisterCall() - { - MockFileSystem sut = new(); - string path = "foo"; - IEnumerable contents = ["foo", "bar"]; - CancellationToken cancellationToken = CancellationToken.None; - await sut.File.WriteAllLinesAsync(path, contents, cancellationToken); + sut.File.WriteAllText(path, contents, encoding); - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllLinesAsync), - path, contents, cancellationToken); + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllText), + path, contents, encoding); } [SkippableFact] - public async Task - Method_WriteAllLinesAsync_String_IEnumerableString_Encoding_CancellationToken_ShouldRegisterCall() + public void Method_WriteAllText_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); string path = "foo"; - IEnumerable contents = ["foo", "bar"]; - Encoding encoding = Encoding.UTF8; - CancellationToken cancellationToken = CancellationToken.None; + string contents = "foo"; - await sut.File.WriteAllLinesAsync(path, contents, encoding, cancellationToken); + sut.File.WriteAllText(path, contents); - sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllLinesAsync), - path, contents, encoding, cancellationToken); + sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllText), + path, contents); } -#endif #if FEATURE_FILESYSTEM_ASYNC [SkippableFact] @@ -1354,7 +1366,9 @@ public async Task Method_WriteAllTextAsync_String_String_CancellationToken_Shoul sut.Statistics.File.ShouldOnlyContainMethodCall(nameof(IFile.WriteAllTextAsync), path, contents, cancellationToken); } +#endif +#if FEATURE_FILESYSTEM_ASYNC [SkippableFact] public async Task Method_WriteAllTextAsync_String_String_Encoding_CancellationToken_ShouldRegisterCall() diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs index 9247086b8..eee17f5e8 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileStreamStatisticsTests.cs @@ -21,9 +21,9 @@ public void Method_BeginRead_ByteArray_Int_Int_AsyncCallback_Object_ShouldRegist fileStream.BeginRead(buffer, offset, count, callback, state); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( - nameof(FileSystemStream.BeginRead), - buffer, offset, count, callback, state); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.BeginRead), + buffer, offset, count, callback, state); } [SkippableFact] @@ -39,9 +39,9 @@ public void Method_BeginWrite_ByteArray_Int_Int_AsyncCallback_Object_ShouldRegis fileStream.BeginWrite(buffer, offset, count, callback, state); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( - nameof(FileSystemStream.BeginWrite), - buffer, offset, count, callback, state); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.BeginWrite), + buffer, offset, count, callback, state); } [SkippableFact] @@ -54,9 +54,9 @@ public void Method_CopyTo_Stream_Int_ShouldRegisterCall() fileStream.CopyTo(destination, bufferSize); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( - nameof(FileSystemStream.CopyTo), - destination, bufferSize); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.CopyTo), + destination, bufferSize); } [SkippableFact] @@ -70,9 +70,9 @@ public async Task Method_CopyToAsync_Stream_Int_CancellationToken_ShouldRegister await fileStream.CopyToAsync(destination, bufferSize, cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( - nameof(FileSystemStream.CopyToAsync), - destination, bufferSize, cancellationToken); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.CopyToAsync), + destination, bufferSize, cancellationToken); } [SkippableFact] @@ -118,8 +118,9 @@ public void Method_Flush_Bool_ShouldRegisterCall() fileStream.Flush(flushToDisk); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Flush), - flushToDisk); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.Flush), + flushToDisk); } [SkippableFact] @@ -143,9 +144,9 @@ public async Task Method_FlushAsync_CancellationToken_ShouldRegisterCall() await fileStream.FlushAsync(cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( - nameof(FileSystemStream.FlushAsync), - cancellationToken); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.FlushAsync), + cancellationToken); } [SkippableFact] @@ -159,8 +160,9 @@ public void Method_Read_ByteArray_Int_Int_ShouldRegisterCall() _ = fileStream.Read(buffer, offset, count); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Read), - buffer, offset, count); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.Read), + buffer, offset, count); } #if FEATURE_SPAN @@ -173,8 +175,9 @@ public void Method_Read_SpanByte_ShouldRegisterCall() _ = fileStream.Read(buffer); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Read), - buffer); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.Read), + buffer); } #endif @@ -190,9 +193,9 @@ public async Task Method_ReadAsync_ByteArray_Int_Int_CancellationToken_ShouldReg _ = await fileStream.ReadAsync(buffer, offset, count, cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( - nameof(FileSystemStream.ReadAsync), - buffer, offset, count, cancellationToken); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.ReadAsync), + buffer, offset, count, cancellationToken); } #if FEATURE_SPAN @@ -206,9 +209,9 @@ public async Task Method_ReadAsync_MemoryByte_CancellationToken_ShouldRegisterCa _ = await fileStream.ReadAsync(buffer, cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( - nameof(FileSystemStream.ReadAsync), - buffer, cancellationToken); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.ReadAsync), + buffer, cancellationToken); } #endif @@ -234,8 +237,9 @@ public void Method_Seek_Int64_SeekOrigin_ShouldRegisterCall() fileStream.Seek(offset, origin); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Seek), - offset, origin); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.Seek), + offset, origin); } [SkippableFact] @@ -247,9 +251,9 @@ public void Method_SetLength_Int64_ShouldRegisterCall() fileStream.SetLength(value); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( - nameof(FileSystemStream.SetLength), - value); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.SetLength), + value); } [SkippableFact] @@ -275,8 +279,9 @@ public void Method_Write_ByteArray_Int_Int_ShouldRegisterCall() fileStream.Write(buffer, offset, count); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Write), - buffer, offset, count); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.Write), + buffer, offset, count); } #if FEATURE_SPAN @@ -289,8 +294,9 @@ public void Method_Write_ReadOnlySpanByte_ShouldRegisterCall() fileStream.Write(buffer); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall(nameof(FileSystemStream.Write), - buffer); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.Write), + buffer); } #endif @@ -306,9 +312,9 @@ public async Task Method_WriteAsync_ByteArray_Int_Int_CancellationToken_ShouldRe await fileStream.WriteAsync(buffer, offset, count, cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( - nameof(FileSystemStream.WriteAsync), - buffer, offset, count, cancellationToken); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.WriteAsync), + buffer, offset, count, cancellationToken); } #if FEATURE_SPAN @@ -322,9 +328,9 @@ public async Task Method_WriteAsync_ReadOnlyMemoryByte_CancellationToken_ShouldR await fileStream.WriteAsync(buffer, cancellationToken); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( - nameof(FileSystemStream.WriteAsync), - buffer, cancellationToken); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.WriteAsync), + buffer, cancellationToken); } #endif @@ -337,9 +343,9 @@ public void Method_WriteByte_Byte_ShouldRegisterCall() fileStream.WriteByte(value); - sut.Statistics.FileStream["foo"].ShouldOnlyContainMethodCall( - nameof(FileSystemStream.WriteByte), - value); + sut.Statistics.FileStream["foo"] + .ShouldOnlyContainMethodCall(nameof(FileSystemStream.WriteByte), + value); } [SkippableFact] diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/PathStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/PathStatisticsTests.cs index 48deea5ae..06c9e6124 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/PathStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/PathStatisticsTests.cs @@ -72,6 +72,34 @@ public void Method_Combine_StringArray_ShouldRegisterCall() paths); } +#if FEATURE_PATH_ADVANCED + [SkippableFact] + public void Method_EndsInDirectorySeparator_ReadOnlySpanChar_ShouldRegisterCall() + { + MockFileSystem sut = new(); + ReadOnlySpan path = new(); + + sut.Path.EndsInDirectorySeparator(path); + + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.EndsInDirectorySeparator), + path); + } +#endif + +#if FEATURE_PATH_ADVANCED + [SkippableFact] + public void Method_EndsInDirectorySeparator_String_ShouldRegisterCall() + { + MockFileSystem sut = new(); + string path = "foo"; + + sut.Path.EndsInDirectorySeparator(path); + + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.EndsInDirectorySeparator), + path); + } +#endif + #if FEATURE_FILESYSTEM_NET7 [SkippableFact] public void Method_Exists_String_ShouldRegisterCall() @@ -388,87 +416,41 @@ public void Method_IsPathRooted_String_ShouldRegisterCall() path); } +#if FEATURE_PATH_JOIN [SkippableFact] - public void Property_AltDirectorySeparatorChar_Get_ShouldRegisterPropertyAccess() - { - MockFileSystem sut = new(); - - _ = sut.Path.AltDirectorySeparatorChar; - - sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess( - nameof(IPath.AltDirectorySeparatorChar)); - } - - [SkippableFact] - public void Property_DirectorySeparatorChar_Get_ShouldRegisterPropertyAccess() - { - MockFileSystem sut = new(); - - _ = sut.Path.DirectorySeparatorChar; - - sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess( - nameof(IPath.DirectorySeparatorChar)); - } - - [SkippableFact] - public void Property_PathSeparator_Get_ShouldRegisterPropertyAccess() - { - MockFileSystem sut = new(); - - _ = sut.Path.PathSeparator; - - sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess(nameof(IPath.PathSeparator)); - } - - [SkippableFact] - public void Property_VolumeSeparatorChar_Get_ShouldRegisterPropertyAccess() - { - MockFileSystem sut = new(); - - _ = sut.Path.VolumeSeparatorChar; - - sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess(nameof(IPath.VolumeSeparatorChar)); - } - -#if FEATURE_PATH_ADVANCED - [SkippableFact] - public void Method_EndsInDirectorySeparator_ReadOnlySpanChar_ShouldRegisterCall() - { - MockFileSystem sut = new(); - ReadOnlySpan path = new(); - - sut.Path.EndsInDirectorySeparator(path); - - sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.EndsInDirectorySeparator), - path); - } - - [SkippableFact] - public void Method_EndsInDirectorySeparator_String_ShouldRegisterCall() + public void + Method_Join_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); - string path = "foo"; + ReadOnlySpan path1 = new(); + ReadOnlySpan path2 = new(); + ReadOnlySpan path3 = new(); + ReadOnlySpan path4 = new(); - sut.Path.EndsInDirectorySeparator(path); + sut.Path.Join(path1, path2, path3, path4); - sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.EndsInDirectorySeparator), - path); + sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), + path1, path2, path3, path4); } #endif #if FEATURE_PATH_JOIN [SkippableFact] - public void Method_Join_StringArray_ShouldRegisterCall() + public void Method_Join_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() { MockFileSystem sut = new(); - string[] paths = ["foo", "bar"]; + ReadOnlySpan path1 = new(); + ReadOnlySpan path2 = new(); + ReadOnlySpan path3 = new(); - sut.Path.Join(paths); + sut.Path.Join(path1, path2, path3); sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), - paths); + path1, path2, path3); } +#endif +#if FEATURE_PATH_JOIN [SkippableFact] public void Method_Join_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() { @@ -481,7 +463,9 @@ public void Method_Join_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), path1, path2); } +#endif +#if FEATURE_PATH_JOIN [SkippableFact] public void Method_Join_String_String_ShouldRegisterCall() { @@ -494,21 +478,9 @@ public void Method_Join_String_String_ShouldRegisterCall() sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), path1, path2); } +#endif - [SkippableFact] - public void Method_Join_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() - { - MockFileSystem sut = new(); - ReadOnlySpan path1 = new(); - ReadOnlySpan path2 = new(); - ReadOnlySpan path3 = new(); - - sut.Path.Join(path1, path2, path3); - - sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), - path1, path2, path3); - } - +#if FEATURE_PATH_JOIN [SkippableFact] public void Method_Join_String_String_String_ShouldRegisterCall() { @@ -522,36 +494,36 @@ public void Method_Join_String_String_String_ShouldRegisterCall() sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), path1, path2, path3); } +#endif +#if FEATURE_PATH_JOIN [SkippableFact] - public void - Method_Join_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_ShouldRegisterCall() + public void Method_Join_String_String_String_String_ShouldRegisterCall() { MockFileSystem sut = new(); - ReadOnlySpan path1 = new(); - ReadOnlySpan path2 = new(); - ReadOnlySpan path3 = new(); - ReadOnlySpan path4 = new(); + string path1 = "foo"; + string path2 = "foo"; + string path3 = "foo"; + string path4 = "foo"; sut.Path.Join(path1, path2, path3, path4); sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), path1, path2, path3, path4); } +#endif +#if FEATURE_PATH_JOIN [SkippableFact] - public void Method_Join_String_String_String_String_ShouldRegisterCall() + public void Method_Join_StringArray_ShouldRegisterCall() { MockFileSystem sut = new(); - string path1 = "foo"; - string path2 = "foo"; - string path3 = "foo"; - string path4 = "foo"; + string[] paths = ["foo", "bar"]; - sut.Path.Join(path1, path2, path3, path4); + sut.Path.Join(paths); sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.Join), - path1, path2, path3, path4); + paths); } #endif @@ -567,7 +539,9 @@ public void Method_TrimEndingDirectorySeparator_ReadOnlySpanChar_ShouldRegisterC sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.TrimEndingDirectorySeparator), path); } +#endif +#if FEATURE_PATH_ADVANCED [SkippableFact] public void Method_TrimEndingDirectorySeparator_String_ShouldRegisterCall() { @@ -584,33 +558,77 @@ public void Method_TrimEndingDirectorySeparator_String_ShouldRegisterCall() #if FEATURE_PATH_JOIN [SkippableFact] public void - Method_TryJoin_ReadOnlySpanChar_ReadOnlySpanChar_SpanChar_OutInt_ShouldRegisterCall() + Method_TryJoin_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_SpanChar_OutInt_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path1 = new(); ReadOnlySpan path2 = new(); + ReadOnlySpan path3 = new(); Span destination = new(); - sut.Path.TryJoin(path1, path2, destination, out int charsWritten); + sut.Path.TryJoin(path1, path2, path3, destination, out int charsWritten); sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.TryJoin), - path1, path2, destination, charsWritten); + path1, path2, path3, destination, charsWritten); } +#endif +#if FEATURE_PATH_JOIN [SkippableFact] public void - Method_TryJoin_ReadOnlySpanChar_ReadOnlySpanChar_ReadOnlySpanChar_SpanChar_OutInt_ShouldRegisterCall() + Method_TryJoin_ReadOnlySpanChar_ReadOnlySpanChar_SpanChar_OutInt_ShouldRegisterCall() { MockFileSystem sut = new(); ReadOnlySpan path1 = new(); ReadOnlySpan path2 = new(); - ReadOnlySpan path3 = new(); Span destination = new(); - sut.Path.TryJoin(path1, path2, path3, destination, out int charsWritten); + sut.Path.TryJoin(path1, path2, destination, out int charsWritten); sut.Statistics.Path.ShouldOnlyContainMethodCall(nameof(IPath.TryJoin), - path1, path2, path3, destination, charsWritten); + path1, path2, destination, charsWritten); } #endif + + [SkippableFact] + public void Property_AltDirectorySeparatorChar_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.Path.AltDirectorySeparatorChar; + + sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess( + nameof(IPath.AltDirectorySeparatorChar)); + } + + [SkippableFact] + public void Property_DirectorySeparatorChar_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.Path.DirectorySeparatorChar; + + sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess( + nameof(IPath.DirectorySeparatorChar)); + } + + [SkippableFact] + public void Property_PathSeparator_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.Path.PathSeparator; + + sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess(nameof(IPath.PathSeparator)); + } + + [SkippableFact] + public void Property_VolumeSeparatorChar_Get_ShouldRegisterPropertyAccess() + { + MockFileSystem sut = new(); + + _ = sut.Path.VolumeSeparatorChar; + + sut.Statistics.Path.ShouldOnlyContainPropertyGetAccess(nameof(IPath.VolumeSeparatorChar)); + } } From e12942a2ece8c629279ea70eda52575dafc9e040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Fri, 15 Mar 2024 17:31:21 +0100 Subject: [PATCH 8/8] Fix test errors --- .../Statistics/FileSystemEntryStatistics.cs | 3 +-- .../ApiAcceptance.cs | 4 +++- .../Testably.Abstractions.Api.Tests/Helper.cs | 2 +- .../FileSystem/DriveInfoStatisticsTests.cs | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs b/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs index ddb32632c..63606ccf8 100644 --- a/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs +++ b/Source/Testably.Abstractions.Testing/Statistics/FileSystemEntryStatistics.cs @@ -61,8 +61,7 @@ private string CreateKey(string currentDirectory, string path) if (Path.IsPathRooted(path)) { - return path - .TrimEnd([Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar]); + return path.TrimEnd([Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar]); } return Path.GetFullPath(Path.Combine(currentDirectory, path)) diff --git a/Tests/Api/Testably.Abstractions.Api.Tests/ApiAcceptance.cs b/Tests/Api/Testably.Abstractions.Api.Tests/ApiAcceptance.cs index 57ae4f19e..6ea8b6805 100644 --- a/Tests/Api/Testably.Abstractions.Api.Tests/ApiAcceptance.cs +++ b/Tests/Api/Testably.Abstractions.Api.Tests/ApiAcceptance.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using System; namespace Testably.Abstractions.Api.Tests; @@ -23,7 +24,8 @@ public void AcceptApiChanges() { foreach (string framework in Helper.GetTargetFrameworks()) { - string publicApi = Helper.CreatePublicApi(framework, assemblyName); + string publicApi = Helper.CreatePublicApi(framework, assemblyName) + .Replace("\n", Environment.NewLine); Helper.SetExpectedApi(framework, assemblyName, publicApi); } } diff --git a/Tests/Api/Testably.Abstractions.Api.Tests/Helper.cs b/Tests/Api/Testably.Abstractions.Api.Tests/Helper.cs index 138773669..ddcb92cba 100644 --- a/Tests/Api/Testably.Abstractions.Api.Tests/Helper.cs +++ b/Tests/Api/Testably.Abstractions.Api.Tests/Helper.cs @@ -16,7 +16,7 @@ public static string CreatePublicApi(string framework, string assemblyName) string assemblyFile = CombinedPaths("Build", "Binaries", framework, $"{assemblyName}.dll"); Assembly assembly = Assembly.LoadFile(assemblyFile); string publicApi = assembly.GeneratePublicApi(options: null); - return publicApi; + return publicApi.Replace("\r\n", "\n"); } public static string GetExpectedApi(string framework, string assemblyName) diff --git a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs index 1f27d9fe0..d2d14f21f 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DriveInfoStatisticsTests.cs @@ -7,6 +7,8 @@ public sealed class DriveInfoStatisticsTests [SkippableFact] public void Property_AvailableFreeSpace_Get_ShouldRegisterPropertyAccess() { + Skip.IfNot(Test.RunsOnWindows); + MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").AvailableFreeSpace; @@ -18,6 +20,8 @@ public void Property_AvailableFreeSpace_Get_ShouldRegisterPropertyAccess() [SkippableFact] public void Property_DriveFormat_Get_ShouldRegisterPropertyAccess() { + Skip.IfNot(Test.RunsOnWindows); + MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").DriveFormat; @@ -29,6 +33,8 @@ public void Property_DriveFormat_Get_ShouldRegisterPropertyAccess() [SkippableFact] public void Property_DriveType_Get_ShouldRegisterPropertyAccess() { + Skip.IfNot(Test.RunsOnWindows); + MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").DriveType; @@ -40,6 +46,8 @@ public void Property_DriveType_Get_ShouldRegisterPropertyAccess() [SkippableFact] public void Property_IsReady_Get_ShouldRegisterPropertyAccess() { + Skip.IfNot(Test.RunsOnWindows); + MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").IsReady; @@ -51,6 +59,8 @@ public void Property_IsReady_Get_ShouldRegisterPropertyAccess() [SkippableFact] public void Property_Name_Get_ShouldRegisterPropertyAccess() { + Skip.IfNot(Test.RunsOnWindows); + MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").Name; @@ -61,6 +71,8 @@ public void Property_Name_Get_ShouldRegisterPropertyAccess() [SkippableFact] public void Property_RootDirectory_Get_ShouldRegisterPropertyAccess() { + Skip.IfNot(Test.RunsOnWindows); + MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").RootDirectory; @@ -72,6 +84,8 @@ public void Property_RootDirectory_Get_ShouldRegisterPropertyAccess() [SkippableFact] public void Property_TotalFreeSpace_Get_ShouldRegisterPropertyAccess() { + Skip.IfNot(Test.RunsOnWindows); + MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").TotalFreeSpace; @@ -83,6 +97,8 @@ public void Property_TotalFreeSpace_Get_ShouldRegisterPropertyAccess() [SkippableFact] public void Property_TotalSize_Get_ShouldRegisterPropertyAccess() { + Skip.IfNot(Test.RunsOnWindows); + MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").TotalSize; @@ -94,6 +110,8 @@ public void Property_TotalSize_Get_ShouldRegisterPropertyAccess() [SkippableFact] public void Property_VolumeLabel_Get_ShouldRegisterPropertyAccess() { + Skip.IfNot(Test.RunsOnWindows); + MockFileSystem sut = new(); _ = sut.DriveInfo.New("F:").VolumeLabel;