System.IO.Abstractions icon indicating copy to clipboard operation
System.IO.Abstractions copied to clipboard

MockFileSystem.Directory.CreateDirectory should NOT throw IOException if conflicting file exists

Open EnomisG opened this issue 1 month ago • 2 comments

Describe the bug The MockFileSystem throws an IOException if a conflicting file exists. The real System.IO.Directory.CreateDirectory method returns an object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.

To Reproduce Steps to reproduce the behavior:

var fileSystem = new MockFileSystem();
fileSystem.AddDirectory(@"c:\test");
fileSystem.Directory.CreateDirectory(@"c:\test");

Expected behavior An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.

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

EnomisG avatar Dec 03 '25 10:12 EnomisG

Thanks for reporting. Do you want to create a pull request for this issue?

vbreuss avatar Dec 04 '25 08:12 vbreuss

I can't seem to reproduce this, with v22.1.0 on Linux. The provided code snippet acts as expected, ie does not error, with the third line (fileSystem.Directory.CreateDirectory(@"c:\test");) returning info about the existing c:\test as expected. Maybe I am missing something, or its my platform/environment?

HarrisonTCodes avatar Dec 08 '25 17:12 HarrisonTCodes