diff --git a/Source/Testably.Abstractions.Testing/Helpers/PathHelper.cs b/Source/Testably.Abstractions.Testing/Helpers/PathHelper.cs index dddd3272f..a61cb86c5 100644 --- a/Source/Testably.Abstractions.Testing/Helpers/PathHelper.cs +++ b/Source/Testably.Abstractions.Testing/Helpers/PathHelper.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.IO; namespace Testably.Abstractions.Testing.Helpers; @@ -161,9 +160,7 @@ private static void CheckPathCharacters(string path, MockFileSystem fileSystem, fileSystem.Execute.Path.GetFullPath(path), hResult); } - fileSystem.Execute.OnWindowsIf(path.LastIndexOf(':') > 1 && - path.LastIndexOf(':') < - path.IndexOf(Path.DirectorySeparatorChar), + fileSystem.Execute.OnWindowsIf(path.LastIndexOf(':') > 1, () => throw ExceptionFactory.PathHasIncorrectSyntax( fileSystem.Execute.Path.GetFullPath(path), hResult)); } diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/File/CopyTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/File/CopyTests.cs index 53de0c2e8..a43b5ecf1 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/File/CopyTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/File/CopyTests.cs @@ -107,7 +107,10 @@ public void } else { - exception.Should().BeException(hResult: -2147024773); + exception.Should().BeException( + messageContains: + "The filename, directory name, or volume label syntax is incorrect", + hResult: -2147024773); } } @@ -313,6 +316,27 @@ public void Copy_SourceAccessedWithWriteShare_ShouldNotThrowOnLinuxOrMac( FileSystem.File.ReadAllText(destinationPath).Should().Be(sourceContents); } + [SkippableTheory] + [AutoData] + public void Copy_SourceDirectoryMissing_ShouldThrowDirectoryNotFoundException( + string missingDirectory, + string sourceName, + string destinationName) + { + string source = FileSystem.Path.Combine(missingDirectory, sourceName); + Exception? exception = Record.Exception(() => + { + FileSystem.File.Copy(source, destinationName); + }); + + exception.Should().BeException( + messageContains: Test.IsNetFramework + ? null + : $"'{FileSystem.Path.GetFullPath(source)}'", + hResult: -2147024893); + FileSystem.Should().NotHaveFile(destinationName); + } + [SkippableTheory] [AutoData] public void Copy_SourceIsDirectory_ShouldThrowUnauthorizedAccessException_AndNotCopyFile( @@ -327,10 +351,10 @@ public void Copy_SourceIsDirectory_ShouldThrowUnauthorizedAccessException_AndNot }); exception.Should().BeException( - hResult: -2147024891, messageContains: Test.IsNetFramework ? $"'{sourceName}'" - : $"'{FileSystem.Path.GetFullPath(sourceName)}'"); + : $"'{FileSystem.Path.GetFullPath(sourceName)}'", + hResult: -2147024891); FileSystem.Should().HaveDirectory(sourceName); FileSystem.Should().NotHaveFile(destinationName); } @@ -379,10 +403,10 @@ public void Copy_SourceMissing_ShouldThrowFileNotFoundException( }); exception.Should().BeException( - hResult: -2147024894, messageContains: Test.IsNetFramework ? null - : $"'{FileSystem.Path.GetFullPath(sourceName)}'"); + : $"'{FileSystem.Path.GetFullPath(sourceName)}'", + hResult: -2147024894); FileSystem.Should().NotHaveFile(destinationName); } }