Skip to content
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

Merged
merged 5 commits into from
Sep 8, 2018

Conversation

herebebeasties
Copy link
Contributor

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 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.
@herebebeasties
Copy link
Contributor Author

This implements #351.

@@ -62,5 +62,7 @@ public interface IMockFileDataAccessor
IDriveInfoFactory DriveInfo { get; }

PathVerifier PathVerifier { get; }

IFileSystem FileSystem { get; }
Copy link
Contributor Author

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.

Copy link
Contributor

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)
Copy link
Contributor Author

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?

Copy link
Contributor

@fgreinacher fgreinacher left a 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!

@herebebeasties
Copy link
Contributor Author

I've addressed all your comments, Florian. Thanks. Merged up to master, tests are all green.

@fgreinacher
Copy link
Contributor

Great, thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants