You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DirectoryNotFound is not Thrown by MockFile Create #278
I had added a test to my project where I wanted to make sure that my code would create the directory for an output file before writing the output file, this test passed, but when I went to run my code for real, I got a DirectoryNotFound exception. It turns out in my implementation, I had neglected to create the directory. When I investigated why my test reported that the directory was created, when there was no code to create the directory, I found the following.
public override Stream Create(string path)
{
if (path == null)
{
throw new ArgumentNullException("path", "Path cannot be null.");
}
mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");
mockFileDataAccessor.AddFile(path, new MockFileData(new byte[0]));
var stream = OpenWrite(path);
return stream;
}
We see that this code doesn't check that the directory part of the path parameter exists. When AddFile is called, the directory gets added to the mock file systems known directories. I think this code should throw a DirectoryNotFound exception when the directory does not exist.
This appears to be similar to the issue described here: #140
Activity
jpreese commentedon Jul 6, 2018
This has been merged. Thanks for the PR @wleader !