Skip to content

Commit 405b6ec

Browse files
authored
fix: initialize streams returned by MockFile.Create with ReadWrite access (#802)
Fixes #801
1 parent 88abe85 commit 405b6ec

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/System.IO.Abstractions.TestingHelpers/MockFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public override Stream Create(string path, int bufferSize) =>
138138

139139
/// <inheritdoc />
140140
public override Stream Create(string path, int bufferSize, FileOptions options) =>
141-
CreateInternal(path, FileAccess.Write, options);
141+
CreateInternal(path, FileAccess.ReadWrite, options);
142142

143143
private Stream CreateInternal(string path, FileAccess access, FileOptions options)
144144
{

tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,5 +288,18 @@ public void MockFile_Create_ShouldWorkWithRelativePath()
288288

289289
Assert.That(fileSystem.File.Exists(relativeFile));
290290
}
291+
292+
[Test]
293+
public void MockFile_Create_CanReadFromNewStream()
294+
{
295+
string fullPath = XFS.Path(@"c:\something\demo.txt");
296+
var fileSystem = new MockFileSystem();
297+
fileSystem.AddDirectory(XFS.Path(@"c:\something"));
298+
299+
using (var stream = fileSystem.File.Create(fullPath))
300+
{
301+
Assert.That(stream.CanRead, Is.True);
302+
}
303+
}
291304
}
292305
}

0 commit comments

Comments
 (0)