Skip to content

Commit

Permalink
add missing test for scenario when destination file is larger than so…
Browse files Browse the repository at this point in the history
…urce file (it needs to be truncated) (#64537)
  • Loading branch information
adamsitnik committed Jan 31, 2022
1 parent ca6716a commit d201ebb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libraries/System.IO.FileSystem/tests/File/Copy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using Xunit;

namespace System.IO.Tests
Expand Down Expand Up @@ -350,6 +351,21 @@ public void WindowsAlternateDataStreamOverwrite(string defaultStream, string alt
Assert.Throws<IOException>(() => Copy(testFileAlternateStream, testFile2, overwrite: true));
Assert.Throws<IOException>(() => Copy(testFileAlternateStream, testFile2 + alternateStream, overwrite: true));
}

[Fact]
public void DestinationFileIsTruncatedWhenItsLargerThanSourceFile()
{
string sourcePath = GetTestFilePath();
string destPath = GetTestFilePath();

byte[] content = RandomNumberGenerator.GetBytes(1000);
File.WriteAllBytes(sourcePath, content);
File.WriteAllBytes(destPath, RandomNumberGenerator.GetBytes(content.Length * 2));

Copy(sourcePath, destPath, overwrite: true);

Assert.Equal(content, File.ReadAllBytes(destPath));
}
}

/// <summary>
Expand Down

0 comments on commit d201ebb

Please sign in to comment.