diff --git a/Tests/aweXpect.Testably.Tests/Statistics.Recorded.Directory.Tests.cs b/Tests/aweXpect.Testably.Tests/Statistics.Recorded.Directory.Tests.cs index 8c97983..1b78c91 100644 --- a/Tests/aweXpect.Testably.Tests/Statistics.Recorded.Directory.Tests.cs +++ b/Tests/aweXpect.Testably.Tests/Statistics.Recorded.Directory.Tests.cs @@ -107,6 +107,44 @@ but it was recorded 0 times public sealed class DeleteTests { + [Fact] + public async Task Delete_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.Delete(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.Delete with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task Delete_WithRecursiveFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.Delete(recursive: b => b).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.Delete with recursive matching b => b exactly once, + but it was recorded 0 times + """); + } + [Fact] public async Task WithAtLeastOnce_ShouldSucceedAfterTwoCalls() { @@ -242,6 +280,44 @@ but it was recorded 0 times public sealed class EnumerateFilesTests { + [Fact] + public async Task EnumerateFiles_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.EnumerateFiles(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.EnumerateFiles with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task EnumerateFiles_WithSearchPatternFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.EnumerateFiles(searchPattern: p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.EnumerateFiles with searchPattern matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + [Fact] public async Task EnumerateFiles_ShouldRecord() { @@ -509,6 +585,25 @@ await That(fileSystem.Statistics).Recorded() public sealed class GetCreationTimeTests { + [Fact] + public async Task GetCreationTime_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.GetCreationTime(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.GetCreationTime with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + [Fact] public async Task WhenCalled_ShouldRecord() { @@ -528,6 +623,25 @@ await That(fileSystem.Statistics).Recorded() public sealed class GetCreationTimeUtcTests { + [Fact] + public async Task GetCreationTimeUtc_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.GetCreationTimeUtc(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.GetCreationTimeUtc with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + [Fact] public async Task WhenCalled_ShouldRecord() { @@ -644,6 +758,25 @@ await That(fileSystem.Statistics).Recorded() public sealed class GetDirectoryRootTests { + [Fact] + public async Task GetDirectoryRoot_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.GetDirectoryRoot(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.GetDirectoryRoot with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + [Fact] public async Task GetDirectoryRoot_NoMatch_ShouldFailWithMessage() { @@ -681,6 +814,44 @@ await That(fileSystem.Statistics).Recorded() public sealed class GetFileSystemEntriesTests { + [Fact] + public async Task GetFileSystemEntries_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.GetFileSystemEntries(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.GetFileSystemEntries with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task GetFileSystemEntries_WithSearchPatternFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.GetFileSystemEntries(searchPattern: p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.GetFileSystemEntries with searchPattern matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + [Fact] public async Task WhenCalled_ShouldRecord() { @@ -700,6 +871,25 @@ await That(fileSystem.Statistics).Recorded() public sealed class GetLastAccessTimeTests { + [Fact] + public async Task GetLastAccessTime_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.GetLastAccessTime(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.GetLastAccessTime with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + [Fact] public async Task WhenCalled_ShouldRecord() { @@ -719,6 +909,25 @@ await That(fileSystem.Statistics).Recorded() public sealed class GetLastAccessTimeUtcTests { + [Fact] + public async Task GetLastAccessTimeUtc_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.GetLastAccessTimeUtc(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.GetLastAccessTimeUtc with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + [Fact] public async Task WhenCalled_ShouldRecord() { @@ -736,6 +945,381 @@ await That(fileSystem.Statistics).Recorded() } } + public sealed class GetLastWriteTimeTests + { + [Fact] + public async Task GetLastWriteTime_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.GetLastWriteTime(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.GetLastWriteTime with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class GetLastWriteTimeUtcTests + { + [Fact] + public async Task GetLastWriteTimeUtc_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.GetLastWriteTimeUtc(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.GetLastWriteTimeUtc with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class GetParentTests + { + [Fact] + public async Task GetParent_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.GetParent(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.GetParent with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class MoveTests + { + [Fact] + public async Task Move_WithDestDirNameFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.Move(destDirName: p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.Move with destDirName matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task Move_WithSourceDirNameFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.Move(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.Move with sourceDirName matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetCreationTimeTests + { + [Fact] + public async Task SetCreationTime_WithCreationTimeFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetCreationTime(creationTime: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetCreationTime with creationTime matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetCreationTime_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetCreationTime(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetCreationTime with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetCreationTimeUtcTests + { + [Fact] + public async Task SetCreationTimeUtc_WithCreationTimeUtcFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetCreationTimeUtc(creationTimeUtc: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetCreationTimeUtc with creationTimeUtc matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetCreationTimeUtc_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetCreationTimeUtc(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetCreationTimeUtc with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetCurrentDirectoryTests + { + [Fact] + public async Task SetCurrentDirectory_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetCurrentDirectory(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetCurrentDirectory with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetLastAccessTimeTests + { + [Fact] + public async Task SetLastAccessTime_WithLastAccessTimeFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetLastAccessTime(lastAccessTime: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetLastAccessTime with lastAccessTime matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetLastAccessTime_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetLastAccessTime(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetLastAccessTime with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetLastAccessTimeUtcTests + { + [Fact] + public async Task SetLastAccessTimeUtc_WithLastAccessTimeUtcFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetLastAccessTimeUtc(lastAccessTimeUtc: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetLastAccessTimeUtc with lastAccessTimeUtc matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetLastAccessTimeUtc_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetLastAccessTimeUtc(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetLastAccessTimeUtc with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetLastWriteTimeTests + { + [Fact] + public async Task SetLastWriteTime_WithLastWriteTimeFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetLastWriteTime(lastWriteTime: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetLastWriteTime with lastWriteTime matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetLastWriteTime_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetLastWriteTime(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetLastWriteTime with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetLastWriteTimeUtcTests + { + [Fact] + public async Task SetLastWriteTimeUtc_WithLastWriteTimeUtcFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetLastWriteTimeUtc(lastWriteTimeUtc: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetLastWriteTimeUtc with lastWriteTimeUtc matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetLastWriteTimeUtc_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .Directory.SetLastWriteTimeUtc(p => p == "foo").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to Directory.SetLastWriteTimeUtc with path matching p => p == "foo" exactly once, + but it was recorded 0 times + """); + } + } + #if NET8_0_OR_GREATER public sealed class ResolveLinkTargetTests { diff --git a/Tests/aweXpect.Testably.Tests/Statistics.Recorded.File.Tests.cs b/Tests/aweXpect.Testably.Tests/Statistics.Recorded.File.Tests.cs index 57881d3..b576fd0 100644 --- a/Tests/aweXpect.Testably.Tests/Statistics.Recorded.File.Tests.cs +++ b/Tests/aweXpect.Testably.Tests/Statistics.Recorded.File.Tests.cs @@ -1345,6 +1345,744 @@ await That(fileSystem.Statistics).Recorded() } } + public sealed class OpenTests + { + [Fact] + public async Task Open_WithAccessFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.Open(access: a => a == FileAccess.Read).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.Open with access matching a => a == FileAccess.Read exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task Open_WithModeFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.Open(mode: m => m == FileMode.Open).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.Open with mode matching m => m == FileMode.Open exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task Open_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.Open(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.Open with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task Open_WithShareFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.Open(share: s => s == FileShare.None).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.Open with share matching s => s == FileShare.None exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class OpenReadTests + { + [Fact] + public async Task OpenRead_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.OpenRead(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.OpenRead with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class OpenTextTests + { + [Fact] + public async Task OpenText_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.OpenText(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.OpenText with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class OpenWriteTests + { + [Fact] + public async Task OpenWrite_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.OpenWrite(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.OpenWrite with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class ReadAllBytesTests + { + [Fact] + public async Task ReadAllBytes_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.ReadAllBytes(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.ReadAllBytes with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class ReadAllLinesTests + { + [Fact] + public async Task ReadAllLines_WithEncodingFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.ReadAllLines(encoding: e => e == Encoding.UTF8).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.ReadAllLines with encoding matching e => e == Encoding.UTF8 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task ReadAllLines_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.ReadAllLines(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.ReadAllLines with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class ReadAllTextTests + { + [Fact] + public async Task ReadAllText_WithEncodingFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.ReadAllText(encoding: e => e == Encoding.UTF8).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.ReadAllText with encoding matching e => e == Encoding.UTF8 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task ReadAllText_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.ReadAllText(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.ReadAllText with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class ReadLinesTests + { + [Fact] + public async Task ReadLines_WithEncodingFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.ReadLines(encoding: e => e == Encoding.UTF8).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.ReadLines with encoding matching e => e == Encoding.UTF8 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task ReadLines_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.ReadLines(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.ReadLines with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class ReplaceTests + { + [Fact] + public async Task Replace_WithDestinationBackupFileNameFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.Replace(destinationBackupFileName: p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.Replace with destinationBackupFileName matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task Replace_WithDestinationFileNameFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.Replace(destinationFileName: p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.Replace with destinationFileName matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task Replace_WithIgnoreMetadataErrorsFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.Replace(ignoreMetadataErrors: b => b).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.Replace with ignoreMetadataErrors matching b => b exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task Replace_WithSourceFileNameFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.Replace(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.Replace with sourceFileName matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetAttributesTests + { + [Fact] + public async Task SetAttributes_WithFileAttributesFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetAttributes(fileAttributes: a => a == FileAttributes.ReadOnly).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetAttributes with fileAttributes matching a => a == FileAttributes.ReadOnly exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetAttributes_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetAttributes(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetAttributes with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetCreationTimeTests + { + [Fact] + public async Task SetCreationTime_WithCreationTimeFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetCreationTime(creationTime: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetCreationTime with creationTime matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetCreationTime_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetCreationTime(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetCreationTime with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetCreationTimeUtcTests + { + [Fact] + public async Task SetCreationTimeUtc_WithCreationTimeUtcFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetCreationTimeUtc(creationTimeUtc: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetCreationTimeUtc with creationTimeUtc matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetCreationTimeUtc_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetCreationTimeUtc(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetCreationTimeUtc with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetLastAccessTimeTests + { + [Fact] + public async Task SetLastAccessTime_WithLastAccessTimeFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetLastAccessTime(lastAccessTime: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetLastAccessTime with lastAccessTime matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetLastAccessTime_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetLastAccessTime(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetLastAccessTime with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetLastAccessTimeUtcTests + { + [Fact] + public async Task SetLastAccessTimeUtc_WithLastAccessTimeUtcFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetLastAccessTimeUtc(lastAccessTimeUtc: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetLastAccessTimeUtc with lastAccessTimeUtc matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetLastAccessTimeUtc_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetLastAccessTimeUtc(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetLastAccessTimeUtc with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetLastWriteTimeTests + { + [Fact] + public async Task SetLastWriteTime_WithLastWriteTimeFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetLastWriteTime(lastWriteTime: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetLastWriteTime with lastWriteTime matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetLastWriteTime_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetLastWriteTime(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetLastWriteTime with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class SetLastWriteTimeUtcTests + { + [Fact] + public async Task SetLastWriteTimeUtc_WithLastWriteTimeUtcFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetLastWriteTimeUtc(lastWriteTimeUtc: t => t.Year == 2000).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetLastWriteTimeUtc with lastWriteTimeUtc matching t => t.Year == 2000 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task SetLastWriteTimeUtc_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.SetLastWriteTimeUtc(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.SetLastWriteTimeUtc with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class WriteAllBytesTests + { + [Fact] + public async Task WriteAllBytes_WithBytesFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.WriteAllBytes(bytes: _ => true).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.WriteAllBytes with bytes matching _ => true exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task WriteAllBytes_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.WriteAllBytes(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.WriteAllBytes with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + + public sealed class WriteAllLinesTests + { + [Fact] + public async Task WriteAllLines_WithEncodingFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.WriteAllLines(encoding: e => e == Encoding.UTF8).Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.WriteAllLines with encoding matching e => e == Encoding.UTF8 exactly once, + but it was recorded 0 times + """); + } + + [Fact] + public async Task WriteAllLines_WithPathFilter_NoMatch_ShouldFailWithMessage() + { + MockFileSystem fileSystem = new(); + + async Task Act() + { + await That(fileSystem.Statistics).Recorded() + .File.WriteAllLines(p => p == "foo.txt").Once(); + } + + await That(Act).ThrowsException() + .WithMessage(""" + Expected that fileSystem.Statistics + recorded a call to File.WriteAllLines with path matching p => p == "foo.txt" exactly once, + but it was recorded 0 times + """); + } + } + #if NET8_0_OR_GREATER public sealed class AppendAllLinesAsyncTests {