-
Notifications
You must be signed in to change notification settings - Fork 267
Closed
Labels
state: in workIssues that are currently worked onIssues that are currently worked ontype: bugIssues that describe misbehaving functionalityIssues that describe misbehaving functionality
Description
Using System.IO.Abstractions.TestingHelpers 2.1.0.231
FileStream.Create with FileMode.Truncate doesn't correctly truncate existing files. If the new content written to the file is smaller than the old content, the smaller content will overwrite the begining of the file, but then the old content will remain.
Example:
using (var stream = fileSystem.FileStream.Create("c:\\t\\test", FileMode.Create, FileAccess.Write))
{
using (var writer = new StreamWriter(stream))
{
writer.Write("test1234TEST5678");
}
}
using (var stream = fileSystem.FileStream.Create("c:\\t\\test", FileMode.Truncate, FileAccess.Write))
{
using (var writer = new StreamWriter(stream))
{
writer.Write("ab");
}
}
fileSystem.File.ReadAllLines("c:\\t\\test").Should().Equal("ab");- If
fileSystem = new FileSystem(), then the test passes. - But if
fileSystem = new MockFileSystem(), then the test fails because the file contents is: abst1234TEST5678 (first 2 characters overwritten, followed by characters from the original file that shouldn't be there anymore)
Metadata
Metadata
Assignees
Labels
state: in workIssues that are currently worked onIssues that are currently worked ontype: bugIssues that describe misbehaving functionalityIssues that describe misbehaving functionality