Skip to content

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

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.

Activity

  1. added a commit that references this issue on Apr 18, 2023
    659f7b4
  2. github-actions commented on Apr 18, 2023

    @github-actions

    This is addressed in release v19.2.12.

  3. aaron-meyers commented on Apr 25, 2023

    @aaron-meyers
    Author

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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