Skip to content

MockFileSystem.Directory.CreateDirectory throws IoException when directory exists and argument has trailing slash #210

@cmeeren

Description

@cmeeren

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions