Files
VirtualFS/VirtualFS.Tests/RootFileSystemTest.cs

52 lines
1.7 KiB
C#

using VirtualFS.Implementation;
using VirtualFS.Physical;
namespace VirtualFS.Tests;
public sealed class RootFileSystemTests : IDisposable
{
private readonly string _realRootPath;
private readonly RootFileSystem _root;
public RootFileSystemTests()
{
_realRootPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "VirtualFS.Tests", Guid.NewGuid().ToString("N"));
System.IO.Directory.CreateDirectory(_realRootPath);
_root = new RootFileSystem();
_root.Mount(new PhysicalFileSystem(new System.IO.DirectoryInfo(_realRootPath)), (Path)"/");
}
[Fact]
public void EnumerateMergesMountedEntriesWithoutDuplicates()
{
var sharedRoot = new System.IO.DirectoryInfo(_realRootPath);
System.IO.File.WriteAllText(System.IO.Path.Combine(_realRootPath, "first.txt"), "first");
var root = new RootFileSystem();
root.Mount(new PhysicalFileSystem(sharedRoot), (Path)"/");
root.Mount(new PhysicalFileSystem(sharedRoot), (Path)"/");
Assert.Equal(new PhysicalFileSystem(sharedRoot).GetEntries("/").Count(), root.GetEntries("/").Count());
}
[Fact]
public void DirectoryCreateAndDeleteReflectsOnMountedPhysicalFileSystem()
{
var dir = _root.Root.Create("Test");
var expectedPath = System.IO.Path.Combine(_realRootPath, "Test");
Assert.True(System.IO.Directory.Exists(expectedPath));
dir.Delete();
Assert.False(System.IO.Directory.Exists(expectedPath));
}
public void Dispose()
{
if (System.IO.Directory.Exists(_realRootPath))
System.IO.Directory.Delete(_realRootPath, recursive: true);
}
}