Skip to content

MockFileSystem.Directory.CreateDirectory should throw IOException if conflicting file exists #968

@aaron-meyers

Description

@aaron-meyers

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    state: needs discussionIssues that need further discussionstate: releasedIssues that are releasedtype: bugIssues that describe misbehaving functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions