Ejemplo n.º 1
0
        public void TestFallback()
        {
            // aggregate_fs (fs)
            //      => aggregate_fs (subFs)
            //              => memory_fs (subFsMemFs)
            //      => memory_fs (subMemFs)
            //      => memory_fs (root)
            var root       = new MemoryFileSystem();
            var fs         = new AggregateFileSystem(root);
            var subFsMemFs = new MemoryFileSystem();
            var subFs      = new AggregateFileSystem(subFsMemFs);

            fs.AddFileSystem(subFs);
            var subMemFs = new MemoryFileSystem();

            fs.AddFileSystem(subMemFs);

            root.CreateDirectory("/a");
            root.CreateDirectory("/b");
            root.CreateDirectory("/c");
            {
                using var a = root.OpenFile("/a.txt", FileMode.Create, FileAccess.Write);
                using var b = root.OpenFile("/b.txt", FileMode.Create, FileAccess.Write);
                using var c = root.OpenFile("/c.txt", FileMode.Create, FileAccess.Write);
            }
            subFsMemFs.CreateDirectory("/b");
            {
                using var b = subFsMemFs.OpenFile("/b.txt", FileMode.Create, FileAccess.Write);
            }
            subMemFs.CreateDirectory("/a");
            {
                using var a = subMemFs.OpenFile("/a.txt", FileMode.Create, FileAccess.Write);
            }

            var findA = fs.FindFirstFileSystemEntry("/a");

            Assert.Equal(subMemFs, findA?.FileSystem);

            var findB = fs.FindFirstFileSystemEntry("/b");

            Assert.Equal(subFsMemFs, findB?.FileSystem);

            var findC = fs.FindFirstFileSystemEntry("/c");

            Assert.Equal(root, findC?.FileSystem);

            Assert.True(fs.DirectoryExists("/c"));
            Assert.True(fs.DirectoryExists("/b"));
            Assert.True(fs.DirectoryExists("/a"));

            Assert.True(fs.FileExists("/c.txt"));
            Assert.True(fs.FileExists("/b.txt"));
            Assert.True(fs.FileExists("/a.txt"));
        }
Ejemplo n.º 2
0
        public void TestFindFileSystemEntries()
        {
            var fs = new AggregateFileSystem();

            var memfs1 = new MemoryFileSystem();

            memfs1.WriteAllText("/a.txt", "content1");
            memfs1.WriteAllText("/b", "notused");
            fs.AddFileSystem(memfs1);

            var memfs2 = new MemoryFileSystem();

            memfs2.WriteAllText("/a.txt", "content2");
            memfs2.CreateDirectory("/b");
            fs.AddFileSystem(memfs2);

            {
                var entries = fs.FindFileSystemEntries("/a.txt");
                Assert.Equal(2, entries.Count);

                Assert.IsType <FileEntry>(entries[0]);
                Assert.IsType <FileEntry>(entries[1]);
                Assert.Equal(memfs2, entries[0].FileSystem);
                Assert.Equal(memfs1, entries[1].FileSystem);
                Assert.Equal("/a.txt", entries[0].Path.FullName);
                Assert.Equal("/a.txt", entries[1].Path.FullName);
            }

            {
                var entries = fs.FindFileSystemEntries("/b");
                Assert.Single(entries);

                Assert.IsType <DirectoryEntry>(entries[0]);
                Assert.Equal(memfs2, entries[0].FileSystem);
                Assert.Equal("/b", entries[0].Path.FullName);
            }

            {
                var entry = fs.FindFirstFileSystemEntry("/a.txt");
                Assert.NotNull(entry);

                Assert.IsType <FileEntry>(entry);
                Assert.Equal(memfs2, entry.FileSystem);
                Assert.Equal("/a.txt", entry.Path.FullName);
            }
        }