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;
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>

View File

@@ -5,7 +5,7 @@ VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualFS", "VirtualFS\VirtualFS.csproj", "{1FB8AADC-9568-41A3-AD8E-6181E028A80B}"
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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -28,7 +28,4 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {22781EB3-2148-4CA4-845A-B55265A7B5C2}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Tester\Tester.csproj
EndGlobalSection
EndGlobal

View File

@@ -1,31 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net472;net6.0;net7.0;net8.0</TargetFrameworks>
<Description>Virtual File System library.</Description>
<Copyright>Copyright © RUSSEK Software 2012-2024</Copyright>
<Company>RUSSEK Software</Company>
<Authors>Grzegorz Russek</Authors>
<VersionPrefix>1.6</VersionPrefix>
<RepositoryUrl>https://git.dr4cul4.pl/RUSSEK-Software/VirtualFS</RepositoryUrl>
<PackageProjectUrl>https://dr4cul4.pl</PackageProjectUrl>
<Product>VirtualFS</Product>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net472;net6.0;net8.0;net10.0</TargetFrameworks>
<Description>Virtual File System library.</Description>
<Copyright>Copyright © RUSSEK Software 2012-2026</Copyright>
<Company>RUSSEK Software</Company>
<Authors>Grzegorz Russek</Authors>
<Product>VirtualFS</Product>
<VersionPrefix>1.6</VersionPrefix>
<RepositoryUrl>https://git.dr4cul4.pl/RUSSEK-Software/VirtualFS</RepositoryUrl>
<PackageProjectUrl>https://dr4cul4.pl</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="SSH.NET" Version="2024.0.0" />
<PackageReference Include="System.Net.FtpClient" Version="1.0.5824.34026" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="SSH.NET" Version="2024.0.0" />
<PackageReference Include="System.Net.FtpClient" Version="1.0.5824.34026" />
</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" />
</ItemGroup>
</ItemGroup>
</Project>