Skip to content

Commit 1d33ec7

Browse files
committed
Merge pull request #75 from ericnewton76/feature/file-open-coreframework-realign
made all File.Open methods mimic core framework semantics as closely as possible
2 parents ab2d577 + b4909f6 commit 1d33ec7

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

TestingHelpers/MockFile.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ private void ValidateParameter(string value, string paramName) {
215215
}
216216

217217
public override Stream Open(string path, FileMode mode)
218+
{
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)
218228
{
219229
bool exists = mockFileDataAccessor.FileExists(path);
220230

@@ -242,22 +252,9 @@ public override Stream Open(string path, FileMode mode)
242252
return stream;
243253
}
244254

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-
255255
public override Stream OpenRead(string path)
256256
{
257-
return new MemoryStream(
258-
mockFileDataAccessor
259-
.GetFile(path)
260-
.Contents);
257+
return Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
261258
}
262259

263260
public override StreamReader OpenText(string path)

0 commit comments

Comments
 (0)