diff --git a/Directory.Packages.props b/Directory.Packages.props index cd9f1e9f1..1bfd4ec7d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -36,6 +36,7 @@ + diff --git a/Tests/Testably.Abstractions.Testing.Tests/FileSystem/ChangeHandlerTests.cs b/Tests/Testably.Abstractions.Testing.Tests/FileSystem/ChangeHandlerTests.cs index 8dc7c9525..8b42c3736 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/FileSystem/ChangeHandlerTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/FileSystem/ChangeHandlerTests.cs @@ -22,7 +22,7 @@ public void CreateDirectory_CustomException_ShouldNotCreateDirectory( { FileSystem.Intercept.Event(_ => { - FileSystem.Directory.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(path); throw exceptionToThrow; }); Exception? exception = Record.Exception(() => @@ -30,7 +30,7 @@ public void CreateDirectory_CustomException_ShouldNotCreateDirectory( FileSystem.Directory.CreateDirectory(path); }); - FileSystem.Directory.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(path); exception.Should().Be(exceptionToThrow); } diff --git a/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileSystemExtensibilityTests.cs b/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileSystemExtensibilityTests.cs index d7a7672ee..2aec14b04 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileSystemExtensibilityTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileSystemExtensibilityTests.cs @@ -13,7 +13,7 @@ public void Directory_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -24,7 +24,7 @@ public void DirectoryInfo_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -35,7 +35,7 @@ public void DirectoryInfoFactory_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -46,7 +46,7 @@ public void DriveInfo_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -57,7 +57,7 @@ public void DriveInfoFactory_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -68,7 +68,7 @@ public void File_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -79,7 +79,7 @@ public void FileInfo_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -90,7 +90,7 @@ public void FileInfoFactory_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -101,7 +101,7 @@ public void FileStreamFactory_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -112,7 +112,7 @@ public void FileSystemInfo_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -123,7 +123,7 @@ public void FileSystemWatcher_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -134,7 +134,7 @@ public void FileSystemWatcherFactory_ShouldSetExtensionPoint(IFileSystem fileSys IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } [SkippableTheory] @@ -145,7 +145,7 @@ public void Path_ShouldSetExtensionPoint(IFileSystem fileSystem) IFileSystem result = sut.FileSystem; - result.Should().Be(fileSystem); + result.Should().BeSameAs(fileSystem); } public static IEnumerable GetFileSystems => diff --git a/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileSystemWatcherMockTests.cs b/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileSystemWatcherMockTests.cs index 7b52d7b79..73e1356d7 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileSystemWatcherMockTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileSystemWatcherMockTests.cs @@ -165,8 +165,10 @@ public void InternalBufferSize_ShouldResetQueue(string path1, string path2) { break; } + FileSystem.Directory.CreateDirectory($"{i}_{path1}"); } + fileSystemWatcher.InternalBufferSize = 4196; FileSystem.Directory.CreateDirectory(path2); for (int i = 0; i < 4196 / 128; i++) @@ -175,6 +177,7 @@ public void InternalBufferSize_ShouldResetQueue(string path1, string path2) { break; } + FileSystem.Directory.CreateDirectory($"{i}_{path2}"); } diff --git a/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializer/FileSystemInitializerTests.cs b/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializer/FileSystemInitializerTests.cs index cbaf4417b..0506f3ab3 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializer/FileSystemInitializerTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializer/FileSystemInitializerTests.cs @@ -17,7 +17,7 @@ public void With_DirectoryDescriptions_ShouldCreateDirectories( foreach (DirectoryDescription directory in directories) { - fileSystem.Directory.Exists(directory.Name).Should().BeTrue(); + fileSystem.Should().HaveDirectory(directory.Name); } } @@ -31,7 +31,7 @@ public void With_FileDescriptions_ShouldCreateFileContent(string name, string co sut.With(description); - fileSystem.File.Exists(name).Should().BeTrue(); + fileSystem.Should().HaveFile(name); fileSystem.File.ReadAllText(name).Should().Be(content); } @@ -46,7 +46,7 @@ public void With_FileDescriptions_ShouldCreateFiles(FileDescription[] files) foreach (FileDescription file in files) { - fileSystem.File.Exists(file.Name).Should().BeTrue(); + fileSystem.Should().HaveFile(file.Name); } } @@ -64,7 +64,7 @@ public void With_FileDescriptions_ShouldSetIsReadOnlyFlag(bool isReadOnly, strin sut.With(description); - fileSystem.File.Exists(name).Should().BeTrue(); + fileSystem.Should().HaveFile(name); fileSystem.FileInfo.New(name).IsReadOnly.Should().Be(isReadOnly); } @@ -79,8 +79,8 @@ public void With_FilesAndDirectories_ShouldBothBeCreated(string fileName, string sut.With(fileDescription, directoryDescription); - fileSystem.File.Exists(fileName).Should().BeTrue(); - fileSystem.Directory.Exists(directoryName).Should().BeTrue(); + fileSystem.Should().HaveFile(fileName); + fileSystem.Should().HaveDirectory(directoryName); } [Theory] @@ -120,7 +120,7 @@ public void WithFile_HasStringContent_ShouldWriteFileContent(string path) sut.WithFile(path).Which(f => f.HasStringContent("foo")); - fileSystem.File.Exists(path).Should().BeTrue(); + fileSystem.Should().HaveFile(path); fileSystem.File.ReadAllText(path).Should().Be("foo"); } @@ -135,8 +135,8 @@ public void WithFile_MissingDirectory_ShouldCreateDirectory(string directoryPath sut.WithFile(path); - fileSystem.File.Exists(path).Should().BeTrue(); - fileSystem.Directory.Exists(directoryPath).Should().BeTrue(); + fileSystem.Should().HaveFile(path); + fileSystem.Should().HaveDirectory(directoryPath); } [Theory] @@ -151,7 +151,7 @@ public void WithSubdirectories_ShouldCreateAllDirectories(string[] paths) foreach (string path in paths) { - fileSystem.Directory.Exists(path).Should().BeTrue(); + fileSystem.Should().HaveDirectory(path); } result.Should().Be(sut); @@ -196,7 +196,7 @@ public void WithSubdirectory_MultipleDirectoryLevels(string level1, string level IFileSystemDirectoryInitializer result = sut .WithSubdirectory(path); - fileSystem.Directory.Exists(path).Should().BeTrue(); - result.FileSystem.Should().Be(fileSystem); + fileSystem.Should().HaveDirectory(path); + result.FileSystem.Should().BeSameAs(fileSystem); } } diff --git a/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializerExtensionsTests.cs b/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializerExtensionsTests.cs index 159a5d968..b0ee7e94f 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializerExtensionsTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/FileSystemInitializerExtensionsTests.cs @@ -207,7 +207,7 @@ public void result.Length.Should().Be(2); result.Should().Contain(x => x.EndsWith("TestFile1.txt")); result.Should().Contain(x => x.EndsWith("TestFile2.txt")); - fileSystem.Directory.Exists(Path.Combine(path, "SubResource")).Should().BeFalse(); + fileSystem.Should().NotHaveDirectory(Path.Combine(path, "SubResource")); } [Theory] diff --git a/Tests/Testably.Abstractions.Testing.Tests/Storage/InMemoryContainerTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Storage/InMemoryContainerTests.cs index fb7bf1f23..92fb2c8f7 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Storage/InMemoryContainerTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Storage/InMemoryContainerTests.cs @@ -221,8 +221,8 @@ public void Container_ShouldProvideCorrectTimeAndFileSystem(string path) IStorageLocation location = InMemoryLocation.New(null, path); IStorageContainer sut = InMemoryContainer.NewFile(location, fileSystem); - sut.FileSystem.Should().Be(fileSystem); - sut.TimeSystem.Should().Be(fileSystem.TimeSystem); + sut.FileSystem.Should().BeSameAs(fileSystem); + sut.TimeSystem.Should().BeSameAs(fileSystem.TimeSystem); } [Theory] diff --git a/Tests/Testably.Abstractions.Testing.Tests/Storage/NullContainerTests.cs b/Tests/Testably.Abstractions.Testing.Tests/Storage/NullContainerTests.cs index 74b31f7f4..8c88d234b 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Storage/NullContainerTests.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/Storage/NullContainerTests.cs @@ -35,8 +35,8 @@ public void Constructor_ShouldSetFileAndTimeSystem() IStorageContainer sut = NullContainer.New(fileSystem); - sut.FileSystem.Should().Be(fileSystem); - sut.TimeSystem.Should().Be(fileSystem.TimeSystem); + sut.FileSystem.Should().BeSameAs(fileSystem); + sut.TimeSystem.Should().BeSameAs(fileSystem.TimeSystem); } [Fact] diff --git a/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/Usings.cs b/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/Usings.cs index 011d29062..7498584f1 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/Usings.cs +++ b/Tests/Testably.Abstractions.Testing.Tests/TestHelpers/Usings.cs @@ -2,4 +2,5 @@ global using FluentAssertions; global using System; global using System.IO.Abstractions; +global using Testably.Abstractions.FluentAssertions; global using Xunit; diff --git a/Tests/Testably.Abstractions.Testing.Tests/Testably.Abstractions.Testing.Tests.csproj b/Tests/Testably.Abstractions.Testing.Tests/Testably.Abstractions.Testing.Tests.csproj index a978f1e65..2f4a934c6 100644 --- a/Tests/Testably.Abstractions.Testing.Tests/Testably.Abstractions.Testing.Tests.csproj +++ b/Tests/Testably.Abstractions.Testing.Tests/Testably.Abstractions.Testing.Tests.csproj @@ -21,6 +21,10 @@ + + + + True diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/CreateDirectoryTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/CreateDirectoryTests.cs index 05c9051e4..f7f07919f 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/CreateDirectoryTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/CreateDirectoryTests.cs @@ -19,7 +19,7 @@ public void CreateDirectory_AlreadyExisting_ShouldDoNothing(string path) }); exception.Should().BeNull(); - FileSystem.Directory.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveDirectory(path); } [SkippableTheory] @@ -39,14 +39,14 @@ public void CreateDirectory_ReadOnlyParent_ShouldStillCreateDirectory(string par if (Test.RunsOnWindows) { exception.Should().BeNull(); - FileSystem.Directory.Exists(subdirectoryPath).Should().BeTrue(); + FileSystem.Should().HaveDirectory(subdirectoryPath); FileSystem.DirectoryInfo.New(parent).Attributes .Should().HaveFlag(FileAttributes.ReadOnly); } else { exception.Should().BeException(hResult: -2147024891); - FileSystem.Directory.Exists(subdirectoryPath).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(subdirectoryPath); } } @@ -63,7 +63,7 @@ public void CreateDirectory_FileWithSameNameAlreadyExists_ShouldThrowIOException exception.Should().BeException( hResult: Test.RunsOnWindows ? -2147024713 : 17); - FileSystem.Directory.Exists(name).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(name); } [SkippableFact] @@ -78,7 +78,7 @@ public void CreateDirectory_Root_ShouldNotThrowException() }); exception.Should().BeNull(); - FileSystem.Directory.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveDirectory(path); } [SkippableTheory] @@ -218,9 +218,8 @@ public void CreateDirectory_NullCharacter_ShouldThrowArgumentException() public void CreateDirectory_ShouldCreateDirectoryInBasePath() { IDirectoryInfo result = FileSystem.Directory.CreateDirectory("foo"); - bool exists = FileSystem.Directory.Exists("foo"); - exists.Should().BeTrue(); + FileSystem.Should().HaveDirectory("foo"); result.FullName.Should().StartWith(BasePath); } @@ -263,7 +262,7 @@ public void CreateDirectory_TrailingDirectorySeparator_ShouldNotBeTrimmed( result.FullName.Should().Be(System.IO.Path.Combine(BasePath, expectedName .Replace(FileSystem.Path.AltDirectorySeparatorChar, FileSystem.Path.DirectorySeparatorChar))); - FileSystem.Directory.Exists(nameWithSuffix).Should().BeTrue(); + FileSystem.Should().HaveDirectory(nameWithSuffix); } [SkippableTheory] @@ -285,7 +284,7 @@ public void CreateDirectory_EmptyOrWhitespace_ShouldReturnEmptyString( result.FullName.Should().Be(System.IO.Path.Combine(BasePath, expectedName .Replace(FileSystem.Path.AltDirectorySeparatorChar, FileSystem.Path.DirectorySeparatorChar))); - FileSystem.Directory.Exists(nameWithSuffix).Should().BeTrue(); + FileSystem.Should().HaveDirectory(nameWithSuffix); } #else [SkippableTheory] @@ -317,7 +316,7 @@ public void CreateDirectory_TrailingDirectorySeparator_ShouldNotBeTrimmed( result.FullName.Should().Be(System.IO.Path.Combine(BasePath, expectedName .Replace(FileSystem.Path.AltDirectorySeparatorChar, FileSystem.Path.DirectorySeparatorChar))); - FileSystem.Directory.Exists(nameWithSuffix).Should().BeTrue(); + FileSystem.Should().HaveDirectory(nameWithSuffix); } #endif } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/DeleteTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/DeleteTests.cs index f7d227186..8d1cee7ad 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/DeleteTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/DeleteTests.cs @@ -29,8 +29,7 @@ public void else { exception.Should().BeNull(); - FileSystem.Directory.Exists(directoryName.ToUpperInvariant()) - .Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(directoryName.ToUpperInvariant()); } } @@ -43,7 +42,7 @@ public void Delete_FullPath_ShouldDeleteDirectory(string directoryName) FileSystem.Directory.Delete(result.FullName); - FileSystem.Directory.Exists(directoryName).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(directoryName); result.Exists.Should().BeFalse(); } @@ -105,12 +104,12 @@ public void Delete_Recursive_WithOpenFile_ShouldThrowIOException_OnWindows( { exception.Should().BeException($"{filename}'", hResult: -2147024864); - FileSystem.File.Exists(filePath).Should().BeTrue(); + FileSystem.Should().HaveFile(filePath); } else { exception.Should().BeNull(); - FileSystem.File.Exists(filePath).Should().BeFalse(); + FileSystem.Should().NotHaveFile(filePath); } } @@ -129,8 +128,8 @@ public void FileSystem.Directory.Delete(subdirectory, true); - FileSystem.Directory.Exists(subdirectory).Should().BeFalse(); - FileSystem.File.Exists(fileName).Should().BeTrue(); + FileSystem.Should().NotHaveDirectory(subdirectory); + FileSystem.Should().HaveFile(fileName); } [SkippableTheory] @@ -140,12 +139,12 @@ public void Delete_Recursive_WithSubdirectory_ShouldDeleteDirectoryWithContent( { string subdirectoryPath = FileSystem.Path.Combine(path, subdirectory); FileSystem.Directory.CreateDirectory(subdirectoryPath); - FileSystem.Directory.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveDirectory(path); FileSystem.Directory.Delete(path, true); - FileSystem.Directory.Exists(path).Should().BeFalse(); - FileSystem.Directory.Exists(subdirectoryPath).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(path); + FileSystem.Should().NotHaveDirectory(subdirectoryPath); } [SkippableTheory] @@ -195,9 +194,7 @@ public void Delete_ShouldDeleteDirectory(string directoryName) FileSystem.Directory.Delete(directoryName); - bool exists = FileSystem.Directory.Exists(directoryName); - - exists.Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(directoryName); result.Exists.Should().BeFalse(); } @@ -213,8 +210,8 @@ public void Delete_WithSimilarNamedFile_ShouldOnlyDeleteDirectory( FileSystem.Directory.Delete(subdirectory); - FileSystem.Directory.Exists(subdirectory).Should().BeFalse(); - FileSystem.File.Exists(fileName).Should().BeTrue(); + FileSystem.Should().NotHaveDirectory(subdirectory); + FileSystem.Should().HaveFile(fileName); } [SkippableTheory] @@ -223,7 +220,7 @@ public void Delete_WithSubdirectory_ShouldThrowIOException_AndNotDeleteDirectory string path, string subdirectory) { FileSystem.Directory.CreateDirectory(FileSystem.Path.Combine(path, subdirectory)); - FileSystem.Directory.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveDirectory(path); Exception? exception = Record.Exception(() => { @@ -236,5 +233,6 @@ public void Delete_WithSubdirectory_ShouldThrowIOException_AndNotDeleteDirectory messageContains: !Test.RunsOnWindows || Test.IsNetFramework ? null : $"'{System.IO.Path.Combine(BasePath, path)}'"); + FileSystem.Should().HaveDirectory(path); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateDirectoriesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateDirectoriesTests.cs index 32f2819de..179f5b011 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateDirectoriesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateDirectoriesTests.cs @@ -37,7 +37,7 @@ public void exception.Should().BeException( $"'{expectedPath}'", hResult: -2147024893); - FileSystem.Directory.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(path); } [SkippableFact] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateFileSystemInfosTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateFileSystemInfosTests.cs index 5e3c9ee37..10f81c6d6 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateFileSystemInfosTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateFileSystemInfosTests.cs @@ -24,7 +24,7 @@ public void exception.Should().BeException( $"'{expectedPath}'", hResult: -2147024893); - FileSystem.Directory.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateFilesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateFilesTests.cs index 17667b654..b1af9085e 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateFilesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateFilesTests.cs @@ -24,7 +24,7 @@ public void exception.Should().BeException( $"'{expectedPath}'", hResult: -2147024893); - FileSystem.Directory.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetDirectoriesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetDirectoriesTests.cs index 1a0f5fe33..a87c10171 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetDirectoriesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetDirectoriesTests.cs @@ -22,7 +22,7 @@ public void exception.Should().BeException($"'{expectedPath}'", hResult: -2147024893); - FileSystem.Directory.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetFileSystemInfosTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetFileSystemInfosTests.cs index 126562613..56932ec8c 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetFileSystemInfosTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetFileSystemInfosTests.cs @@ -23,7 +23,7 @@ public void exception.Should().BeException($"'{expectedPath}'.", hResult: -2147024893); - FileSystem.Directory.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetFilesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetFilesTests.cs index df0c0de3c..a850305a9 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetFilesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/GetFilesTests.cs @@ -23,7 +23,7 @@ public void exception.Should().BeException(expectedPath, hResult: -2147024893); - FileSystem.Directory.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(path); } [SkippableTheory] @@ -185,10 +185,11 @@ public void GetFiles_WithRelativePathAndSubfolders_ShouldReturnRelativeFilePath( { FileSystem.File.Create(System.IO.Path.Combine(workingDirectory, file)); } + FileSystem.Directory.SetCurrentDirectory(subfolder1); IEnumerable expectation = files.Select(f => System.IO.Path.Combine("..", subfolder1, subfolder2, f)); - var path = System.IO.Path.Combine("..", subfolder1, subfolder2); + string path = System.IO.Path.Combine("..", subfolder1, subfolder2); List result = FileSystem.Directory.GetFiles(path).ToList(); diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/MoveTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/MoveTests.cs index 6809b4077..dd76d9044 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/MoveTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/MoveTests.cs @@ -29,7 +29,7 @@ public void Move_CaseOnlyChange_ShouldMoveDirectoryWithContent(string path) FileSystem.Directory.Move(source, destination); FileSystem.Directory.Exists(source).Should().Be(!Test.RunsOnLinux); - FileSystem.Directory.Exists(destination).Should().BeTrue(); + FileSystem.Should().HaveDirectory(destination); FileSystem.Directory.GetDirectories(".").Should() .ContainSingle(d => d.Contains(destination)); FileSystem.Directory.GetFiles(destination, initialized[1].Name) @@ -110,8 +110,8 @@ public void Move_ShouldMoveDirectoryWithContent(string source, string destinatio FileSystem.Directory.Move(source, destination); - FileSystem.Directory.Exists(source).Should().BeFalse(); - FileSystem.Directory.Exists(destination).Should().BeTrue(); + FileSystem.Should().NotHaveDirectory(source); + FileSystem.Should().HaveDirectory(destination); FileSystem.Directory.GetFiles(destination, initialized[1].Name) .Should().ContainSingle(); FileSystem.Directory.GetDirectories(destination, initialized[2].Name) @@ -201,8 +201,8 @@ public void Move_WithLockedFile_ShouldThrowIOException_AndNotMoveDirectoryAtAll_ }); exception.Should().BeException(hResult: -2147024891); - FileSystem.Directory.Exists(source).Should().BeTrue(); - FileSystem.Directory.Exists(destination).Should().BeFalse(); + FileSystem.Should().HaveDirectory(source); + FileSystem.Should().NotHaveDirectory(destination); IDirectoryInfo sourceDirectory = FileSystem.DirectoryInfo.New(source); sourceDirectory.GetFiles(initialized[1].Name) @@ -241,8 +241,8 @@ public void Move_WithLockedFile_ShouldStillMoveDirectory_NotOnWindows( }); exception.Should().BeNull(); - FileSystem.Directory.Exists(source).Should().BeFalse(); - FileSystem.Directory.Exists(destination).Should().BeTrue(); + FileSystem.Should().NotHaveDirectory(source); + FileSystem.Should().HaveDirectory(destination); IDirectoryInfo destinationDirectory = FileSystem.DirectoryInfo.New(destination); destinationDirectory.GetFiles(initialized[1].Name) @@ -273,8 +273,8 @@ public void Move_WithReadOnlyFile_ShouldMoveDirectoryWithContent( FileSystem.Directory.Move(source, destination); - FileSystem.Directory.Exists(source).Should().BeFalse(); - FileSystem.Directory.Exists(destination).Should().BeTrue(); + FileSystem.Should().NotHaveDirectory(source); + FileSystem.Should().HaveDirectory(destination); IDirectoryInfo destinationDirectory = FileSystem.DirectoryInfo.New(destination); destinationDirectory.GetFiles(initialized[1].Name) diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/AttributesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/AttributesTests.cs index c59350970..502f443d8 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/AttributesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/AttributesTests.cs @@ -16,8 +16,8 @@ public void Attributes_ClearAllAttributes_ShouldRemainDirectory(string path) sut.Attributes = 0; - FileSystem.Directory.Exists(path).Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().HaveDirectory(path); + FileSystem.Should().NotHaveFile(path); sut.Attributes.Should().HaveFlag(FileAttributes.Directory); } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateSubdirectoryTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateSubdirectoryTests.cs index adfc8e2a7..56af81467 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateSubdirectoryTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateSubdirectoryTests.cs @@ -22,7 +22,7 @@ public void CreateSubdirectory_FileWithSameNameAlreadyExists_ShouldThrowIOExcept exception.Should().BeException( hResult: Test.RunsOnWindows ? -2147024713 : 17); - FileSystem.Directory.Exists(name).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(name); } [SkippableTheory] @@ -35,9 +35,9 @@ public void CreateSubdirectory_MissingParent_ShouldCreateDirectory( IDirectoryInfo result = sut.CreateSubdirectory(subdirectory); sut.Exists.Should().BeFalse(); - FileSystem.Directory.Exists(sut.FullName).Should().BeTrue(); + FileSystem.Should().HaveDirectory(sut.FullName); result.Exists.Should().BeTrue(); - FileSystem.Directory.Exists(result.FullName).Should().BeTrue(); + FileSystem.Should().HaveDirectory(result.FullName); } [SkippableTheory] @@ -49,8 +49,8 @@ public void CreateSubdirectory_ShouldCreateDirectory(string path, string subdire IDirectoryInfo result = sut.CreateSubdirectory(subdirectory); sut.Exists.Should().BeTrue(); - FileSystem.Directory.Exists(sut.FullName).Should().BeTrue(); + FileSystem.Should().HaveDirectory(sut.FullName); result.Exists.Should().BeTrue(); - FileSystem.Directory.Exists(result.FullName).Should().BeTrue(); + FileSystem.Should().HaveDirectory(result.FullName); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs index cb4c9437a..96e2b5522 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs @@ -21,7 +21,7 @@ public void Create_FileWithSameNameAlreadyExists_ShouldThrowIOException(string n exception.Should().BeException( hResult: Test.RunsOnWindows ? -2147024713 : 17); - FileSystem.Directory.Exists(name).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(name); } [SkippableTheory] @@ -39,17 +39,17 @@ public void Create_ShouldCreateDirectory(string path) #else sut.Exists.Should().BeTrue(); #endif - FileSystem.Directory.Exists(sut.FullName).Should().BeTrue(); + FileSystem.Should().HaveDirectory(sut.FullName); } [SkippableFact] public void Create_ShouldCreateInBasePath() { IDirectoryInfo result = FileSystem.DirectoryInfo.New("foo"); + result.Create(); - bool exists = FileSystem.Directory.Exists("foo"); - exists.Should().BeTrue(); + FileSystem.Should().HaveDirectory("foo"); result.FullName.Should().StartWith(BasePath); } @@ -100,7 +100,7 @@ public void Create_ShouldRefreshExistsCacheForCurrentItem_ExceptOnNetFramework(s sut3.Exists.Should().BeTrue(); } - FileSystem.Directory.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveDirectory(path); } [SkippableTheory] @@ -133,6 +133,6 @@ public void Create_TrailingDirectorySeparator_ShouldNotBeTrimmed( result.FullName.Should().Be(System.IO.Path.Combine(BasePath, expectedName .Replace(FileSystem.Path.AltDirectorySeparatorChar, FileSystem.Path.DirectorySeparatorChar))); - FileSystem.Directory.Exists(nameWithSuffix).Should().BeTrue(); + FileSystem.Should().HaveDirectory(nameWithSuffix); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/DeleteTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/DeleteTests.cs index edb3d17dc..ca409a9c1 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/DeleteTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/DeleteTests.cs @@ -52,12 +52,12 @@ public void Delete_Recursive_WithOpenFile_ShouldThrowIOException( { exception.Should().BeException($"{filename}'", hResult: -2147024864); - FileSystem.File.Exists(filePath).Should().BeTrue(); + FileSystem.Should().HaveFile(filePath); } else { exception.Should().BeNull(); - FileSystem.File.Exists(filePath).Should().BeFalse(); + FileSystem.Should().NotHaveFile(filePath); } } @@ -79,8 +79,8 @@ public void Delete_Recursive_WithSubdirectory_ShouldDeleteDirectoryWithContent( #else sut.Exists.Should().BeFalse(); #endif - FileSystem.Directory.Exists(sut.FullName).Should().BeFalse(); - FileSystem.Directory.Exists(subdirectoryPath).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(sut.FullName); + FileSystem.Should().NotHaveDirectory(subdirectoryPath); } [SkippableTheory] @@ -99,7 +99,7 @@ public void Delete_ShouldDeleteDirectory(string path) #else sut.Exists.Should().BeFalse(); #endif - FileSystem.Directory.Exists(sut.FullName).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(sut.FullName); } [SkippableTheory] @@ -124,6 +124,6 @@ public void Delete_WithSubdirectory_ShouldThrowIOException_AndNotDeleteDirectory : $"'{sut.FullName}'"); sut.Exists.Should().BeTrue(); - FileSystem.Directory.Exists(sut.FullName).Should().BeTrue(); + FileSystem.Should().HaveDirectory(sut.FullName); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs index 2731c4a73..aea1b8ef4 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs @@ -12,7 +12,7 @@ public void Exists_ArbitraryPath_ShouldBeFalse(string path) IDirectoryInfo sut = FileSystem.DirectoryInfo.New(path); sut.Exists.Should().BeFalse(); - FileSystem.Directory.Exists(sut.FullName).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(sut.FullName); } [SkippableTheory] @@ -25,7 +25,7 @@ public void Exists_ExistedPreviously_ShouldOnlyUpdateOnInitialization(string pat FileSystem.Directory.Delete(path); sut.Exists.Should().BeTrue(); - FileSystem.Directory.Exists(sut.FullName).Should().BeFalse(); + FileSystem.Should().NotHaveDirectory(sut.FullName); } [SkippableTheory] @@ -47,7 +47,7 @@ public void Exists_NotExistedPreviously_ShouldOnlyUpdateOnInitialization(string FileSystem.Directory.CreateDirectory(path); sut.Exists.Should().BeFalse(); - FileSystem.Directory.Exists(sut.FullName).Should().BeTrue(); + FileSystem.Should().HaveDirectory(sut.FullName); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/MoveToTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/MoveToTests.cs index 3db790fd6..8f410f8ac 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/MoveToTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/MoveToTests.cs @@ -25,8 +25,8 @@ public void MoveTo_ShouldMoveDirectoryWithContent(string source, string destinat sut.MoveTo(destination); - FileSystem.Directory.Exists(source).Should().BeFalse(); - FileSystem.Directory.Exists(destination).Should().BeTrue(); + FileSystem.Should().NotHaveDirectory(source); + FileSystem.Should().HaveDirectory(destination); FileSystem.Directory.GetFiles(destination, initialized[1].Name) .Should().ContainSingle(); FileSystem.Directory.GetDirectories(destination, initialized[2].Name) @@ -94,8 +94,8 @@ public void MoveTo_WithLockedFile_ShouldThrowIOException_AndNotMoveDirectory_OnW exception.Should().BeException(hResult: -2147024891); } - FileSystem.Directory.Exists(source).Should().BeTrue(); - FileSystem.Directory.Exists(destination).Should().BeFalse(); + FileSystem.Should().HaveDirectory(source); + FileSystem.Should().NotHaveDirectory(destination); IDirectoryInfo sourceDirectory = FileSystem.DirectoryInfo.New(source); sourceDirectory.GetFiles(initialized[1].Name) @@ -135,8 +135,8 @@ public void MoveTo_WithLockedFile_ShouldMoveDirectory_NotOnWindows( }); exception.Should().BeNull(); - FileSystem.Directory.Exists(source).Should().BeFalse(); - FileSystem.Directory.Exists(destination).Should().BeTrue(); + FileSystem.Should().NotHaveDirectory(source); + FileSystem.Should().HaveDirectory(destination); IDirectoryInfo destinationDirectory = FileSystem.DirectoryInfo.New(destination); destinationDirectory.GetFiles(initialized[1].Name) @@ -168,8 +168,8 @@ public void MoveTo_WithReadOnlyFile_ShouldMoveDirectoryWithContent( sut.MoveTo(destination); - FileSystem.Directory.Exists(source).Should().BeFalse(); - FileSystem.Directory.Exists(destination).Should().BeTrue(); + FileSystem.Should().NotHaveDirectory(source); + FileSystem.Should().HaveDirectory(destination); IDirectoryInfo destinationDirectory = FileSystem.DirectoryInfo.New(destination); destinationDirectory.GetFiles(initialized[1].Name) diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DriveInfoFactory/Tests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DriveInfoFactory/Tests.cs index 63b5ed213..fde9c0046 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DriveInfoFactory/Tests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DriveInfoFactory/Tests.cs @@ -42,7 +42,7 @@ public void MissingDrive_CreateDirectoryInfo_ShouldOnlyThrowWhenAccessingData( [SkippableTheory] [AutoData] public void MissingDrive_WriteAllBytes_ShouldThrowDirectoryNotFoundException( - string path, byte[] contents) + string path, byte[] bytes) { Skip.IfNot(Test.RunsOnWindows); @@ -52,7 +52,7 @@ public void MissingDrive_WriteAllBytes_ShouldThrowDirectoryNotFoundException( Exception? exception = Record.Exception(() => { - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); }); exception.Should().BeException($"'{path}'", diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllLinesAsyncTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllLinesAsyncTests.cs index dbd1742bb..cad47ca7c 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllLinesAsyncTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllLinesAsyncTests.cs @@ -50,14 +50,14 @@ public async Task public async Task AppendAllLinesAsync_ExistingFile_ShouldAppendLinesToFile( string path, List previousContents, List contents) { + string expectedContent = string.Join(Environment.NewLine, previousContents.Concat(contents)) + + Environment.NewLine; await FileSystem.File.AppendAllLinesAsync(path, previousContents); await FileSystem.File.AppendAllLinesAsync(path, contents); - FileSystem.File.Exists(path).Should().BeTrue(); - FileSystem.File.ReadAllLines(path).Should() - .BeEquivalentTo(previousContents.Concat(contents), - o => o.WithStrictOrdering()); + FileSystem.Should().HaveFile(path) + .Which.HasContent(expectedContent); } [SkippableTheory] @@ -79,10 +79,13 @@ public async Task AppendAllLinesAsync_MissingDirectory_ShouldThrowDirectoryNotFo public async Task AppendAllLinesAsync_MissingFile_ShouldCreateFile( string path, List contents) { + string expectedContent = string.Join(Environment.NewLine, contents) + + Environment.NewLine; + await FileSystem.File.AppendAllLinesAsync(path, contents); - FileSystem.File.Exists(path).Should().BeTrue(); - FileSystem.File.ReadAllLines(path).Should().BeEquivalentTo(contents); + FileSystem.Should().HaveFile(path) + .Which.HasContent(expectedContent); } [SkippableTheory] @@ -127,7 +130,8 @@ public async Task AppendAllLinesAsync_ShouldEndWithNewline(string path) await FileSystem.File.AppendAllLinesAsync(path, contents); - FileSystem.File.ReadAllText(path).Should().BeEquivalentTo(expectedResult); + FileSystem.Should().HaveFile(path) + .Which.HasContent(expectedResult); } [SkippableTheory] @@ -145,8 +149,8 @@ public async Task exception.Should().BeException( hResult: -2147024891); - FileSystem.Directory.Exists(path).Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().HaveDirectory(path); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllLinesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllLinesTests.cs index 668750435..3e9e40b80 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllLinesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllLinesTests.cs @@ -15,14 +15,14 @@ public abstract partial class AppendAllLinesTests public void AppendAllLines_ExistingFile_ShouldAppendLinesToFile( string path, List previousContents, List contents) { + string expectedContent = string.Join(Environment.NewLine, previousContents.Concat(contents)) + + Environment.NewLine; FileSystem.File.AppendAllLines(path, previousContents); FileSystem.File.AppendAllLines(path, contents); - FileSystem.File.Exists(path).Should().BeTrue(); - FileSystem.File.ReadAllLines(path).Should() - .BeEquivalentTo(previousContents.Concat(contents), - o => o.WithStrictOrdering()); + FileSystem.Should().HaveFile(path) + .Which.HasContent(expectedContent); } [SkippableTheory] @@ -30,11 +30,12 @@ public void AppendAllLines_ExistingFile_ShouldAppendLinesToFile( public void AppendAllLines_MissingFile_ShouldCreateFile( string path, List contents) { + string expectedContent = string.Join(Environment.NewLine, contents) + + Environment.NewLine; FileSystem.File.AppendAllLines(path, contents); - FileSystem.File.Exists(path).Should().BeTrue(); - FileSystem.File.ReadAllLines(path).Should() - .BeEquivalentTo(contents, o => o.WithStrictOrdering()); + FileSystem.Should().HaveFile(path) + .Which.HasContent(expectedContent); } [SkippableTheory] @@ -79,7 +80,8 @@ public void AppendAllLines_ShouldEndWithNewline(string path) FileSystem.File.AppendAllLines(path, contents); - FileSystem.File.ReadAllText(path).Should().BeEquivalentTo(expectedResult); + FileSystem.Should().HaveFile(path) + .Which.HasContent(expectedResult); } [SkippableTheory] @@ -97,8 +99,8 @@ public void exception.Should().BeException( hResult: -2147024891); - FileSystem.Directory.Exists(path).Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().HaveDirectory(path); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllTextAsyncTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllTextAsyncTests.cs index 1f1b079bc..61fb7a996 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllTextAsyncTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllTextAsyncTests.cs @@ -51,9 +51,8 @@ public async Task AppendAllTextAsync_ExistingFile_ShouldAppendLinesToFile( await FileSystem.File.AppendAllTextAsync(path, contents); - FileSystem.File.Exists(path).Should().BeTrue(); - FileSystem.File.ReadAllText(path).Should() - .BeEquivalentTo(previousContents + contents); + FileSystem.Should().HaveFile(path) + .Which.HasContent(previousContents + contents); } [SkippableTheory] @@ -77,8 +76,8 @@ public async Task AppendAllTextAsync_MissingFile_ShouldCreateFile( { await FileSystem.File.AppendAllTextAsync(path, contents); - FileSystem.File.Exists(path).Should().BeTrue(); - FileSystem.File.ReadAllLines(path).Should().BeEquivalentTo(contents); + FileSystem.Should().HaveFile(path) + .Which.HasContent(contents); } [SkippableTheory] @@ -89,7 +88,8 @@ public async Task AppendAllTextAsync_ShouldNotEndWithNewline(string path) await FileSystem.File.AppendAllTextAsync(path, contents); - FileSystem.File.ReadAllText(path).Should().BeEquivalentTo(contents); + FileSystem.Should().HaveFile(path) + .Which.HasContent(contents); } [SkippableTheory] @@ -107,8 +107,8 @@ public async Task exception.Should().BeException( hResult: -2147024891); - FileSystem.Directory.Exists(path).Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().HaveDirectory(path); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllTextTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllTextTests.cs index 61ba050ed..3202bd0ca 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllTextTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendAllTextTests.cs @@ -18,9 +18,8 @@ public void AppendAllText_ExistingFile_ShouldAppendLinesToFile( FileSystem.File.AppendAllText(path, contents); - FileSystem.File.Exists(path).Should().BeTrue(); - FileSystem.File.ReadAllText(path).Should() - .BeEquivalentTo(previousContents + contents); + FileSystem.Should().HaveFile(path) + .Which.HasContent(previousContents + contents); } [SkippableTheory] @@ -44,8 +43,8 @@ public void AppendAllText_MissingFile_ShouldCreateFile( { FileSystem.File.AppendAllText(path, contents); - FileSystem.File.Exists(path).Should().BeTrue(); - FileSystem.File.ReadAllText(path).Should().Be(contents); + FileSystem.Should().HaveFile(path) + .Which.HasContent(contents); } [SkippableTheory] @@ -71,8 +70,8 @@ public void AppendAllText_MissingFile_ShouldCreateFileWithByteOrderMark( FileSystem.File.AppendAllText(path, "AA", Encoding.UTF32); - FileSystem.File.ReadAllBytes(path) - .Should().BeEquivalentTo(expectedBytes); + FileSystem.Should().HaveFile(path) + .Which.HasContent(expectedBytes); } [SkippableTheory] @@ -120,7 +119,8 @@ public void AppendAllText_ShouldNotEndWithNewline(string path) FileSystem.File.AppendAllText(path, contents); - FileSystem.File.ReadAllText(path).Should().BeEquivalentTo(contents); + FileSystem.Should().HaveFile(path) + .Which.HasContent(contents); } [SkippableTheory] @@ -138,8 +138,8 @@ public void exception.Should().BeException( hResult: -2147024891); - FileSystem.Directory.Exists(path).Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().HaveDirectory(path); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendTextTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendTextTests.cs index cdffa5b24..9b36bfef0 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendTextTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/AppendTextTests.cs @@ -17,10 +17,8 @@ public void AppendText_MissingFile_ShouldCreateFile( stream.Write(appendText); } - string result = FileSystem.File.ReadAllText(path); - - result.Should().Be(appendText); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path) + .Which.HasContent(appendText); } [SkippableTheory] @@ -35,8 +33,7 @@ public void AppendText_ShouldAddTextToExistingFile( stream.Write(appendText); } - string result = FileSystem.File.ReadAllText(path); - - result.Should().Be(contents + appendText); + FileSystem.Should().HaveFile(path) + .Which.HasContent(contents + appendText); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/CopyTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/CopyTests.cs index fad3397c8..3e4d77fc4 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/CopyTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/CopyTests.cs @@ -43,10 +43,10 @@ public void Copy_DestinationExists_ShouldThrowIOException_AndNotCopyFile( exception.Should().BeException(hResult: Test.RunsOnWindows ? -2147024816 : 17); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(sourceContents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(destinationContents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(destinationContents); } #if FEATURE_FILE_MOVETO_OVERWRITE @@ -63,10 +63,10 @@ public void Copy_DestinationExists_WithOverwrite_ShouldOverwriteDestination( FileSystem.File.Copy(sourceName, destinationName, true); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(sourceContents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); } #endif @@ -121,11 +121,12 @@ public void Copy_ReadOnly_ShouldCopyFile( FileSystem.File.Copy(sourceName, destinationName); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(contents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(contents); FileSystem.File.GetAttributes(destinationName) .Should().HaveFlag(FileAttributes.ReadOnly); - FileSystem.File.ReadAllText(destinationName).Should().Be(contents); } [SkippableTheory] @@ -212,8 +213,8 @@ public void Copy_ShouldCloneBinaryContent( binaryWriter.Write("Some text"); } - FileSystem.File.ReadAllBytes(destination).Should() - .BeEquivalentTo(original); + FileSystem.Should().HaveFile(destination) + .Which.HasContent(original); FileSystem.File.ReadAllBytes(destination).Should() .NotBeEquivalentTo(FileSystem.File.ReadAllBytes(source)); } @@ -252,10 +253,10 @@ public void Copy_ShouldCopyFileWithContent( TimeSystem.Thread.Sleep(1000); FileSystem.File.Copy(sourceName, destinationName); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(contents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(contents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(contents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(contents); } [SkippableTheory] @@ -276,8 +277,8 @@ public void Copy_SourceIsDirectory_ShouldThrowUnauthorizedAccessException_AndNot messageContains: Test.IsNetFramework ? $"'{sourceName}'" : $"'{FileSystem.Path.GetFullPath(sourceName)}'"); - FileSystem.Directory.Exists(sourceName).Should().BeTrue(); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().HaveDirectory(sourceName); + FileSystem.Should().NotHaveFile(destinationName); } [SkippableTheory] @@ -298,12 +299,12 @@ public void Copy_SourceLocked_ShouldThrowIOException( if (Test.RunsOnWindows) { exception.Should().BeException(hResult: -2147024864); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(destinationName); } else { - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().HaveFile(sourceName); + FileSystem.Should().NotHaveFile(destinationName); } } @@ -323,6 +324,6 @@ public void Copy_SourceMissing_ShouldThrowFileNotFoundException( messageContains: Test.IsNetFramework ? null : $"'{FileSystem.Path.GetFullPath(sourceName)}'"); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(destinationName); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/CreateTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/CreateTests.cs index 45f567f2f..6a4f858b2 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/CreateTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/CreateTests.cs @@ -21,7 +21,8 @@ public void Create_ExistingFile_ShouldBeOverwritten( streamWriter.Dispose(); stream.Dispose(); - FileSystem.File.ReadAllText(path).Should().Be(newContent); + FileSystem.Should().HaveFile(path) + .Which.HasContent(newContent); } [SkippableTheory] @@ -61,7 +62,7 @@ public void Create_MissingFile_ShouldCreateFile(string path) { using FileSystemStream stream = FileSystem.File.Create(path); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/CreateTextTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/CreateTextTests.cs index aa0e69411..9c5a700bb 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/CreateTextTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/CreateTextTests.cs @@ -17,10 +17,8 @@ public void CreateText_MissingFile_ShouldCreateFile( stream.Write(appendText); } - string result = FileSystem.File.ReadAllText(path); - - result.Should().Be(appendText); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path) + .Which.HasContent(appendText); } [SkippableTheory] @@ -35,8 +33,7 @@ public void CreateText_ShouldReplaceTextInExistingFile( stream.Write(appendText); } - string result = FileSystem.File.ReadAllText(path); - - result.Should().Be(appendText); + FileSystem.Should().HaveFile(path) + .Which.HasContent(appendText); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/DeleteTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/DeleteTests.cs index 260c89e32..4e58d598d 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/DeleteTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/DeleteTests.cs @@ -60,12 +60,12 @@ public void Delete_WithOpenFile_ShouldThrowIOException_OnWindows(string filename { exception.Should().BeException($"{filename}'", hResult: -2147024864); - FileSystem.File.Exists(filename).Should().BeTrue(); + FileSystem.Should().HaveFile(filename); } else { exception.Should().BeNull(); - FileSystem.File.Exists(filename).Should().BeFalse(); + FileSystem.Should().NotHaveFile(filename); } } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/MoveTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/MoveTests.cs index 641552228..362a13500 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/MoveTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/MoveTests.cs @@ -21,11 +21,11 @@ public void Move_CaseOnlyChange_ShouldMoveFileWithContent( if (Test.RunsOnLinux) { // sourceName and destinationName are considered different only on Linux - FileSystem.File.Exists(sourceName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(sourceName); } - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(contents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(contents); } [SkippableTheory] @@ -65,10 +65,10 @@ public void Move_DestinationExists_ShouldThrowIOException_AndNotMoveFile( exception.Should().BeException( hResult: Test.RunsOnWindows ? -2147024713 : 17); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(sourceContents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(destinationContents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(destinationContents); } #if FEATURE_FILE_MOVETO_OVERWRITE @@ -85,9 +85,9 @@ public void Move_DestinationExists_WithOverwrite_ShouldOverwriteDestination( FileSystem.File.Move(sourceName, destinationName, true); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); } #endif @@ -101,11 +101,11 @@ public void Move_ReadOnly_ShouldMoveFile( FileSystem.File.Move(sourceName, destinationName); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(contents); FileSystem.File.GetAttributes(destinationName) .Should().HaveFlag(FileAttributes.ReadOnly); - FileSystem.File.ReadAllText(destinationName).Should().Be(contents); } [SkippableTheory] @@ -117,9 +117,9 @@ public void Move_ShouldMoveFileWithContent( FileSystem.File.Move(sourceName, destinationName); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(contents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(contents); } [SkippableTheory] @@ -181,7 +181,7 @@ public void Move_SourceDirectoryMissing_ShouldThrowFileNotFoundException( exception.Should().BeException( $"'{FileSystem.Path.GetFullPath(sourcePath)}'", hResult: -2147024894); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(destinationName); } [SkippableTheory] @@ -203,12 +203,12 @@ public void Move_SourceLocked_ShouldThrowIOException_OnWindows( { exception.Should().BeException( hResult: -2147024864); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(destinationName); } else { - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName); } } @@ -241,6 +241,6 @@ public void Move_SourceMissing_ShouldThrowFileNotFoundException( exception.Should().BeException( $"'{FileSystem.Path.GetFullPath(sourceName)}'", hResult: -2147024894); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(destinationName); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/OpenWriteTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/OpenWriteTests.cs index f3275b56d..e62d646b3 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/OpenWriteTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/OpenWriteTests.cs @@ -13,7 +13,7 @@ public void OpenWrite_MissingFile_ShouldCreateFile(string path) { using FileSystemStream stream = FileSystem.File.OpenWrite(path); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/ReadAllBytesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/ReadAllBytesTests.cs index e157ab1a0..76ab1b6e9 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/ReadAllBytesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/ReadAllBytesTests.cs @@ -80,7 +80,9 @@ public void ReadAllBytes_ShouldNotGetAReferenceToFileContent( byte[] results = FileSystem.File.ReadAllBytes(path); results[0] = (byte)~results[0]; - FileSystem.File.ReadAllBytes(path).Should().BeEquivalentTo(bytes); + byte[] result = FileSystem.File.ReadAllBytes(path); + + result.Should().BeEquivalentTo(bytes); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/ReplaceTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/ReplaceTests.cs index 8992dd750..134e472ae 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/ReplaceTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/ReplaceTests.cs @@ -65,7 +65,7 @@ public void Replace_DestinationMissing_ShouldThrowFileNotFoundException( }); exception.Should().BeException(hResult: -2147024894); - FileSystem.File.Exists(backupName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(backupName); } [SkippableTheory] @@ -83,13 +83,13 @@ public void Replace_ReadOnly_WithIgnoreMetadataError_ShouldReplaceFile( FileSystem.File.Replace(sourceName, destinationName, backupName, true); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); FileSystem.File.GetAttributes(destinationName) .Should().HaveFlag(FileAttributes.ReadOnly); - FileSystem.File.Exists(backupName).Should().BeTrue(); - FileSystem.File.ReadAllText(backupName).Should().Be(destinationContents); + FileSystem.Should().HaveFile(backupName) + .Which.HasContent(destinationContents); } [SkippableTheory] @@ -114,22 +114,22 @@ public void if (Test.RunsOnWindows) { exception.Should().BeException(hResult: -2147024891); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(sourceContents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(destinationContents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(destinationContents); FileSystem.File.GetAttributes(destinationName) .Should().NotHaveFlag(FileAttributes.ReadOnly); - FileSystem.File.Exists(backupName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(backupName); } else { exception.Should().BeNull(); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); - FileSystem.File.Exists(backupName).Should().BeTrue(); - FileSystem.File.ReadAllText(backupName).Should().Be(destinationContents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(backupName) + .Which.HasContent(destinationContents); } } @@ -147,11 +147,11 @@ public void Replace_ShouldReplaceFile( FileSystem.File.Replace(sourceName, destinationName, backupName); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); - FileSystem.File.Exists(backupName).Should().BeTrue(); - FileSystem.File.ReadAllText(backupName).Should().Be(destinationContents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(backupName) + .Which.HasContent(destinationContents); } [SkippableTheory] @@ -197,21 +197,21 @@ public void Replace_SourceLocked_ShouldThrowIOException_OnWindows( if (Test.RunsOnWindows) { exception.Should().BeException(hResult: -2147024864); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(sourceContents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(destinationContents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(destinationContents); FileSystem.File.GetAttributes(destinationName) .Should().NotHaveFlag(FileAttributes.ReadOnly); - FileSystem.File.Exists(backupName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(backupName); } else { - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); - FileSystem.File.Exists(backupName).Should().BeTrue(); - FileSystem.File.ReadAllText(backupName).Should().Be(destinationContents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(backupName) + .Which.HasContent(destinationContents); } } @@ -233,7 +233,7 @@ public void Replace_SourceMissing_ShouldThrowFileNotFoundException( if (Test.RunsOnWindows) { // Behaviour on Linux/MacOS is uncertain - FileSystem.File.Exists(backupName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(backupName); } } @@ -253,11 +253,11 @@ public void Replace_WithExistingBackupFile_ShouldIgnoreBackup( FileSystem.File.Replace(sourceName, destinationName, null); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); - FileSystem.File.Exists(backupName).Should().BeTrue(); - FileSystem.File.ReadAllText(backupName).Should().Be(backupContents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(backupName) + .Which.HasContent(backupContents); } [SkippableTheory] @@ -273,8 +273,8 @@ public void Replace_WithoutBackup_ShouldReplaceFile( FileSystem.File.Replace(sourceName, destinationName, null); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/SetAttributesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/SetAttributesTests.cs index 79eede4e8..d58fc552d 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/SetAttributesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/SetAttributesTests.cs @@ -47,7 +47,7 @@ public void SetAttributes_Directory_ShouldRemainFile(string path) FileSystem.File.SetAttributes(path, FileAttributes.Directory); - FileSystem.Directory.Exists(path).Should().BeFalse(); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().NotHaveDirectory(path); + FileSystem.Should().HaveFile(path); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllBytesAsyncTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllBytesAsyncTests.cs index 746116afa..e08270274 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllBytesAsyncTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllBytesAsyncTests.cs @@ -35,8 +35,8 @@ public async Task WriteAllBytesAsync_PreviousFile_ShouldOverwriteFileWithBytes( await FileSystem.File.WriteAllBytesAsync(path, bytes); - byte[] result = FileSystem.File.ReadAllBytes(path); - result.Should().BeEquivalentTo(bytes); + FileSystem.Should().HaveFile(path) + .Which.HasContent(bytes); } [SkippableTheory] @@ -46,8 +46,8 @@ public async Task WriteAllBytesAsync_ShouldCreateFileWithBytes( { await FileSystem.File.WriteAllBytesAsync(path, bytes); - byte[] result = FileSystem.File.ReadAllBytes(path); - result.Should().BeEquivalentTo(bytes); + FileSystem.Should().HaveFile(path) + .Which.HasContent(bytes); } [SkippableTheory] @@ -78,8 +78,8 @@ public async Task exception.Should().BeException( hResult: -2147024891); - FileSystem.Directory.Exists(path).Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().HaveDirectory(path); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllBytesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllBytesTests.cs index 3d7df9726..3f76e6a59 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllBytesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllBytesTests.cs @@ -17,8 +17,8 @@ public void WriteAllBytes_PreviousFile_ShouldOverwriteFileWithBytes( FileSystem.File.WriteAllBytes(path, bytes); - byte[] result = FileSystem.File.ReadAllBytes(path); - result.Should().BeEquivalentTo(bytes); + FileSystem.Should().HaveFile(path) + .Which.HasContent(bytes); } [SkippableTheory] @@ -27,8 +27,8 @@ public void WriteAllBytes_ShouldCreateFileWithBytes(string path, byte[] bytes) { FileSystem.File.WriteAllBytes(path, bytes); - byte[] result = FileSystem.File.ReadAllBytes(path); - result.Should().BeEquivalentTo(bytes); + FileSystem.Should().HaveFile(path) + .Which.HasContent(bytes); } [SkippableTheory] @@ -58,8 +58,8 @@ public void exception.Should().BeException( hResult: -2147024891); - FileSystem.Directory.Exists(path).Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().HaveDirectory(path); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllLinesAsyncTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllLinesAsyncTests.cs index 0f8865146..24c3c8bf2 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllLinesAsyncTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllLinesAsyncTests.cs @@ -136,8 +136,8 @@ public async Task exception.Should().BeException( hResult: -2147024891); - FileSystem.Directory.Exists(path).Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().HaveDirectory(path); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllLinesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllLinesTests.cs index f1a5f73cf..5ef3cfa5b 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllLinesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllLinesTests.cs @@ -82,8 +82,8 @@ public void exception.Should().BeException( hResult: -2147024891); - FileSystem.Directory.Exists(path).Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().HaveDirectory(path); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllTextAsyncTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllTextAsyncTests.cs index 0ba36e689..65a54f1fb 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllTextAsyncTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllTextAsyncTests.cs @@ -119,8 +119,8 @@ public async Task exception.Should().BeException( hResult: -2147024891); - FileSystem.Directory.Exists(path).Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().HaveDirectory(path); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllTextTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllTextTests.cs index 6a636002d..3cf625cb5 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllTextTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/WriteAllTextTests.cs @@ -97,8 +97,8 @@ public void WriteAllText_ShouldCreateFileWithByteOrderMark( FileSystem.File.WriteAllText(path, "AA", Encoding.UTF32); - FileSystem.File.ReadAllBytes(path) - .Should().BeEquivalentTo(expectedBytes); + FileSystem.Should().HaveFile(path) + .Which.HasContent(expectedBytes); } [SkippableTheory] @@ -163,8 +163,8 @@ public void WriteAllText_WhenDirectoryWithSameNameExists_ShouldThrowUnauthorized exception.Should().BeException( hResult: -2147024891); - FileSystem.Directory.Exists(path).Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().HaveDirectory(path); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/AppendTextTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/AppendTextTests.cs index 9a2ece140..ff7df041c 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/AppendTextTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/AppendTextTests.cs @@ -19,10 +19,8 @@ public void AppendText_MissingFile_ShouldCreateFile( stream.Write(appendText); } - string result = FileSystem.File.ReadAllText(path); - - result.Should().Be(appendText); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path) + .Which.HasContent(appendText); } [SkippableTheory] @@ -38,8 +36,7 @@ public void AppendText_ShouldAddTextToExistingFile( stream.Write(appendText); } - string result = FileSystem.File.ReadAllText(path); - - result.Should().Be(contents + appendText); + FileSystem.Should().HaveFile(path) + .Which.HasContent(contents + appendText); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CopyToTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CopyToTests.cs index d032392ed..9ca2d2d42 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CopyToTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CopyToTests.cs @@ -27,10 +27,10 @@ public void CopyTo_DestinationExists_ShouldThrowIOException_AndNotCopyFile( exception.Should().BeException( hResult: Test.RunsOnWindows ? -2147024816 : 17); sut.Exists.Should().BeTrue(); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(sourceContents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(destinationContents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(destinationContents); } #if FEATURE_FILE_MOVETO_OVERWRITE @@ -52,10 +52,10 @@ public void CopyTo_DestinationExists_WithOverwrite_ShouldOverwriteDestination( sut.FullName.Should().Be(FileSystem.Path.GetFullPath(sourceName)); result.Exists.Should().BeTrue(); result.FullName.Should().Be(FileSystem.Path.GetFullPath(destinationName)); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(sourceContents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); } #endif @@ -70,11 +70,11 @@ public void CopyTo_ReadOnly_ShouldCopyFile( sut.CopyTo(destinationName); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); + FileSystem.Should().HaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(contents); FileSystem.File.GetAttributes(destinationName) .Should().HaveFlag(FileAttributes.ReadOnly); - FileSystem.File.ReadAllText(destinationName).Should().Be(contents); } [SkippableTheory] @@ -120,10 +120,10 @@ public void CopyTo_ShouldCopyFileWithContent( sut.Exists.Should().BeTrue(); result.Exists.Should().BeTrue(); result.FullName.Should().Be(FileSystem.Path.GetFullPath(destinationName)); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(contents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(contents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(contents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(contents); } [SkippableTheory] @@ -190,8 +190,8 @@ public void CopyTo_SourceIsDirectory_ShouldThrowUnauthorizedAccessException_AndN exception.Should().BeException( $"'{FileSystem.Path.GetFullPath(sourceName)}'", hResult: -2147024891); - FileSystem.Directory.Exists(sourceName).Should().BeTrue(); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().HaveDirectory(sourceName); + FileSystem.Should().NotHaveFile(destinationName); } [SkippableTheory] @@ -213,12 +213,12 @@ public void CopyTo_SourceLocked_ShouldThrowIOException( if (Test.RunsOnWindows) { exception.Should().BeException(hResult: -2147024864); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(destinationName); } else { - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().HaveFile(sourceName); + FileSystem.Should().NotHaveFile(destinationName); } } @@ -240,6 +240,6 @@ public void CopyTo_SourceMissing_ShouldThrowFileNotFoundException( messageContains: Test.IsNetFramework ? null : $"'{FileSystem.Path.GetFullPath(sourceName)}'"); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(destinationName); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs index 0e86821f3..e227f94d9 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs @@ -12,11 +12,11 @@ public abstract partial class CreateTests public void Create_MissingFile_ShouldCreateFile(string path) { IFileInfo sut = FileSystem.FileInfo.New(path); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveFile(path); using FileSystemStream stream = sut.Create(); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path); } [SkippableTheory] @@ -45,7 +45,7 @@ public void Create_ShouldRefreshExistsCacheForCurrentItem_ExceptOnNetFramework(s sut3.Exists.Should().BeTrue(); } - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTextTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTextTests.cs index 7968364c9..d391ededa 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTextTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTextTests.cs @@ -19,10 +19,8 @@ public void CreateText_MissingFile_ShouldCreateFile( stream.Write(appendText); } - string result = FileSystem.File.ReadAllText(path); - - result.Should().Be(appendText); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path) + .Which.HasContent(appendText); } [SkippableTheory] @@ -39,7 +37,7 @@ public void CreateText_ShouldNotRefreshExistsCache( } fileInfo.Exists.Should().BeFalse(); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path); } [SkippableTheory] @@ -55,8 +53,7 @@ public void CreateText_ShouldReplaceTextInExistingFile( stream.Write(appendText); } - string result = FileSystem.File.ReadAllText(path); - - result.Should().Be(appendText); + FileSystem.Should().HaveFile(path) + .Which.HasContent(appendText); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/DeleteTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/DeleteTests.cs index c87c63b55..e652f59d2 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/DeleteTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/DeleteTests.cs @@ -54,7 +54,7 @@ public void Delete_ShouldRefreshExistsCache_ExceptOnNetFramework(string path) sut.Exists.Should().BeFalse(); } - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] @@ -84,12 +84,12 @@ public void Delete_WithOpenFile_ShouldThrowIOException_OnWindows(string filename exception.Should().BeException( messageContains: $"{filename}'", hResult: -2147024864); - FileSystem.File.Exists(filename).Should().BeTrue(); + FileSystem.Should().HaveFile(filename); } else { exception.Should().BeNull(); - FileSystem.File.Exists(filename).Should().BeFalse(); + FileSystem.Should().NotHaveFile(filename); } } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/MoveToTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/MoveToTests.cs index 38c2e0920..a952a511c 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/MoveToTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/MoveToTests.cs @@ -28,10 +28,10 @@ public void MoveTo_DestinationExists_ShouldThrowIOException_AndNotMoveFile( hResult: Test.RunsOnWindows ? -2147024713 : 17); sut.Exists.Should().BeTrue(); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(sourceContents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(destinationContents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(destinationContents); } #if FEATURE_FILE_MOVETO_OVERWRITE @@ -52,9 +52,9 @@ public void MoveTo_DestinationExists_WithOverwrite_ShouldOverwriteDestination( sut.Exists.Should().BeTrue(); sut.ToString().Should().Be(destinationName); sut.FullName.Should().Be(FileSystem.Path.GetFullPath(destinationName)); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); } #endif @@ -92,7 +92,7 @@ public void MoveTo_Itself_SourceMissing_ShouldThrowFileNotFoundException( messageContains: Test.IsNetFramework ? null : $"'{FileSystem.Path.GetFullPath(sourceName)}'"); - FileSystem.File.Exists(sourceName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(sourceName); } [SkippableTheory] @@ -117,9 +117,9 @@ public void exception.Should().BeException(hResult: -2147024893); sut.Exists.Should().BeTrue(); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(sourceContents); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(sourceContents); + FileSystem.Should().NotHaveFile(destinationName); } [SkippableTheory] @@ -133,11 +133,11 @@ public void MoveTo_ReadOnly_ShouldMoveFile( sut.MoveTo(destinationName); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(contents); FileSystem.File.GetAttributes(destinationName) .Should().HaveFlag(FileAttributes.ReadOnly); - FileSystem.File.ReadAllText(destinationName).Should().Be(contents); } [SkippableTheory] @@ -203,9 +203,9 @@ public void MoveTo_ShouldMoveFileWithContent( sut.FullName.Should().Be(FileSystem.Path.GetFullPath(destinationName)); sut.Exists.Should().BeTrue(); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(contents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(contents); } [SkippableTheory] @@ -254,12 +254,12 @@ public void MoveTo_SourceLocked_ShouldThrowIOException( if (Test.RunsOnWindows) { exception.Should().BeException(hResult: -2147024864); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(destinationName); } else { - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName); } } @@ -281,6 +281,6 @@ public void MoveTo_SourceMissing_ShouldThrowFileNotFoundException( ? null : $"'{FileSystem.Path.GetFullPath(sourceName)}'", hResult: -2147024894); - FileSystem.File.Exists(destinationName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(destinationName); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/OpenTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/OpenTests.cs index 9d52a8811..3ad27c4f4 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/OpenTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/OpenTests.cs @@ -160,7 +160,7 @@ public void Open_MissingFileAndCorrectMode_ShouldCreateFile( exception.Should().BeNull(); sut.Exists.Should().BeTrue(); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/OpenWriteTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/OpenWriteTests.cs index 43e860a8e..719a211c2 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/OpenWriteTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/OpenWriteTests.cs @@ -15,7 +15,7 @@ public void OpenWrite_MissingFile_ShouldCreateFile(string path) using FileSystemStream stream = sut.OpenWrite(); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/ReplaceTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/ReplaceTests.cs index 67dadffca..2598a3f24 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/ReplaceTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/ReplaceTests.cs @@ -83,7 +83,7 @@ public void Replace_DestinationMissing_ShouldThrowFileNotFoundException( }); exception.Should().BeException(hResult: -2147024894); - FileSystem.File.Exists(backupName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(backupName); } [SkippableTheory] @@ -103,14 +103,14 @@ public void Replace_ReadOnly_WithIgnoreMetadataError_ShouldReplaceFile( IFileInfo result = sut.Replace(destinationName, backupName, true); sut.Exists.Should().BeFalse(); - FileSystem.File.Exists(sourceName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(sourceName); result.FullName.Should().Be(FileSystem.Path.GetFullPath(destinationName)); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); FileSystem.File.GetAttributes(destinationName) .Should().HaveFlag(FileAttributes.ReadOnly); - FileSystem.File.Exists(backupName).Should().BeTrue(); - FileSystem.File.ReadAllText(backupName).Should().Be(destinationContents); + FileSystem.Should().HaveFile(backupName) + .Which.HasContent(destinationContents); } [SkippableTheory] @@ -136,23 +136,23 @@ public void if (Test.RunsOnWindows) { exception.Should().BeException(hResult: -2147024891); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(sourceContents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(destinationContents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(destinationContents); FileSystem.File.GetAttributes(destinationName) .Should().NotHaveFlag(FileAttributes.ReadOnly); - FileSystem.File.Exists(backupName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(backupName); } else { exception.Should().BeNull(); sut.Exists.Should().BeFalse(); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); - FileSystem.File.Exists(backupName).Should().BeTrue(); - FileSystem.File.ReadAllText(backupName).Should().Be(destinationContents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(backupName) + .Which.HasContent(destinationContents); } } @@ -263,12 +263,12 @@ public void Replace_ShouldReplaceFile( IFileInfo result = sut.Replace(destinationName, backupName); sut.Exists.Should().BeFalse(); - FileSystem.File.Exists(sourceName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(sourceName); result.FullName.Should().Be(FileSystem.Path.GetFullPath(destinationName)); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); - FileSystem.File.Exists(backupName).Should().BeTrue(); - FileSystem.File.ReadAllText(backupName).Should().Be(destinationContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(backupName) + .Which.HasContent(destinationContents); } [SkippableTheory] @@ -336,22 +336,22 @@ public void Replace_SourceLocked_ShouldThrowIOException_OnWindows( { exception.Should().BeException(hResult: -2147024864); sut.Exists.Should().BeTrue(); - FileSystem.File.Exists(sourceName).Should().BeTrue(); - FileSystem.File.ReadAllText(sourceName).Should().Be(sourceContents); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(destinationContents); + FileSystem.Should().HaveFile(sourceName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(destinationContents); FileSystem.File.GetAttributes(destinationName) .Should().NotHaveFlag(FileAttributes.ReadOnly); - FileSystem.File.Exists(backupName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(backupName); } else { sut.Exists.Should().BeFalse(); - FileSystem.File.Exists(sourceName).Should().BeFalse(); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); - FileSystem.File.Exists(backupName).Should().BeTrue(); - FileSystem.File.ReadAllText(backupName).Should().Be(destinationContents); + FileSystem.Should().NotHaveFile(sourceName); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(backupName) + .Which.HasContent(destinationContents); } } @@ -374,7 +374,7 @@ public void Replace_SourceMissing_ShouldThrowFileNotFoundException( if (Test.RunsOnWindows) { // Behaviour on Linux/MacOS is uncertain - FileSystem.File.Exists(backupName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(backupName); } } @@ -396,12 +396,12 @@ public void Replace_WithExistingBackupFile_ShouldIgnoreBackup( IFileInfo result = sut.Replace(destinationName, null); sut.Exists.Should().BeFalse(); - FileSystem.File.Exists(sourceName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(sourceName); result.FullName.Should().Be(FileSystem.Path.GetFullPath(destinationName)); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); - FileSystem.File.Exists(backupName).Should().BeTrue(); - FileSystem.File.ReadAllText(backupName).Should().Be(backupContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); + FileSystem.Should().HaveFile(backupName) + .Which.HasContent(backupContents); } [SkippableTheory] @@ -419,9 +419,9 @@ public void Replace_WithoutBackup_ShouldReplaceFile( IFileInfo result = sut.Replace(destinationName, null); sut.Exists.Should().BeFalse(); - FileSystem.File.Exists(sourceName).Should().BeFalse(); + FileSystem.Should().NotHaveFile(sourceName); result.FullName.Should().Be(FileSystem.Path.GetFullPath(destinationName)); - FileSystem.File.Exists(destinationName).Should().BeTrue(); - FileSystem.File.ReadAllText(destinationName).Should().Be(sourceContents); + FileSystem.Should().HaveFile(destinationName) + .Which.HasContent(sourceContents); } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/AdjustTimesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/AdjustTimesTests.cs index beddeb312..abc98f0cf 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/AdjustTimesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/AdjustTimesTests.cs @@ -12,15 +12,15 @@ public abstract partial class AdjustTimesTests { [SkippableTheory] [AutoData] - public void CopyTo_ShouldAdjustTimes(string path, byte[] contents) + public void CopyTo_ShouldAdjustTimes(string path, byte[] bytes) { Skip.If(Test.IsNetFramework && FileSystem is RealFileSystem, "Works unreliable on .NET Framework"); Test.SkipIfLongRunningTestsShouldBeSkipped(FileSystem); - byte[] buffer = new byte[contents.Length]; + byte[] buffer = new byte[bytes.Length]; DateTime creationTimeStart = TimeSystem.DateTime.UtcNow; - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); DateTime creationTimeEnd = TimeSystem.DateTime.UtcNow; TimeSystem.Thread.Sleep(FileTestHelper.AdjustTimesDelay); using FileSystemStream stream = FileSystem.File.OpenRead(path); @@ -58,13 +58,13 @@ public void CopyTo_ShouldAdjustTimes(string path, byte[] contents) #if FEATURE_SPAN [SkippableTheory] [AutoData] - public void Read_AsSpan_ShouldAdjustTimes(string path, byte[] contents) + public void Read_AsSpan_ShouldAdjustTimes(string path, byte[] bytes) { Test.SkipIfLongRunningTestsShouldBeSkipped(FileSystem); byte[] buffer = new byte[2]; DateTime creationTimeStart = TimeSystem.DateTime.UtcNow; - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); DateTime creationTimeEnd = TimeSystem.DateTime.UtcNow; TimeSystem.Thread.Sleep(FileTestHelper.AdjustTimesDelay); DateTime updateTime = TimeSystem.DateTime.UtcNow; @@ -100,7 +100,7 @@ public void Read_AsSpan_ShouldAdjustTimes(string path, byte[] contents) [SkippableTheory] [AutoData] - public void Read_ShouldAdjustTimes(string path, byte[] contents) + public void Read_ShouldAdjustTimes(string path, byte[] bytes) { Skip.If(Test.IsNetFramework && FileSystem is RealFileSystem, "Works unreliable on .NET Framework"); @@ -108,7 +108,7 @@ public void Read_ShouldAdjustTimes(string path, byte[] contents) byte[] buffer = new byte[2]; DateTime creationTimeStart = TimeSystem.DateTime.UtcNow; - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); DateTime creationTimeEnd = TimeSystem.DateTime.UtcNow; TimeSystem.Thread.Sleep(FileTestHelper.AdjustTimesDelay); DateTime updateTime = TimeSystem.DateTime.UtcNow; @@ -144,13 +144,13 @@ public void Read_ShouldAdjustTimes(string path, byte[] contents) #if FEATURE_SPAN [SkippableTheory] [AutoData] - public async Task ReadAsync_AsMemory_ShouldAdjustTimes(string path, byte[] contents) + public async Task ReadAsync_AsMemory_ShouldAdjustTimes(string path, byte[] bytes) { Test.SkipIfLongRunningTestsShouldBeSkipped(FileSystem); byte[] buffer = new byte[2]; DateTime creationTimeStart = TimeSystem.DateTime.UtcNow; - await FileSystem.File.WriteAllBytesAsync(path, contents); + await FileSystem.File.WriteAllBytesAsync(path, bytes); DateTime creationTimeEnd = TimeSystem.DateTime.UtcNow; await TimeSystem.Task.Delay(FileTestHelper.AdjustTimesDelay); DateTime updateTime = TimeSystem.DateTime.UtcNow; @@ -187,7 +187,7 @@ public async Task ReadAsync_AsMemory_ShouldAdjustTimes(string path, byte[] conte #if FEATURE_FILESYSTEM_ASYNC [SkippableTheory] [AutoData] - public async Task ReadAsync_ShouldAdjustTimes(string path, byte[] contents) + public async Task ReadAsync_ShouldAdjustTimes(string path, byte[] bytes) { Skip.If(Test.IsNetFramework && FileSystem is RealFileSystem, "Works unreliable on .NET Framework"); @@ -195,7 +195,7 @@ public async Task ReadAsync_ShouldAdjustTimes(string path, byte[] contents) byte[] buffer = new byte[2]; DateTime creationTimeStart = TimeSystem.DateTime.UtcNow; - await FileSystem.File.WriteAllBytesAsync(path, contents); + await FileSystem.File.WriteAllBytesAsync(path, bytes); DateTime creationTimeEnd = TimeSystem.DateTime.UtcNow; await TimeSystem.Task.Delay(FileTestHelper.AdjustTimesDelay); DateTime updateTime = TimeSystem.DateTime.UtcNow; @@ -233,14 +233,14 @@ public async Task ReadAsync_ShouldAdjustTimes(string path, byte[] contents) [SkippableTheory] [AutoData] - public void ReadByte_ShouldAdjustTimes(string path, byte[] contents) + public void ReadByte_ShouldAdjustTimes(string path, byte[] bytes) { Skip.If(Test.IsNetFramework && FileSystem is RealFileSystem, "Works unreliable on .NET Framework"); Test.SkipIfLongRunningTestsShouldBeSkipped(FileSystem); DateTime creationTimeStart = TimeSystem.DateTime.UtcNow; - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); DateTime creationTimeEnd = TimeSystem.DateTime.UtcNow; TimeSystem.Thread.Sleep(FileTestHelper.AdjustTimesDelay); DateTime updateTime = TimeSystem.DateTime.UtcNow; @@ -275,14 +275,14 @@ public void ReadByte_ShouldAdjustTimes(string path, byte[] contents) [SkippableTheory] [AutoData] - public void Seek_ShouldNotAdjustTimes(string path, byte[] contents) + public void Seek_ShouldNotAdjustTimes(string path, byte[] bytes) { Skip.If(Test.IsNetFramework && FileSystem is RealFileSystem, "Works unreliable on .NET Framework"); Test.SkipIfLongRunningTestsShouldBeSkipped(FileSystem); DateTime creationTimeStart = TimeSystem.DateTime.UtcNow; - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); DateTime creationTimeEnd = TimeSystem.DateTime.UtcNow; TimeSystem.Thread.Sleep(FileTestHelper.AdjustTimesDelay); using FileSystemStream stream = FileSystem.File.OpenWrite(path); @@ -311,7 +311,7 @@ public void Seek_ShouldNotAdjustTimes(string path, byte[] contents) #if FEATURE_SPAN [SkippableTheory] [AutoData] - public void Write_AsSpan_ShouldAdjustTimes(string path, byte[] contents) + public void Write_AsSpan_ShouldAdjustTimes(string path, byte[] bytes) { Test.SkipIfLongRunningTestsShouldBeSkipped(FileSystem); @@ -322,7 +322,7 @@ public void Write_AsSpan_ShouldAdjustTimes(string path, byte[] contents) DateTime updateTime = TimeSystem.DateTime.UtcNow; using FileSystemStream stream = FileSystem.File.OpenWrite(path); - stream.Write(contents.AsSpan()); + stream.Write(bytes.AsSpan()); stream.Dispose(); DateTime lastWriteTime = WaitToBeUpdatedToAfter( @@ -352,7 +352,7 @@ public void Write_AsSpan_ShouldAdjustTimes(string path, byte[] contents) [SkippableTheory] [AutoData] - public void Write_ShouldAdjustTimes(string path, byte[] contents) + public void Write_ShouldAdjustTimes(string path, byte[] bytes) { Skip.If(Test.IsNetFramework && FileSystem is RealFileSystem, "Works unreliable on .NET Framework"); @@ -365,7 +365,7 @@ public void Write_ShouldAdjustTimes(string path, byte[] contents) DateTime updateTime = TimeSystem.DateTime.UtcNow; using FileSystemStream stream = FileSystem.File.OpenWrite(path); - stream.Write(contents, 0, 2); + stream.Write(bytes, 0, 2); stream.Dispose(); DateTime lastWriteTime = WaitToBeUpdatedToAfter( @@ -395,7 +395,7 @@ public void Write_ShouldAdjustTimes(string path, byte[] contents) #if FEATURE_SPAN [SkippableTheory] [AutoData] - public async Task WriteAsync_AsMemory_ShouldAdjustTimes(string path, byte[] contents) + public async Task WriteAsync_AsMemory_ShouldAdjustTimes(string path, byte[] bytes) { Test.SkipIfLongRunningTestsShouldBeSkipped(FileSystem); @@ -406,7 +406,7 @@ public async Task WriteAsync_AsMemory_ShouldAdjustTimes(string path, byte[] cont DateTime updateTime = TimeSystem.DateTime.UtcNow; await using FileSystemStream stream = FileSystem.File.OpenWrite(path); - await stream.WriteAsync(contents.AsMemory()); + await stream.WriteAsync(bytes.AsMemory()); await stream.DisposeAsync(); DateTime lastWriteTime = WaitToBeUpdatedToAfter( @@ -437,7 +437,7 @@ public async Task WriteAsync_AsMemory_ShouldAdjustTimes(string path, byte[] cont #if FEATURE_FILESYSTEM_ASYNC [SkippableTheory] [AutoData] - public async Task WriteAsync_ShouldAdjustTimes(string path, byte[] contents) + public async Task WriteAsync_ShouldAdjustTimes(string path, byte[] bytes) { Skip.If(Test.IsNetFramework && FileSystem is RealFileSystem, "Works unreliable on .NET Framework"); @@ -451,7 +451,7 @@ public async Task WriteAsync_ShouldAdjustTimes(string path, byte[] contents) await using FileSystemStream stream = FileSystem.File.OpenWrite(path); #pragma warning disable CA1835 - await stream.WriteAsync(contents, 0, 2); + await stream.WriteAsync(bytes, 0, 2); #pragma warning restore CA1835 await stream.DisposeAsync(); @@ -482,20 +482,20 @@ public async Task WriteAsync_ShouldAdjustTimes(string path, byte[] contents) [SkippableTheory] [AutoData] - public void WriteByte_ShouldAdjustTimes(string path, byte[] contents, byte content) + public void WriteByte_ShouldAdjustTimes(string path, byte[] bytes, byte singleByte) { Skip.If(Test.IsNetFramework && FileSystem is RealFileSystem, "Works unreliable on .NET Framework"); Test.SkipIfLongRunningTestsShouldBeSkipped(FileSystem); DateTime creationTimeStart = TimeSystem.DateTime.UtcNow; - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); DateTime creationTimeEnd = TimeSystem.DateTime.UtcNow; TimeSystem.Thread.Sleep(FileTestHelper.AdjustTimesDelay); DateTime updateTime = TimeSystem.DateTime.UtcNow; using FileSystemStream stream = FileSystem.File.OpenWrite(path); - stream.WriteByte(content); + stream.WriteByte(singleByte); stream.Dispose(); DateTime lastWriteTime = WaitToBeUpdatedToAfter( diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/DisposeTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/DisposeTests.cs index 643273e29..04633b28f 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/DisposeTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/DisposeTests.cs @@ -14,22 +14,22 @@ public abstract partial class DisposeTests [SkippableTheory] [AutoData] public void Dispose_CalledTwiceShouldDoNothing( - string path, byte[] contents) + string path, byte[] bytes) { Test.SkipBrittleTestsOnRealFileSystem(FileSystem); - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.FileStream.New(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, 10, FileOptions.DeleteOnClose); stream.Dispose(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveFile(path); FileSystem.File.WriteAllText(path, "foo"); stream.Dispose(); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/OptionsTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/OptionsTests.cs index 7ee3e2379..733222083 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/OptionsTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/OptionsTests.cs @@ -17,11 +17,11 @@ public void Options_DeleteOnClose_ShouldDeleteFileOnClose( using FileSystemStream stream = FileSystem.FileStream.New(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 10, FileOptions.DeleteOnClose); - FileSystem.File.Exists(path).Should().BeTrue(); + FileSystem.Should().HaveFile(path); stream.Close(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] @@ -36,7 +36,7 @@ public void Options_DeleteOnClose_ShouldDeleteFileOnDispose( stream.Dispose(); - FileSystem.File.Exists(path).Should().BeFalse(); + FileSystem.Should().NotHaveFile(path); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/ReadTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/ReadTests.cs index 7fd29da4d..9e55287d6 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/ReadTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/ReadTests.cs @@ -13,13 +13,13 @@ public abstract partial class ReadTests [SkippableTheory] [AutoData] public void BeginRead_ShouldCopyContentsToBuffer( - string path, byte[] contents) + string path, byte[] bytes) { ManualResetEventSlim ms = new(); - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.File.OpenRead(path); - byte[] buffer = new byte[contents.Length]; + byte[] buffer = new byte[bytes.Length]; stream.BeginRead(buffer, 0, buffer.Length, ar => { // ReSharper disable once AccessToDisposedClosure @@ -28,18 +28,18 @@ public void BeginRead_ShouldCopyContentsToBuffer( }, null); ms.Wait(30000); - buffer.Should().BeEquivalentTo(contents); + buffer.Should().BeEquivalentTo(bytes); } [SkippableTheory] [AutoData] public void BeginRead_CanReadFalse_ShouldThrowNotSupportedException( - string path, byte[] contents) + string path, byte[] bytes) { - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); FileSystemStream stream = FileSystem.FileInfo.New(path).OpenWrite(); - byte[] buffer = new byte[contents.Length]; + byte[] buffer = new byte[bytes.Length]; Exception? exception = Record.Exception(() => { // ReSharper disable once AccessToDisposedClosure @@ -54,9 +54,9 @@ public void BeginRead_CanReadFalse_ShouldThrowNotSupportedException( [SkippableTheory] [AutoData] public void EndRead_Null_ShouldThrowArgumentNullException( - string path, byte[] contents) + string path, byte[] bytes) { - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.File.OpenRead(path); Exception? exception = Record.Exception(() => @@ -70,18 +70,18 @@ public void EndRead_Null_ShouldThrowArgumentNullException( [SkippableTheory] [AutoData] - public void EndRead_ShouldNotAdjustTimes(string path, byte[] contents) + public void EndRead_ShouldNotAdjustTimes(string path, byte[] bytes) { Test.SkipBrittleTestsOnRealFileSystem(FileSystem); ManualResetEventSlim ms = new(); DateTime creationTimeStart = TimeSystem.DateTime.UtcNow; - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); DateTime creationTimeEnd = TimeSystem.DateTime.UtcNow; using FileSystemStream stream = FileSystem.File.OpenRead(path); DateTime updateTime = DateTime.MinValue; - byte[] buffer = new byte[contents.Length]; + byte[] buffer = new byte[bytes.Length]; stream.BeginRead(buffer, 0, buffer.Length, ar => { TimeSystem.Thread.Sleep(FileTestHelper.AdjustTimesDelay); @@ -111,16 +111,16 @@ public void EndRead_ShouldNotAdjustTimes(string path, byte[] contents) [SkippableTheory] [AutoData] public void Read_CanReadFalse_ShouldThrowNotSupportedException( - string path, byte[] contents) + string path, byte[] bytes) { - byte[] buffer = new byte[contents.Length]; - FileSystem.File.WriteAllBytes(path, contents); + byte[] buffer = new byte[bytes.Length]; + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.File.OpenWrite(path); Exception? exception = Record.Exception(() => { // ReSharper disable once AccessToDisposedClosure - _ = stream.Read(buffer, 0, contents.Length); + _ = stream.Read(buffer, 0, bytes.Length); }); stream.Dispose(); @@ -130,24 +130,24 @@ public void Read_CanReadFalse_ShouldThrowNotSupportedException( [SkippableTheory] [AutoData] - public void Read_ShouldFillBuffer(string path, byte[] contents) + public void Read_ShouldFillBuffer(string path, byte[] bytes) { - byte[] buffer = new byte[contents.Length]; - FileSystem.File.WriteAllBytes(path, contents); + byte[] buffer = new byte[bytes.Length]; + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.File.OpenRead(path); - int result = stream.Read(buffer, 0, contents.Length); + int result = stream.Read(buffer, 0, bytes.Length); - result.Should().Be(contents.Length); - buffer.Should().BeEquivalentTo(contents); + result.Should().Be(bytes.Length); + buffer.Should().BeEquivalentTo(bytes); } [SkippableTheory] [AutoData] public void ReadByte_CanReadFalse_ShouldThrowNotSupportedException( - string path, byte[] contents) + string path, byte[] bytes) { - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.File.OpenWrite(path); @@ -165,9 +165,9 @@ public void ReadByte_CanReadFalse_ShouldThrowNotSupportedException( [SkippableTheory] [AutoData] public void ReadByte_ShouldReadSingleByteAndAdvancePosition( - string path, byte[] contents) + string path, byte[] bytes) { - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.File.OpenRead(path); @@ -175,8 +175,8 @@ public void ReadByte_ShouldReadSingleByteAndAdvancePosition( int result2 = stream.ReadByte(); stream.Position.Should().Be(2); - result1.Should().Be(contents[0]); - result2.Should().Be(contents[1]); + result1.Should().Be(bytes[0]); + result2.Should().Be(bytes[1]); } [SkippableTheory] @@ -198,25 +198,25 @@ public void ReadTimeout_ShouldThrowInvalidOperationException( #if FEATURE_SPAN [SkippableTheory] [AutoData] - public void Read_AsSpan_ShouldFillBuffer(string path, byte[] contents) + public void Read_AsSpan_ShouldFillBuffer(string path, byte[] bytes) { - byte[] buffer = new byte[contents.Length]; - FileSystem.File.WriteAllBytes(path, contents); + byte[] buffer = new byte[bytes.Length]; + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.File.OpenRead(path); int result = stream.Read(buffer.AsSpan()); - result.Should().Be(contents.Length); - buffer.Should().BeEquivalentTo(contents); + result.Should().Be(bytes.Length); + buffer.Should().BeEquivalentTo(bytes); } [SkippableTheory] [AutoData] public void Read_AsSpan_CanReadFalse_ShouldThrowNotSupportedException( - string path, byte[] contents) + string path, byte[] bytes) { - byte[] buffer = new byte[contents.Length]; - FileSystem.File.WriteAllBytes(path, contents); + byte[] buffer = new byte[bytes.Length]; + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.File.OpenWrite(path); Exception? exception = Record.Exception(() => @@ -234,36 +234,36 @@ public void Read_AsSpan_CanReadFalse_ShouldThrowNotSupportedException( #if FEATURE_FILESYSTEM_ASYNC [SkippableTheory] [AutoData] - public async Task ReadAsync_ShouldFillBuffer(string path, byte[] contents) + public async Task ReadAsync_ShouldFillBuffer(string path, byte[] bytes) { using CancellationTokenSource cts = new(30000); - byte[] buffer = new byte[contents.Length]; - await FileSystem.File.WriteAllBytesAsync(path, contents, cts.Token); + byte[] buffer = new byte[bytes.Length]; + await FileSystem.File.WriteAllBytesAsync(path, bytes, cts.Token); await using FileSystemStream stream = FileSystem.File.OpenRead(path); #pragma warning disable CA1835 - int result = await stream.ReadAsync(buffer, 0, contents.Length, cts.Token); + int result = await stream.ReadAsync(buffer, 0, bytes.Length, cts.Token); #pragma warning restore CA1835 - result.Should().Be(contents.Length); - buffer.Should().BeEquivalentTo(contents); + result.Should().Be(bytes.Length); + buffer.Should().BeEquivalentTo(bytes); } [SkippableTheory] [AutoData] public async Task ReadAsync_CanReadFalse_ShouldThrowNotSupportedException( - string path, byte[] contents) + string path, byte[] bytes) { using CancellationTokenSource cts = new(30000); - byte[] buffer = new byte[contents.Length]; - await FileSystem.File.WriteAllBytesAsync(path, contents, cts.Token); + byte[] buffer = new byte[bytes.Length]; + await FileSystem.File.WriteAllBytesAsync(path, bytes, cts.Token); await using FileSystemStream stream = FileSystem.File.OpenWrite(path); Exception? exception = await Record.ExceptionAsync(async () => { // ReSharper disable once AccessToDisposedClosure #pragma warning disable CA1835 - _ = await stream.ReadAsync(buffer, 0, contents.Length, cts.Token); + _ = await stream.ReadAsync(buffer, 0, bytes.Length, cts.Token); #pragma warning restore CA1835 }); @@ -275,11 +275,11 @@ public async Task ReadAsync_CanReadFalse_ShouldThrowNotSupportedException( [SkippableTheory] [AutoData] public async Task ReadAsync_Memory_CanReadFalse_ShouldThrowNotSupportedException( - string path, byte[] contents) + string path, byte[] bytes) { using CancellationTokenSource cts = new(30000); - byte[] buffer = new byte[contents.Length]; - await FileSystem.File.WriteAllBytesAsync(path, contents, cts.Token); + byte[] buffer = new byte[bytes.Length]; + await FileSystem.File.WriteAllBytesAsync(path, bytes, cts.Token); await using FileSystemStream stream = FileSystem.File.OpenWrite(path); Exception? exception = await Record.ExceptionAsync(async () => diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/Tests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/Tests.cs index b38a47bb1..fe3101545 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/Tests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/Tests.cs @@ -55,26 +55,26 @@ public void Close_CalledMultipleTimes_ShouldNotThrow( [SkippableTheory] [AutoData] public void CopyTo_ShouldCopyBytes( - string path, byte[] contents) + string path, byte[] bytes) { - byte[] buffer = new byte[contents.Length]; - FileSystem.File.WriteAllBytes(path, contents); + byte[] buffer = new byte[bytes.Length]; + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.File.OpenRead(path); using MemoryStream destination = new(buffer); stream.CopyTo(destination); destination.Flush(); - buffer.Should().BeEquivalentTo(contents); + buffer.Should().BeEquivalentTo(bytes); } [SkippableTheory] [AutoData] public void CopyTo_BufferSizeZero_ShouldThrowArgumentOutOfRangeException( - string path, byte[] contents) + string path, byte[] bytes) { - byte[] buffer = new byte[contents.Length]; - FileSystem.File.WriteAllBytes(path, contents); + byte[] buffer = new byte[bytes.Length]; + FileSystem.File.WriteAllBytes(path, bytes); Exception? exception = Record.Exception(() => { @@ -91,26 +91,26 @@ public void CopyTo_BufferSizeZero_ShouldThrowArgumentOutOfRangeException( [SkippableTheory] [AutoData] public async Task CopyToAsync_ShouldCopyBytes( - string path, byte[] contents) + string path, byte[] bytes) { - byte[] buffer = new byte[contents.Length]; - await FileSystem.File.WriteAllBytesAsync(path, contents); + byte[] buffer = new byte[bytes.Length]; + await FileSystem.File.WriteAllBytesAsync(path, bytes); await using FileSystemStream stream = FileSystem.File.OpenRead(path); using MemoryStream destination = new(buffer); await stream.CopyToAsync(destination); await destination.FlushAsync(); - buffer.Should().BeEquivalentTo(contents); + buffer.Should().BeEquivalentTo(bytes); } [SkippableTheory] [AutoData] public async Task CopyToAsync_BufferSizeZero_ShouldThrowArgumentOutOfRangeException( - string path, byte[] contents) + string path, byte[] bytes) { - byte[] buffer = new byte[contents.Length]; - await FileSystem.File.WriteAllBytesAsync(path, contents); + byte[] buffer = new byte[bytes.Length]; + await FileSystem.File.WriteAllBytesAsync(path, bytes); Exception? exception = await Record.ExceptionAsync(async () => { @@ -204,7 +204,8 @@ public void Flush_ShouldNotUpdateFileContentWhenAlreadyFlushed( stream2.Dispose(); stream1.Dispose(); - FileSystem.File.ReadAllBytes(path).Should().BeEquivalentTo(bytes2); + FileSystem.Should().HaveFile(path) + .Which.HasContent(bytes2); } [SkippableTheory] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/WriteTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/WriteTests.cs index 0ee8b7a25..36eb66dd4 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/WriteTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileStream/WriteTests.cs @@ -14,12 +14,12 @@ public abstract partial class WriteTests [SkippableTheory] [AutoData] public void BeginWrite_CanWriteFalse_ShouldThrowNotSupportedException( - string path, byte[] contents) + string path, byte[] bytes) { - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); FileSystemStream stream = FileSystem.FileInfo.New(path).OpenRead(); - byte[] buffer = new byte[contents.Length]; + byte[] buffer = new byte[bytes.Length]; Exception? exception = Record.Exception(() => { // ReSharper disable once AccessToDisposedClosure @@ -34,13 +34,13 @@ public void BeginWrite_CanWriteFalse_ShouldThrowNotSupportedException( [SkippableTheory] [AutoData] public void BeginWrite_ShouldCopyContentsToFile( - string path, byte[] contents) + string path, byte[] bytes) { ManualResetEventSlim ms = new(); using FileSystemStream stream = FileSystem.File.Create(path); stream.Flush(); - stream.BeginWrite(contents, 0, contents.Length, ar => + stream.BeginWrite(bytes, 0, bytes.Length, ar => { // ReSharper disable once AccessToDisposedClosure stream.EndWrite(ar); @@ -49,7 +49,8 @@ public void BeginWrite_ShouldCopyContentsToFile( ms.Wait(30000); stream.Dispose(); - FileSystem.File.ReadAllBytes(path).Should().BeEquivalentTo(contents); + FileSystem.Should().HaveFile(path) + .Which.HasContent(bytes); } [SkippableTheory] @@ -69,18 +70,18 @@ public void EndWrite_Null_ShouldThrowArgumentNullException(string path) [SkippableTheory] [AutoData] - public void EndWrite_ShouldAdjustTimes(string path, byte[] contents) + public void EndWrite_ShouldAdjustTimes(string path, byte[] bytes) { Test.SkipBrittleTestsOnRealFileSystem(FileSystem); ManualResetEventSlim ms = new(); DateTime creationTimeStart = TimeSystem.DateTime.UtcNow; - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); DateTime creationTimeEnd = TimeSystem.DateTime.UtcNow; using FileSystemStream stream = FileSystem.File.Create(path); DateTime updateTime = DateTime.MinValue; - stream.BeginWrite(contents, 0, contents.Length, ar => + stream.BeginWrite(bytes, 0, bytes.Length, ar => { TimeSystem.Thread.Sleep(FileTestHelper.AdjustTimesDelay); updateTime = TimeSystem.DateTime.UtcNow; @@ -118,16 +119,16 @@ public void EndWrite_ShouldAdjustTimes(string path, byte[] contents) [SkippableTheory] [AutoData] public void Write_CanWriteFalse_ShouldThrowNotSupportedException( - string path, byte[] contents) + string path, byte[] bytes) { - byte[] buffer = new byte[contents.Length]; - FileSystem.File.WriteAllBytes(path, contents); + byte[] buffer = new byte[bytes.Length]; + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.File.OpenRead(path); Exception? exception = Record.Exception(() => { // ReSharper disable once AccessToDisposedClosure - stream.Write(buffer, 0, contents.Length); + stream.Write(buffer, 0, bytes.Length); }); stream.Dispose(); @@ -137,23 +138,23 @@ public void Write_CanWriteFalse_ShouldThrowNotSupportedException( [SkippableTheory] [AutoData] - public void Write_ShouldFillBuffer(string path, byte[] contents) + public void Write_ShouldFillBuffer(string path, byte[] bytes) { using FileSystemStream stream = FileSystem.File.Create(path); - stream.Write(contents, 0, contents.Length); + stream.Write(bytes, 0, bytes.Length); stream.Dispose(); - FileSystem.File.ReadAllBytes(path) - .Should().BeEquivalentTo(contents); + FileSystem.Should().HaveFile(path) + .Which.HasContent(bytes); } [SkippableTheory] [AutoData] public void WriteByte_HiddenFile_ShouldNotThrow( - string path, byte[] contents) + string path, byte[] bytes) { - FileSystem.File.WriteAllBytes(path, contents); + FileSystem.File.WriteAllBytes(path, bytes); FileSystem.File.SetAttributes(path, FileAttributes.Hidden); using FileSystemStream stream = FileSystem.File.OpenWrite(path); @@ -181,8 +182,8 @@ public void WriteByte_ShouldWriteSingleByteAndAdvancePosition( stream.Position.Should().Be(2); stream.Dispose(); - FileSystem.File.ReadAllBytes(path) - .Should().BeEquivalentTo(new[] + FileSystem.Should().HaveFile(path) + .Which.HasContent(new[] { byte1, byte2 }); @@ -208,24 +209,24 @@ public void WriteTimeout_ShouldThrowInvalidOperationException( #if FEATURE_SPAN [SkippableTheory] [AutoData] - public void Write_AsSpan_ShouldFillBuffer(string path, byte[] contents) + public void Write_AsSpan_ShouldFillBuffer(string path, byte[] bytes) { using FileSystemStream stream = FileSystem.File.Create(path); - stream.Write(contents.AsSpan()); + stream.Write(bytes.AsSpan()); stream.Dispose(); - FileSystem.File.ReadAllBytes(path) - .Should().BeEquivalentTo(contents); + FileSystem.Should().HaveFile(path) + .Which.HasContent(bytes); } [SkippableTheory] [AutoData] public void Write_AsSpan_CanWriteFalse_ShouldThrowNotSupportedException( - string path, byte[] contents) + string path, byte[] bytes) { - byte[] buffer = new byte[contents.Length]; - FileSystem.File.WriteAllBytes(path, contents); + byte[] buffer = new byte[bytes.Length]; + FileSystem.File.WriteAllBytes(path, bytes); using FileSystemStream stream = FileSystem.File.OpenRead(path); Exception? exception = Record.Exception(() => @@ -243,35 +244,35 @@ public void Write_AsSpan_CanWriteFalse_ShouldThrowNotSupportedException( #if FEATURE_FILESYSTEM_ASYNC [SkippableTheory] [AutoData] - public async Task WriteAsync_ShouldFillBuffer(string path, byte[] contents) + public async Task WriteAsync_ShouldFillBuffer(string path, byte[] bytes) { using CancellationTokenSource cts = new(30000); await using FileSystemStream stream = FileSystem.File.Create(path); #pragma warning disable CA1835 - await stream.WriteAsync(contents, 0, contents.Length, cts.Token); + await stream.WriteAsync(bytes, 0, bytes.Length, cts.Token); #pragma warning restore CA1835 await stream.DisposeAsync(); - (await FileSystem.File.ReadAllBytesAsync(path, cts.Token)) - .Should().BeEquivalentTo(contents); + FileSystem.Should().HaveFile(path) + .Which.HasContent(bytes); } [SkippableTheory] [AutoData] public async Task WriteAsync_CanWriteFalse_ShouldThrowNotSupportedException( - string path, byte[] contents) + string path, byte[] bytes) { using CancellationTokenSource cts = new(30000); - byte[] buffer = new byte[contents.Length]; - await FileSystem.File.WriteAllBytesAsync(path, contents, cts.Token); + byte[] buffer = new byte[bytes.Length]; + await FileSystem.File.WriteAllBytesAsync(path, bytes, cts.Token); await using FileSystemStream stream = FileSystem.File.OpenRead(path); Exception? exception = await Record.ExceptionAsync(async () => { // ReSharper disable once AccessToDisposedClosure #pragma warning disable CA1835 - await stream.WriteAsync(buffer, 0, contents.Length, cts.Token); + await stream.WriteAsync(buffer, 0, bytes.Length, cts.Token); #pragma warning restore CA1835 }); diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemTests.cs index 3abe67419..5e11440bf 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemTests.cs @@ -13,7 +13,7 @@ public void Paths_UnderWindows_ShouldUseNormalSlashAndBackslashInterchangeable() FileSystem.Directory.CreateDirectory("foo\\bar"); FileSystem.File.WriteAllText("foo\\bar\\file.txt", "some content"); - FileSystem.File.Exists("foo/bar/file.txt").Should().BeTrue(); + FileSystem.Should().HaveFile("foo/bar/file.txt"); FileSystem.Directory.GetFiles("foo/bar").Length .Should().Be(1); } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/Tests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/Tests.cs index a784cff75..dad7ea1fe 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/Tests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/Tests.cs @@ -239,8 +239,10 @@ public void Dispose() /// public ISite? Site { get; set; } + #pragma warning disable CS0067 // Event is required by the interface /// public event EventHandler? Disposed; + #pragma warning restore CS0067 } } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Path/ExceptionTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Path/ExceptionTests.cs index 3cfa87825..13cb5f8ca 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Path/ExceptionTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Path/ExceptionTests.cs @@ -93,5 +93,5 @@ public void Operations_WhenValueIsNull_ShouldThrowArgumentNullException( #endif } -#endregion + #endregion } diff --git a/Tests/Testably.Abstractions.Tests/TestHelpers/Usings.cs b/Tests/Testably.Abstractions.Tests/TestHelpers/Usings.cs index 71d979ff3..5761b3561 100644 --- a/Tests/Testably.Abstractions.Tests/TestHelpers/Usings.cs +++ b/Tests/Testably.Abstractions.Tests/TestHelpers/Usings.cs @@ -3,6 +3,7 @@ global using System; global using System.IO.Abstractions; global using Testably.Abstractions.FileSystem; +global using Testably.Abstractions.FluentAssertions; global using Testably.Abstractions.Testing; global using Testably.Abstractions.TestHelpers; global using Testably.Abstractions.Tests.TestHelpers; diff --git a/Tests/Testably.Abstractions.Tests/Testably.Abstractions.Tests.csproj b/Tests/Testably.Abstractions.Tests/Testably.Abstractions.Tests.csproj index d2f919918..e23bf8b43 100644 --- a/Tests/Testably.Abstractions.Tests/Testably.Abstractions.Tests.csproj +++ b/Tests/Testably.Abstractions.Tests/Testably.Abstractions.Tests.csproj @@ -8,10 +8,11 @@ + - + diff --git a/Tests/Testably.Abstractions.Tests/TimeSystem/TimerTests.cs b/Tests/Testably.Abstractions.Tests/TimeSystem/TimerTests.cs index af730d156..ef1a2116b 100644 --- a/Tests/Testably.Abstractions.Tests/TimeSystem/TimerTests.cs +++ b/Tests/Testably.Abstractions.Tests/TimeSystem/TimerTests.cs @@ -134,6 +134,7 @@ public void Change_WithInt_ShouldResetTimer() { ms3.Set(); } + Thread.Sleep(10); }, null, 0 * TimerMultiplier, 200 * TimerMultiplier); ms.Wait(30000).Should().BeTrue(); @@ -152,6 +153,7 @@ public void Change_WithInt_ShouldResetTimer() { triggerTimes.RemoveAt(0); } + triggerTimes[0].Should() .BeGreaterThan(70 * TimerMultiplier).And .BeLessThan(130 * TimerMultiplier); @@ -185,6 +187,7 @@ public void Change_WithLong_ShouldResetTimer() { ms3.Set(); } + Thread.Sleep(10); }, null, 0L * TimerMultiplier, 200L * TimerMultiplier); ms.Wait(30000).Should().BeTrue(); @@ -203,6 +206,7 @@ public void Change_WithLong_ShouldResetTimer() { triggerTimes.RemoveAt(0); } + triggerTimes[0].Should() .BeGreaterThan(70 * TimerMultiplier).And .BeLessThan(130 * TimerMultiplier); @@ -258,6 +262,7 @@ public void Change_WithTimeSpan_ShouldResetTimer() { triggerTimes.RemoveAt(0); } + triggerTimes[0].Should() .BeGreaterThan(70 * TimerMultiplier).And .BeLessThan(130 * TimerMultiplier);