Skip to content

Commit 5cf33c2

Browse files
committed
made all File.Open methods mimic core framework semantics as closely as possible.
1 parent ba2c78f commit 5cf33c2

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

TestingHelpers/MockFile.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,17 @@ private void ValidateParameter(string value, string paramName) {
216216

217217
public override Stream Open(string path, FileMode mode)
218218
{
219+
return Open(path, mode, (mode == FileMode.Append ? FileAccess.Write : FileAccess.ReadWrite), FileShare.None);
220+
}
221+
222+
public override Stream Open(string path, FileMode mode, FileAccess access)
223+
{
224+
return Open(path, mode, access, FileShare.None);
225+
}
226+
227+
public override Stream Open(string path, FileMode mode, FileAccess access, FileShare share)
228+
{
229+
//return new MockFileStream(path, mode, access, share);
219230
bool exists = mockFileDataAccessor.FileExists(path);
220231

221232
if (mode == FileMode.CreateNew && exists)
@@ -242,22 +253,9 @@ public override Stream Open(string path, FileMode mode)
242253
return stream;
243254
}
244255

245-
public override Stream Open(string path, FileMode mode, FileAccess access)
246-
{
247-
throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all.");
248-
}
249-
250-
public override Stream Open(string path, FileMode mode, FileAccess access, FileShare share)
251-
{
252-
throw new NotImplementedException("This test helper hasn't been implemented yet. They are implemented on an as-needed basis. As it seems like you need it, now would be a great time to send us a pull request over at https://github.com/tathamoddie/System.IO.Abstractions. You know, because it's open source and all.");
253-
}
254-
255256
public override Stream OpenRead(string path)
256257
{
257-
return new MemoryStream(
258-
mockFileDataAccessor
259-
.GetFile(path)
260-
.Contents);
258+
return Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
261259
}
262260

263261
public override StreamReader OpenText(string path)
@@ -269,6 +267,7 @@ public override StreamReader OpenText(string path)
269267
public override Stream OpenWrite(string path)
270268
{
271269
return new MockFileStream(mockFileDataAccessor, path);
270+
//return Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
272271
}
273272

274273
public override byte[] ReadAllBytes(string path)

0 commit comments

Comments
 (0)