Skip to content

MockDirectory.Move does not throw exception if (part of the) target's parent folder does not exist #551

@comecme

Description

@comecme

MockDirectory.Move should throw a DirectoryNotFoundException if (part of) the parent folder of the target folder does not exist.

If you move from "c:\temp\exists\foldertomove" to "c:\temp\doesnotexist\foldertomove" and "c:\temp\doesnotexist" does not exist, an exception should be thrown.

In the code below, method MockDirectory_Move_ShouldMoveDirectories does not throw an exception on the Move, where Directory_Move_ShouldMoveDirectories does.

And what's even worse: the first assert in MockDirectory_Move_ShouldMoveDirectories succeeds, while the second assert fails. So according to the MockDirectory, the folder "c:\temp\doesnotexist" does not exist, but "c:\temp\doesnotexist\foldertomove" does exist!?

[TestClass]
public class MockDirectoryTests
{
    [TestMethod]
    public void MockDirectory_Move_ShouldMoveDirectories()
    {
        // Arange
        var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
        {
            {@"c:\temp\exists\foldertomove", new MockDirectoryData()}
        });

        string folderToMove = @"c:\temp\exists\foldertomove";
        string targetDirName = @"c:\temp\doesnotexist\foldertomove";

        // Act
        fileSystem.Directory.Move(folderToMove, targetDirName);

        // Assert
        Assert.IsTrue(fileSystem.Directory.Exists(@"c:\temp\doesnotexist\foldertomove"));
        Assert.IsTrue(fileSystem.Directory.Exists(@"c:\temp\doesnotexist"));
    }

    [TestMethod]
    public void Directory_Move_ShouldMoveDirectories()
    {
        // Arange
        Directory.CreateDirectory(@"c:\temp\exists\foldertomove");

        string folderToMove = @"c:\temp\exists\foldertomove";
        string targetDirName = @"c:\temp\doesnotexist\foldertomove";

        // Act
        // Move will throw a DirectoryNotFoundException: Could not find a part of the path
        Directory.Move(folderToMove, targetDirName);

        // Assert
        Assert.IsTrue(Directory.Exists(@"c:\temp\doesnotexist\foldertomove"));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked onstate: staletype: 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