diff --git a/src/System.IO.FileSystem/tests/File/Copy.cs b/src/System.IO.FileSystem/tests/File/Copy.cs index 0796425d1b2a..454d4cad69a0 100644 --- a/src/System.IO.FileSystem/tests/File/Copy.cs +++ b/src/System.IO.FileSystem/tests/File/Copy.cs @@ -331,5 +331,17 @@ public void WindowsAlternateDataStreamOverwrite(string defaultStream, string alt Assert.Throws(() => Copy(testFileAlternateStream, testFile2, overwrite: true)); Assert.Throws(() => Copy(testFileAlternateStream, testFile2 + alternateStream, overwrite: true)); } + + [Fact] + public void CopyOntoLockedFile() + { + string testFileSource = GetTestFilePath(); + string testFileDest = GetTestFilePath(); + File.Create(testFileSource).Dispose(); + using (var stream = new FileStream(testFileDest, FileMode.Open, FileAccess.Read, FileShare.None)) + { + Assert.Throws(() => Copy(testFileSource, testFileDest, overwrite: true)); + } + } } }