Add FileStreamFactory and support for mocking FileStreams#177
Conversation
|
@caioproiete thanks for the PR! At first glance, this looks like it's in pretty decent shape, but does have some merge conflicts. |
|
@jpreese I resolved the merge conflicts and updated it to handle the changes to MockFileStream. For me it looks good now - and fills an major functionality gap. |
|
@jpreese You're welcome! You know... The PR had zero merge conflicts 2 years ago when I created it 🙃 haha anyway thanks for reviewing it @fgreinacher Awesome! Thanks for helping to move this one forward! |
|
@caioproiete you're alive! Again, truly sorry for the delay in all of this. We're working on getting some momentum on this project again. Your PR is very appreciated. |
|
@jpreese 😄 No worries! Great to see some traction on this project again! It's a great library! |
| FileBase File { get; } | ||
| DirectoryBase Directory { get; } | ||
| IFileInfoFactory FileInfo { get; } | ||
| IFileStreamFactory FileStream { get; } |
There was a problem hiding this comment.
This is my only concern. Since we're adding onto IFileSystem, it's a breaking change.. but is anyone really writing their own classes using IFileSystem?
There was a problem hiding this comment.
Yeah, same goes for 07227bc... I also don't think this will be a big problem for people. Whenever we are done with the old issues/PRs we should again think about release strategy, versioning, issue tagging, etc...
There was a problem hiding this comment.
To be clear. I would merge this one and as a follow-up take care about our future strategy.
There was a problem hiding this comment.
Yeah, I would agree. It's probably an incredibly small subset of users it would impact.
| Stream Create(string path, FileMode mode, FileSystemRights rights, FileShare share, int bufferSize, FileOptions options); | ||
| #endif | ||
|
|
||
| #if NET40 || NETSTANDARD_20 |
There was a problem hiding this comment.
Do we need the NET40/NETSTANDARD check here? I don't see a mirroring check in the MockFileStreamFactory
There was a problem hiding this comment.
Yeah, because the “real” implementation doesn’t support these overloads on NS1.4.
| return new MockFileStream(mockFileSystem, path, GetStreamType(mode, access)); | ||
| } | ||
|
|
||
| public Stream Create(string path, FileMode mode, FileSystemRights rights, FileShare share, int bufferSize, FileOptions options, FileSecurity fileSecurity) |
There was a problem hiding this comment.
The interface has a preprocessor check, but this is exposed
There was a problem hiding this comment.
Oops, will add a check here.
|
Have a couple eye raises around the NET40/NETSTANDARD stuff, seems to be some inconcistencies. |
…System.IO.Abstractions into add-file-stream-factory-etc
|
OK, feedback is addressed. I also mixed in some minor cleanups :) |
| [Test] | ||
| [TestCase(FileMode.Create)] | ||
| [TestCase(FileMode.Append)] | ||
| public void MockFileStreamFactory_Create_string_FileMode__ShouldReturnStreamForNonExistingFile(FileMode fileMode) |
There was a problem hiding this comment.
This test name could use some love. MockFileStreamFactory_Create_ShouldReturnStreamForNonExistingFile()?
Quick tangent... I'm not a huge fan of the idea that we include the name of the class in the name of the test. In a greenfield scenario, I'd name this test Create_FileDoesNotExist_ReturnsStream -- but I think the suggestion follows more suite with how our tests are currently named.
| [Test] | ||
| [TestCase(FileMode.Create)] | ||
| [TestCase(FileMode.Append)] | ||
| public void MockFileStreamFactory_Create_string_FileMode__ShouldReturnStreamForExistingFile(FileMode fileMode) |
| [Serializable] | ||
| internal sealed class FileStreamFactory : IFileStreamFactory | ||
| { | ||
| public Stream Create(string path, FileMode mode) |
There was a problem hiding this comment.
Not a nit, but thought this was interesting.
https://ericlippert.com/2014/09/15/internal-or-public/
There was a problem hiding this comment.
👍 That's a good read, thanks! I also prefer public in these cases, but I could never provide non-subjective reasons for that
jpreese
left a comment
There was a problem hiding this comment.
Looks fine to me overall, just a small issue with the test naming.
|
a6dc64d addresses the feedback and simplifies the test cases a bit more. |
|
Merging this - if there is additional feedback on the changes just add it here and I’ll address it in a follow-up. |
Add
IFileStreamFactory,FileStreamFactory, andMockFileStreamFactoryto allow creating instances ofFileStreamwith more advanced options not exposed byFileBaseandFileInfo, such asbufferSize,FileOptions,FileSecurity, andFileSystemRights, as well as openingFileStreamfrom aSafeFileHandleinstead of a file path, etc.I've included all public constructors/overloads of the
FileStreaminIFileStreamFactoryand consequently inFileStreamFactory