Modernize project targets and Docker test flow

This commit is contained in:
2026-02-28 17:27:20 +01:00
parent 02d95583e9
commit 654bcd8a1b
8 changed files with 161 additions and 122 deletions

View File

@@ -1,47 +1,45 @@
namespace VirtualFS.Tests
namespace VirtualFS.Tests;
public class PathTests
{
[TestClass]
public class PathTests
[Fact]
public void PathCast()
{
[TestMethod]
public virtual void TestPathCast()
{
Path p = "/test/path";
Path path = "/test/path";
Assert.IsNotNull(p);
Assert.AreEqual("/test/path", (string)p);
}
Assert.NotNull(path);
Assert.Equal("/test/path", (string)path);
}
[TestMethod]
public virtual void TestPathDirectoryNotDirectory()
{
Assert.IsFalse(((Path)"/test/path").IsDirectory == ((Path)"/test/path/").IsDirectory);
}
[Fact]
public void FileAndDirectoryPathsDiffer()
{
Assert.False(((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");
}
[Fact]
public void AppendCombinesDirectoryAndName()
{
Assert.Equal((Path)"/test/path/SomeFile.txt", ((Path)"/test/path/") + "SomeFile.txt");
}
[TestMethod]
public virtual void TestPathExt()
{
Assert.AreEqual("txt", ((Path)"/test/path/SomeFile.txt").GetExtension());
}
[Fact]
public void ExtensionIsReadFromFilePath()
{
Assert.Equal("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"));
}
[Fact]
public void ParentIsResolvedCorrectly()
{
Assert.Null(new Path().Parent);
Assert.Equal(new Path(), ((Path)"/test/").Parent);
Assert.Equal((Path)"/test/", ((Path)"/test/path/").Parent);
}
[Fact]
public void InvalidPathThrows()
{
Assert.Throws<InvalidOperationException>(() => new Path("test"));
}
}

View File

@@ -1,14 +1,31 @@
using VirtualFS.Physical;
namespace VirtualFS.Tests.Physical
namespace VirtualFS.Tests.Physical;
public sealed class PhysicalFileSystemTests : IDisposable
{
[TestClass]
public class PhysicalFileSystemTests
private readonly string _rootPath;
private readonly PhysicalFileSystem _fileSystem;
public PhysicalFileSystemTests()
{
[TestMethod]
public void TestEnumerate()
{
Assert.IsTrue(new PhysicalFileSystem(new DirectoryInfo("C:\\")).GetEntries("/").Count() > 0);
}
_rootPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "VirtualFS.Physical.Tests", Guid.NewGuid().ToString("N"));
System.IO.Directory.CreateDirectory(_rootPath);
System.IO.File.WriteAllText(System.IO.Path.Combine(_rootPath, "entry.txt"), "content");
System.IO.Directory.CreateDirectory(System.IO.Path.Combine(_rootPath, "nested"));
_fileSystem = new PhysicalFileSystem(new DirectoryInfo(_rootPath));
}
}
[Fact]
public void EnumerateReturnsEntriesFromMountedDirectory()
{
Assert.True(_fileSystem.GetEntries("/").Count() > 0);
}
public void Dispose()
{
if (System.IO.Directory.Exists(_rootPath))
System.IO.Directory.Delete(_rootPath, recursive: true);
}
}

View File

@@ -1,44 +1,51 @@
using VirtualFS.Implementation;
using VirtualFS.Physical;
namespace VirtualFS.Tests
namespace VirtualFS.Tests;
public sealed class RootFileSystemTests : IDisposable
{
[TestClass]
public class RootFileSystemTest
private readonly string _realRootPath;
private readonly RootFileSystem _root;
public RootFileSystemTests()
{
private RootFileSystem _root;
private string _realRootPath = "C:\\Temp\\";
_realRootPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "VirtualFS.Tests", Guid.NewGuid().ToString("N"));
System.IO.Directory.CreateDirectory(_realRootPath);
[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\\"));
}
_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);
}
}

View File

@@ -1,27 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
</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" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="xunit.v3" Version="3.2.2" />
<PackageReference Include="coverlet.collector" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VirtualFS\VirtualFS.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
</Project>