MockFileSystem.Directory.CreateDirectory throws an IoException if the directory already exists and the argument to CreateDirectory() contains a trailing slash.
The following works correctly:
var fs = new MockFileSystem();
fs.AddDirectory(@"C:\test\"); // Trailing slash here doesn't matter
fs.Directory.CreateDirectory(@"C:\test"); // No trailing slash works correctly
The following throws an IOException:
var fs = new MockFileSystem();
fs.AddDirectory(@"C:\test\"); // Trailing slash here doesn't matter
fs.Directory.CreateDirectory(@"C:\test\"); // Trailing slash here causes error
System.IO.IOException : Cannot create "C:\test\" because a file or directory with the same name already exists.
at System.IO.Abstractions.TestingHelpers.MockDirectory.CreateDirectory(String path, DirectorySecurity directorySecurity)
at System.IO.Abstractions.TestingHelpers.MockDirectory.CreateDirectory(String path)
The correct behaviour is silently ignoring existing directories, like System.Io.Directory.CreateDirectory() does (documented behavior).
MockFileSystem.Directory.CreateDirectorythrows anIoExceptionif the directory already exists and the argument toCreateDirectory()contains a trailing slash.The following works correctly:
The following throws an
IOException:The correct behaviour is silently ignoring existing directories, like
System.Io.Directory.CreateDirectory()does (documented behavior).