-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#351: Add IFileSystem property to base classes #352
Conversation
This allows people to get at the underlying IFileSystem implementation when developing extension methods. For example, it may make sense to put your extension method on DirectoryBase, but you may require FileBase to actually implement it. This makes that possible. In addition it fixes a bug in MockFileInfo.Replace where the returned FileInfo was for the concrete FileSystem not the mock one (bug caused by implicit casting). I think this commit actually removes the need for supporting implicit casting at all.
This implements #351. |
@@ -62,5 +62,7 @@ public interface IMockFileDataAccessor | |||
IDriveInfoFactory DriveInfo { get; } | |||
|
|||
PathVerifier PathVerifier { get; } | |||
|
|||
IFileSystem FileSystem { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels slightly icky to me, but it was the least invasive change to make, as the various constructors for all the mock classes can then remain the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it this way!
@@ -18,7 +18,7 @@ public class MockDirectory : DirectoryBase | |||
|
|||
private string currentDirectory; | |||
|
|||
public MockDirectory(IMockFileDataAccessor mockFileDataAccessor, FileBase fileBase, string currentDirectory) | |||
public MockDirectory(IMockFileDataAccessor mockFileDataAccessor, FileBase fileBase, string currentDirectory) : base(mockFileDataAccessor?.FileSystem) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason the above feels a bit icky is that you end up with these null
checks which don't make all that much sense. The alternative here is obviously to pass in both the IMockFileDataAccessor
and the IFileSystem
to all these. Would people prefer we do that instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor things - other than that this looks great!
I really can't see the point of any of this - none of these constructors do any real work.
I've addressed all your comments, Florian. Thanks. Merged up to master, tests are all green. |
Great, thanks again! |
This allows people to get at the underlying IFileSystem implementation when developing extension methods.
For example, it may make sense to put your extension method on DirectoryBase, but you may require FileBase to actually implement it. This makes that possible.
In addition it fixes a bug in MockFileInfo.Replace where the returned FileInfo was for the concrete FileSystem not the mock one (bug caused by implicit casting).
I think this commit actually removes the need for supporting implicit casting at all.