Initial commit

This commit is contained in:
grzegorz.russek
2024-05-15 09:38:41 +02:00
commit 5f748e55a2
23 changed files with 3488 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
namespace VirtualFS.Tests
{
[TestClass]
public class PathTests
{
[TestMethod]
public virtual void TestPathCast()
{
Path p = "/test/path";
Assert.IsNotNull(p);
Assert.AreEqual("/test/path", (string)p);
}
[TestMethod]
public virtual void TestPathDirectoryNotDirectory()
{
Assert.IsFalse(((Path)"/test/path").IsDirectory == ((Path)"/test/path/").IsDirectory);
}
[TestMethod]
public virtual void TestPathAddPath()
{
Assert.AreEqual((Path)"/test/path/SomeFile.txt", ((Path)"/test/path/") + "SomeFile.txt");
}
[TestMethod]
public virtual void TestPathExt()
{
Assert.AreEqual("txt", ((Path)"/test/path/SomeFile.txt").GetExtension());
}
[TestMethod]
public virtual void TestPathParent()
{
Assert.IsNull(new Path().Parent);
Assert.AreEqual(new Path(), ((Path)"/test/").Parent);
Assert.AreEqual((Path)"/test/", ((Path)"/test/path/").Parent);
}
[TestMethod]
public virtual void TestInvalidPath()
{
Assert.ThrowsException<InvalidOperationException>(() => new Path("test"));
}
}
}

View File

@@ -0,0 +1,14 @@
using VirtualFS.Physical;
namespace VirtualFS.Tests.Physical
{
[TestClass]
public class PhysicalFileSystemTests
{
[TestMethod]
public void TestEnumerate()
{
Assert.IsTrue(new PhysicalFileSystem(new System.IO.DirectoryInfo("C:\\")).GetEntries("/").Count() > 0);
}
}
}

View File

@@ -0,0 +1,44 @@
using VirtualFS.Implementation;
using VirtualFS.Physical;
namespace VirtualFS.Tests
{
[TestClass]
public class RootFileSystemTest
{
private RootFileSystem _root;
private string _realRootPath = "C:\\Temp\\";
[TestInitialize]
public virtual void SetUp()
{
if (!System.IO.Directory.Exists(_realRootPath))
System.IO.Directory.CreateDirectory(_realRootPath);
_root = new RootFileSystem();
_root.Mount(new PhysicalFileSystem(new System.IO.DirectoryInfo(_realRootPath)), (Path)"/");
}
[TestMethod]
public virtual void TestEnumerate()
{
var root = new RootFileSystem();
root.Mount(new PhysicalFileSystem(new System.IO.DirectoryInfo("C:\\")), (Path)"/");
root.Mount(new PhysicalFileSystem(new System.IO.DirectoryInfo("C:\\")), (Path)"/");
Assert.AreEqual(new PhysicalFileSystem(new System.IO.DirectoryInfo("C:\\")).GetEntries("/").Count(), root.GetEntries("/").Count());
}
[TestMethod]
public virtual void TestDirectoryCreateAndDelete()
{
var dir = _root.Root.Create("Test");
Assert.IsTrue(System.IO.Directory.Exists(_realRootPath + "Test\\"));
dir.Delete();
Assert.IsFalse(System.IO.Directory.Exists(_realRootPath + "Test\\"));
}
}
}

View File

@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VirtualFS\VirtualFS.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
</Project>