-
Notifications
You must be signed in to change notification settings - Fork 267
Closed
Labels
area: testinghelpersIssues that address the testing helpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked onIssues that are ready for being worked ontype: bugIssues that describe misbehaving functionalityIssues that describe misbehaving functionality
Description
Found in version 3.0.10.
This is very similar, though distinct from, #357. Creating a stream with FileMode.Create is fine when the file does not exist, but does not truncate if the file exists. The following test should pass, but does not:
var fileSystem = new MockFileSystem();
const string FilePath = "File.txt";
using(var stream = fileSystem.FileStream.Create(FilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
using(var writer = new System.IO.StreamWriter(stream, System.Text.Encoding.UTF8, 4096, leaveOpen: true))
{
writer.Write("1234567890");
}
}
using(var stream = fileSystem.FileStream.Create(FilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
using(var writer = new System.IO.StreamWriter(stream, System.Text.Encoding.UTF8, 4096, leaveOpen: true))
{
writer.Write("AAAAA");
}
}
string text = fileSystem.File.ReadAllText(FilePath);
Assert.AreEqual("AAAAA", text); // text == "AAAAA67890"
Note that if you substitute FileMode.Truncate when opening the second stream, the test passes.
Metadata
Metadata
Assignees
Labels
area: testinghelpersIssues that address the testing helpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked onIssues that are ready for being worked ontype: bugIssues that describe misbehaving functionalityIssues that describe misbehaving functionality