From ca5508704220ddba7658b1a17fe307e3c122f471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 07:37:08 +0100 Subject: [PATCH 01/18] Add `NUnit.Analyzers` package --- ...stableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj | 3 ++- .../TestableIO.System.IO.Abstractions.Wrappers.Tests.csproj | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj index 2cd82a72c..b4fb165b1 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj @@ -34,7 +34,8 @@ - + + diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/TestableIO.System.IO.Abstractions.Wrappers.Tests.csproj b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/TestableIO.System.IO.Abstractions.Wrappers.Tests.csproj index 3d2659e44..2115e283d 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/TestableIO.System.IO.Abstractions.Wrappers.Tests.csproj +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/TestableIO.System.IO.Abstractions.Wrappers.Tests.csproj @@ -19,7 +19,8 @@ - + + From ce539ed9d8a80214e54ef69df60d70863eba4939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 08:03:53 +0100 Subject: [PATCH 02/18] Fix NUnit analyzer errors due to missing `.Kind` in AreNotEqual check --- .../MockFileInfoTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs index 1d9574b34..60f6062d0 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs @@ -893,7 +893,7 @@ public void MockFileInfo_LastAccessTimeUtcWithUnspecifiedDateTimeKind_ShouldSetL }; Assert.AreEqual(date, fileInfo.LastAccessTimeUtc); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastAccessTimeUtc); + Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastAccessTimeUtc.Kind); } [Test] @@ -909,7 +909,7 @@ public void MockFileInfo_LastAccessTimeWithUnspecifiedDateTimeKind_ShouldSetLast }; Assert.AreEqual(date, fileInfo.LastAccessTime); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastAccessTime); + Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastAccessTime.Kind); } [Test] @@ -925,7 +925,7 @@ public void MockFileInfo_CreationTimeUtcWithUnspecifiedDateTimeKind_ShouldSetCre }; Assert.AreEqual(date, fileInfo.CreationTimeUtc); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.CreationTimeUtc); + Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.CreationTimeUtc.Kind); } [Test] @@ -941,7 +941,7 @@ public void MockFileInfo_CreationTimeWithUnspecifiedDateTimeKind_ShouldSetCreati }; Assert.AreEqual(date, fileInfo.CreationTime); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.CreationTime); + Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.CreationTime.Kind); } [Test] @@ -957,7 +957,7 @@ public void MockFileInfo_LastWriteTimeUtcWithUnspecifiedDateTimeKind_ShouldSetLa }; Assert.AreEqual(date, fileInfo.LastWriteTimeUtc); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastWriteTimeUtc); + Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastWriteTimeUtc.Kind); } [Test] @@ -973,7 +973,7 @@ public void MockFileInfo_LastWriteTimeWithUnspecifiedDateTimeKind_ShouldSetLastW }; Assert.AreEqual(date, fileInfo.LastWriteTime); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastWriteTime); + Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastWriteTime.Kind); } } } From f924ef94b19a60c3d281e072e295f8a717652513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 08:05:38 +0100 Subject: [PATCH 03/18] Fix NUnit1002 (Consider using nameof(xxx) instead of "xxx") --- .../MockDirectoryInfoTests.cs | 4 ++-- .../MockDirectoryTests.cs | 2 +- .../MockFileArgumentPathTests.cs | 2 +- .../MockFileTests.cs | 2 +- .../MockFileWriteAllLinesTests.cs | 24 +++++++++---------- .../MockFileWriteAllTextTests.cs | 4 ++-- .../MockPathTests.cs | 6 ++--- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs index 766cd9ef4..cb279d043 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs @@ -19,7 +19,7 @@ public static IEnumerable MockDirectoryInfo_GetExtension_Cases } } - [TestCaseSource("MockDirectoryInfo_GetExtension_Cases")] + [TestCaseSource(nameof(MockDirectoryInfo_GetExtension_Cases))] public void MockDirectoryInfo_GetExtension_ShouldReturnEmptyString(string directoryPath) { // Arrange @@ -42,7 +42,7 @@ public static IEnumerable MockDirectoryInfo_Exists_Cases } } - [TestCaseSource("MockDirectoryInfo_Exists_Cases")] + [TestCaseSource(nameof(MockDirectoryInfo_Exists_Cases))] public void MockDirectoryInfo_Exists(string path, bool expected) { var fileSystem = new MockFileSystem(new Dictionary diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 289b8dc90..10422c1e4 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -1533,7 +1533,7 @@ public void Move_DirectoryExistsWithDifferentCase_DirectorySuccessfullyMoved() Assert.IsTrue(fileSystem.File.Exists(XFS.Path(@"C:\NewLocation\Data\someFile.txt"))); } - [TestCaseSource("GetPathsForMoving")] + [TestCaseSource(nameof(GetPathsForMoving))] public void MockDirectory_Move_ShouldMoveDirectories(string sourceDirName, string destDirName, string filePathOne, string filePathTwo) { // Arrange diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileArgumentPathTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileArgumentPathTests.cs index 860198de7..307a8404f 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileArgumentPathTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileArgumentPathTests.cs @@ -55,7 +55,7 @@ private static IEnumerable> GetFileSystemActionsForArgumentNullExc yield return fs => fs.Encrypt(null); } - [TestCaseSource("GetFileSystemActionsForArgumentNullException")] + [TestCaseSource(nameof(GetFileSystemActionsForArgumentNullException))] public void Operations_ShouldThrowArgumentNullExceptionIfPathIsNull(Action action) { // Arrange diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs index 7c0d6c5a1..028dbbc3f 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs @@ -392,7 +392,7 @@ public static IEnumerable GetEncodingsForReadAllText() yield return new ASCIIEncoding(); } - [TestCaseSource(typeof(MockFileTests), "GetEncodingsForReadAllText")] + [TestCaseSource(typeof(MockFileTests), nameof(GetEncodingsForReadAllText))] public void MockFile_ReadAllText_ShouldReturnTheOriginalContentWhenTheFileContainsDifferentEncodings(Encoding encoding) { // Arrange diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllLinesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllLinesTests.cs index f4a7bbb41..d5c259c55 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllLinesTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllLinesTests.cs @@ -401,7 +401,7 @@ await fileSystem.File.WriteAllLinesAsync( } - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForDifferentEncoding")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForDifferentEncoding))] public void MockFile_WriteAllLinesGeneric_ShouldWriteTheCorrectContent(IMockFileDataAccessor fileSystem, Action action, string expectedContent) { // Arrange @@ -415,7 +415,7 @@ public void MockFile_WriteAllLinesGeneric_ShouldWriteTheCorrectContent(IMockFile Assert.That(actualContent, Is.EqualTo(expectedContent)); } - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForNullPath")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForNullPath))] public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentNullExceptionIfPathIsNull(TestDelegate action) { // Arrange @@ -445,7 +445,7 @@ public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentNullExceptionIfEn Assert.That(exception.ParamName, Does.StartWith("encoding")); } - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForIllegalPath")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForIllegalPath))] [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentExceptionIfPathContainsIllegalCharacters(TestDelegate action) { @@ -460,7 +460,7 @@ public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentExceptionIfPathCo Assert.That(exception.Message, Is.EqualTo("Illegal characters in path.")); } - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForPathIsDirectory")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForPathIsDirectory))] public void MockFile_WriteAllLinesGeneric_ShouldThrowAnUnauthorizedAccessExceptionIfPathIsOneDirectory(TestDelegate action, string path) { // Arrange @@ -475,7 +475,7 @@ public void MockFile_WriteAllLinesGeneric_ShouldThrowAnUnauthorizedAccessExcepti Assert.That(exception.Message, Is.EqualTo(expectedMessage)); } - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForFileIsReadOnly")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForFileIsReadOnly))] public void MockFile_WriteAllLinesGeneric_ShouldThrowOneUnauthorizedAccessExceptionIfFileIsReadOnly(TestDelegate action, string path) { // Arrange @@ -490,7 +490,7 @@ public void MockFile_WriteAllLinesGeneric_ShouldThrowOneUnauthorizedAccessExcept Assert.That(exception.Message, Is.EqualTo(expectedMessage)); } - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForContentsIsNull")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForContentsIsNull))] public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentNullExceptionIfContentsIsNull(TestDelegate action) { // Arrange @@ -506,7 +506,7 @@ public void MockFile_WriteAllLinesGeneric_ShouldThrowAnArgumentNullExceptionIfCo } #if FEATURE_ASYNC_FILE - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForDifferentEncodingAsync")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForDifferentEncodingAsync))] public void MockFile_WriteAllLinesAsyncGeneric_ShouldWriteTheCorrectContent(IMockFileDataAccessor fileSystem, Action action, string expectedContent) { // Arrange @@ -520,7 +520,7 @@ public void MockFile_WriteAllLinesAsyncGeneric_ShouldWriteTheCorrectContent(IMoc Assert.That(actualContent, Is.EqualTo(expectedContent)); } - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForNullPathAsync")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForNullPathAsync))] public void MockFile_WriteAllLinesAsyncGeneric_ShouldThrowAnArgumentNullExceptionIfPathIsNull(AsyncTestDelegate action) { // Arrange @@ -550,7 +550,7 @@ public void MockFile_WriteAllLinesAsyncGeneric_ShouldThrowAnArgumentNullExceptio Assert.That(exception.ParamName, Does.StartWith("encoding")); } - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForIllegalPathAsync")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForIllegalPathAsync))] [WindowsOnly(WindowsSpecifics.StrictPathRules)] public void MockFile_WriteAllLinesAsyncGeneric_ShouldThrowAnArgumentExceptionIfPathContainsIllegalCharacters(AsyncTestDelegate action) { @@ -565,7 +565,7 @@ public void MockFile_WriteAllLinesAsyncGeneric_ShouldThrowAnArgumentExceptionIfP Assert.That(exception.Message, Is.EqualTo("Illegal characters in path.")); } - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForPathIsDirectoryAsync")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForPathIsDirectoryAsync))] public void MockFile_WriteAllLinesAsyncGeneric_ShouldThrowAnUnauthorizedAccessExceptionIfPathIsOneDirectory(AsyncTestDelegate action, string path) { // Arrange @@ -580,7 +580,7 @@ public void MockFile_WriteAllLinesAsyncGeneric_ShouldThrowAnUnauthorizedAccessEx Assert.That(exception.Message, Is.EqualTo(expectedMessage)); } - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForFileIsReadOnlyAsync")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForFileIsReadOnlyAsync))] public void MockFile_WriteAllLinesAsyncGeneric_ShouldThrowOneUnauthorizedAccessExceptionIfFileIsReadOnly(AsyncTestDelegate action, string path) { // Arrange @@ -595,7 +595,7 @@ public void MockFile_WriteAllLinesAsyncGeneric_ShouldThrowOneUnauthorizedAccessE Assert.That(exception.Message, Is.EqualTo(expectedMessage)); } - [TestCaseSource(typeof(TestDataForWriteAllLines), "ForContentsIsNullAsync")] + [TestCaseSource(typeof(TestDataForWriteAllLines), nameof(TestDataForWriteAllLines.ForContentsIsNullAsync))] public void MockFile_WriteAllLinesAsyncGeneric_ShouldThrowAnArgumentNullExceptionIfContentsIsNull(AsyncTestDelegate action) { // Arrange diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs index dfb9c9844..e6e4ce281 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs @@ -184,7 +184,7 @@ public static IEnumerable> GetEncodingsWithExpect }; } - [TestCaseSource(typeof(MockFileWriteAllTextTests), "GetEncodingsWithExpectedBytes")] + [TestCaseSource(typeof(MockFileWriteAllTextTests), nameof(GetEncodingsWithExpectedBytes))] public void MockFile_WriteAllText_Encoding_ShouldWriteTextFileToMemoryFileSystem(KeyValuePair encodingsWithContents) { // Arrange @@ -375,7 +375,7 @@ public void MockFile_WriteAllTextAsync_ShouldThrowDirectoryNotFoundExceptionIfPa Assert.ThrowsAsync(action); } - [TestCaseSource(typeof(MockFileWriteAllTextTests), "GetEncodingsWithExpectedBytes")] + [TestCaseSource(typeof(MockFileWriteAllTextTests), nameof(GetEncodingsWithExpectedBytes))] public async Task MockFile_WriteAllTextAsync_Encoding_ShouldWriteTextFileToMemoryFileSystem(KeyValuePair encodingsWithContents) { // Arrange diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs index 0cdcaab1f..616b7bcd8 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs @@ -153,7 +153,7 @@ public static IEnumerable GetFullPath_RelativePaths_Cases } } - [TestCaseSource("GetFullPath_RelativePaths_Cases")] + [TestCaseSource(nameof(GetFullPath_RelativePaths_Cases))] public void GetFullPath_RelativePaths_ShouldReturnTheAbsolutePathWithCurrentDirectory(string currentDir, string relativePath, string expectedResult) { //Arrange @@ -180,7 +180,7 @@ public static IEnumerable GetFullPath_RootedPathWithRelativeSegments_C } } - [TestCaseSource("GetFullPath_RootedPathWithRelativeSegments_Cases")] + [TestCaseSource(nameof(GetFullPath_RootedPathWithRelativeSegments_Cases))] public void GetFullPath_RootedPathWithRelativeSegments_ShouldReturnAnRootedAbsolutePath(string rootedPath, string expectedResult) { //Arrange @@ -209,7 +209,7 @@ public static IEnumerable GetFullPath_AbsolutePaths_Cases } } - [TestCaseSource("GetFullPath_AbsolutePaths_Cases")] + [TestCaseSource(nameof(GetFullPath_AbsolutePaths_Cases))] public void GetFullPath_AbsolutePaths_ShouldReturnThePathWithTheRoot_Or_Unc(string currentDir, string absolutePath, string expectedResult) { //Arrange From 35d1a7f9c1713fe594c51e26749bc51959ece107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 08:08:02 +0100 Subject: [PATCH 04/18] Fix NUnit2006 (Consider using the constraint model, Assert.That(actual, Is.Not.EqualTo(expected)), instead of the classic model, ClassicAssert.AreNotEqual(expected, actual)) --- .../MockFileReadAllBytesTests.cs | 2 +- .../MockFileWriteAllBytesTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs index 58462eeb4..9b871566e 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs @@ -81,7 +81,7 @@ public void MockFile_ReadAllBytes_ShouldReturnANewCopyOfTheFileContents() firstRead[i] += 1; } - Assert.AreNotEqual(firstRead, secondRead); + Assert.That(firstRead, Is.Not.EqualTo(secondRead)); } #if FEATURE_ASYNC_FILE diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs index 7a3f0a02a..eee29ef66 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs @@ -100,7 +100,7 @@ public void MockFile_WriteAllBytes_ShouldWriteASeparateCopyToTheFileSystem() var readAgain = fileSystem.File.ReadAllBytes(path); - Assert.AreNotEqual(fileContent, readAgain); + Assert.That(fileContent, Is.Not.EqualTo(readAgain)); } From 8c5e4701e986a9b8c01c62a88b2425963c5cc7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 08:09:35 +0100 Subject: [PATCH 05/18] Fix NUnit2007 (The actual value should not be a constant) --- .../MockFileStreamTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs index 8a32806d4..0cd36a9a7 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs @@ -241,9 +241,9 @@ public void MockFileStream_Null_ShouldHaveExpectedProperties() { var result = MockFileStream.Null; - Assert.AreEqual(result.Name, "."); - Assert.AreEqual(result.Length, 0); - Assert.AreEqual(result.IsAsync, true); + Assert.That(result.Name, Is.EqualTo(".")); + Assert.That(result.Length, Is.Zero); + Assert.That(result.IsAsync, Is.True); } } } From 77625677aa9d737a8bef5ac1bb82947d3ee010cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:05:20 +0100 Subject: [PATCH 06/18] Fix NUnit2005 (Consider using Assert.That(actual, Is.EqualTo(expected)) instead of Assert.AreEqual(expected, actual)) --- README.md | 2 +- ...stem.IO.Abstractions.TestingHelpers.csproj | 1 + .../MockDirectoryArgumentPathTests.cs | 2 +- .../MockDirectoryInfoSymlinkTests.cs | 6 +- .../MockDirectoryInfoTests.cs | 28 +++---- .../MockDirectorySymlinkTests.cs | 14 ++-- .../MockDirectoryTests.cs | 38 ++++----- .../MockDriveInfoTests.cs | 8 +- .../MockFileAppendAllLinesTests.cs | 23 ++--- .../MockFileAppendAllTextTests.cs | 22 ++--- .../MockFileArgumentPathTests.cs | 2 +- .../MockFileCopyTests.cs | 10 +-- .../MockFileDeleteTests.cs | 4 +- .../MockFileGetCreationTimeTests.cs | 2 +- .../MockFileGetCreationTimeUtcTests.cs | 2 +- .../MockFileGetLastAccessTimeTests.cs | 2 +- .../MockFileGetLastAccessTimeUtcTests.cs | 2 +- .../MockFileGetLastWriteTimeTests.cs | 2 +- .../MockFileGetLastWriteTimeUtcTests.cs | 2 +- .../MockFileInfoSymlinkTests.cs | 6 +- .../MockFileInfoTests.cs | 84 +++++++++---------- .../MockFileOpenTests.cs | 12 +-- .../MockFileReadAllBytesTests.cs | 8 +- .../MockFileStreamFactoryTests.cs | 2 +- .../MockFileStreamTests.cs | 10 +-- .../MockFileSymlinkTests.cs | 14 ++-- .../MockFileSystemOptionTests.cs | 4 +- .../MockFileSystemSerializationTests.cs | 8 +- .../MockFileSystemTests.cs | 14 ++-- .../MockFileTests.cs | 38 ++++----- .../MockFileWriteAllBytesTests.cs | 4 +- .../MockFileWriteAllTextTests.cs | 24 ++---- .../MockPathTests.cs | 50 +++++------ .../MockUnixSupportTests.cs | 4 +- .../StringExtensionsTests.cs | 18 ++-- ...O.Abstractions.TestingHelpers.Tests.csproj | 5 +- .../DirectoryWrapperTests.cs | 4 +- 37 files changed, 231 insertions(+), 250 deletions(-) diff --git a/README.md b/README.md index 7748621f1..10c8d62ea 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ public void MyComponent_Validate_ShouldThrowNotSupportedExceptionIfTestingIsNotA catch (NotSupportedException ex) { // Assert - Assert.AreEqual("We can't go on together. It's not me, it's you.", ex.Message); + Assert.That(ex.Message, Is.EqualTo("We can't go on together. It's not me, it's you.")); return; } diff --git a/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj b/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj index 5162cf0e1..38d0c1037 100644 --- a/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj +++ b/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj @@ -10,6 +10,7 @@ + diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryArgumentPathTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryArgumentPathTests.cs index d76e2d08f..8ef9f5b21 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryArgumentPathTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryArgumentPathTests.cs @@ -39,7 +39,7 @@ public void Operations_ShouldThrowArgumentNullExceptionIfPathIsNull(Action(wrapped); - Assert.AreEqual("path", exception.ParamName); + Assert.That(exception.ParamName, Is.EqualTo("path")); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoSymlinkTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoSymlinkTests.cs index 77d5a52cd..56b463cf0 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoSymlinkTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoSymlinkTests.cs @@ -23,7 +23,7 @@ public void MockDirectoryInfo_ResolveLinkTarget_ShouldReturnPathOfTargetLink() var result = fileSystem.DirectoryInfo.New("foo").ResolveLinkTarget(false); - Assert.AreEqual("bar", result.Name); + Assert.That(result.Name, Is.EqualTo("bar")); } [Test] @@ -36,7 +36,7 @@ public void MockDirectoryInfo_ResolveLinkTarget_WithFinalTarget_ShouldReturnPath var result = fileSystem.DirectoryInfo.New("foo1").ResolveLinkTarget(true); - Assert.AreEqual("bar", result.Name); + Assert.That(result.Name, Is.EqualTo("bar")); } [Test] @@ -49,7 +49,7 @@ public void MockDirectoryInfo_ResolveLinkTarget_WithoutFinalTarget_ShouldReturnF var result = fileSystem.DirectoryInfo.New("foo1").ResolveLinkTarget(false); - Assert.AreEqual("foo", result.Name); + Assert.That(result.Name, Is.EqualTo("foo")); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs index cb279d043..21e6c1f72 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs @@ -30,7 +30,7 @@ public void MockDirectoryInfo_GetExtension_ShouldReturnEmptyString(string direct var result = directoryInfo.Extension; // Assert - Assert.AreEqual(string.Empty, result); + Assert.That(result, Is.Empty); } public static IEnumerable MockDirectoryInfo_Exists_Cases @@ -106,7 +106,7 @@ public void MockDirectoryInfo_GetFiles_ShouldWorkWithUNCPath() var files = directoryInfo.GetFiles(); // Assert - Assert.AreEqual(fileName, files[0].FullName); + Assert.That(files[0].FullName, Is.EqualTo(fileName)); } [Test] @@ -129,7 +129,7 @@ public void MockDirectoryInfo_GetFiles_ShouldWorkWithUNCPath_WhenCurrentDirector var files = directoryInfo.GetFiles(); // Assert - Assert.AreEqual(fileName, files[0].FullName); + Assert.That(files[0].FullName, Is.EqualTo(fileName)); } [Test] @@ -263,7 +263,7 @@ public void MockDirectoryInfo_GetParent_ShouldReturnDirectoriesAndNamesWithSearc var result = directoryInfo.Parent; // Assert - Assert.AreEqual(XFS.Path(@"c:\a\b"), result.FullName); + Assert.That(result.FullName, Is.EqualTo(XFS.Path(@"c:\a\b"))); } [Test] @@ -287,7 +287,7 @@ public void MockDirectoryInfo_EnumerateFiles_ShouldReturnAllFiles() var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\temp\folder")); // Assert - Assert.AreEqual(new[] { "b.txt", "c.txt" }, directoryInfo.EnumerateFiles().ToList().Select(x => x.Name).ToArray()); + Assert.That(directoryInfo.EnumerateFiles().ToList().Select(x => x.Name).ToArray(), Is.EqualTo(new[] { "b.txt", "c.txt" })); } [Test] @@ -309,7 +309,7 @@ public void MockDirectoryInfo_EnumerateDirectories_ShouldReturnAllDirectories() var directories = directoryInfo.EnumerateDirectories().Select(a => a.Name).ToArray(); // Assert - Assert.AreEqual(new[] { "b", "c" }, directories); + Assert.That(directories, Is.EqualTo(new[] { "b", "c" })); } [TestCase(@"\\unc\folder", @"\\unc\folder")] @@ -327,7 +327,7 @@ public void MockDirectoryInfo_FullName_ShouldReturnNormalizedUNCPath(string dire var actualFullName = directoryInfo.FullName; // Assert - Assert.AreEqual(expectedFullName, actualFullName); + Assert.That(actualFullName, Is.EqualTo(expectedFullName)); } [TestCase(@"c:\temp\\folder", @"c:\temp\folder")] @@ -345,7 +345,7 @@ public void MockDirectoryInfo_FullName_ShouldReturnNormalizedPath(string directo var actualFullName = directoryInfo.FullName; // Assert - Assert.AreEqual(expectedFullName, actualFullName); + Assert.That(actualFullName, Is.EqualTo(expectedFullName)); } [TestCase(@"c:\temp\folder ", @"c:\temp\folder")] @@ -360,7 +360,7 @@ public void MockDirectoryInfo_FullName_ShouldReturnPathWithTrimmedTrailingSpaces var actualFullName = directoryInfo.FullName; // Assert - Assert.AreEqual(expectedFullName, actualFullName); + Assert.That(actualFullName, Is.EqualTo(expectedFullName)); } [Test] @@ -377,7 +377,7 @@ public void MockDirectoryInfo_MoveTo_ShouldUpdateFullName() directoryInfo.MoveTo(destination); // Assert - Assert.AreEqual(destination, directoryInfo.FullName); + Assert.That(directoryInfo.FullName, Is.EqualTo(destination)); } [TestCase(@"c:\temp\\folder ", @"folder")] @@ -392,7 +392,7 @@ public void MockDirectoryInfo_Name_ShouldReturnNameWithTrimmedTrailingSpaces(str var actualName = directoryInfo.Name; // Assert - Assert.AreEqual(expectedName, actualName); + Assert.That(actualName, Is.EqualTo(expectedName)); } [TestCase(@"c:\", @"c:\")] @@ -407,7 +407,7 @@ public void MockDirectoryInfo_Name_ShouldReturnPathRoot_IfDirectoryPathIsPathRoo var actualName = directoryInfo.Name; // Assert - Assert.AreEqual(expectedName, actualName); + Assert.That(actualName, Is.EqualTo(expectedName)); } [Test] @@ -462,7 +462,7 @@ public void MockDirectoryInfo_ToString_ShouldReturnDirectoryName(string director var mockDirectoryInfo = new MockDirectoryInfo(new MockFileSystem(), directoryPath); // Assert - Assert.AreEqual(directoryPath, mockDirectoryInfo.ToString()); + Assert.That(mockDirectoryInfo.ToString(), Is.EqualTo(directoryPath)); } [Test] @@ -582,7 +582,7 @@ public void MockDirectoryInfo_LastAccessTime_ShouldReflectChangedValue() directoryInfo.LastAccessTime = lastAccessTime; // Assert - Assert.AreEqual(lastAccessTime, directoryInfo.LastAccessTime); + Assert.That(directoryInfo.LastAccessTime, Is.EqualTo(lastAccessTime)); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs index c751ef546..0267af172 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs @@ -23,8 +23,8 @@ public void MockDirectory_CreateSymbolicLink_ShouldReturnFileSystemInfo() IFileSystemInfo fileSystemInfo = fileSystem.Directory.CreateSymbolicLink(path, pathToTarget); // Assert - Assert.AreEqual(path, fileSystemInfo.FullName); - Assert.AreEqual(pathToTarget, fileSystemInfo.LinkTarget); + Assert.That(fileSystemInfo.FullName, Is.EqualTo(path)); + Assert.That(fileSystemInfo.LinkTarget, Is.EqualTo(pathToTarget)); } [Test] @@ -41,8 +41,8 @@ public void MockDirectory_CreateSymbolicLink_ShouldSucceedFromDirectoryInfo() IDirectoryInfo directoryInfo = fileSystem.DirectoryInfo.New(path); // Assert - Assert.AreEqual(path, directoryInfo.FullName); - Assert.AreEqual(pathToTarget, directoryInfo.LinkTarget); + Assert.That(directoryInfo.FullName, Is.EqualTo(path)); + Assert.That(directoryInfo.LinkTarget, Is.EqualTo(pathToTarget)); } [Test] @@ -221,7 +221,7 @@ public void MockDirectory_ResolveLinkTarget_ShouldReturnPathOfTargetLink() var result = fileSystem.Directory.ResolveLinkTarget("foo", false); - Assert.AreEqual("bar", result.Name); + Assert.That(result.Name, Is.EqualTo("bar")); } [Test] @@ -242,7 +242,7 @@ public void MockDirectory_ResolveLinkTarget_WithFinalTarget_ShouldReturnPathOfTa var result = fileSystem.Directory.ResolveLinkTarget(previousPath, true); - Assert.AreEqual("bar", result.Name); + Assert.That(result.Name, Is.EqualTo("bar")); } [Test] @@ -275,7 +275,7 @@ public void MockDirectory_ResolveLinkTarget_WithoutFinalTarget_ShouldReturnFirst var result = fileSystem.Directory.ResolveLinkTarget("foo1", false); - Assert.AreEqual("foo", result.Name); + Assert.That(result.Name, Is.EqualTo("foo")); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 10422c1e4..23735595e 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -1030,9 +1030,9 @@ public void MockDirectory_GetFileSystemEntries_Returns_Files_And_Directories() }); var entries = fileSystem.Directory.GetFileSystemEntries(XFS.Path(@"c:\foo")).OrderBy(k => k); - Assert.AreEqual(2, entries.Count()); - Assert.AreEqual(testDir, entries.First()); - Assert.AreEqual(testPath, entries.Last()); + Assert.That(entries.Count(), Is.EqualTo(2)); + Assert.That(entries.First(), Is.EqualTo(testDir)); + Assert.That(entries.Last(), Is.EqualTo(testPath)); } [Test] @@ -1048,9 +1048,9 @@ public void MockDirectory_GetFileSystemEntries_ShouldNotReturnSubDirectory_WithS }); var entries = fileSystem.Directory.GetFileSystemEntries(XFS.Path(@"c:\foo"), "*", SearchOption.TopDirectoryOnly).OrderBy(k => k); - Assert.AreEqual(2, entries.Count()); - Assert.AreEqual(testDir, entries.First()); - Assert.AreEqual(testPath, entries.Last()); + Assert.That(entries.Count(), Is.EqualTo(2)); + Assert.That(entries.First(), Is.EqualTo(testDir)); + Assert.That(entries.Last(), Is.EqualTo(testPath)); } [Test] @@ -1087,8 +1087,8 @@ public void MockDirectory_GetFiles_Returns_Files() }); var entries = fileSystem.Directory.GetFiles(XFS.Path(@"c:\foo")).OrderBy(k => k); - Assert.AreEqual(1, entries.Count()); - Assert.AreEqual(testPath, entries.First()); + Assert.That(entries.Count(), Is.EqualTo(1)); + Assert.That(entries.First(), Is.EqualTo(testPath)); } [Test] @@ -1102,7 +1102,7 @@ public void MockDirectory_GetFiles_Returns_Files_WithRelativePath() fileSystem.Directory.SetCurrentDirectory(directory); fileSystem.AddFile(XFS.Path(@"C:\test.txt"), new MockFileData("Some ASCII text.")); - Assert.AreEqual(fileSystem.Directory.GetFiles(XFS.Path(@"..\")).Length, 1); // Assert with relative path + Assert.That(fileSystem.Directory.GetFiles(XFS.Path(@"..\")).Length, Is.EqualTo(1)); // Assert with relative path } [Test] @@ -1211,7 +1211,7 @@ public void MockDirectory_GetRoot_Returns_Root() { testDir, new MockDirectoryData() } }); - Assert.AreEqual(XFS.Path("C:\\"), fileSystem.Directory.GetDirectoryRoot(XFS.Path(@"C:\foo\bar"))); + Assert.That(fileSystem.Directory.GetDirectoryRoot(XFS.Path(@"C:\foo\bar")), Is.EqualTo(XFS.Path("C:\\"))); } [Test] @@ -1228,12 +1228,12 @@ public void MockDirectory_GetLogicalDrives_Returns_LogicalDrives() if (XFS.IsUnixPlatform()) { - Assert.AreEqual(1, drives.Length); + Assert.That(drives.Length, Is.EqualTo(1)); Assert.IsTrue(drives.Contains("/")); } else { - Assert.AreEqual(2, drives.Length); + Assert.That(drives.Length, Is.EqualTo(2)); Assert.IsTrue(drives.Contains(@"C:\")); Assert.IsTrue(drives.Contains(@"D:\")); } @@ -1254,7 +1254,7 @@ public void MockDirectory_GetDirectories_Returns_Child_Directories() Assert.IsFalse(directories.Contains(XFS.Path(@"A:\folder1"))); //Check that it correctly returns all child directories - Assert.AreEqual(2, directories.Count()); + Assert.That(directories.Count(), Is.EqualTo(2)); Assert.IsTrue(directories.Contains(XFS.Path(@"A:\folder1\folder2"))); Assert.IsTrue(directories.Contains(XFS.Path(@"A:\folder1\folder4"))); } @@ -1398,7 +1398,7 @@ public void MockDirectory_EnumerateDirectories_Returns_Child_Directories() Assert.IsFalse(directories.Contains(XFS.Path(@"A:\folder1"))); //Check that it correctly returns all child directories - Assert.AreEqual(2, directories.Count()); + Assert.That(directories.Count(), Is.EqualTo(2)); Assert.IsTrue(directories.Contains(XFS.Path(@"A:\folder1\folder2"))); Assert.IsTrue(directories.Contains(XFS.Path(@"A:\folder1\folder4"))); } @@ -1652,7 +1652,7 @@ public void MockDirectory_GetCurrentDirectory_ShouldReturnValueFromFileSystemCon var actual = fileSystem.Directory.GetCurrentDirectory(); - Assert.AreEqual(directory, actual); + Assert.That(actual, Is.EqualTo(directory)); } [Test] @@ -1664,7 +1664,7 @@ public void MockDirectory_GetCurrentDirectory_ShouldReturnDefaultPathWhenNotSet( var actual = fileSystem.Directory.GetCurrentDirectory(); - Assert.AreEqual(directory, actual); + Assert.That(actual, Is.EqualTo(directory)); } [Test] @@ -1678,7 +1678,7 @@ public void MockDirectory_SetCurrentDirectory_ShouldChangeCurrentDirectory() fileSystem.Directory.SetCurrentDirectory(directory); - Assert.AreEqual(directory, fileSystem.Directory.GetCurrentDirectory()); + Assert.That(fileSystem.Directory.GetCurrentDirectory(), Is.EqualTo(directory)); } [Test] @@ -1771,7 +1771,7 @@ public void MockDirectory_GetParent_ShouldReturnRootIfDirectoryIsInRoot() var parent = fileSystem.Directory.GetParent("/bar"); // Assert - Assert.AreEqual("/", parent.FullName); + Assert.That(parent.FullName, Is.EqualTo("/")); } public static IEnumerable MockDirectory_GetParent_Cases @@ -1794,7 +1794,7 @@ public void MockDirectory_GetParent_ShouldReturnTheParentWithoutTrailingDirector var actualResult = fileSystem.Directory.GetParent(path); // Assert - Assert.AreEqual(expectedResult, actualResult.FullName); + Assert.That(actualResult.FullName, Is.EqualTo(expectedResult)); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoTests.cs index 81731f570..5b95cea13 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoTests.cs @@ -21,7 +21,7 @@ public void MockDriveInfo_Constructor_ShouldInitializeLocalWindowsDrives(string var driveInfo = new MockDriveInfo(fileSystem, path); // Assert - Assert.AreEqual(@"c:\", driveInfo.Name); + Assert.That(driveInfo.Name, Is.EqualTo(@"c:\")); } [Test] @@ -35,7 +35,7 @@ public void MockDriveInfo_Constructor_ShouldInitializeLocalWindowsDrives_Special var driveInfo = new MockDriveInfo(fileSystem, "c"); // Assert - Assert.AreEqual(@"c:\", driveInfo.Name); + Assert.That(driveInfo.Name, Is.EqualTo(@"c:\")); } [TestCase(@"\\unc\share")] @@ -65,7 +65,7 @@ public void MockDriveInfo_RootDirectory_ShouldReturnTheDirectoryBase() var actualDirectory = driveInfo.RootDirectory; // Assert - Assert.AreEqual(expectedDirectory, actualDirectory.FullName); + Assert.That(actualDirectory.FullName, Is.EqualTo(expectedDirectory)); } [TestCase("c:", "c:\\")] @@ -82,7 +82,7 @@ public void MockDriveInfo_ToString_ShouldReturnTheDrivePath(string path, string var mockDriveInfo = new MockDriveInfo(new MockFileSystem(), directoryPath); // Assert - Assert.AreEqual(expectedPath, mockDriveInfo.ToString()); + Assert.That(mockDriveInfo.ToString(), Is.EqualTo(expectedPath)); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllLinesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllLinesTests.cs index 778a31f28..0ebc61b94 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllLinesTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllLinesTests.cs @@ -24,9 +24,8 @@ public void MockFile_AppendAllLines_ShouldPersistNewLinesToExistingFile() file.AppendAllLines(path, new[] { "line 1", "line 2", "line 3" }); // Assert - Assert.AreEqual( - "Demo text contentline 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine, - file.ReadAllText(path)); + Assert.That(file.ReadAllText(path), + Is.EqualTo("Demo text contentline 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine)); } [Test] @@ -44,9 +43,8 @@ public void MockFile_AppendAllLines_ShouldPersistNewLinesToNewFile() file.AppendAllLines(path, new[] { "line 1", "line 2", "line 3" }); // Assert - Assert.AreEqual( - "line 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine, - file.ReadAllText(path)); + Assert.That(file.ReadAllText(path), + Is.EqualTo("line 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine)); } [Test] @@ -138,9 +136,8 @@ public async Task MockFile_AppendAllLinesAsync_ShouldPersistNewLinesToExistingFi await file.AppendAllLinesAsync(path, new[] { "line 1", "line 2", "line 3" }); // Assert - Assert.AreEqual( - "Demo text contentline 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine, - file.ReadAllText(path)); + Assert.That(file.ReadAllText(path), + Is.EqualTo("Demo text contentline 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine)); } [Test] @@ -158,10 +155,8 @@ public async Task MockFile_AppendAllLinesAsync_ShouldPersistNewLinesToNewFile() await file.AppendAllLinesAsync(path, new[] { "line 1", "line 2", "line 3" }); // Assert - Assert.AreEqual( - "line 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine, - file.ReadAllText(path) - ); + Assert.That(file.ReadAllText(path), + Is.EqualTo("line 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine)); } [Test] @@ -183,7 +178,7 @@ await fileSystem.File.AppendAllLinesAsync( ); // Assert - Assert.AreEqual("line 1", fileSystem.File.ReadAllText(path)); + Assert.That(fileSystem.File.ReadAllText(path), Is.EqualTo("line 1")); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllTextTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllTextTests.cs index 05e3cee4d..6f0fe41a2 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllTextTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllTextTests.cs @@ -30,9 +30,8 @@ public void MockFile_AppendAllText_ShouldPersistNewText() file.AppendAllText(path, "+ some text"); // Assert - Assert.AreEqual( - "Demo text content+ some text", - file.ReadAllText(path)); + Assert.That(file.ReadAllText(path), + Is.EqualTo("Demo text content+ some text")); } [Test] @@ -70,9 +69,8 @@ public void MockFile_AppendAllText_ShouldCreateIfNotExist() fileSystem.File.AppendAllText(path, " some text"); // Assert - Assert.AreEqual( - "Demo text content some text", - fileSystem.File.ReadAllText(path)); + Assert.That(fileSystem.File.ReadAllText(path), + Is.EqualTo("Demo text content some text")); } [Test] @@ -174,9 +172,8 @@ public async Task MockFile_AppendAllTextAsync_ShouldPersistNewText() await file.AppendAllTextAsync(path, "+ some text"); // Assert - Assert.AreEqual( - "Demo text content+ some text", - file.ReadAllText(path)); + Assert.That(file.ReadAllText(path), + Is.EqualTo("Demo text content+ some text")); } [Test] @@ -198,7 +195,7 @@ await fileSystem.File.AppendAllTextAsync( ); // Assert - Assert.AreEqual("line 1", fileSystem.File.ReadAllText(path)); + Assert.That(fileSystem.File.ReadAllText(path), Is.EqualTo("line 1")); } [Test] @@ -236,9 +233,8 @@ public async Task MockFile_AppendAllTextAsync_ShouldCreateIfNotExist() await fileSystem.File.AppendAllTextAsync(path, " some text"); // Assert - Assert.AreEqual( - "Demo text content some text", - fileSystem.File.ReadAllText(path)); + Assert.That(fileSystem.File.ReadAllText(path), + Is.EqualTo("Demo text content some text")); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileArgumentPathTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileArgumentPathTests.cs index 307a8404f..c41d9871f 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileArgumentPathTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileArgumentPathTests.cs @@ -66,7 +66,7 @@ public void Operations_ShouldThrowArgumentNullExceptionIfPathIsNull(Action(wrapped); - Assert.AreEqual("path", exception.ParamName); + Assert.That(exception.ParamName, Is.EqualTo("path")); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs index 8dd4b2e47..e0ca5d31b 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs @@ -24,7 +24,7 @@ public void MockFile_Copy_ShouldOverwriteFileWhenOverwriteFlagIsTrue() fileSystem.File.Copy(sourceFileName, destFileName, true); var copyResult = fileSystem.GetFile(destFileName); - Assert.AreEqual(copyResult.Contents, sourceContents.Contents); + Assert.That(sourceContents.Contents, Is.EqualTo(copyResult.Contents)); } [Test] @@ -39,9 +39,9 @@ public void MockFile_Copy_ShouldAdjustTimestampsOnDestination() var sourceFileInfo = mockFileSystem.FileInfo.New(sourceFileName); var destFileInfo = mockFileSystem.FileInfo.New(destFileName); - Assert.AreEqual(sourceFileInfo.LastWriteTime, destFileInfo.LastWriteTime); + Assert.That(destFileInfo.LastWriteTime, Is.EqualTo(sourceFileInfo.LastWriteTime)); Assert.LessOrEqual(DateTime.Now - destFileInfo.CreationTime, TimeSpan.FromSeconds(1)); - Assert.AreEqual(destFileInfo.CreationTime, destFileInfo.LastAccessTime); + Assert.That(destFileInfo.LastAccessTime, Is.EqualTo(destFileInfo.CreationTime)); } [Test] @@ -62,7 +62,7 @@ public void MockFile_Copy_ShouldCloneContents() binaryWriter.Write("Modified"); } - Assert.AreEqual("Original", mockFileSystem.File.ReadAllText(destFileName)); + Assert.That(mockFileSystem.File.ReadAllText(destFileName), Is.EqualTo("Original")); } [Test] @@ -101,7 +101,7 @@ public void MockFile_Copy_ShouldCreateFileAtNewDestination() fileSystem.File.Copy(sourceFileName, destFileName, false); var copyResult = fileSystem.GetFile(destFileName); - Assert.AreEqual(copyResult.Contents, sourceContents.Contents); + Assert.That(sourceContents.Contents, Is.EqualTo(copyResult.Contents)); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileDeleteTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileDeleteTests.cs index 505148987..6fbbd6fe5 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileDeleteTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileDeleteTests.cs @@ -19,8 +19,8 @@ public void MockFile_Delete_ShouldDeleteFile() fileSystem.File.Delete(path); var fileCount2 = fileSystem.Directory.GetFiles(directory, "*").Length; - Assert.AreEqual(1, fileCount1, "File should have existed"); - Assert.AreEqual(0, fileCount2, "File should have been deleted"); + Assert.That(fileCount1, Is.EqualTo(1), "File should have existed"); + Assert.That(fileCount2, Is.EqualTo(0), "File should have been deleted"); } [TestCase(" ")] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeTests.cs index 1d213924d..c4f838cf5 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeTests.cs @@ -30,7 +30,7 @@ public void MockFile_GetCreationTime_ShouldReturnDefaultTimeIfFileDoesNotExist() var actualCreationTime = fileSystem.File.GetCreationTime(@"c:\does\not\exist.txt"); // Assert - Assert.AreEqual(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc).ToLocalTime(), actualCreationTime); + Assert.That(actualCreationTime, Is.EqualTo(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc).ToLocalTime())); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeUtcTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeUtcTests.cs index 30cb6e1d5..54297f7ba 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeUtcTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeUtcTests.cs @@ -30,7 +30,7 @@ public void MockFile_GetCreationTimeUtc_ShouldReturnDefaultTimeIfFileDoesNotExis var actualCreationTime = fileSystem.File.GetCreationTimeUtc(@"c:\does\not\exist.txt"); // Assert - Assert.AreEqual(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc), actualCreationTime); + Assert.That(actualCreationTime, Is.EqualTo(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc))); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeTests.cs index fbf3ef09f..ecf7de168 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeTests.cs @@ -30,7 +30,7 @@ public void MockFile_GetLastAccessTime_ShouldReturnDefaultTimeIfFileDoesNotExist var actualLastAccessTime = fileSystem.File.GetLastAccessTime(@"c:\does\not\exist.txt"); // Assert - Assert.AreEqual(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc).ToLocalTime(), actualLastAccessTime); + Assert.That(actualLastAccessTime, Is.EqualTo(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc).ToLocalTime())); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeUtcTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeUtcTests.cs index c42bc6c44..dba0ba8c3 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeUtcTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeUtcTests.cs @@ -30,7 +30,7 @@ public void MockFile_GetLastAccessTimeUtc_ShouldReturnDefaultTimeIfFileDoesNotEx var actualLastAccessTime = fileSystem.File.GetLastAccessTimeUtc(@"c:\does\not\exist.txt"); // Assert - Assert.AreEqual(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc), actualLastAccessTime); + Assert.That(actualLastAccessTime, Is.EqualTo(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc))); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeTests.cs index 5ceaf25f7..90bb617a9 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeTests.cs @@ -30,7 +30,7 @@ public void MockFile_GetLastWriteTime_ShouldReturnDefaultTimeIfFileDoesNotExist( var actualLastWriteTime = fileSystem.File.GetLastWriteTime(@"c:\does\not\exist.txt"); // Assert - Assert.AreEqual(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc).ToLocalTime(), actualLastWriteTime); + Assert.That(actualLastWriteTime, Is.EqualTo(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc).ToLocalTime())); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeUtcTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeUtcTests.cs index 4783e7e7f..eac18ff9b 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeUtcTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeUtcTests.cs @@ -29,7 +29,7 @@ public void MockFile_GetLastWriteTimeUtc_ShouldReturnDefaultTimeIfFileDoesNotExi var actualLastWriteTime = fileSystem.File.GetLastWriteTimeUtc(@"c:\does\not\exist.txt"); // Assert - Assert.AreEqual(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc), actualLastWriteTime); + Assert.That(actualLastWriteTime, Is.EqualTo(new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc))); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoSymlinkTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoSymlinkTests.cs index d3eae0faa..9273599a4 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoSymlinkTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoSymlinkTests.cs @@ -23,7 +23,7 @@ public void MockFileInfo_ResolveLinkTarget_ShouldReturnPathOfTargetLink() var result = fileSystem.FileInfo.New("foo").ResolveLinkTarget(false); - Assert.AreEqual("bar", result.Name); + Assert.That(result.Name, Is.EqualTo("bar")); } [Test] @@ -36,7 +36,7 @@ public void MockFileInfo_ResolveLinkTarget_WithFinalTarget_ShouldReturnPathOfTar var result = fileSystem.FileInfo.New("foo1").ResolveLinkTarget(true); - Assert.AreEqual("bar", result.Name); + Assert.That(result.Name, Is.EqualTo("bar")); } [Test] @@ -49,7 +49,7 @@ public void MockFileInfo_ResolveLinkTarget_WithoutFinalTarget_ShouldReturnFirstL var result = fileSystem.FileInfo.New("foo1").ResolveLinkTarget(false); - Assert.AreEqual("foo", result.Name); + Assert.That(result.Name, Is.EqualTo("foo")); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs index 60f6062d0..ff3928903 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs @@ -77,7 +77,7 @@ public void MockFileInfo_Length_ShouldReturnLengthOfFileInMemoryFileSystem() var result = fileInfo.Length; - Assert.AreEqual(fileContent.Length, result); + Assert.That(result, Is.EqualTo(fileContent.Length)); } [Test] @@ -93,7 +93,7 @@ public void MockFileInfo_Length_ShouldThrowFileNotFoundExceptionIfFileDoesNotExi var ex = Assert.Throws(() => fileInfo.Length.ToString(CultureInfo.InvariantCulture)); - Assert.AreEqual(XFS.Path(@"c:\foo.txt"), ex.FileName); + Assert.That(ex.FileName, Is.EqualTo(XFS.Path(@"c:\foo.txt"))); } [Test] @@ -108,7 +108,7 @@ public void MockFileInfo_Length_ShouldThrowFileNotFoundExceptionIfPathLeadsToDir var ex = Assert.Throws(() => fileInfo.Length.ToString(CultureInfo.InvariantCulture)); - Assert.AreEqual(XFS.Path(@"c:\a\b"), ex.FileName); + Assert.That(ex.FileName, Is.EqualTo(XFS.Path(@"c:\a\b"))); } [Test] @@ -124,7 +124,7 @@ public void MockFileInfo_CreationTimeUtc_ShouldReturnCreationTimeUtcOfFileInMemo var result = fileInfo.CreationTimeUtc; - Assert.AreEqual(creationTime.ToUniversalTime(), result); + Assert.That(result, Is.EqualTo(creationTime.ToUniversalTime())); } [Test] @@ -135,7 +135,7 @@ public void MockFileInfo_CreationTimeUtc_ShouldReturnDefaultTimeForNonExistingFi var result = fileInfo.CreationTimeUtc; - Assert.AreEqual(MockFileData.DefaultDateTimeOffset.UtcDateTime, result); + Assert.That(result, Is.EqualTo(MockFileData.DefaultDateTimeOffset.UtcDateTime)); } [Test] @@ -152,7 +152,7 @@ public void MockFileInfo_CreationTimeUtc_ShouldSetCreationTimeUtcOfFileInMemoryF var newUtcTime = DateTime.UtcNow; fileInfo.CreationTimeUtc = newUtcTime; - Assert.AreEqual(newUtcTime, fileInfo.CreationTimeUtc); + Assert.That(fileInfo.CreationTimeUtc, Is.EqualTo(newUtcTime)); } @@ -169,7 +169,7 @@ public void MockFileInfo_CreationTime_ShouldReturnCreationTimeOfFileInMemoryFile var result = fileInfo.CreationTime; - Assert.AreEqual(creationTime, result); + Assert.That(result, Is.EqualTo(creationTime)); } [Test] @@ -180,7 +180,7 @@ public void MockFileInfo_CreationTime_ShouldReturnDefaultTimeForNonExistingFile( var result = fileInfo.CreationTime; - Assert.AreEqual(MockFileData.DefaultDateTimeOffset.LocalDateTime, result); + Assert.That(result, Is.EqualTo(MockFileData.DefaultDateTimeOffset.LocalDateTime)); } [Test] @@ -197,7 +197,7 @@ public void MockFileInfo_CreationTime_ShouldSetCreationTimeOfFileInMemoryFileSys fileInfo.CreationTime = newTime; - Assert.AreEqual(newTime, fileInfo.CreationTime); + Assert.That(fileInfo.CreationTime, Is.EqualTo(newTime)); } [Test] @@ -231,7 +231,7 @@ public void MockFileInfo_IsReadOnly_ShouldSetReadOnlyAttributeOfFileInMemoryFile fileInfo.IsReadOnly = true; - Assert.AreEqual(FileAttributes.ReadOnly, fileData.Attributes & FileAttributes.ReadOnly); + Assert.That(fileData.Attributes & FileAttributes.ReadOnly, Is.EqualTo(FileAttributes.ReadOnly)); } [Test] @@ -268,7 +268,7 @@ public void MockFileInfo_AppendText_ShouldAddTextToFileInMemoryFileSystem() newcontents = newfile.ReadToEnd(); } - Assert.AreEqual($"Demo text contentThis should be at the end{Environment.NewLine}", newcontents); + Assert.That(newcontents, Is.EqualTo($"Demo text contentThis should be at the end{Environment.NewLine}")); } [Test] @@ -288,7 +288,7 @@ public void MockFileInfo_AppendText_ShouldCreateFileIfMissing() } Assert.That(fileSystem.File.Exists(targetFile), Is.True); - Assert.AreEqual($"This should be the contents{Environment.NewLine}", newcontents); + Assert.That(newcontents, Is.EqualTo($"This should be the contents{Environment.NewLine}")); } [Test] @@ -314,7 +314,7 @@ public void MockFileInfo_OpenWrite_ShouldAddDataToFileInMemoryFileSystem() newcontents = newfile.ReadToEnd(); } - Assert.AreEqual("ABCDEtext content", newcontents); + Assert.That(newcontents, Is.EqualTo("ABCDEtext content")); } [Test] @@ -329,7 +329,7 @@ public void MockFileInfo_Encrypt_ShouldSetEncryptedAttributeOfFileInMemoryFileSy fileInfo.Encrypt(); - Assert.AreEqual(FileAttributes.Encrypted, fileData.Attributes & FileAttributes.Encrypted); + Assert.That(fileData.Attributes & FileAttributes.Encrypted, Is.EqualTo(FileAttributes.Encrypted)); } [Test] @@ -361,7 +361,7 @@ public void MockFileInfo_LastAccessTimeUtc_ShouldReturnLastAccessTimeUtcOfFileIn var result = fileInfo.LastAccessTimeUtc; - Assert.AreEqual(lastAccessTime.ToUniversalTime(), result); + Assert.That(result, Is.EqualTo(lastAccessTime.ToUniversalTime())); } [Test] @@ -372,7 +372,7 @@ public void MockFileInfo_LastAccessTimeUtc_ShouldReturnDefaultTimeForNonExisting var result = fileInfo.LastAccessTimeUtc; - Assert.AreEqual(MockFileData.DefaultDateTimeOffset.UtcDateTime, result); + Assert.That(result, Is.EqualTo(MockFileData.DefaultDateTimeOffset.UtcDateTime)); } [Test] @@ -389,7 +389,7 @@ public void MockFileInfo_LastAccessTimeUtc_ShouldSetCreationTimeUtcOfFileInMemor var newUtcTime = DateTime.UtcNow; fileInfo.LastAccessTimeUtc = newUtcTime; - Assert.AreEqual(newUtcTime, fileInfo.LastAccessTimeUtc); + Assert.That(fileInfo.LastAccessTimeUtc, Is.EqualTo(newUtcTime)); } [Test] @@ -400,7 +400,7 @@ public void MockFileInfo_LastWriteTime_ShouldReturnDefaultTimeForNonExistingFile var result = fileInfo.LastWriteTime; - Assert.AreEqual(MockFileData.DefaultDateTimeOffset.LocalDateTime, result); + Assert.That(result, Is.EqualTo(MockFileData.DefaultDateTimeOffset.LocalDateTime)); } [Test] @@ -416,7 +416,7 @@ public void MockFileInfo_LastWriteTimeUtc_ShouldReturnLastWriteTimeUtcOfFileInMe var result = fileInfo.LastWriteTimeUtc; - Assert.AreEqual(lastWriteTime.ToUniversalTime(), result); + Assert.That(result, Is.EqualTo(lastWriteTime.ToUniversalTime())); } [Test] @@ -427,7 +427,7 @@ public void MockFileInfo_LastWriteTimeUtc_ShouldReturnDefaultTimeForNonExistingF var result = fileInfo.LastWriteTimeUtc; - Assert.AreEqual(MockFileData.DefaultDateTimeOffset.UtcDateTime, result); + Assert.That(result, Is.EqualTo(MockFileData.DefaultDateTimeOffset.UtcDateTime)); } [Test] @@ -444,7 +444,7 @@ public void MockFileInfo_LastWriteTimeUtc_ShouldSetLastWriteTimeUtcOfFileInMemor var newUtcTime = DateTime.UtcNow; fileInfo.LastWriteTimeUtc = newUtcTime; - Assert.AreEqual(newUtcTime, fileInfo.LastWriteTimeUtc); + Assert.That(fileInfo.LastWriteTimeUtc, Is.EqualTo(newUtcTime)); } [Test] @@ -455,7 +455,7 @@ public void MockFileInfo_GetExtension_ShouldReturnExtension() var result = fileInfo.Extension; - Assert.AreEqual(".txt", result); + Assert.That(result, Is.EqualTo(".txt")); } [Test] @@ -466,7 +466,7 @@ public void MockFileInfo_GetExtensionWithoutExtension_ShouldReturnEmptyString() var result = fileInfo.Extension; - Assert.AreEqual(string.Empty, result); + Assert.That(result, Is.Empty); } [Test] @@ -476,7 +476,7 @@ public void MockFileInfo_GetDirectoryName_ShouldReturnCompleteDirectoryPath() var result = fileInfo.DirectoryName; - Assert.AreEqual(XFS.Path(@"c:\temp\level1\level2"), result); + Assert.That(result, Is.EqualTo(XFS.Path(@"c:\temp\level1\level2"))); } [Test] @@ -486,7 +486,7 @@ public void MockFileInfo_GetDirectory_ShouldReturnDirectoryInfoWithCorrectPath() var result = fileInfo.Directory; - Assert.AreEqual(XFS.Path(@"c:\temp\level1\level2"), result.FullName); + Assert.That(result.FullName, Is.EqualTo(XFS.Path(@"c:\temp\level1\level2"))); } [Test] @@ -502,7 +502,7 @@ public void MockFileInfo_OpenRead_ShouldReturnByteContentOfFile() stream.Read(result, 0, 2); } - Assert.AreEqual(new byte[] { 1, 2 }, result); + Assert.That(result, Is.EqualTo(new byte[] { 1, 2 })); } [Test] @@ -518,7 +518,7 @@ public void MockFileInfo_OpenText_ShouldReturnStringContentOfFile() result = streamReader.ReadToEnd(); } - Assert.AreEqual(@"line 1\r\nline 2", result); + Assert.That(result, Is.EqualTo(@"line 1\r\nline 2")); } [Test] @@ -534,8 +534,8 @@ public void MockFileInfo_MoveTo_NonExistentDestination_ShouldUpdateFileInfoDirec fileInfo.MoveTo(destinationPath); - Assert.AreEqual(fileInfo.DirectoryName, destinationFolder); - Assert.AreEqual(fileInfo.FullName, destinationPath); + Assert.That(fileInfo.DirectoryName, Is.EqualTo(destinationFolder)); + Assert.That(fileInfo.FullName, Is.EqualTo(destinationPath)); } [Test] @@ -573,7 +573,7 @@ public void MockFileInfo_MoveTo_SameSourceAndTargetIsANoOp() fileInfo.MoveTo(destination); - Assert.AreEqual(fileInfo.FullName, destination); + Assert.That(fileInfo.FullName, Is.EqualTo(destination)); Assert.True(fileInfo.Exists); } @@ -635,7 +635,7 @@ public void MockFileInfo_MoveToOnlyCaseChanging_ShouldSucceed() var fileInfo = fileSystem.FileInfo.New(sourceFilePath); fileInfo.MoveTo(destFilePath); - Assert.AreEqual(fileInfo.FullName, destFilePath); + Assert.That(fileInfo.FullName, Is.EqualTo(destFilePath)); Assert.True(fileInfo.Exists); } @@ -664,7 +664,7 @@ public void MockFileInfo_ToString_ShouldReturnOriginalFilePath(string path) var mockFileInfo = new MockFileInfo(new MockFileSystem(), filePath); //Assert - Assert.AreEqual(filePath, mockFileInfo.ToString()); + Assert.That(mockFileInfo.ToString(), Is.EqualTo(filePath)); } @@ -682,7 +682,7 @@ public void New_Paths_NormalizePaths(string input, string expected) var result = mockFileInfo.FullName; // Assert - Assert.AreEqual(expected, result); + Assert.That(result, Is.EqualTo(expected)); } public static IEnumerable New_Paths_NormalizePaths_Cases @@ -711,7 +711,7 @@ public void MockFileInfo_Replace_ShouldReplaceFileContents() // Act fileInfo1.Replace(path2, null); - Assert.AreEqual("1", fileInfo2.OpenText().ReadToEnd()); + Assert.That(fileInfo2.OpenText().ReadToEnd(), Is.EqualTo("1")); } [Test] @@ -730,7 +730,7 @@ public void MockFileInfo_Replace_ShouldCreateBackup() // Act fileInfo1.Replace(path2, path3); - Assert.AreEqual("2", fileInfo3.OpenText().ReadToEnd()); + Assert.That(fileInfo3.OpenText().ReadToEnd(), Is.EqualTo("2")); } [Test] @@ -764,7 +764,7 @@ public void MockFileInfo_Replace_ShouldReturnDestinationFileInfo() // Act var result = fileInfo1.Replace(path2, null); - Assert.AreEqual(fileInfo2.FullName, result.FullName); + Assert.That(result.FullName, Is.EqualTo(fileInfo2.FullName)); } [Test] @@ -892,7 +892,7 @@ public void MockFileInfo_LastAccessTimeUtcWithUnspecifiedDateTimeKind_ShouldSetL LastAccessTimeUtc = date }; - Assert.AreEqual(date, fileInfo.LastAccessTimeUtc); + Assert.That(fileInfo.LastAccessTimeUtc, Is.EqualTo(date)); Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastAccessTimeUtc.Kind); } @@ -908,7 +908,7 @@ public void MockFileInfo_LastAccessTimeWithUnspecifiedDateTimeKind_ShouldSetLast LastAccessTime = date }; - Assert.AreEqual(date, fileInfo.LastAccessTime); + Assert.That(fileInfo.LastAccessTime, Is.EqualTo(date)); Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastAccessTime.Kind); } @@ -924,7 +924,7 @@ public void MockFileInfo_CreationTimeUtcWithUnspecifiedDateTimeKind_ShouldSetCre CreationTimeUtc = date }; - Assert.AreEqual(date, fileInfo.CreationTimeUtc); + Assert.That(fileInfo.CreationTimeUtc, Is.EqualTo(date)); Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.CreationTimeUtc.Kind); } @@ -940,7 +940,7 @@ public void MockFileInfo_CreationTimeWithUnspecifiedDateTimeKind_ShouldSetCreati CreationTime = date }; - Assert.AreEqual(date, fileInfo.CreationTime); + Assert.That(fileInfo.CreationTime, Is.EqualTo(date)); Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.CreationTime.Kind); } @@ -956,7 +956,7 @@ public void MockFileInfo_LastWriteTimeUtcWithUnspecifiedDateTimeKind_ShouldSetLa LastWriteTimeUtc = date }; - Assert.AreEqual(date, fileInfo.LastWriteTimeUtc); + Assert.That(fileInfo.LastWriteTimeUtc, Is.EqualTo(date)); Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastWriteTimeUtc.Kind); } @@ -972,7 +972,7 @@ public void MockFileInfo_LastWriteTimeWithUnspecifiedDateTimeKind_ShouldSetLastW LastWriteTime = date }; - Assert.AreEqual(date, fileInfo.LastWriteTime); + Assert.That(fileInfo.LastWriteTime, Is.EqualTo(date)); Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastWriteTime.Kind); } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs index fd83d5c54..9943ae963 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs @@ -207,7 +207,7 @@ public void MockFile_OpenText_ShouldRetainLastWriteTime() } // Assert - Assert.AreEqual(lastWriteTime, fs.FileInfo.New(filepath).LastWriteTime); + Assert.That(fs.FileInfo.New(filepath).LastWriteTime, Is.EqualTo(lastWriteTime)); } [Test] @@ -250,7 +250,7 @@ public void MockFile_Read_ShouldRetainCreationTimeAndUpdateLastAccessTime() stream.Read(buffer, 0, buffer.Length); fi.Refresh(); // Assert - Assert.AreEqual(creationTime, fi.CreationTime); + Assert.That(fi.CreationTime, Is.EqualTo(creationTime)); Assert.LessOrEqual(DateTime.Now - fi.LastAccessTime, TimeSpan.FromSeconds(1)); } @@ -273,7 +273,7 @@ public async Task MockFile_ReadAsync_ShouldRetainCreationTimeAndUpdateLastAccess await stream.ReadAsync(buffer, 0, buffer.Length); fi.Refresh(); // Assert - Assert.AreEqual(creationTime, fi.CreationTime); + Assert.That(fi.CreationTime, Is.EqualTo(creationTime)); Assert.LessOrEqual(DateTime.Now - fi.LastAccessTime, TimeSpan.FromSeconds(1)); } @@ -296,7 +296,7 @@ public void MockFile_Write_ShouldRetainCreationTimeAndUpdateLastAccessTimeAndLas stream.Write(buffer, 0, buffer.Length); fi.Refresh(); // Assert - Assert.AreEqual(creationTime, fi.CreationTime); + Assert.That(fi.CreationTime, Is.EqualTo(creationTime)); Assert.LessOrEqual(DateTime.Now - fi.LastAccessTime, TimeSpan.FromSeconds(1)); Assert.LessOrEqual(DateTime.Now - fi.LastWriteTime, TimeSpan.FromSeconds(1)); } @@ -320,7 +320,7 @@ public async Task MockFile_WriteAsync_ShouldRetainCreationTimeAndUpdateLastAcces await stream.WriteAsync(buffer, 0, buffer.Length); fi.Refresh(); // Assert - Assert.AreEqual(creationTime, fi.CreationTime); + Assert.That(fi.CreationTime, Is.EqualTo(creationTime)); Assert.LessOrEqual(DateTime.Now - fi.LastAccessTime, TimeSpan.FromSeconds(1)); Assert.LessOrEqual(DateTime.Now - fi.LastWriteTime, TimeSpan.FromSeconds(1)); } @@ -343,7 +343,7 @@ public void MockFile_OpenText_ShouldRetainCreationTime() } // Assert - Assert.AreEqual(creationTime, fs.FileInfo.New(filepath).CreationTime); + Assert.That(fs.FileInfo.New(filepath).CreationTime, Is.EqualTo(creationTime)); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs index 9b871566e..7ba11acb1 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs @@ -36,7 +36,7 @@ public void MockFile_ReadAllBytes_ShouldReturnDataSavedByWriteAllBytes() fileSystem.File.WriteAllBytes(path, fileContent); - Assert.AreEqual(fileContent, fileSystem.File.ReadAllBytes(path)); + Assert.That(fileSystem.File.ReadAllBytes(path), Is.EqualTo(fileContent)); } [Test] @@ -60,7 +60,7 @@ public void MockFile_ReadAllBytes_ShouldTolerateAltDirectorySeparatorInPath() fileSystem.AddFile(path, new MockFileData(data)); - Assert.AreEqual(data, fileSystem.File.ReadAllBytes(altPath)); + Assert.That(fileSystem.File.ReadAllBytes(altPath), Is.EqualTo(data)); } [Test] @@ -113,7 +113,7 @@ public async Task MockFile_ReadAllBytesAsync_ShouldReturnDataSavedByWriteAllByte fileSystem.File.WriteAllBytes(path, fileContent); - Assert.AreEqual(fileContent, await fileSystem.File.ReadAllBytesAsync(path)); + Assert.That(await fileSystem.File.ReadAllBytesAsync(path), Is.EqualTo(fileContent)); } [Test] @@ -148,7 +148,7 @@ public async Task MockFile_ReadAllBytesAsync_ShouldTolerateAltDirectorySeparator fileSystem.AddFile(path, new MockFileData(data)); - Assert.AreEqual(data, await fileSystem.File.ReadAllBytesAsync(altPath)); + Assert.That(await fileSystem.File.ReadAllBytesAsync(altPath), Is.EqualTo(data)); } #endif } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs index fb419da81..576b34fe6 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs @@ -65,7 +65,7 @@ public void MockFileStreamFactory_CreateForAnExistingFile_ShouldReplaceFileConte } var text = fileSystem.File.ReadAllText(FilePath); - Assert.AreEqual("AAAAA", text); + Assert.That(text, Is.EqualTo("AAAAA")); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs index 0cd36a9a7..6381c02b0 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs @@ -66,9 +66,9 @@ public void MockFileStream_Dispose_ShouldNotResurrectFile() stream.Dispose(); var fileCount3 = fileSystem.Directory.GetFiles(directory, "*").Length; - Assert.AreEqual(1, fileCount1, "File should have existed"); - Assert.AreEqual(0, fileCount2, "File should have been deleted"); - Assert.AreEqual(0, fileCount3, "Disposing stream should not have resurrected the file"); + Assert.That(fileCount1, Is.EqualTo(1), "File should have existed"); + Assert.That(fileCount2, Is.EqualTo(0), "File should have been deleted"); + Assert.That(fileCount3, Is.EqualTo(0), "Disposing stream should not have resurrected the file"); } [Test] @@ -203,7 +203,7 @@ public void MockFileStream_Flush_ShouldNotChangePosition() stream.Flush(); // Assert - Assert.AreEqual(200, stream.Position); + Assert.That(stream.Position, Is.EqualTo(200)); } } @@ -223,7 +223,7 @@ public void MockFileStream_FlushBool_ShouldNotChangePosition([Values] bool flush stream.Flush(flushToDisk); // Assert - Assert.AreEqual(200, stream.Position); + Assert.That(stream.Position, Is.EqualTo(200)); } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs index 39f6b7c6b..12d13a8b2 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs @@ -24,8 +24,8 @@ public void MockFile_CreateSymbolicLink_ShouldReturnFileSystemInfo() IFileSystemInfo fileSystemInfo = fileSystem.File.CreateSymbolicLink(path, pathToTarget); // Assert - Assert.AreEqual(path, fileSystemInfo.FullName); - Assert.AreEqual(pathToTarget, fileSystemInfo.LinkTarget); + Assert.That(fileSystemInfo.FullName, Is.EqualTo(path)); + Assert.That(fileSystemInfo.LinkTarget, Is.EqualTo(pathToTarget)); } [Test] @@ -43,8 +43,8 @@ public void MockFile_CreateSymbolicLink_ShouldSucceedFromFileInfo() IFileInfo directoryInfo = fileSystem.FileInfo.New(path); // Assert - Assert.AreEqual(path, directoryInfo.FullName); - Assert.AreEqual(pathToTarget, directoryInfo.LinkTarget); + Assert.That(directoryInfo.FullName, Is.EqualTo(path)); + Assert.That(directoryInfo.LinkTarget, Is.EqualTo(pathToTarget)); } [Test] @@ -251,7 +251,7 @@ public void MockFile_ResolveLinkTarget_ShouldReturnPathOfTargetLink() var result = fileSystem.File.ResolveLinkTarget("foo", false); - Assert.AreEqual("bar", result.Name); + Assert.That(result.Name, Is.EqualTo("bar")); } [Test] @@ -272,7 +272,7 @@ public void MockFile_ResolveLinkTarget_WithFinalTarget_ShouldReturnPathOfTargetL var result = fileSystem.File.ResolveLinkTarget(previousPath, true); - Assert.AreEqual("bar", result.Name); + Assert.That(result.Name, Is.EqualTo("bar")); } [Test] @@ -305,7 +305,7 @@ public void MockFile_ResolveLinkTarget_WithoutFinalTarget_ShouldReturnFirstLink( var result = fileSystem.File.ResolveLinkTarget("foo1", false); - Assert.AreEqual("foo", result.Name); + Assert.That(result.Name, Is.EqualTo("foo")); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemOptionTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemOptionTests.cs index caa3fa208..20993a9a9 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemOptionTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemOptionTests.cs @@ -18,7 +18,7 @@ public void CreateDefaultTempDir_ShouldBeConsidered(bool createTempDir) var result = fileSystem.Directory.Exists(fileSystem.Path.GetTempPath()); - Assert.AreEqual(createTempDir, result); + Assert.That(result, Is.EqualTo(createTempDir)); } [Test] @@ -34,7 +34,7 @@ public void CurrentDirectory_ShouldBeConsidered(string currentDirectory) var result = fileSystem.Directory.GetCurrentDirectory(); - Assert.AreEqual(currentDirectory, result); + Assert.That(result, Is.EqualTo(currentDirectory)); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs index ddb5651f4..abdd3391e 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemSerializationTests.cs @@ -33,12 +33,8 @@ public void SerializationBytes() memoryStream.Dispose(); // Assert - Assert.AreEqual( - expected, - fileSystem.GetFile(path).Contents); - Assert.AreEqual( - content, - fileSystem.File.ReadAllBytes(path)); + Assert.That(fileSystem.GetFile(path).Contents, Is.EqualTo(expected)); + Assert.That(fileSystem.File.ReadAllBytes(path), Is.EqualTo(content)); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index f3df2aca7..52748e526 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -38,7 +38,7 @@ public void MockFileSystem_GetFile_ShouldReturnFileRegisteredInConstructor() var result = fileSystem.GetFile(@"c:\something\demo.txt"); - Assert.AreEqual(file1, result); + Assert.That(result, Is.EqualTo(file1)); } [Test] @@ -54,7 +54,7 @@ public void MockFileSystem_GetFile_ShouldReturnFileRegisteredInConstructorWhenPa var result = fileSystem.GetFile(@"c:\SomeThing\DEMO.txt"); - Assert.AreEqual(file1, result); + Assert.That(result, Is.EqualTo(file1)); } [Test] @@ -84,7 +84,7 @@ public void MockFileSystem_AddFile_ShouldHandleUnnormalizedSlashes() var fileCount = fs.Directory.GetFiles(alternateParentPath).Length; var fileExists = fs.File.Exists(alternatePath); - Assert.AreEqual(1, fileCount); + Assert.That(fileCount, Is.EqualTo(1)); Assert.IsTrue(fileExists); } @@ -282,7 +282,7 @@ public void MockFileSystem_AddFileFromEmbeddedResource_ShouldAddTheFile() fileSystem.AddFileFromEmbeddedResource(XFS.Path(@"C:\TestFile.txt"), Assembly.GetExecutingAssembly(), "System.IO.Abstractions.TestingHelpers.Tests.TestFiles.TestFile.txt"); var result = fileSystem.GetFile(XFS.Path(@"C:\TestFile.txt")); - Assert.AreEqual(new UTF8Encoding().GetBytes("This is a test file."), result.Contents); + Assert.That(result.Contents, Is.EqualTo(new UTF8Encoding().GetBytes("This is a test file."))); } [Test] @@ -372,7 +372,7 @@ public void MockFileSystem_AllNodes_ShouldReturnAllNodes() var result = fileSystem.AllNodes; - Assert.AreEqual(expectedNodes, result); + Assert.That(result, Is.EqualTo(expectedNodes)); } [Test] @@ -421,7 +421,7 @@ public void MockFileSystem_Constructor_ThrowsForNonRootedCurrentDirectory() var ae = Assert.Throws(() => new MockFileSystem(null, "non-rooted") ); - Assert.AreEqual("currentDirectory", ae.ParamName); + Assert.That(ae.ParamName, Is.EqualTo("currentDirectory")); } [Test] @@ -442,7 +442,7 @@ public void MockFileSystem_FileSystemWatcher_Can_Be_Overridden() var path = XFS.Path(@"C:\root"); var fileSystem = new TestFileSystem(new TestFileSystemWatcherFactory()); var watcher = fileSystem.FileSystemWatcher.New(path); - Assert.AreEqual(path, watcher.Path); + Assert.That(watcher.Path, Is.EqualTo(path)); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs index 028dbbc3f..72015017e 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs @@ -42,7 +42,7 @@ public void MockFile_GetSetCreationTime_ShouldPersist() var result = file.GetCreationTime(path); // Assert - Assert.AreEqual(creationTime, result); + Assert.That(result, Is.EqualTo(creationTime)); } [Test] @@ -62,7 +62,7 @@ public void MockFile_SetCreationTimeUtc_ShouldAffectCreationTime() var result = file.GetCreationTime(path); // Assert - Assert.AreEqual(creationTime, result); + Assert.That(result, Is.EqualTo(creationTime)); } [Test] @@ -82,7 +82,7 @@ public void MockFile_SetCreationTime_ShouldAffectCreationTimeUtc() var result = file.GetCreationTimeUtc(path); // Assert - Assert.AreEqual(creationTime.ToUniversalTime(), result); + Assert.That(result, Is.EqualTo(creationTime.ToUniversalTime())); } [Test] @@ -102,7 +102,7 @@ public void MockFile_GetSetLastAccessTime_ShouldPersist() var result = file.GetLastAccessTime(path); // Assert - Assert.AreEqual(lastAccessTime, result); + Assert.That(result, Is.EqualTo(lastAccessTime)); } [Test] @@ -122,7 +122,7 @@ public void MockFile_SetLastAccessTimeUtc_ShouldAffectLastAccessTime() var result = file.GetLastAccessTime(path); // Assert - Assert.AreEqual(lastAccessTime, result); + Assert.That(result, Is.EqualTo(lastAccessTime)); } [Test] @@ -142,7 +142,7 @@ public void MockFile_SetLastAccessTime_ShouldAffectLastAccessTimeUtc() var result = file.GetLastAccessTimeUtc(path); // Assert - Assert.AreEqual(lastAccessTime.ToUniversalTime(), result); + Assert.That(result, Is.EqualTo(lastAccessTime.ToUniversalTime())); } [Test] @@ -162,7 +162,7 @@ public void MockFile_GetSetLastWriteTime_ShouldPersist() var result = file.GetLastWriteTime(path); // Assert - Assert.AreEqual(lastWriteTime, result); + Assert.That(result, Is.EqualTo(lastWriteTime)); } static void ExecuteDefaultValueTest(Func getDateValue) @@ -316,7 +316,7 @@ public void MockFile_SetLastWriteTimeUtc_ShouldAffectLastWriteTime() var result = file.GetLastWriteTime(path); // Assert - Assert.AreEqual(lastWriteTime, result); + Assert.That(result, Is.EqualTo(lastWriteTime)); } [Test] @@ -336,7 +336,7 @@ public void MockFile_SetLastWriteTime_ShouldAffectLastWriteTimeUtc() var result = file.GetLastWriteTimeUtc(path); // Assert - Assert.AreEqual(lastWriteTime.ToUniversalTime(), result); + Assert.That(result, Is.EqualTo(lastWriteTime.ToUniversalTime())); } [Test] @@ -355,9 +355,7 @@ public void MockFile_ReadAllText_ShouldReturnOriginalTextData() var result = file.ReadAllText(XFS.Path(@"c:\something\demo.txt")); // Assert - Assert.AreEqual( - "Demo text content", - result); + Assert.That(result, Is.EqualTo("Demo text content")); } [Test] @@ -377,7 +375,7 @@ public void MockFile_ReadAllText_ShouldReturnOriginalDataWithCustomEncoding() var result = file.ReadAllText(XFS.Path(@"c:\something\demo.txt"), Encoding.BigEndianUnicode); // Assert - Assert.AreEqual(text, result); + Assert.That(result, Is.EqualTo(text)); } public static IEnumerable GetEncodingsForReadAllText() @@ -408,7 +406,7 @@ public void MockFile_ReadAllText_ShouldReturnTheOriginalContentWhenTheFileContai var actualText = fileSystem.File.ReadAllText(path); // Assert - Assert.AreEqual(text, actualText); + Assert.That(actualText, Is.EqualTo(text)); } [Test] @@ -479,9 +477,9 @@ public void MockFile_Delete_Should_RemoveFiles() string filePath = XFS.Path(@"c:\something\demo.txt"); string fileContent = "this is some content"; var fileSystem = new MockFileSystem(new Dictionary { { filePath, new MockFileData(fileContent) } }); - Assert.AreEqual(1, fileSystem.AllFiles.Count()); + Assert.That(fileSystem.AllFiles.Count(), Is.EqualTo(1)); fileSystem.File.Delete(filePath); - Assert.AreEqual(0, fileSystem.AllFiles.Count()); + Assert.That(fileSystem.AllFiles.Count(), Is.EqualTo(0)); } [Test] @@ -591,7 +589,7 @@ public void MockFile_Encrypt_ShouldSetEncryptedAttribute() var attributes = fileSystem.File.GetAttributes(filePath); // Assert - Assert.AreEqual(FileAttributes.Encrypted, attributes & FileAttributes.Encrypted); + Assert.That(attributes & FileAttributes.Encrypted, Is.EqualTo(FileAttributes.Encrypted)); } [Test] @@ -628,7 +626,7 @@ public void MockFile_Replace_ShouldReplaceFileContents() // Act fileSystem.File.Replace(path1, path2, null); - Assert.AreEqual("1", fileSystem.File.ReadAllText(path2)); + Assert.That(fileSystem.File.ReadAllText(path2), Is.EqualTo("1")); } [Test] @@ -645,8 +643,8 @@ public void MockFile_Replace_ShouldCreateBackup() // Act fileSystem.File.Replace(path1, path2, path3); - Assert.AreEqual("2", fileSystem.File.ReadAllText(path3)); - } + Assert.That(fileSystem.File.ReadAllText(path3), Is.EqualTo("2")); + } [Test] public void MockFile_Replace_ShouldThrowIfDirectoryOfBackupPathDoesNotExist() diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs index eee29ef66..f76c80803 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs @@ -30,7 +30,7 @@ public void MockFile_WriteAllBytes_ShouldWriteDataToMemoryFileSystem() fileSystem.File.WriteAllBytes(path, fileContent); - Assert.AreEqual(fileContent, fileSystem.GetFile(path).Contents); + Assert.That(fileSystem.GetFile(path).Contents, Is.EqualTo(fileContent)); } [Test] @@ -146,7 +146,7 @@ public async Task MockFile_WriteAllBytesAsync_ShouldWriteDataToMemoryFileSystem( await fileSystem.File.WriteAllBytesAsync(path, fileContent); - Assert.AreEqual(fileContent, fileSystem.GetFile(path).Contents); + Assert.That(fileSystem.GetFile(path).Contents, Is.EqualTo(fileContent)); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs index e6e4ce281..5127501db 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs @@ -26,9 +26,7 @@ public void MockFile_WriteAllText_ShouldWriteTextFileToMemoryFileSystem() fileSystem.File.WriteAllText(path, fileContent); // Assert - Assert.AreEqual( - fileContent, - fileSystem.GetFile(path).TextContents); + Assert.That(fileSystem.GetFile(path).TextContents, Is.EqualTo(fileContent)); } [Test] @@ -46,7 +44,7 @@ public void MockFile_WriteAllText_ShouldOverwriteAnExistingFile() fileSystem.File.WriteAllText(path, "bar"); // Assert - Assert.AreEqual("bar", fileSystem.GetFile(path).TextContents); + Assert.That(fileSystem.GetFile(path).TextContents, Is.EqualTo("bar")); } [Test] @@ -200,7 +198,7 @@ public void MockFile_WriteAllText_Encoding_ShouldWriteTextFileToMemoryFileSystem // Assert var actualBytes = fileSystem.GetFile(path).Contents; - Assert.AreEqual(expectedBytes, actualBytes); + Assert.That(actualBytes, Is.EqualTo(expectedBytes)); } [Test] @@ -219,9 +217,7 @@ public void MockFile_WriteAllTextMultipleLines_ShouldWriteTextFileToMemoryFileSy fileSystem.File.WriteAllLines(path, fileContent); // Assert - Assert.AreEqual( - expected, - fileSystem.GetFile(path).TextContents); + Assert.That(fileSystem.GetFile(path).TextContents, Is.EqualTo(expected)); } #if FEATURE_ASYNC_FILE @@ -238,9 +234,7 @@ public async Task MockFile_WriteAllTextAsync_ShouldWriteTextFileToMemoryFileSyst await fileSystem.File.WriteAllTextAsync(path, fileContent); // Assert - Assert.AreEqual( - fileContent, - fileSystem.GetFile(path).TextContents); + Assert.That(fileSystem.GetFile(path).TextContents, Is.EqualTo(fileContent)); } [Test] @@ -277,7 +271,7 @@ public async Task MockFile_WriteAllTextAsync_ShouldOverriteAnExistingFile() await fileSystem.File.WriteAllTextAsync(path, "bar"); // Assert - Assert.AreEqual("bar", fileSystem.GetFile(path).TextContents); + Assert.That(fileSystem.GetFile(path).TextContents, Is.EqualTo("bar")); } [Test] @@ -391,7 +385,7 @@ public async Task MockFile_WriteAllTextAsync_Encoding_ShouldWriteTextFileToMemor // Assert var actualBytes = fileSystem.GetFile(path).Contents; - Assert.AreEqual(expectedBytes, actualBytes); + Assert.That(actualBytes, Is.EqualTo(expectedBytes)); } [Test] @@ -410,9 +404,7 @@ public async Task MockFile_WriteAllTextAsyncMultipleLines_ShouldWriteTextFileToM await fileSystem.File.WriteAllLinesAsync(path, fileContent); // Assert - Assert.AreEqual( - expected, - fileSystem.GetFile(path).TextContents); + Assert.That(fileSystem.GetFile(path).TextContents, Is.EqualTo(expected)); } #endif } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs index 616b7bcd8..610e39b3e 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs @@ -19,7 +19,7 @@ public void ChangeExtension_ExtensionNoPeriod_PeriodAdded() var result = mockPath.ChangeExtension(TestPath, "doc"); //Assert - Assert.AreEqual(XFS.Path("C:\\test\\test.doc"), result); + Assert.That(result, Is.EqualTo(XFS.Path("C:\\test\\test.doc"))); } [Test] @@ -32,7 +32,7 @@ public void Combine_SentTwoPaths_Combines() var result = mockPath.Combine(XFS.Path("C:\\test"), "test.bmp"); //Assert - Assert.AreEqual(XFS.Path("C:\\test\\test.bmp"), result); + Assert.That(result, Is.EqualTo(XFS.Path("C:\\test\\test.bmp"))); } [Test] @@ -45,7 +45,7 @@ public void Combine_SentThreePaths_Combines() var result = mockPath.Combine(XFS.Path("C:\\test"), "subdir1", "test.bmp"); //Assert - Assert.AreEqual(XFS.Path("C:\\test\\subdir1\\test.bmp"), result); + Assert.That(result, Is.EqualTo(XFS.Path("C:\\test\\subdir1\\test.bmp"))); } [Test] @@ -58,7 +58,7 @@ public void Combine_SentFourPaths_Combines() var result = mockPath.Combine(XFS.Path("C:\\test"), "subdir1", "subdir2", "test.bmp"); //Assert - Assert.AreEqual(XFS.Path("C:\\test\\subdir1\\subdir2\\test.bmp"), result); + Assert.That(result, Is.EqualTo(XFS.Path("C:\\test\\subdir1\\subdir2\\test.bmp"))); } [Test] @@ -71,7 +71,7 @@ public void Combine_SentFivePaths_Combines() var result = mockPath.Combine(XFS.Path("C:\\test"), "subdir1", "subdir2", "subdir3", "test.bmp"); //Assert - Assert.AreEqual(XFS.Path("C:\\test\\subdir1\\subdir2\\subdir3\\test.bmp"), result); + Assert.That(result, Is.EqualTo(XFS.Path("C:\\test\\subdir1\\subdir2\\subdir3\\test.bmp"))); } [Test] @@ -84,7 +84,7 @@ public void GetDirectoryName_SentPath_ReturnsDirectory() var result = mockPath.GetDirectoryName(TestPath); //Assert - Assert.AreEqual(XFS.Path("C:\\test"), result); + Assert.That(result, Is.EqualTo(XFS.Path("C:\\test"))); } [Test] @@ -97,7 +97,7 @@ public void GetExtension_SendInPath_ReturnsExtension() var result = mockPath.GetExtension(TestPath); //Assert - Assert.AreEqual(".bmp", result); + Assert.That(result, Is.EqualTo(".bmp")); } [Test] @@ -110,7 +110,7 @@ public void GetFileName_SendInPath_ReturnsFilename() var result = mockPath.GetFileName(TestPath); //Assert - Assert.AreEqual("test.bmp", result); + Assert.That(result, Is.EqualTo("test.bmp")); } [Test] @@ -123,7 +123,7 @@ public void GetFileNameWithoutExtension_SendInPath_ReturnsFileNameNoExt() var result = mockPath.GetFileNameWithoutExtension(TestPath); //Assert - Assert.AreEqual("test", result); + Assert.That(result, Is.EqualTo("test")); } [Test] @@ -136,7 +136,7 @@ public void GetFullPath_SendInPath_ReturnsFullPath() var result = mockPath.GetFullPath(TestPath); //Assert - Assert.AreEqual(TestPath, result); + Assert.That(result, Is.EqualTo(TestPath)); } public static IEnumerable GetFullPath_RelativePaths_Cases @@ -165,7 +165,7 @@ public void GetFullPath_RelativePaths_ShouldReturnTheAbsolutePathWithCurrentDire var actualResult = mockPath.GetFullPath(relativePath); //Assert - Assert.AreEqual(expectedResult, actualResult); + Assert.That(actualResult, Is.EqualTo(expectedResult)); } public static IEnumerable GetFullPath_RootedPathWithRelativeSegments_Cases @@ -191,7 +191,7 @@ public void GetFullPath_RootedPathWithRelativeSegments_ShouldReturnAnRootedAbsol var actualResult = mockPath.GetFullPath(rootedPath); //Assert - Assert.AreEqual(expectedResult, actualResult); + Assert.That(actualResult, Is.EqualTo(expectedResult)); } public static IEnumerable GetFullPath_AbsolutePaths_Cases @@ -221,7 +221,7 @@ public void GetFullPath_AbsolutePaths_ShouldReturnThePathWithTheRoot_Or_Unc(stri var actualResult = mockPath.GetFullPath(absolutePath); //Assert - Assert.AreEqual(expectedResult, actualResult); + Assert.That(actualResult, Is.EqualTo(expectedResult)); } [Test] @@ -287,7 +287,7 @@ public void GetFullPath_WithMultipleDirectorySeparators_ShouldReturnTheNormalize var actualFullPath = mockPath.GetFullPath(XFS.Path(@"c:\foo\\//bar\file.dat")); //Assert - Assert.AreEqual(XFS.Path(@"c:\foo\bar\file.dat"), actualFullPath); + Assert.That(actualFullPath, Is.EqualTo(XFS.Path(@"c:\foo\bar\file.dat"))); } [Test] @@ -326,7 +326,7 @@ public void GetPathRoot_SendInPath_ReturnsRoot() var result = mockPath.GetPathRoot(TestPath); //Assert - Assert.AreEqual(XFS.Path("C:\\"), result); + Assert.That(result, Is.EqualTo(XFS.Path("C:\\"))); } [Test] @@ -366,7 +366,7 @@ public void GetTempFileName_Called_CreatesEmptyFileInTempDirectory() var result = mockPath.GetTempFileName(); Assert.True(fileSystem.FileExists(result)); - Assert.AreEqual(0, fileSystem.FileInfo.New(result).Length); + Assert.That(fileSystem.FileInfo.New(result).Length, Is.Zero); } [Test] @@ -410,7 +410,7 @@ public void GetTempPath_Called_WithNonNullVirtualTempDirectory_ReturnsVirtualTem var result = mockPath.GetTempPath(); //Assert - Assert.AreEqual(tempDirectory, result); + Assert.That(result, Is.EqualTo(tempDirectory)); } [Test] @@ -438,7 +438,7 @@ public void HasExtension_PathSentIn_DeterminesExtension() var result = mockPath.HasExtension(TestPath); //Assert - Assert.AreEqual(true, result); + Assert.That(result, Is.True); } [Test] @@ -451,7 +451,7 @@ public void IsPathRooted_PathSentIn_DeterminesPathExists() var result = mockPath.IsPathRooted(TestPath); //Assert - Assert.AreEqual(true, result); + Assert.That(result, Is.True); } #if FEATURE_ADVANCED_PATH_OPERATIONS @@ -504,7 +504,7 @@ public void GetRelativePath_Works() var result = mockPath.GetRelativePath(XFS.Path("c:\\d"), XFS.Path("c:\\d\\e\\f.txt")); //Assert - Assert.AreEqual(XFS.Path("e\\f.txt"), result); + Assert.That(result, Is.EqualTo(XFS.Path("e\\f.txt"))); } [Test] @@ -517,7 +517,7 @@ public void GetRelativePath_WhenPathIsNull_ShouldThrowArgumentNullException() mockPath.GetRelativePath("foo", null); }); - Assert.AreEqual("path", exception.ParamName); + Assert.That(exception.ParamName, Is.EqualTo("path")); } [Test] @@ -530,7 +530,7 @@ public void GetRelativePath_WhenPathIsWhitespace_ShouldThrowArgumentException() mockPath.GetRelativePath("foo", " "); }); - Assert.AreEqual("path", exception.ParamName); + Assert.That(exception.ParamName, Is.EqualTo("path")); } [Test] @@ -543,7 +543,7 @@ public void GetRelativePath_WhenRelativeToNull_ShouldThrowArgumentNullException( mockPath.GetRelativePath(null, "foo"); }); - Assert.AreEqual("relativeTo", exception.ParamName); + Assert.That(exception.ParamName, Is.EqualTo("relativeTo")); } [Test] @@ -556,7 +556,7 @@ public void GetRelativePath_WhenRelativeToIsWhitespace_ShouldThrowArgumentExcept mockPath.GetRelativePath(" ", "foo"); }); - Assert.AreEqual("relativeTo", exception.ParamName); + Assert.That(exception.ParamName, Is.EqualTo("relativeTo")); } #endif @@ -632,7 +632,7 @@ public void GetRelativePath_ShouldUseCurrentDirectoryFromMockFileSystem() var result = fs.Path.GetRelativePath("/input", "a.txt"); - Assert.AreEqual("a.txt", result); + Assert.That(result, Is.EqualTo("a.txt")); } #endif } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockUnixSupportTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockUnixSupportTests.cs index 2641e431b..306a7756b 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockUnixSupportTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockUnixSupportTests.cs @@ -11,14 +11,14 @@ public class MockUnixSupportTests [UnixOnly(UnixSpecifics.SlashRoot)] public void Should_Convert_Backslashes_To_Slashes_On_Unix() { - Assert.AreEqual("/test/", XFS.Path(@"\test\")); + Assert.That(XFS.Path(@"\test\"), Is.EqualTo("/test/")); } [Test] [UnixOnly(UnixSpecifics.SlashRoot)] public void Should_Remove_Drive_Letter_On_Unix() { - Assert.AreEqual("/test/", XFS.Path(@"c:\test\")); + Assert.That(XFS.Path(@"c:\test\"), Is.EqualTo("/test/")); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/StringExtensionsTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/StringExtensionsTests.cs index a68106c35..d45b6229d 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/StringExtensionsTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/StringExtensionsTests.cs @@ -66,55 +66,55 @@ public void SplitLines_InputWithTwoLinesSeparatedWithAllLineEndings_ShouldReturn [WindowsOnly(WindowsSpecifics.Drives)] public void TrimSlashes_DriveRoot_PreserveTrailingSlash() { - Assert.AreEqual(@"c:\", @"c:\".TrimSlashes()); + Assert.That(@"c:\".TrimSlashes(), Is.EqualTo(@"c:\")); } [Test] [WindowsOnly(WindowsSpecifics.Drives)] public void TrimSlashes_DriveRoot_AppendsTrailingSlash() { - Assert.AreEqual(@"c:\", @"c:".TrimSlashes()); + Assert.That(@"c:".TrimSlashes(), Is.EqualTo(@"c:\")); } [Test] [WindowsOnly(WindowsSpecifics.Drives)] public void TrimSlashes_DriveRoot_TrimsExcessTrailingSlash() { - Assert.AreEqual(@"c:\", @"c:\\".TrimSlashes()); + Assert.That(@"c:\\".TrimSlashes(), Is.EqualTo(@"c:\")); } [Test] [WindowsOnly(WindowsSpecifics.Drives)] public void TrimSlashes_DriveRoot_NormalizeAlternateSlash() { - Assert.AreEqual(@"c:\", @"c:/".TrimSlashes()); + Assert.That(@"c:/".TrimSlashes(), Is.EqualTo(@"c:\")); } [Test] [WindowsOnly(WindowsSpecifics.Drives)] public void TrimSlashes_RootedPath_TrimsAllTrailingSlashes() { - Assert.AreEqual(@"c:\x", @"c:\x\".TrimSlashes()); + Assert.That(@"c:\x\".TrimSlashes(), Is.EqualTo(@"c:\x")); } [Test] public void TrimSlashes_RootedPath_DoNotAlterPathWithoutTrailingSlashes() { - Assert.AreEqual(XFS.Path(@"c:\x"), XFS.Path(@"c:\x").TrimSlashes()); + Assert.That(XFS.Path(@"c:\x").TrimSlashes(), Is.EqualTo(XFS.Path(@"c:\x"))); } [Test] [UnixOnly(UnixSpecifics.SlashRoot)] public void TrimSlashes_SlashRoot_TrimsExcessTrailingSlash() { - Assert.AreEqual("/", "//".TrimSlashes()); + Assert.That("//".TrimSlashes(), Is.EqualTo("/")); } [Test] [UnixOnly(UnixSpecifics.SlashRoot)] public void TrimSlashes_SlashRoot_PreserveSlashRoot() { - Assert.AreEqual("/", "/".TrimSlashes()); + Assert.That("/".TrimSlashes(), Is.EqualTo("/")); } [TestCase(@"\\unc\folder\file.txt", @"\\unc\folder\file.txt")] @@ -122,7 +122,7 @@ public void TrimSlashes_SlashRoot_PreserveSlashRoot() [WindowsOnly(WindowsSpecifics.UNCPaths)] public void NormalizeSlashes_KeepsUNCPathPrefix(string path, string expectedValue) { - Assert.AreEqual(expectedValue, path.NormalizeSlashes()); + Assert.That(path.NormalizeSlashes(), Is.EqualTo(expectedValue)); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj index b4fb165b1..d3f010b14 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests.csproj @@ -35,7 +35,10 @@ - + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryWrapperTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryWrapperTests.cs index a10f61848..93453491f 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryWrapperTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryWrapperTests.cs @@ -31,7 +31,7 @@ public void GetParent_ForSimpleSubfolderPath_ShouldReturnRoot() var result = wrapperFilesystem.Directory.GetParent(subfolder); // Assert - Assert.AreEqual(root, result.FullName); + Assert.That(result.FullName, Is.EqualTo(root)); } [Test] @@ -47,7 +47,7 @@ public void GetParent_ForSimpleFilePath_ShouldReturnSubfolder() var result = wrapperFilesystem.Directory.GetParent(file); // Assert - Assert.AreEqual(subfolder, result.FullName); + Assert.That(result.FullName, Is.EqualTo(subfolder)); } } } From b43e7be83c45d11a2cce1aeb64cf703af076626d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:14:46 +0100 Subject: [PATCH 07/18] Avoid CollectionAssert --- .../MockDirectoryTests.cs | 7 ++--- .../MockFileAppendAllTextTests.cs | 28 +++++++------------ .../MockFileCopyTests.cs | 2 +- .../MockFileOpenTests.cs | 4 +-- .../MockFileReadAllBytesTests.cs | 10 +++---- .../MockFileReadAllLinesTests.cs | 26 ++++++----------- .../MockFileReadLinesTests.cs | 8 ++---- .../MockFileStreamTests.cs | 6 ++-- .../MockFileSystemTests.cs | 4 +-- 9 files changed, 35 insertions(+), 60 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 23735595e..50b6c87ad 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -1320,10 +1320,7 @@ public void MockDirectory_GetDirectories_RelativeDirectory_WithChildren_ShouldRe var actualResult = fileSystem.Directory.GetDirectories(XFS.Path(relativeDirPath)); // Assert - CollectionAssert.AreEqual( - new[] { XFS.Path(relativeDirPath + @"\child") }, - actualResult - ); + Assert.That(actualResult, Is.EqualTo(new[] { XFS.Path(relativeDirPath + @"\child") })); } [Test] @@ -1496,7 +1493,7 @@ public void MockDirectory_EnumerateDirectories_ShouldReturnPathsPrefixedWithQuer var actualResult = fileSystem.Directory.EnumerateDirectories(queryPath); - CollectionAssert.AreEqual(new[] { expectedPath }, actualResult); + Assert.That(actualResult, Is.EqualTo(new[] { expectedPath })); } private static IEnumerable GetPrefixTestPaths() diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllTextTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllTextTests.cs index 6f0fe41a2..1f5187061 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllTextTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllTextTests.cs @@ -50,9 +50,8 @@ public void MockFile_AppendAllText_ShouldPersistNewTextWithDifferentEncoding() file.AppendAllText(Path, "BB", Encoding.UTF8); // Assert - CollectionAssert.AreEqual( - new byte[] { 255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0, 66, 66 }, - fileSystem.GetFile(Path).Contents); + Assert.That(fileSystem.GetFile(Path).Contents, + Is.EqualTo(new byte[] { 255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0, 66, 66 })); } [Test] @@ -85,9 +84,8 @@ public void MockFile_AppendAllText_ShouldCreateIfNotExistWithBom() fileSystem.File.AppendAllText(path, "AA", Encoding.UTF32); // Assert - CollectionAssert.AreEqual( - new byte[] { 255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0 }, - fileSystem.GetFile(path).Contents); + Assert.That(fileSystem.GetFile(path).Contents, + Is.EqualTo(new byte[] { 255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0 })); } [Test] @@ -139,9 +137,7 @@ public void MockFile_AppendAllText_ShouldPersistNewTextWithCustomEncoding() 0, 32, 0, 116, 0, 101, 0, 120, 0, 116 }; - CollectionAssert.AreEqual( - expected, - file.ReadAllBytes(path)); + Assert.That(file.ReadAllBytes(path), Is.EqualTo(expected)); } [Test] @@ -214,9 +210,8 @@ public async Task MockFile_AppendAllTextAsync_ShouldPersistNewTextWithDifferentE await file.AppendAllTextAsync(Path, "BB", Encoding.UTF8); // Assert - CollectionAssert.AreEqual( - new byte[] { 255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0, 66, 66 }, - fileSystem.GetFile(Path).Contents); + Assert.That(fileSystem.GetFile(Path).Contents, + Is.EqualTo(new byte[] { 255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0, 66, 66 })); } [Test] @@ -249,9 +244,8 @@ public async Task MockFile_AppendAllTextAsync_ShouldCreateIfNotExistWithBom() await fileSystem.File.AppendAllTextAsync(path, "AA", Encoding.UTF32); // Assert - CollectionAssert.AreEqual( - new byte[] { 255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0 }, - fileSystem.GetFile(path).Contents); + Assert.That(fileSystem.GetFile(path).Contents, + Is.EqualTo(new byte[] { 255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0 })); } [Test] @@ -303,9 +297,7 @@ public async Task MockFile_AppendAllTextAsync_ShouldPersistNewTextWithCustomEnco 0, 32, 0, 116, 0, 101, 0, 120, 0, 116 }; - CollectionAssert.AreEqual( - expected, - file.ReadAllBytes(path)); + Assert.That(file.ReadAllBytes(path), Is.EqualTo(expected)); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs index e0ca5d31b..9a01332f3 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs @@ -84,7 +84,7 @@ public void MockFile_Copy_ShouldCloneBinaryContents() binaryWriter.Write("Modified"); } - CollectionAssert.AreEqual(original, mockFileSystem.File.ReadAllBytes(destFileName)); + Assert.That(mockFileSystem.File.ReadAllBytes(destFileName), Is.EqualTo(original)); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs index 9943ae963..91edbd592 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs @@ -133,7 +133,7 @@ public void MockFile_Open_OpensExistingFileOnOpen() using (var br = new BinaryReader(stream)) data = br.ReadBytes((int)stream.Length); - CollectionAssert.AreEqual(file.Contents, data); + Assert.That(data, Is.EqualTo(file.Contents)); } [Test] @@ -155,7 +155,7 @@ public void MockFile_Open_OpensExistingFileOnOpenOrCreate() using (var br = new BinaryReader(stream)) data = br.ReadBytes((int)stream.Length); - CollectionAssert.AreEqual(file.Contents, data); + Assert.That(data, Is.EqualTo(file.Contents)); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs index 7ba11acb1..ea196a48c 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllBytesTests.cs @@ -21,9 +21,8 @@ public void MockFile_ReadAllBytes_ShouldReturnOriginalByteData() var result = file.ReadAllBytes(XFS.Path(@"c:\something\other.gif")); - CollectionAssert.AreEqual( - new byte[] { 0x21, 0x58, 0x3f, 0xa9 }, - result); + Assert.That(result, + Is.EqualTo(new byte[] { 0x21, 0x58, 0x3f, 0xa9 })); } [Test] @@ -98,9 +97,8 @@ public async Task MockFile_ReadAllBytesAsync_ShouldReturnOriginalByteData() var result = await file.ReadAllBytesAsync(XFS.Path(@"c:\something\other.gif")); - CollectionAssert.AreEqual( - new byte[] { 0x21, 0x58, 0x3f, 0xa9 }, - result); + Assert.That(result, + Is.EqualTo(new byte[] { 0x21, 0x58, 0x3f, 0xa9 })); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllLinesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllLinesTests.cs index e80aea213..96196c87f 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllLinesTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadAllLinesTests.cs @@ -29,9 +29,8 @@ public void MockFile_ReadAllLines_ShouldReturnOriginalTextData() var result = file.ReadAllLines(XFS.Path(@"c:\something\demo.txt")); // Assert - CollectionAssert.AreEqual( - new[] { "Demo", "text", "content", "value" }, - result); + Assert.That(result, + Is.EqualTo(new[] { "Demo", "text", "content", "value" })); } [Test] @@ -51,9 +50,8 @@ public void MockFile_ReadAllLines_ShouldReturnOriginalDataWithCustomEncoding() var result = file.ReadAllLines(XFS.Path(@"c:\something\demo.txt"), Encoding.BigEndianUnicode); // Assert - CollectionAssert.AreEqual( - new[] { "Hello", "there", "Bob", "Bob!" }, - result); + Assert.That(result, + Is.EqualTo(new[] { "Hello", "there", "Bob", "Bob!" })); } [Test] @@ -104,9 +102,7 @@ public async Task MockFile_ReadAllLinesAsync_ShouldReturnOriginalTextData() var result = await file.ReadAllLinesAsync(XFS.Path(@"c:\something\demo.txt")); // Assert - CollectionAssert.AreEqual( - new[] { "Demo", "text", "content", "value" }, - result); + Assert.That(result, Is.EqualTo(new[] { "Demo", "text", "content", "value" })); } [Test] @@ -126,9 +122,7 @@ public async Task MockFile_ReadAllLinesAsync_ShouldReturnOriginalDataWithCustomE var result = await file.ReadAllLinesAsync(XFS.Path(@"c:\something\demo.txt"), Encoding.BigEndianUnicode); // Assert - CollectionAssert.AreEqual( - new[] { "Hello", "there", "Bob", "Bob!" }, - result); + Assert.That(result, Is.EqualTo(new[] { "Hello", "there", "Bob", "Bob!" })); } [Test] @@ -177,9 +171,7 @@ public async Task MockFile_ReadLinesAsync_ShouldReturnOriginalTextData() result.Add(line); // Assert - CollectionAssert.AreEqual( - new[] { "Demo", "text", "content", "value" }, - result); + Assert.That(result, Is.EqualTo(new[] { "Demo", "text", "content", "value" })); } [Test] @@ -202,9 +194,7 @@ public async Task MockFile_ReadLinesAsync_ShouldReturnOriginalDataWithCustomEnco result.Add(line); // Assert - CollectionAssert.AreEqual( - new[] { "Hello", "there", "Bob", "Bob!" }, - result); + Assert.That(result, Is.EqualTo(new[] { "Hello", "there", "Bob", "Bob!" })); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadLinesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadLinesTests.cs index fdf2ef820..a3b46a437 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadLinesTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileReadLinesTests.cs @@ -26,9 +26,7 @@ public void MockFile_ReadLines_ShouldReturnOriginalTextData() var result = file.ReadLines(XFS.Path(@"c:\something\demo.txt")); // Assert - CollectionAssert.AreEqual( - new[] { "Demo", "text", "content", "value" }, - result); + Assert.That(result, Is.EqualTo(new[] { "Demo", "text", "content", "value" })); } [Test] @@ -48,9 +46,7 @@ public void MockFile_ReadLines_ShouldReturnOriginalDataWithCustomEncoding() var result = file.ReadLines(XFS.Path(@"c:\something\demo.txt"), Encoding.BigEndianUnicode); // Assert - CollectionAssert.AreEqual( - new[] { "Hello", "there", "Bob", "Bob!" }, - result); + Assert.That(result, Is.EqualTo(new[] { "Hello", "there", "Bob", "Bob!" })); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs index 6381c02b0..a5bee2205 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs @@ -25,7 +25,8 @@ public void MockFileStream_Flush_WritesByteToFile() cut.Flush(); // Assert - CollectionAssert.AreEqual(new byte[] { 255 }, fileSystem.GetFile(filepath).Contents); + Assert.That(fileSystem.GetFile(filepath).Contents, + Is.EqualTo(new byte[] { 255 })); } [Test] @@ -46,7 +47,8 @@ public async Task MockFileStream_FlushAsync_WritesByteToFile() await cut.FlushAsync(); // Assert - CollectionAssert.AreEqual(new byte[] { 255 }, fileSystem.GetFile(filepath).Contents); + Assert.That(fileSystem.GetFile(filepath).Contents, + Is.EqualTo(new byte[] { 255 })); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index 52748e526..bc27fa1a2 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -305,7 +305,7 @@ public void MockFileSystem_MoveDirectory_MovesDirectoryWithoutRenamingFiles() fileSystem.MoveDirectory(XFS.Path(@"C:\dir1"), XFS.Path(@"C:\dir2")); var expected = new[] { XFS.Path(@"C:\dir2\dir1\dir1.txt") }; - CollectionAssert.AreEquivalent(expected, fileSystem.AllFiles); + Assert.That(fileSystem.AllFiles, Is.EqualTo(expected)); } [Test] @@ -319,7 +319,7 @@ public void MockFileSystem_MoveDirectoryAndFile_ShouldMoveCorrectly() fileSystem.File.Move(XFS.Path(@"C:\target\project.txt"), XFS.Path(@"C:\target\proj.txt")); var expected = new[] { XFS.Path(@"C:\target\proj.txt"), XFS.Path(@"C:\target\subdir\other.txt") }; - CollectionAssert.AreEquivalent(expected, fileSystem.AllFiles); + Assert.That(fileSystem.AllFiles, Is.EqualTo(expected)); } [Test] From 2d699b087a553bd3f4f9dbf90bd70879f6813210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:17:54 +0100 Subject: [PATCH 08/18] Use constraint model for "StartWith" --- .../MockDirectoryTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 50b6c87ad..93372c0d0 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -832,7 +832,7 @@ public void MockDirectory_CreateDirectory_ShouldFailIfTryingToCreateUNCPathOnlyS var ex = Assert.Throws(() => fileSystem.Directory.CreateDirectory(@"\\server")); // Assert - StringAssert.StartsWith("The UNC path should be of the form \\\\server\\share.", ex.Message); + Assert.That(ex.Message, Does.StartWith("The UNC path should be of the form \\\\server\\share.")); Assert.That(ex.ParamName, Is.EqualTo("path")); } From 5e36de8f526e8ebea13c17a21d1cc63d9dd320b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:19:59 +0100 Subject: [PATCH 09/18] Use constraint model for "NotEqualTo" --- .../MockDirectoryTests.cs | 2 +- .../MockFileInfoTests.cs | 16 ++++++++-------- .../MockFileTests.cs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 93372c0d0..7c35bb088 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -1671,7 +1671,7 @@ public void MockDirectory_SetCurrentDirectory_ShouldChangeCurrentDirectory() var fileSystem = new MockFileSystem(); // Precondition - Assert.AreNotEqual(directory, fileSystem.Directory.GetCurrentDirectory()); + Assert.That(fileSystem.Directory.GetCurrentDirectory(), Is.Not.EqualTo(directory)); fileSystem.Directory.SetCurrentDirectory(directory); diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs index ff3928903..f94055048 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs @@ -246,7 +246,7 @@ public void MockFileInfo_IsReadOnly_ShouldSetNotReadOnlyAttributeOfFileInMemoryF fileInfo.IsReadOnly = false; - Assert.AreNotEqual(FileAttributes.ReadOnly, fileData.Attributes & FileAttributes.ReadOnly); + Assert.That(fileData.Attributes & FileAttributes.ReadOnly, Is.Not.EqualTo(FileAttributes.ReadOnly)); } [Test] @@ -345,7 +345,7 @@ public void MockFileInfo_Decrypt_ShouldUnsetEncryptedAttributeOfFileInMemoryFile fileInfo.Decrypt(); - Assert.AreNotEqual(FileAttributes.Encrypted, fileData.Attributes & FileAttributes.Encrypted); + Assert.That(fileData.Attributes & FileAttributes.Encrypted, Is.Not.EqualTo(FileAttributes.Encrypted)); } [Test] @@ -893,7 +893,7 @@ public void MockFileInfo_LastAccessTimeUtcWithUnspecifiedDateTimeKind_ShouldSetL }; Assert.That(fileInfo.LastAccessTimeUtc, Is.EqualTo(date)); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastAccessTimeUtc.Kind); + Assert.That(fileInfo.LastAccessTimeUtc.Kind, Is.Not.EqualTo(DateTimeKind.Unspecified)); } [Test] @@ -909,7 +909,7 @@ public void MockFileInfo_LastAccessTimeWithUnspecifiedDateTimeKind_ShouldSetLast }; Assert.That(fileInfo.LastAccessTime, Is.EqualTo(date)); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastAccessTime.Kind); + Assert.That(fileInfo.LastAccessTime.Kind, Is.Not.EqualTo(DateTimeKind.Unspecified)); } [Test] @@ -925,7 +925,7 @@ public void MockFileInfo_CreationTimeUtcWithUnspecifiedDateTimeKind_ShouldSetCre }; Assert.That(fileInfo.CreationTimeUtc, Is.EqualTo(date)); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.CreationTimeUtc.Kind); + Assert.That(fileInfo.CreationTimeUtc.Kind, Is.Not.EqualTo(DateTimeKind.Unspecified)); } [Test] @@ -941,7 +941,7 @@ public void MockFileInfo_CreationTimeWithUnspecifiedDateTimeKind_ShouldSetCreati }; Assert.That(fileInfo.CreationTime, Is.EqualTo(date)); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.CreationTime.Kind); + Assert.That(fileInfo.CreationTime.Kind, Is.Not.EqualTo(DateTimeKind.Unspecified)); } [Test] @@ -957,7 +957,7 @@ public void MockFileInfo_LastWriteTimeUtcWithUnspecifiedDateTimeKind_ShouldSetLa }; Assert.That(fileInfo.LastWriteTimeUtc, Is.EqualTo(date)); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastWriteTimeUtc.Kind); + Assert.That(fileInfo.LastWriteTimeUtc.Kind, Is.Not.EqualTo(DateTimeKind.Unspecified)); } [Test] @@ -973,7 +973,7 @@ public void MockFileInfo_LastWriteTimeWithUnspecifiedDateTimeKind_ShouldSetLastW }; Assert.That(fileInfo.LastWriteTime, Is.EqualTo(date)); - Assert.AreNotEqual(DateTimeKind.Unspecified, fileInfo.LastWriteTime.Kind); + Assert.That(fileInfo.LastWriteTime.Kind, Is.Not.EqualTo(DateTimeKind.Unspecified)); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs index 72015017e..c4f16a988 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs @@ -610,7 +610,7 @@ public void MockFile_Decrypt_ShouldRemoveEncryptedAttribute() var attributes = fileSystem.File.GetAttributes(filePath); // Assert - Assert.AreNotEqual(FileAttributes.Encrypted, attributes & FileAttributes.Encrypted); + Assert.That(attributes & FileAttributes.Encrypted, Is.Not.EqualTo(FileAttributes.Encrypted)); } [Test] From f95de7bbc4e86181ac369d7963a0e56b551c3e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:20:32 +0100 Subject: [PATCH 10/18] Use constraint model for "SameAs" --- .../MockFileStreamTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs index a5bee2205..8454c7ea4 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs @@ -235,7 +235,7 @@ public void MockFileStream_Null_ShouldReturnSingletonObject() var result1 = MockFileStream.Null; var result2 = MockFileStream.Null; - Assert.AreSame(result1, result2); + Assert.That(result1, Is.SameAs(result2)); } [Test] From 30d5f34358517c61082be4c93bb91844b644400f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:22:35 +0100 Subject: [PATCH 11/18] Use constraint model for "Contains" --- .../MockFileSystemTests.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index bc27fa1a2..346a4827f 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -230,10 +230,10 @@ public void MockFileSystem_AddFile_ShouldMatchCapitalization_PerfectMatch() fileSystem.AddDirectory(XFS.Path(@"C:\test\SUBDirectory")); fileSystem.AddDirectory(XFS.Path(@"C:\LOUD\SUBDirectory")); - Assert.Contains(XFS.Path(@"C:\test\file.txt"), fileSystem.AllFiles.ToList()); - Assert.Contains(XFS.Path(@"C:\LOUD\file.txt"), fileSystem.AllFiles.ToList()); - Assert.Contains(XFS.Path(@"C:\test\SUBDirectory"), fileSystem.AllDirectories.ToList()); - Assert.Contains(XFS.Path(@"C:\LOUD\SUBDirectory"), fileSystem.AllDirectories.ToList()); + Assert.That(fileSystem.AllFiles.ToList(), Does.Contain(XFS.Path(@"C:\test\file.txt"))); + Assert.That(fileSystem.AllFiles.ToList(), Does.Contain(XFS.Path(@"C:\LOUD\file.txt"))); + Assert.That(fileSystem.AllDirectories.ToList(), Does.Contain(XFS.Path(@"C:\test\SUBDirectory"))); + Assert.That(fileSystem.AllDirectories.ToList(), Does.Contain(XFS.Path(@"C:\LOUD\SUBDirectory"))); } [Test] @@ -249,10 +249,10 @@ public void MockFileSystem_AddFile_ShouldMatchCapitalization_PartialMatch() fileSystem.AddDirectory(XFS.Path(@"C:\test\SUBTEST\SUBDirectory")); fileSystem.AddDirectory(XFS.Path(@"C:\LOUD\subloud\SUBDirectory")); - Assert.Contains(XFS.Path(@"C:\test\subtest\file.txt"), fileSystem.AllFiles.ToList()); - Assert.Contains(XFS.Path(@"C:\LOUD\SUBLOUD\file.txt"), fileSystem.AllFiles.ToList()); - Assert.Contains(XFS.Path(@"C:\test\subtest\SUBDirectory"), fileSystem.AllDirectories.ToList()); - Assert.Contains(XFS.Path(@"C:\LOUD\SUBLOUD\SUBDirectory"), fileSystem.AllDirectories.ToList()); + Assert.That(fileSystem.AllFiles.ToList(), Does.Contain(XFS.Path(@"C:\test\subtest\file.txt"))); + Assert.That(fileSystem.AllFiles.ToList(), Does.Contain(XFS.Path(@"C:\LOUD\SUBLOUD\file.txt"))); + Assert.That(fileSystem.AllDirectories.ToList(), Does.Contain(XFS.Path(@"C:\test\subtest\SUBDirectory"))); + Assert.That(fileSystem.AllDirectories.ToList(), Does.Contain(XFS.Path(@"C:\LOUD\SUBLOUD\SUBDirectory"))); } [Test] @@ -268,10 +268,10 @@ public void MockFileSystem_AddFile_ShouldMatchCapitalization_PartialMatch_Furthe fileSystem.AddDirectory(XFS.Path(@"C:\test\SUBTEST\new\SUBDirectory")); fileSystem.AddDirectory(XFS.Path(@"C:\LOUD\subloud\new\SUBDirectory")); - Assert.Contains(XFS.Path(@"C:\test\subtest\new\file.txt"), fileSystem.AllFiles.ToList()); - Assert.Contains(XFS.Path(@"C:\LOUD\SUBLOUD\new\file.txt"), fileSystem.AllFiles.ToList()); - Assert.Contains(XFS.Path(@"C:\test\subtest\new\SUBDirectory"), fileSystem.AllDirectories.ToList()); - Assert.Contains(XFS.Path(@"C:\LOUD\SUBLOUD\new\SUBDirectory"), fileSystem.AllDirectories.ToList()); + Assert.That(fileSystem.AllFiles.ToList(), Does.Contain(XFS.Path(@"C:\test\subtest\new\file.txt"))); + Assert.That(fileSystem.AllFiles.ToList(), Does.Contain(XFS.Path(@"C:\LOUD\SUBLOUD\new\file.txt"))); + Assert.That(fileSystem.AllDirectories.ToList(), Does.Contain(XFS.Path(@"C:\test\subtest\new\SUBDirectory"))); + Assert.That(fileSystem.AllDirectories.ToList(), Does.Contain(XFS.Path(@"C:\LOUD\SUBLOUD\new\SUBDirectory"))); } [Test] @@ -292,8 +292,8 @@ public void MockFileSystem_AddFilesFromEmbeddedResource_ShouldAddAllTheFiles() fileSystem.AddFilesFromEmbeddedNamespace(XFS.Path(@"C:\"), Assembly.GetExecutingAssembly(), "System.IO.Abstractions.TestingHelpers.Tests.TestFiles"); - Assert.Contains(XFS.Path(@"C:\TestFile.txt"), fileSystem.AllFiles.ToList()); - Assert.Contains(XFS.Path(@"C:\SecondTestFile.txt"), fileSystem.AllFiles.ToList()); + Assert.That(fileSystem.AllFiles.ToList(), Does.Contain(XFS.Path(@"C:\TestFile.txt"))); + Assert.That(fileSystem.AllFiles.ToList(), Does.Contain(XFS.Path(@"C:\SecondTestFile.txt"))); } [Test] From 0ce1b97cf11aabc5a63330dec17181fc8f095433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:22:57 +0100 Subject: [PATCH 12/18] Use constraint model for "Empty" --- .../MockFileSystemTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index 346a4827f..6e9a4819b 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -99,7 +99,7 @@ public void MockFileSystem_AddFile_ShouldHandleNullFileDataAsEmpty() var result = fileSystem.File.ReadAllText(path); - Assert.IsEmpty(result, "Null MockFileData should be allowed for and result in an empty file."); + Assert.That(result, Is.Empty, "Null MockFileData should be allowed for and result in an empty file."); } [Test] From c0dc01d64119d9f00ddd8dcd104fe43a9e114c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:25:31 +0100 Subject: [PATCH 13/18] Use constraint model for "LessThanOrEqual" --- .../MockFileCopyTests.cs | 2 +- .../MockFileOpenTests.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs index 9a01332f3..5b8512fab 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs @@ -40,7 +40,7 @@ public void MockFile_Copy_ShouldAdjustTimestampsOnDestination() var sourceFileInfo = mockFileSystem.FileInfo.New(sourceFileName); var destFileInfo = mockFileSystem.FileInfo.New(destFileName); Assert.That(destFileInfo.LastWriteTime, Is.EqualTo(sourceFileInfo.LastWriteTime)); - Assert.LessOrEqual(DateTime.Now - destFileInfo.CreationTime, TimeSpan.FromSeconds(1)); + Assert.That(DateTime.Now - destFileInfo.CreationTime, Is.LessThanOrEqualTo( TimeSpan.FromSeconds(1))); Assert.That(destFileInfo.LastAccessTime, Is.EqualTo(destFileInfo.CreationTime)); } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs index 91edbd592..9902cd1dc 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs @@ -228,7 +228,7 @@ public void MockFile_OpenText_ShouldUpdateLastAccessTime() } // Assert - Assert.LessOrEqual(DateTime.Now - fs.FileInfo.New(filepath).LastAccessTime, TimeSpan.FromSeconds(1)); + Assert.That(DateTime.Now - fs.FileInfo.New(filepath).LastAccessTime, Is.LessThanOrEqualTo(TimeSpan.FromSeconds(1))); } [Test] @@ -251,7 +251,7 @@ public void MockFile_Read_ShouldRetainCreationTimeAndUpdateLastAccessTime() fi.Refresh(); // Assert Assert.That(fi.CreationTime, Is.EqualTo(creationTime)); - Assert.LessOrEqual(DateTime.Now - fi.LastAccessTime, TimeSpan.FromSeconds(1)); + Assert.That(DateTime.Now - fi.LastAccessTime, Is.LessThanOrEqualTo(TimeSpan.FromSeconds(1))); } [Test] @@ -274,7 +274,7 @@ public async Task MockFile_ReadAsync_ShouldRetainCreationTimeAndUpdateLastAccess fi.Refresh(); // Assert Assert.That(fi.CreationTime, Is.EqualTo(creationTime)); - Assert.LessOrEqual(DateTime.Now - fi.LastAccessTime, TimeSpan.FromSeconds(1)); + Assert.That(DateTime.Now - fi.LastAccessTime, Is.LessThanOrEqualTo(TimeSpan.FromSeconds(1))); } [Test] @@ -297,8 +297,8 @@ public void MockFile_Write_ShouldRetainCreationTimeAndUpdateLastAccessTimeAndLas fi.Refresh(); // Assert Assert.That(fi.CreationTime, Is.EqualTo(creationTime)); - Assert.LessOrEqual(DateTime.Now - fi.LastAccessTime, TimeSpan.FromSeconds(1)); - Assert.LessOrEqual(DateTime.Now - fi.LastWriteTime, TimeSpan.FromSeconds(1)); + Assert.That(DateTime.Now - fi.LastAccessTime, Is.LessThanOrEqualTo(TimeSpan.FromSeconds(1))); + Assert.That(DateTime.Now - fi.LastWriteTime, Is.LessThanOrEqualTo(TimeSpan.FromSeconds(1))); } [Test] @@ -321,8 +321,8 @@ public async Task MockFile_WriteAsync_ShouldRetainCreationTimeAndUpdateLastAcces fi.Refresh(); // Assert Assert.That(fi.CreationTime, Is.EqualTo(creationTime)); - Assert.LessOrEqual(DateTime.Now - fi.LastAccessTime, TimeSpan.FromSeconds(1)); - Assert.LessOrEqual(DateTime.Now - fi.LastWriteTime, TimeSpan.FromSeconds(1)); + Assert.That(DateTime.Now - fi.LastAccessTime, Is.LessThanOrEqualTo(TimeSpan.FromSeconds(1))); + Assert.That(DateTime.Now - fi.LastWriteTime, Is.LessThanOrEqualTo(TimeSpan.FromSeconds(1))); } [Test] From 9220515bcf83781c84b03e2b1d79082a674641d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:30:29 +0100 Subject: [PATCH 14/18] Use constraint model for "IsFalse" --- .../MockDirectoryInfoTests.cs | 6 ++-- .../MockDirectoryTests.cs | 36 +++++++++---------- .../MockFileCreateTests.cs | 4 +-- .../MockFileExistsTests.cs | 12 +++---- .../MockFileInfoTests.cs | 8 ++--- .../MockFileStreamFactoryTests.cs | 2 +- .../MockFileStreamTests.cs | 2 +- .../MockFileSystemTests.cs | 2 +- .../MockFileTests.cs | 2 +- .../MockFileWriteAllBytesTests.cs | 2 +- .../MockFileWriteAllLinesTests.cs | 2 +- .../MockFileWriteAllTextTests.cs | 2 +- .../MockPathTests.cs | 8 ++--- 13 files changed, 44 insertions(+), 44 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs index 21e6c1f72..207f83e46 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs @@ -477,7 +477,7 @@ public void MockDirectoryInfo_Exists_ShouldReturnCachedData() fileSystem.AddDirectory(path); // Assert - Assert.IsFalse(directoryInfo.Exists); + Assert.That(directoryInfo.Exists, Is.False); } [Test] @@ -535,7 +535,7 @@ public void Directory_does_not_exist_after_delete() directoryInfo.Delete(); // Assert - Assert.IsFalse(directoryInfo.Exists); + Assert.That(directoryInfo.Exists, Is.False); } [Test] @@ -549,7 +549,7 @@ public void Directory_does_not_exist_after_recursive_delete() directoryInfo.Delete(true); // Assert - Assert.IsFalse(directoryInfo.Exists); + Assert.That(directoryInfo.Exists, Is.False); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 7c35bb088..23c824529 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -604,7 +604,7 @@ public void MockDirectory_Exists_ShouldReturnFalseForDirectoryNotDefinedInMemory var result = fileSystem.Directory.Exists(XFS.Path(@"c:\baz")); // Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -620,7 +620,7 @@ public void MockDirectory_Exists_ShouldReturnFalseForDirectoryNotDefinedInMemory var result = fileSystem.Directory.Exists(XFS.Path(@"c:\baz\")); // Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -637,7 +637,7 @@ public void MockDirectory_Exists_ShouldReturnFalseForDirectoryNotDefinedInMemory var result = fileSystem.Directory.Exists(XFS.Path(@"c:\baz")); // Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -683,7 +683,7 @@ public void MockDirectory_Exists_ShouldReturnFalseForIllegalPath(string path) var result = fileSystem.Directory.Exists(path); // Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -710,7 +710,7 @@ public void MockDirectory_Exists_ShouldReturnFalseForFiles() var result = fileSystem.Directory.Exists(XFS.Path(@"c:\foo\bar.txt")); // Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -894,7 +894,7 @@ public void MockDirectory_Delete_ShouldDeleteDirectory() fileSystem.Directory.Delete(XFS.Path(@"c:\bar"), true); // Assert - Assert.IsFalse(fileSystem.Directory.Exists(XFS.Path(@"c:\bar"))); + Assert.That(fileSystem.Directory.Exists(XFS.Path(@"c:\bar")), Is.False); } [Test] @@ -915,8 +915,8 @@ public void MockDirectory_Delete_ShouldNotDeleteAllDirectories() fileSystem.Directory.Delete(folder1Path, recursive: true); // Assert - Assert.IsFalse(fileSystem.Directory.Exists(folder1Path)); - Assert.IsFalse(fileSystem.Directory.Exists(folder1SubFolderPath)); + Assert.That(fileSystem.Directory.Exists(folder1Path), Is.False); + Assert.That(fileSystem.Directory.Exists(folder1SubFolderPath), Is.False); Assert.IsTrue(fileSystem.Directory.Exists(folder2Path)); } @@ -934,7 +934,7 @@ public void MockDirectory_Delete_ShouldDeleteDirectoryCaseInsensitively() fileSystem.Directory.Delete(XFS.Path(@"c:\BAR"), true); // Assert - Assert.IsFalse(fileSystem.Directory.Exists(XFS.Path(@"c:\bar"))); + Assert.That(fileSystem.Directory.Exists(XFS.Path(@"c:\bar")), Is.False); } [Test] @@ -968,7 +968,7 @@ public void MockDirectory_Delete_ShouldDeleteDirectoryCaseSensitively() fileSystem.Directory.Delete("/bar", true); // Assert - Assert.IsFalse(fileSystem.Directory.Exists("/bar")); + Assert.That(fileSystem.Directory.Exists("/bar"), Is.False); } [Test] @@ -1014,8 +1014,8 @@ public void MockDirectory_Delete_ShouldDeleteDirectoryRecursively() fileSystem.DirectoryInfo.New(XFS.Path(@"c:\bar")).Delete(true); // Assert - Assert.IsFalse(fileSystem.Directory.Exists(XFS.Path(@"c:\bar"))); - Assert.IsFalse(fileSystem.Directory.Exists(XFS.Path(@"c:\bar\bar2"))); + Assert.That(fileSystem.Directory.Exists(XFS.Path(@"c:\bar")), Is.False); + Assert.That(fileSystem.Directory.Exists(XFS.Path(@"c:\bar\bar2")), Is.False); } [Test] @@ -1251,7 +1251,7 @@ public void MockDirectory_GetDirectories_Returns_Child_Directories() var directories = fileSystem.Directory.GetDirectories(XFS.Path(@"A:\folder1")).ToArray(); //Check that it does not returns itself - Assert.IsFalse(directories.Contains(XFS.Path(@"A:\folder1"))); + Assert.That(directories.Contains(XFS.Path(@"A:\folder1")), Is.False); //Check that it correctly returns all child directories Assert.That(directories.Count(), Is.EqualTo(2)); @@ -1392,7 +1392,7 @@ public void MockDirectory_EnumerateDirectories_Returns_Child_Directories() var directories = fileSystem.Directory.EnumerateDirectories(XFS.Path(@"A:\folder1")).ToArray(); //Check that it does not returns itself - Assert.IsFalse(directories.Contains(XFS.Path(@"A:\folder1"))); + Assert.That(directories.Contains(XFS.Path(@"A:\folder1")), Is.False); //Check that it correctly returns all child directories Assert.That(directories.Count(), Is.EqualTo(2)); @@ -1544,7 +1544,7 @@ public void MockDirectory_Move_ShouldMoveDirectories(string sourceDirName, strin fileSystem.DirectoryInfo.New(sourceDirName).MoveTo(destDirName); // Assert - Assert.IsFalse(fileSystem.Directory.Exists(sourceDirName)); + Assert.That(fileSystem.Directory.Exists(sourceDirName), Is.False); Assert.IsTrue(fileSystem.File.Exists(XFS.Path(destDirName + filePathOne))); Assert.IsTrue(fileSystem.File.Exists(XFS.Path(destDirName + filePathTwo))); } @@ -1616,7 +1616,7 @@ public void MockDirectory_Move_ShouldMoveDirectoryWithReadOnlySubDirectory() fileSystem.DirectoryInfo.New(sourceDirName).MoveTo(destDirName); // Assert - Assert.IsFalse(fileSystem.Directory.Exists(sourceSubDirName)); + Assert.That(fileSystem.Directory.Exists(sourceSubDirName), Is.False); Assert.IsTrue(fileSystem.FileExists(destSubDirName)); } @@ -2133,7 +2133,7 @@ public void Move_Directory_Throws_When_Target_Directory_Parent_Does_Not_Exist( fileSystem.Directory.Move(sourceDirName, targetDirName)); // Assert - Assert.IsFalse(fileSystem.Directory.Exists(targetDirName)); + Assert.That(fileSystem.Directory.Exists(targetDirName), Is.False); Assert.IsTrue(fileSystem.Directory.Exists(sourceDirName)); } @@ -2172,7 +2172,7 @@ public void Move_Directory_DoesNotThrow_When_Target_Directory_Parent_Exists( // Assert Assert.IsTrue(fileSystem.Directory.Exists(targetDirName)); - Assert.IsFalse(fileSystem.Directory.Exists(sourceDirName)); + Assert.That(fileSystem.Directory.Exists(sourceDirName), Is.False); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs index 6f84551f5..40c120e42 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs @@ -244,7 +244,7 @@ public void MockFile_Create_DeleteOnCloseOption_FileDeletedWhenStreamIsClosed() { } - Assert.IsFalse(fileSystem.File.Exists(filePath)); + Assert.That(fileSystem.File.Exists(filePath), Is.False); } [Test] @@ -258,7 +258,7 @@ public void MockFile_Create_EncryptedOption_FileNotYetEncryptedWhenStreamIsOpen( using (var stream = fileSystem.File.Create(filePath, 4096, FileOptions.Encrypted)) { var fileInfo = fileSystem.FileInfo.New(filePath); - Assert.IsFalse(fileInfo.Attributes.HasFlag(FileAttributes.Encrypted)); + Assert.That(fileInfo.Attributes.HasFlag(FileAttributes.Encrypted), Is.False); } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileExistsTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileExistsTests.cs index a622e7e2a..1a17585ed 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileExistsTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileExistsTests.cs @@ -55,7 +55,7 @@ public void MockFile_Exists_ShouldReturnFalseForPathVaryingByCase() var result = fileSystem.File.Exists("/SomeThing/DEMO.txt"); // Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -72,7 +72,7 @@ public void MockFile_Exists_ShouldReturnFalseForEntirelyDifferentPath() var result = fileSystem.File.Exists(XFS.Path(@"C:\SomeThing\DoesNotExist.gif")); // Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -85,7 +85,7 @@ public void MockFile_Exists_ShouldReturnFalseForNullPath() var result = fileSystem.File.Exists(null); // Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -98,7 +98,7 @@ public void MockFile_Exists_ShouldReturnFalseForEmptyStringPath() var result = fileSystem.File.Exists(string.Empty); // Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -111,7 +111,7 @@ public void MockFile_Exists_ShouldReturnFalseForInvalidCharactersInPath() var result = fileSystem.File.Exists(@"C:""*/:<>?|abc"); // Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -128,7 +128,7 @@ public void MockFile_Exists_ShouldReturnFalseForDirectories() var result = fileSystem.File.Exists(XFS.Path(@"C:\something\")); // Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } } } \ No newline at end of file diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs index f94055048..017291854 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs @@ -47,7 +47,7 @@ public void MockFileInfo_Exists_ShouldReturnFalseIfFileDoesNotExistInMemoryFileS var result = fileInfo.Exists; - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -61,7 +61,7 @@ public void MockFileInfo_Exists_ShouldReturnFalseIfPathLeadsToDirectory() var result = fileInfo.Exists; - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -805,7 +805,7 @@ public void MockFileInfo_Exists_ShouldReturnCachedData() fileSystem.AddFile(path1, new MockFileData("1")); // Assert - Assert.IsFalse(fileInfo.Exists); + Assert.That(fileInfo.Exists, Is.False); } [Test] @@ -864,7 +864,7 @@ public void MockFileInfo_Delete_ShouldUpdateCachedDataAndReturnFalseForExists() fileInfo.Delete(); // Assert - Assert.IsFalse(fileInfo.Exists); + Assert.That(fileInfo.Exists, Is.False); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs index 576b34fe6..9e0a9512b 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs @@ -172,7 +172,7 @@ public void MockFileStream_CanRead_ReturnsFalseForAWriteOnlyStream() var fileStream = fileSystem.FileStream.New("file.txt", FileMode.CreateNew, FileAccess.Write); // Assert - Assert.IsFalse(fileStream.CanRead); + Assert.That(fileStream.CanRead, Is.False); } } } \ No newline at end of file diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs index 8454c7ea4..a31104282 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamTests.cs @@ -100,7 +100,7 @@ public void MockFileStream_Constructor_ReadTypeNotWritable() // Act var stream = new MockFileStream(fileSystem, filePath, FileMode.Open, FileAccess.Read); - Assert.IsFalse(stream.CanWrite); + Assert.That(stream.CanWrite, Is.False); Assert.Throws(() => stream.WriteByte(1)); } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index 6e9a4819b..fc0995b13 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -330,7 +330,7 @@ public void MockFileSystem_RemoveFile_RemovesFiles() fileSystem.RemoveFile(@"C:\file.txt"); - Assert.False(fileSystem.FileExists(@"C:\file.txt")); + Assert.That(fileSystem.FileExists(@"C:\file.txt"), Is.False); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs index c4f16a988..dd91bfb21 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileTests.cs @@ -701,7 +701,7 @@ public void MockFile_OpenRead_ShouldReturnReadOnlyStream() var stream = fileSystem.File.OpenRead(filePath); // Assert - Assert.IsFalse(stream.CanWrite); + Assert.That(stream.CanWrite, Is.False); Assert.Throws(() => stream.WriteByte(0)); } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs index f76c80803..a6ec78747 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllBytesTests.cs @@ -133,7 +133,7 @@ await fileSystem.File.WriteAllTextAsync( ); // Assert - Assert.IsFalse(fileSystem.File.Exists(path)); + Assert.That(fileSystem.File.Exists(path), Is.False); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllLinesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllLinesTests.cs index d5c259c55..85530c067 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllLinesTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllLinesTests.cs @@ -395,7 +395,7 @@ await fileSystem.File.WriteAllLinesAsync( ); // Assert - Assert.IsFalse(fileSystem.File.Exists(path)); + Assert.That(fileSystem.File.Exists(path), Is.False); } #endif diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs index 5127501db..95fdf2f03 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs @@ -253,7 +253,7 @@ await fileSystem.File.WriteAllTextAsync( ); // Assert - Assert.IsFalse(fileSystem.File.Exists(path)); + Assert.That(fileSystem.File.Exists(path), Is.False); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs index 610e39b3e..7802c3785 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs @@ -478,7 +478,7 @@ public void IsPathFullyQualified_WithRelativePath_ReturnsFalse() var result = mockPath.IsPathRooted(XFS.Path("directory\\file.txt")); //Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -491,7 +491,7 @@ public void IsPathFullyQualified_WithRelativePathParts_ReturnsFalse() var result = mockPath.IsPathRooted(XFS.Path("directory\\..\\file.txt")); //Assert - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -567,7 +567,7 @@ public void Exists_Null_ShouldReturnFalse() var fileSystem = new MockFileSystem(); bool result = fileSystem.Path.Exists(null); - Assert.IsFalse(result); + Assert.That(result, Is.False); } [Test] @@ -614,7 +614,7 @@ public void Exists_ExistingFileOrDirectory_ShouldReturnTrue() string path = "some-path"; bool result = fileSystem.Path.Exists(path); - Assert.IsFalse(result); + Assert.That(result, Is.False); } #endif From f518d3d3577a1169359c2a4415b5c365357716ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:37:26 +0100 Subject: [PATCH 15/18] Use constraint model for "IsTrue" --- .../MockDirectoryInfoTests.cs | 8 +-- .../MockDirectorySymlinkTests.cs | 4 +- .../MockDirectoryTests.cs | 60 +++++++++---------- .../MockFileCreateTests.cs | 4 +- .../MockFileExistsTests.cs | 4 +- .../MockFileInfoTests.cs | 12 ++-- .../MockFileOpenTests.cs | 4 +- .../MockFileStreamFactoryTests.cs | 2 +- .../MockFileSymlinkTests.cs | 2 +- .../MockFileSystemTests.cs | 16 ++--- .../MockPathTests.cs | 24 ++++---- 11 files changed, 70 insertions(+), 70 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs index 207f83e46..7532d3558 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs @@ -493,7 +493,7 @@ public void MockDirectoryInfo_Exists_ShouldUpdateCachedDataOnRefresh() directoryInfo.Refresh(); // Assert - Assert.IsTrue(directoryInfo.Exists); + Assert.That(directoryInfo.Exists, Is.True); } [Test] @@ -507,7 +507,7 @@ public void Directory_exists_after_creation() directoryInfo.Create(); // Assert - Assert.IsTrue(directoryInfo.Exists); + Assert.That(directoryInfo.Exists, Is.True); } [Test, WindowsOnly(WindowsSpecifics.AccessControlLists)] @@ -521,7 +521,7 @@ public void Directory_exists_after_creation_with_security() directoryInfo.Create(new DirectorySecurity()); // Assert - Assert.IsTrue(directoryInfo.Exists); + Assert.That(directoryInfo.Exists, Is.True); } [Test] @@ -563,7 +563,7 @@ public void Directory_still_exists_after_move() directoryInfo.MoveTo(XFS.Path(@"c:\abc2")); // Assert - Assert.IsTrue(directoryInfo.Exists); + Assert.That(directoryInfo.Exists, Is.True); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs index 0267af172..9414afc12 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs @@ -195,7 +195,7 @@ public void MockDirectory_CreateSymbolicLink_ShouldNotFailIfTargetDoesNotExist() var fileSystemInfo = fileSystem.Directory.CreateSymbolicLink(path, pathToTarget); // Assert - Assert.IsTrue(fileSystemInfo.Exists); + Assert.That(fileSystemInfo.Exists, Is.True); } [Test] @@ -209,7 +209,7 @@ public void MockDirectory_CreateSymbolicLink_ShouldSetReparsePointAttribute() fileSystem.Directory.CreateSymbolicLink(path, pathToTarget); var attributes = fileSystem.DirectoryInfo.New(path).Attributes; - Assert.IsTrue(attributes.HasFlag(FileAttributes.ReparsePoint)); + Assert.That(attributes.HasFlag(FileAttributes.ReparsePoint), Is.True); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 23c824529..1d9f3698b 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -572,7 +572,7 @@ public void MockDirectory_Exists_ShouldReturnTrueForDirectoryDefinedInMemoryFile var result = fileSystem.Directory.Exists(XFS.Path(@"c:\foo")); // Assert - Assert.IsTrue(result); + Assert.That(result, Is.True); } [Test] @@ -588,7 +588,7 @@ public void MockDirectory_Exists_ShouldReturnTrueForDirectoryDefinedInMemoryFile var result = fileSystem.Directory.Exists(XFS.Path(@"c:\foo\")); // Assert - Assert.IsTrue(result); + Assert.That(result, Is.True); } [Test] @@ -654,7 +654,7 @@ public void MockDirectory_Exists_ShouldReturnTrueForDirectoryCreatedViaMocks() var result = fileSystem.Directory.Exists(XFS.Path(@"c:\bar")); // Assert - Assert.IsTrue(result); + Assert.That(result, Is.True); } [Test] @@ -668,7 +668,7 @@ public void MockDirectory_Exists_ShouldReturnTrueForFolderContainingFileAddedToM var result = fileSystem.Directory.Exists(XFS.Path(@"c:\foo\")); // Assert - Assert.IsTrue(result); + Assert.That(result, Is.True); } [TestCase(@"\\s")] @@ -726,8 +726,8 @@ public void MockDirectory_CreateDirectory_ShouldCreateFolderInMemoryFileSystem() fileSystem.Directory.CreateDirectory(XFS.Path(@"c:\bar")); // Assert - Assert.IsTrue(fileSystem.FileExists(XFS.Path(@"c:\bar\"))); - Assert.IsTrue(fileSystem.AllDirectories.Any(d => d == XFS.Path(@"c:\bar"))); + Assert.That(fileSystem.FileExists(XFS.Path(@"c:\bar\")), Is.True); + Assert.That(fileSystem.AllDirectories.Any(d => d == XFS.Path(@"c:\bar")), Is.True); } [Test] @@ -788,7 +788,7 @@ public void MockDirectory_CreateDirectory_ShouldTrimTrailingSpaces() fileSystem.Directory.CreateDirectory(XFS.Path(@"c:\temp\folder ")); // Assert - Assert.IsTrue(fileSystem.Directory.Exists(XFS.Path(@"c:\temp\folder"))); + Assert.That(fileSystem.Directory.Exists(XFS.Path(@"c:\temp\folder")), Is.True); } [Test] @@ -818,7 +818,7 @@ public void MockDirectory_CreateDirectory_ShouldWorkWithUNCPath() fileSystem.Directory.CreateDirectory(@"\\server\share\path\to\create"); // Assert - Assert.IsTrue(fileSystem.Directory.Exists(@"\\server\share\path\to\create\")); + Assert.That(fileSystem.Directory.Exists(@"\\server\share\path\to\create\"), Is.True); } [Test] @@ -847,7 +847,7 @@ public void MockDirectory_CreateDirectory_ShouldSucceedIfTryingToCreateUNCPathSh fileSystem.Directory.CreateDirectory(@"\\server\share"); // Assert - Assert.IsTrue(fileSystem.Directory.Exists(@"\\server\share\")); + Assert.That(fileSystem.Directory.Exists(@"\\server\share\"), Is.True); } #if FEATURE_CREATE_TEMP_SUBDIRECTORY @@ -861,8 +861,8 @@ public void MockDirectory_CreateTempSubdirectory_ShouldCreateSubdirectoryInTempD var result = fileSystem.Directory.CreateTempSubdirectory(); // Assert - Assert.IsTrue(fileSystem.Directory.Exists(result.FullName)); - Assert.IsTrue(result.FullName.Contains(Path.GetTempPath())); + Assert.That(fileSystem.Directory.Exists(result.FullName), Is.True); + Assert.That(result.FullName.Contains(Path.GetTempPath()), Is.True); } [Test] @@ -875,9 +875,9 @@ public void MockDirectory_CreateTempSubdirectoryWithPrefix_ShouldCreateDirectory var result = fileSystem.Directory.CreateTempSubdirectory("foo-"); // Assert - Assert.IsTrue(fileSystem.Directory.Exists(result.FullName)); - Assert.IsTrue(Path.GetFileName(result.FullName).StartsWith("foo-")); - Assert.IsTrue(result.FullName.Contains(Path.GetTempPath())); + Assert.That(fileSystem.Directory.Exists(result.FullName), Is.True); + Assert.That(Path.GetFileName(result.FullName).StartsWith("foo-"), Is.True); + Assert.That(result.FullName.Contains(Path.GetTempPath()), Is.True); } #endif @@ -917,7 +917,7 @@ public void MockDirectory_Delete_ShouldNotDeleteAllDirectories() // Assert Assert.That(fileSystem.Directory.Exists(folder1Path), Is.False); Assert.That(fileSystem.Directory.Exists(folder1SubFolderPath), Is.False); - Assert.IsTrue(fileSystem.Directory.Exists(folder2Path)); + Assert.That(fileSystem.Directory.Exists(folder2Path), Is.True); } [Test] @@ -1229,13 +1229,13 @@ public void MockDirectory_GetLogicalDrives_Returns_LogicalDrives() if (XFS.IsUnixPlatform()) { Assert.That(drives.Length, Is.EqualTo(1)); - Assert.IsTrue(drives.Contains("/")); + Assert.That(drives.Contains("/"), Is.True); } else { Assert.That(drives.Length, Is.EqualTo(2)); - Assert.IsTrue(drives.Contains(@"C:\")); - Assert.IsTrue(drives.Contains(@"D:\")); + Assert.That(drives.Contains(@"C:\"), Is.True); + Assert.That(drives.Contains(@"D:\"), Is.True); } } @@ -1255,8 +1255,8 @@ public void MockDirectory_GetDirectories_Returns_Child_Directories() //Check that it correctly returns all child directories Assert.That(directories.Count(), Is.EqualTo(2)); - Assert.IsTrue(directories.Contains(XFS.Path(@"A:\folder1\folder2"))); - Assert.IsTrue(directories.Contains(XFS.Path(@"A:\folder1\folder4"))); + Assert.That(directories.Contains(XFS.Path(@"A:\folder1\folder2")), Is.True); + Assert.That(directories.Contains(XFS.Path(@"A:\folder1\folder4")), Is.True); } [Test] @@ -1396,8 +1396,8 @@ public void MockDirectory_EnumerateDirectories_Returns_Child_Directories() //Check that it correctly returns all child directories Assert.That(directories.Count(), Is.EqualTo(2)); - Assert.IsTrue(directories.Contains(XFS.Path(@"A:\folder1\folder2"))); - Assert.IsTrue(directories.Contains(XFS.Path(@"A:\folder1\folder4"))); + Assert.That(directories.Contains(XFS.Path(@"A:\folder1\folder2")), Is.True); + Assert.That(directories.Contains(XFS.Path(@"A:\folder1\folder4")), Is.True); } [Test] @@ -1527,7 +1527,7 @@ public void Move_DirectoryExistsWithDifferentCase_DirectorySuccessfullyMoved() fileSystem.Directory.Move(XFS.Path(@"C:\old_location"), XFS.Path(@"C:\NewLocation\")); // Assert - Assert.IsTrue(fileSystem.File.Exists(XFS.Path(@"C:\NewLocation\Data\someFile.txt"))); + Assert.That(fileSystem.File.Exists(XFS.Path(@"C:\NewLocation\Data\someFile.txt")), Is.True); } [TestCaseSource(nameof(GetPathsForMoving))] @@ -1545,8 +1545,8 @@ public void MockDirectory_Move_ShouldMoveDirectories(string sourceDirName, strin // Assert Assert.That(fileSystem.Directory.Exists(sourceDirName), Is.False); - Assert.IsTrue(fileSystem.File.Exists(XFS.Path(destDirName + filePathOne))); - Assert.IsTrue(fileSystem.File.Exists(XFS.Path(destDirName + filePathTwo))); + Assert.That(fileSystem.File.Exists(XFS.Path(destDirName + filePathOne)), Is.True); + Assert.That(fileSystem.File.Exists(XFS.Path(destDirName + filePathTwo)), Is.True); } [Test] @@ -1591,7 +1591,7 @@ public void MockDirectory_Move_ShouldMoveDirectoryAttributes() // Assert var destDirectoryInfo = fileSystem.DirectoryInfo.New(destDirName); - Assert.IsTrue(destDirectoryInfo.Attributes.HasFlag(FileAttributes.System)); + Assert.That(destDirectoryInfo.Attributes.HasFlag(FileAttributes.System), Is.True); } [Test] @@ -1617,7 +1617,7 @@ public void MockDirectory_Move_ShouldMoveDirectoryWithReadOnlySubDirectory() // Assert Assert.That(fileSystem.Directory.Exists(sourceSubDirName), Is.False); - Assert.IsTrue(fileSystem.FileExists(destSubDirName)); + Assert.That(fileSystem.FileExists(destSubDirName), Is.True); } [Test] @@ -1686,7 +1686,7 @@ public void MockDirectory_SetCurrentDirectory_WithRelativePath_ShouldUseFullPath var result = fileSystem.Directory.GetCurrentDirectory(); - Assert.IsTrue(fileSystem.Path.IsPathRooted(result)); + Assert.That(fileSystem.Path.IsPathRooted(result), Is.True); } [Test] @@ -2134,7 +2134,7 @@ public void Move_Directory_Throws_When_Target_Directory_Parent_Does_Not_Exist( // Assert Assert.That(fileSystem.Directory.Exists(targetDirName), Is.False); - Assert.IsTrue(fileSystem.Directory.Exists(sourceDirName)); + Assert.That(fileSystem.Directory.Exists(sourceDirName), Is.True); } private static IEnumerable Success_DirectoryMoveFromToPaths @@ -2171,7 +2171,7 @@ public void Move_Directory_DoesNotThrow_When_Target_Directory_Parent_Exists( fileSystem.Directory.Move(sourceDirName, targetDirName)); // Assert - Assert.IsTrue(fileSystem.Directory.Exists(targetDirName)); + Assert.That(fileSystem.Directory.Exists(targetDirName), Is.True); Assert.That(fileSystem.Directory.Exists(sourceDirName), Is.False); } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs index 40c120e42..0c9fbdc54 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs @@ -228,7 +228,7 @@ public void MockFile_Create_DeleteOnCloseOption_FileExistsWhileStreamIsOpen() using (fileSystem.File.Create(filePath, 4096, FileOptions.DeleteOnClose)) { - Assert.IsTrue(fileSystem.File.Exists(filePath)); + Assert.That(fileSystem.File.Exists(filePath), Is.True); } } @@ -275,7 +275,7 @@ public void MockFile_Create_EncryptedOption_EncryptsFileWhenStreamIsClose() } var fileInfo = fileSystem.FileInfo.New(filePath); - Assert.IsTrue(fileInfo.Attributes.HasFlag(FileAttributes.Encrypted)); + Assert.That(fileInfo.Attributes.HasFlag(FileAttributes.Encrypted), Is.True); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileExistsTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileExistsTests.cs index 1a17585ed..afff22d17 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileExistsTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileExistsTests.cs @@ -21,7 +21,7 @@ public void MockFile_Exists_ShouldReturnTrueForSamePath() var result = fileSystem.File.Exists(XFS.Path(@"C:\something\other.gif")); // Assert - Assert.IsTrue(result); + Assert.That(result, Is.True); } [Test] @@ -38,7 +38,7 @@ public void MockFile_Exists_ShouldReturnTrueForPathVaryingByCase() var result = fileSystem.File.Exists(@"C:\SomeThing\DEMO.txt"); // Assert - Assert.IsTrue(result); + Assert.That(result, Is.True); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs index 017291854..43b266e7c 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs @@ -32,7 +32,7 @@ public void MockFileInfo_Exists_ShouldReturnTrueIfFileExistsInMemoryFileSystem() var result = fileInfo.Exists; - Assert.IsTrue(result); + Assert.That(result, Is.True); } [Test] @@ -574,7 +574,7 @@ public void MockFileInfo_MoveTo_SameSourceAndTargetIsANoOp() fileInfo.MoveTo(destination); Assert.That(fileInfo.FullName, Is.EqualTo(destination)); - Assert.True(fileInfo.Exists); + Assert.That(fileInfo.Exists, Is.True); } [Test] @@ -636,7 +636,7 @@ public void MockFileInfo_MoveToOnlyCaseChanging_ShouldSucceed() fileInfo.MoveTo(destFilePath); Assert.That(fileInfo.FullName, Is.EqualTo(destFilePath)); - Assert.True(fileInfo.Exists); + Assert.That(fileInfo.Exists, Is.True); } [Test] @@ -821,7 +821,7 @@ public void MockFileInfo_Exists_ShouldUpdateCachedDataOnRefresh() fileInfo.Refresh(); // Assert - Assert.IsTrue(fileInfo.Exists); + Assert.That(fileInfo.Exists, Is.True); } [Test] @@ -836,7 +836,7 @@ public void MockFileInfo_Create_ShouldUpdateCachedDataAndReturnTrueForExists() // Assert var result = fileInfo.Exists; - Assert.IsTrue(result); + Assert.That(result, Is.True); } [Test] @@ -850,7 +850,7 @@ public void MockFileInfo_CreateText_ShouldUpdateCachedDataAndReturnTrueForExists fileInfo.CreateText().Dispose(); // Assert - Assert.IsTrue(fileInfo.Exists); + Assert.That(fileInfo.Exists, Is.True); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs index 9902cd1dc..a5f8d3c2e 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileOpenTests.cs @@ -63,8 +63,8 @@ public void MockFile_Open_AllowsReadWriteOnCreate() var stream = filesystem.File.Open(filepath, FileMode.Create); - Assert.True(stream.CanRead); - Assert.True(stream.CanWrite); + Assert.That(stream.CanRead, Is.True); + Assert.That(stream.CanWrite, Is.True); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs index 9e0a9512b..69256694e 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs @@ -159,7 +159,7 @@ public void MockFileStreamFactory_CreateWithRelativePath_CreatesFileInCurrentDir fileStreamFactory.Create("some_random_file.txt", fileMode); // Assert - Assert.True(fileSystem.File.Exists(XFS.Path("./some_random_file.txt"))); + Assert.That(fileSystem.File.Exists(XFS.Path("./some_random_file.txt")), Is.True); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs index 12d13a8b2..b6ad43906 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs @@ -239,7 +239,7 @@ public void MockFile_CreateSymbolicLink_ShouldSetReparsePointAttribute() fileSystem.File.CreateSymbolicLink(path, pathToTarget); var attributes = fileSystem.FileInfo.New(path).Attributes; - Assert.IsTrue(attributes.HasFlag(FileAttributes.ReparsePoint)); + Assert.That(attributes.HasFlag(FileAttributes.ReparsePoint), Is.True); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index fc0995b13..220511478 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -85,7 +85,7 @@ public void MockFileSystem_AddFile_ShouldHandleUnnormalizedSlashes() var fileExists = fs.File.Exists(alternatePath); Assert.That(fileCount, Is.EqualTo(1)); - Assert.IsTrue(fileExists); + Assert.That(fileExists, Is.True); } [Test] @@ -191,7 +191,7 @@ public void MockFileSystem_AddDirectory_ShouldCreateDirectory() fileSystem.AddDirectory(baseDirectory); - Assert.IsTrue(fileSystem.Directory.Exists(baseDirectory)); + Assert.That(fileSystem.Directory.Exists(baseDirectory), Is.True); } [Test] @@ -385,7 +385,7 @@ public void MockFileSystem_AddDirectory_TrailingSlashAllowedButNotRequired(strin fileSystem.AddDirectory(path2); - Assert.IsTrue(fileSystem.FileExists(path2)); + Assert.That(fileSystem.FileExists(path2), Is.True); } [Test] @@ -412,7 +412,7 @@ public void MockFileSystem_DefaultState_CurrentDirectoryExists(string currentDir var actualCurrentDirectory = fs.DirectoryInfo.New("."); - Assert.IsTrue(actualCurrentDirectory.Exists); + Assert.That(actualCurrentDirectory.Exists, Is.True); } [Test] @@ -432,8 +432,8 @@ public void MockFileSystem_DefaultState_DefaultTempDirectoryExists() var mockFileSystem = new MockFileSystem(); var mockFileSystemOverload = new MockFileSystem(null, string.Empty); - Assert.IsTrue(mockFileSystem.Directory.Exists(tempDirectory)); - Assert.IsTrue(mockFileSystemOverload.Directory.Exists(tempDirectory)); + Assert.That(mockFileSystem.Directory.Exists(tempDirectory), Is.True); + Assert.That(mockFileSystemOverload.Directory.Exists(tempDirectory), Is.True); } [Test] @@ -459,8 +459,8 @@ public void MockFileSystem_DeleteDirectoryRecursive_WithReadOnlyFile_ShouldThrow TestDelegate action = () => fileSystem.Directory.Delete(baseDirectory, true); Assert.Throws(action); - Assert.True(fileSystem.File.Exists(textFile)); - Assert.True(fileSystem.Directory.Exists(baseDirectory)); + Assert.That(fileSystem.File.Exists(textFile), Is.True); + Assert.That(fileSystem.Directory.Exists(baseDirectory), Is.True); } private class TestFileSystem : MockFileSystem diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs index 7802c3785..3748705b0 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs @@ -300,7 +300,7 @@ public void GetInvalidFileNameChars_Called_ReturnsChars() var result = mockPath.GetInvalidFileNameChars(); //Assert - Assert.IsTrue(result.Length > 0); + Assert.That(result.Length > 0, Is.True); } [Test] @@ -313,7 +313,7 @@ public void GetInvalidPathChars_Called_ReturnsChars() var result = mockPath.GetInvalidPathChars(); //Assert - Assert.IsTrue(result.Length > 0); + Assert.That(result.Length > 0, Is.True); } [Test] @@ -339,7 +339,7 @@ public void GetRandomFileName_Called_ReturnsStringLengthGreaterThanZero() var result = mockPath.GetRandomFileName(); //Assert - Assert.IsTrue(result.Length > 0); + Assert.That(result.Length > 0, Is.True); } [Test] @@ -352,7 +352,7 @@ public void GetTempFileName_Called_ReturnsStringLengthGreaterThanZero() var result = mockPath.GetTempFileName(); //Assert - Assert.IsTrue(result.Length > 0); + Assert.That(result.Length > 0, Is.True); } [Test] @@ -365,7 +365,7 @@ public void GetTempFileName_Called_CreatesEmptyFileInTempDirectory() //Act var result = mockPath.GetTempFileName(); - Assert.True(fileSystem.FileExists(result)); + Assert.That(fileSystem.FileExists(result), Is.True); Assert.That(fileSystem.FileInfo.New(result).Length, Is.Zero); } @@ -379,7 +379,7 @@ public void GetTempPath_Called_ReturnsStringLengthGreaterThanZero() var result = mockPath.GetTempPath(); //Assert - Assert.IsTrue(result.Length > 0); + Assert.That(result.Length > 0, Is.True); } [Test] @@ -395,7 +395,7 @@ public void GetTempPath_Called_ReturnsStringLengthGreaterThanZero(string tempDir var result = mockPath.GetTempPath(); //Assert - Assert.IsTrue(result.Length > 0); + Assert.That(result.Length > 0, Is.True); } [Test] @@ -425,7 +425,7 @@ public void GetTempPath_Called_WithNullOrEmptyVirtualTempDirectory_ReturnsFallba var result = mockPath.GetTempPath(); //Assert - Assert.IsTrue(result.Length > 0); + Assert.That(result.Length > 0, Is.True); } [Test] @@ -465,7 +465,7 @@ public void IsPathFullyQualified_WithAbsolutePath_ReturnsTrue() var result = mockPath.IsPathFullyQualified(XFS.Path("C:\\directory\\file.txt")); //Assert - Assert.IsTrue(result); + Assert.That(result, Is.True); } [Test] @@ -580,7 +580,7 @@ public void Exists_ShouldWorkWithAbsolutePaths() bool result = fileSystem.Path.Exists(absolutePath); - Assert.IsTrue(result); + Assert.That(result, Is.True); } [Test] @@ -592,7 +592,7 @@ public void Exists_ExistingFile_ShouldReturnTrue() bool result = fileSystem.Path.Exists(path); - Assert.IsTrue(result); + Assert.That(result, Is.True); } [Test] @@ -604,7 +604,7 @@ public void Exists_ExistingDirectory_ShouldReturnTrue() bool result = fileSystem.Path.Exists(path); - Assert.IsTrue(result); + Assert.That(result, Is.True); } [Test] From e226ab8050e081e4cbd30126a69bda369fa19885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:39:28 +0100 Subject: [PATCH 16/18] Use constraint model for "IsNull" --- .../MockDirectoryInfoFactoryTests.cs | 2 +- .../MockDirectoryTests.cs | 2 +- .../MockDriveInfoFactoryTests.cs | 2 +- .../MockFileInfoFactoryTests.cs | 2 +- .../MockFileSystemTests.cs | 4 ++-- .../MockFileSystemWatcherFactoryTests.cs | 2 +- .../ConvertersTests.cs | 6 +++--- .../DirectoryInfoFactoryTests.cs | 2 +- .../DirectoryInfoTests.cs | 2 +- .../DirectoryWrapperTests.cs | 2 +- .../DriveInfoFactoryTests.cs | 4 ++-- .../FileInfoBaseConversionTests.cs | 2 +- .../FileInfoFactoryTests.cs | 2 +- .../FileSystemWatcherFactoryTests.cs | 2 +- 14 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoFactoryTests.cs index 0c57e50cd..a5430e5e9 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoFactoryTests.cs @@ -12,7 +12,7 @@ public void MockDirectoryInfoFactory_Wrap_WithNull_ShouldReturnNull() var result = fileSystem.DirectoryInfo.Wrap(null); - Assert.IsNull(result); + Assert.That(result, Is.Null); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 1d9f3698b..34a74258d 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -1753,7 +1753,7 @@ public void MockDirectory_GetParent_ShouldReturnNullIfPathIsRoot() var actualResult = fileSystem.Directory.GetParent(XFS.Path(@"c:\")); // Assert - Assert.IsNull(actualResult); + Assert.That(actualResult, Is.Null); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoFactoryTests.cs index 0035ac96e..0fe776aae 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDriveInfoFactoryTests.cs @@ -105,7 +105,7 @@ public void MockDriveInfoFactory_Wrap_WithNull_ShouldReturnNull() var result = fileSystem.DriveInfo.Wrap(null); - Assert.IsNull(result); + Assert.That(result, Is.Null); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoFactoryTests.cs index 2f7655000..af551ff99 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoFactoryTests.cs @@ -49,7 +49,7 @@ public void MockFileInfoFactory_Wrap_WithNull_ShouldReturnNull() var result = fileSystem.FileInfo.Wrap(null); - Assert.IsNull(result); + Assert.That(result, Is.Null); } } } \ No newline at end of file diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index 220511478..5781f9e8c 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -23,7 +23,7 @@ public void MockFileSystem_GetFile_ShouldReturnNullWhenFileIsNotRegistered() var result = fileSystem.GetFile(@"c:\something\else.txt"); - Assert.IsNull(result); + Assert.That(result, Is.Null); } [Test] @@ -69,7 +69,7 @@ public void MockFileSystem_GetFile_ShouldNotReturnFileRegisteredInConstructorWhe var result = fileSystem.GetFile("/SomeThing/DEMO.txt"); - Assert.IsNull(result); + Assert.That(result, Is.Null); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemWatcherFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemWatcherFactoryTests.cs index 8def87d9e..817349c9b 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemWatcherFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemWatcherFactoryTests.cs @@ -45,7 +45,7 @@ public void MockFileSystemWatcherFactory_Wrap_WithNull_ShouldReturnNull() var result = fileSystem.FileSystemWatcher.Wrap(null); - Assert.IsNull(result); + Assert.That(result, Is.Null); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/ConvertersTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/ConvertersTests.cs index ba7aa0bf8..e83483352 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/ConvertersTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/ConvertersTests.cs @@ -55,21 +55,21 @@ public void WrapDirectories_with_IEnumerable_is_lazy() [Test] public void WrapFileSystemInfo_handles_null_FileSystemInfo() { - Assert.IsNull(Converters.WrapFileSystemInfo(null, new FileSystem())); + Assert.That(Converters.WrapFileSystemInfo(null, new FileSystem()), Is.Null); } [Test] public void WrapDirectories_handles_null_DirectoryInfo() { List directoryInfos = new() { null }; - Assert.IsNull(directoryInfos.WrapDirectories(new FileSystem()).Single()); + Assert.That(directoryInfos.WrapDirectories(new FileSystem()).Single(), Is.Null); } [Test] public void WrapFiles_handles_null_FileInfo() { List fileInfos = new() { null }; - Assert.IsNull(fileInfos.WrapFiles(new FileSystem()).Single()); + Assert.That(fileInfos.WrapFiles(new FileSystem()).Single(), Is.Null); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryInfoFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryInfoFactoryTests.cs index 8531c41f6..f0c91d54f 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryInfoFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryInfoFactoryTests.cs @@ -12,7 +12,7 @@ public void Wrap_WithNull_ShouldReturnNull() var result = fileSystem.DirectoryInfo.Wrap(null); - Assert.IsNull(result); + Assert.That(result, Is.Null); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryInfoTests.cs index 674852aad..ca0a4c962 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryInfoTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryInfoTests.cs @@ -13,7 +13,7 @@ public void Parent_ForRootDirectory_ShouldReturnNull() var current = wrapperFilesystem.Directory.GetCurrentDirectory(); var root = wrapperFilesystem.DirectoryInfo.New(current).Root; var rootsParent = root.Parent; - Assert.IsNull(rootsParent); + Assert.That(rootsParent, Is.Null); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryWrapperTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryWrapperTests.cs index 93453491f..80c758149 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryWrapperTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DirectoryWrapperTests.cs @@ -16,7 +16,7 @@ public void GetParent_ForRootDirectory_ShouldReturnNull() var result = wrapperFilesystem.Directory.GetParent(root); // Assert - Assert.IsNull(result); + Assert.That(result, Is.Null); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DriveInfoFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DriveInfoFactoryTests.cs index cfa892845..e752ac1ff 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DriveInfoFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/DriveInfoFactoryTests.cs @@ -11,8 +11,8 @@ public void Wrap_WithNull_ShouldReturnNull() var fileSystem = new FileSystem(); var result = fileSystem.DriveInfo.Wrap(null); - - Assert.IsNull(result); + + Assert.That(result, Is.Null); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileInfoBaseConversionTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileInfoBaseConversionTests.cs index c1e8b4b42..d09f21f09 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileInfoBaseConversionTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileInfoBaseConversionTests.cs @@ -20,7 +20,7 @@ public void FileInfoBase_FromFileInfo_ShouldReturnNullIfFileInfoIsNull() FileInfoBase actual = fileInfo; // Assert - Assert.IsNull(actual); + Assert.That(actual, Is.Null); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileInfoFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileInfoFactoryTests.cs index d91bbc439..e0644f6b0 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileInfoFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileInfoFactoryTests.cs @@ -12,7 +12,7 @@ public void Wrap_WithNull_ShouldReturnNull() var result = fileSystem.FileInfo.Wrap(null); - Assert.IsNull(result); + Assert.That(result, Is.Null); } } } diff --git a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemWatcherFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemWatcherFactoryTests.cs index a63d4b9a3..61585d664 100644 --- a/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemWatcherFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/FileSystemWatcherFactoryTests.cs @@ -12,7 +12,7 @@ public void Wrap_WithNull_ShouldReturnNull() var result = fileSystem.FileSystemWatcher.Wrap(null); - Assert.IsNull(result); + Assert.That(result, Is.Null); } } } From ad6e163a780e84b49288f99ebfc4c4d806df2ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:40:55 +0100 Subject: [PATCH 17/18] Use constraint model for "IsNotNull" --- .../MockDirectoryTests.cs | 6 +++--- .../MockFileInfoFactoryTests.cs | 4 ++-- .../MockFileStreamFactoryTests.cs | 4 ++-- .../MockFileSystemTests.cs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 34a74258d..343a98f26 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -774,7 +774,7 @@ public void MockDirectory_CreateDirectory_ShouldReturnDirectoryInfoBase() var result = fileSystem.Directory.CreateDirectory(XFS.Path(@"c:\bar")); // Assert - Assert.IsNotNull(result); + Assert.That(result, Is.Not.Null); } [Test] @@ -804,7 +804,7 @@ public void MockDirectory_CreMockDirectory_CreateDirectory_ShouldReturnDirectory var result = fileSystem.Directory.CreateDirectory(XFS.Path(@"c:\foo\")); // Assert - Assert.IsNotNull(result); + Assert.That(result, Is.Not.Null); } [Test] @@ -1725,7 +1725,7 @@ public void MockDirectory_GetParent_ShouldReturnADirectoryInfoIfPathDoesNotExist var actualResult = fileSystem.Directory.GetParent(XFS.Path(@"c:\directory\does\not\exist")); // Assert - Assert.IsNotNull(actualResult); + Assert.That(actualResult, Is.Not.Null); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoFactoryTests.cs index af551ff99..291083f48 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoFactoryTests.cs @@ -21,7 +21,7 @@ public void MockFileInfoFactory_New_ShouldReturnFileInfoForExistingFile() var result = fileInfoFactory.New(@"c:\a.txt"); // Assert - Assert.IsNotNull(result); + Assert.That(result, Is.Not.Null); } [Test] @@ -39,7 +39,7 @@ public void MockFileInfoFactory_New_ShouldReturnFileInfoForNonExistentFile() var result = fileInfoFactory.New(@"c:\foo.txt"); // Assert - Assert.IsNotNull(result); + Assert.That(result, Is.Not.Null); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs index 69256694e..d339fa906 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileStreamFactoryTests.cs @@ -26,7 +26,7 @@ public void MockFileStreamFactory_CreateForExistingFile_ShouldReturnStream(FileM var result = fileStreamFactory.Create(@"c:\existing.txt", fileMode, FileAccess.Write); // Assert - Assert.IsNotNull(result); + Assert.That(result, Is.Not.Null); } [Test] @@ -42,7 +42,7 @@ public void MockFileStreamFactory_CreateForNonExistingFile_ShouldReturnStream(Fi var result = fileStreamFactory.Create(XFS.Path(@"c:\not_existing.txt"), fileMode, FileAccess.Write); // Assert - Assert.IsNotNull(result); + Assert.That(result, Is.Not.Null); } [Test] diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs index 5781f9e8c..0294d092d 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs @@ -215,7 +215,7 @@ public void MockFileSystem_DriveInfo_ShouldNotThrowAnyException() var actualResults = fileSystem.DriveInfo.GetDrives(); - Assert.IsNotNull(actualResults); + Assert.That(actualResults, Is.Not.Null); } [Test] From ab25ef63353eb2cf74dd869eef1f57aa9c26773b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Wed, 6 Dec 2023 09:44:52 +0100 Subject: [PATCH 18/18] Undo accidental change --- .../System.IO.Abstractions.TestingHelpers.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj b/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj index 38d0c1037..5162cf0e1 100644 --- a/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj +++ b/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj @@ -10,7 +10,6 @@ -