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

4
.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
.git
.gitignore
**/bin
**/obj

15
Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS restore
WORKDIR /src
COPY VirtualFS.sln ./
COPY VirtualFS/VirtualFS.csproj VirtualFS/
COPY VirtualFS.Tests/VirtualFS.Tests.csproj VirtualFS.Tests/
RUN dotnet restore VirtualFS.sln
FROM restore AS build
COPY . .
RUN dotnet build VirtualFS.sln -c Release --no-restore
FROM build AS test
RUN dotnet test VirtualFS.Tests/VirtualFS.Tests.csproj -c Release --no-build

View File

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

View File

@@ -1,14 +1,31 @@
using VirtualFS.Physical; using VirtualFS.Physical;
namespace VirtualFS.Tests.Physical namespace VirtualFS.Tests.Physical;
public sealed class PhysicalFileSystemTests : IDisposable
{ {
[TestClass] private readonly string _rootPath;
public class PhysicalFileSystemTests private readonly PhysicalFileSystem _fileSystem;
public PhysicalFileSystemTests()
{ {
[TestMethod] _rootPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "VirtualFS.Physical.Tests", Guid.NewGuid().ToString("N"));
public void TestEnumerate() 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.IsTrue(new PhysicalFileSystem(new DirectoryInfo("C:\\")).GetEntries("/").Count() > 0); 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.Implementation;
using VirtualFS.Physical; using VirtualFS.Physical;
namespace VirtualFS.Tests namespace VirtualFS.Tests;
{
[TestClass]
public class RootFileSystemTest
{
private RootFileSystem _root;
private string _realRootPath = "C:\\Temp\\";
[TestInitialize] public sealed class RootFileSystemTests : IDisposable
public virtual void SetUp()
{ {
if (!System.IO.Directory.Exists(_realRootPath)) 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); System.IO.Directory.CreateDirectory(_realRootPath);
_root = new RootFileSystem(); _root = new RootFileSystem();
_root.Mount(new PhysicalFileSystem(new System.IO.DirectoryInfo(_realRootPath)), (Path)"/"); _root.Mount(new PhysicalFileSystem(new System.IO.DirectoryInfo(_realRootPath)), (Path)"/");
} }
[TestMethod] [Fact]
public virtual void TestEnumerate() public void EnumerateMergesMountedEntriesWithoutDuplicates()
{ {
var root = new RootFileSystem(); var sharedRoot = new System.IO.DirectoryInfo(_realRootPath);
root.Mount(new PhysicalFileSystem(new System.IO.DirectoryInfo("C:\\")), (Path)"/"); System.IO.File.WriteAllText(System.IO.Path.Combine(_realRootPath, "first.txt"), "first");
root.Mount(new PhysicalFileSystem(new System.IO.DirectoryInfo("C:\\")), (Path)"/");
Assert.AreEqual(new PhysicalFileSystem(new System.IO.DirectoryInfo("C:\\")).GetEntries("/").Count(), root.GetEntries("/").Count()); 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());
} }
[TestMethod] [Fact]
public virtual void TestDirectoryCreateAndDelete() public void DirectoryCreateAndDeleteReflectsOnMountedPhysicalFileSystem()
{ {
var dir = _root.Root.Create("Test"); var dir = _root.Root.Create("Test");
var expectedPath = System.IO.Path.Combine(_realRootPath, "Test");
Assert.IsTrue(System.IO.Directory.Exists(_realRootPath + "Test\\")); Assert.True(System.IO.Directory.Exists(expectedPath));
dir.Delete(); dir.Delete();
Assert.IsFalse(System.IO.Directory.Exists(_realRootPath + "Test\\")); 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"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject> <IsTestProject>true</IsTestProject>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> <PackageReference Include="xunit.v3" Version="3.2.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" /> <PackageReference Include="coverlet.collector" Version="8.0.0">
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" /> <PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\VirtualFS\VirtualFS.csproj" /> <ProjectReference Include="..\VirtualFS\VirtualFS.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
</Project> </Project>

View File

@@ -5,7 +5,7 @@ VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualFS", "VirtualFS\VirtualFS.csproj", "{1FB8AADC-9568-41A3-AD8E-6181E028A80B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualFS", "VirtualFS\VirtualFS.csproj", "{1FB8AADC-9568-41A3-AD8E-6181E028A80B}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualFS.Tests", "VirtualFS.Tests\VirtualFS.Tests.csproj", "{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualFS.Tests", "VirtualFS.Tests\VirtualFS.Tests.csproj", "{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -28,7 +28,4 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {22781EB3-2148-4CA4-845A-B55265A7B5C2} SolutionGuid = {22781EB3-2148-4CA4-845A-B55265A7B5C2}
EndGlobalSection EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Tester\Tester.csproj
EndGlobalSection
EndGlobal EndGlobal

View File

@@ -1,19 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net472;net6.0;net7.0;net8.0</TargetFrameworks> <TargetFrameworks>netstandard2.0;net472;net6.0;net8.0;net10.0</TargetFrameworks>
<Description>Virtual File System library.</Description> <Description>Virtual File System library.</Description>
<Copyright>Copyright © RUSSEK Software 2012-2024</Copyright> <Copyright>Copyright © RUSSEK Software 2012-2026</Copyright>
<Company>RUSSEK Software</Company> <Company>RUSSEK Software</Company>
<Authors>Grzegorz Russek</Authors> <Authors>Grzegorz Russek</Authors>
<Product>VirtualFS</Product>
<VersionPrefix>1.6</VersionPrefix> <VersionPrefix>1.6</VersionPrefix>
<RepositoryUrl>https://git.dr4cul4.pl/RUSSEK-Software/VirtualFS</RepositoryUrl> <RepositoryUrl>https://git.dr4cul4.pl/RUSSEK-Software/VirtualFS</RepositoryUrl>
<PackageProjectUrl>https://dr4cul4.pl</PackageProjectUrl> <PackageProjectUrl>https://dr4cul4.pl</PackageProjectUrl>
<Product>VirtualFS</Product>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup> <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PropertyGroup>
<IncludeSymbols>true</IncludeSymbols> <IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat> <SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup> </PropertyGroup>
@@ -24,6 +22,7 @@
<PackageReference Include="SSH.NET" Version="2024.0.0" /> <PackageReference Include="SSH.NET" Version="2024.0.0" />
<PackageReference Include="System.Net.FtpClient" Version="1.0.5824.34026" /> <PackageReference Include="System.Net.FtpClient" Version="1.0.5824.34026" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('net4')) AND '$(MSBuildRuntimeType)' == 'Core' AND '$(OS)' != 'Windows_NT'"> <ItemGroup Condition="$(TargetFramework.StartsWith('net4')) AND '$(MSBuildRuntimeType)' == 'Core' AND '$(OS)' != 'Windows_NT'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" /> <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
</ItemGroup> </ItemGroup>