diff --git a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs index d58fd95cfae3d..7abc7ac3a286e 100644 --- a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs +++ b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Security.Cryptography; using Xunit; +using Xunit.Abstractions; namespace System.IO.Tests { @@ -236,6 +237,17 @@ public void WindowsAlternateDataStream(string defaultStream, string alternateStr File.WriteAllText(testFile2DefaultStream, "Bar"); Assert.Throws(() => Copy(testFile2DefaultStream, testFileAlternateStream)); + try + { + Copy(testFile2DefaultStream, testFileAlternateStream); + Assert.Fail(); + } + catch (IOException e) + { + // Error code for "the file exists". + Assert.Equal(-2147024816, e.HResult); + } + // This always throws as you can't copy an alternate stream out (oddly) Assert.Throws(() => Copy(testFileAlternateStream, testFile2)); Assert.Throws(() => Copy(testFileAlternateStream, testFile2 + alternateStream)); @@ -275,6 +287,12 @@ public void OverwriteCopyOntoLink() public class File_Copy_str_str_b : File_Copy_str_str { + private ITestOutputHelper _output; + public File_Copy_str_str_b(ITestOutputHelper output) + { + _output = output; + } + protected override void Copy(string source, string dest) { File.Copy(source, dest, false); @@ -352,6 +370,8 @@ public void WindowsAlternateDataStreamOverwrite(string defaultStream, string alt // Copy the default stream into an alternate stream File.WriteAllText(testFileDefaultStream, "Foo"); + Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream)); + _output.WriteLine("Copying default stream into alternate stream."); Copy(testFileDefaultStream, testFileAlternateStream); Assert.Equal(testFile, testDirectory.GetFiles().Single().FullName); Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream)); @@ -361,6 +381,11 @@ public void WindowsAlternateDataStreamOverwrite(string defaultStream, string alt string testFile2 = Path.Combine(testDirectory.FullName, GetTestFileName()); string testFile2DefaultStream = testFile2 + defaultStream; File.WriteAllText(testFile2DefaultStream, "Bar"); + Assert.Equal("Bar", File.ReadAllText(testFile2DefaultStream)); + Assert.Equal("Foo", File.ReadAllText(testFileAlternateStream)); + _output.WriteLine($"Attributes for '{testFile2DefaultStream}': {File.GetAttributes(testFile2DefaultStream)}"); + _output.WriteLine($"Attributes for '{testFileAlternateStream}': {File.GetAttributes(testFileAlternateStream)}"); + _output.WriteLine("Overwriting alternate stream."); Copy(testFile2DefaultStream, testFileAlternateStream, overwrite: true); Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream)); Assert.Equal("Bar", File.ReadAllText(testFileAlternateStream)); diff --git a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileInfo/CopyTo.cs b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileInfo/CopyTo.cs index 49625c1f0c193..1899a98fea411 100644 --- a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileInfo/CopyTo.cs +++ b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileInfo/CopyTo.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Xunit; +using Xunit.Abstractions; namespace System.IO.Tests { @@ -16,6 +17,11 @@ protected override void Copy(string source, string dest) public class FileInfo_CopyTo_str_b : File_Copy_str_str_b { + public FileInfo_CopyTo_str_b(ITestOutputHelper output) + : base(output) + { + } + protected override void Copy(string source, string dest) { new FileInfo(source).CopyTo(dest, false);