-
Notifications
You must be signed in to change notification settings - Fork 267
Description
Describe the bug
The MockFileSystem allows you to create a directory that conflicts with an existing file. The real System.IO.Directory.CreateDirectory method will throw an IOException if a conflicting file exists.
To Reproduce
Steps to reproduce the behavior:
var fileSystem = new MockFileSystem();
fileSystem.File.WriteAllText(@"c:\test", "test file");
fileSystem.Directory.CreateDirectory(@"c:\test");
If you reverse the lines above and create the directory first, you get an UnauthorizedAccessException:
var fileSystem = new MockFileSystem();
fileSystem.Directory.CreateDirectory(@"c:\test");
fileSystem.File.WriteAllText(@"c:\test", "test file");
Expected behavior
I would expect creation of a directory to fail when there is a conflicting file, just as creating a file fails if there is a conflicting directory.
Additional context
I was trying to write a negative test for a case when I'm trying to create a directory and a conflicting file already exists. This is how I discovered that the MockFileSystem behavior in this case doesn't match the real file system.