Skip to content

MockFileSystem initialization handles absolute paths in an unexpected way #941

@jeyk

Description

@jeyk

I've come across unexpected behaviour of the filesystem initializer. When creating directories with absolute paths, their children end up in unexpected places.

Example (using NUnit):

using NUnit.Framework;
using Testably.Abstractions.Testing;
using Testably.Abstractions.Testing.Initializer;

namespace TestablyAbstractionsTest
{
    [TestFixture]
    public class AbstractionsTest
    {
        private const string DirectoryPath = @"C:\foo\bar";

        [Test]
        public void TestInitialization()
        {
            var fileSystem = new MockFileSystem();
            fileSystem.Initialize().With(
                new DirectoryDescription(DirectoryPath,
                    new FileDescription("baz.txt", "Hello, world!")
                )
            );

            Assert.False(fileSystem.Directory.Exists(@"C:\bar"), @"The directory `C:\bar` should not even exist.");
            Assert.False(fileSystem.File.Exists(@"C:\bar\baz.txt"), @"The file should not be in `C:\bar`.");
            Assert.That(fileSystem.File.Exists(@"C:\foo\bar\baz.txt"), @"The file is not at the expected location.");
            Assert.AreEqual("Hello, world!", fileSystem.File.ReadAllText(@"C:\foo\bar\baz.txt"));
        }
    }
}

All assertions in this test case fail. The file baz.txt is created at C:\bar\baz.txt instead of C:\foo\bar\baz.txt.

None of the documentation uses absolute paths, so I can't say with absolute certainty that this is a bug. At the very least, it's very unexpected behaviour. Did I miss something?

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomers

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions