diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e0ced57 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git +.gitignore +**/bin +**/obj diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5c648a4 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/VirtualFS.Tests/PathTests.cs b/VirtualFS.Tests/PathTests.cs index f822fd6..d2b465b 100644 --- a/VirtualFS.Tests/PathTests.cs +++ b/VirtualFS.Tests/PathTests.cs @@ -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(() => 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(() => new Path("test")); } } diff --git a/VirtualFS.Tests/Physical/PhysicalFileSystemTests.cs b/VirtualFS.Tests/Physical/PhysicalFileSystemTests.cs index cc94a39..35f2d70 100644 --- a/VirtualFS.Tests/Physical/PhysicalFileSystemTests.cs +++ b/VirtualFS.Tests/Physical/PhysicalFileSystemTests.cs @@ -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)); } -} \ No newline at end of file + + [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); + } +} diff --git a/VirtualFS.Tests/RootFileSystemTest.cs b/VirtualFS.Tests/RootFileSystemTest.cs index d1baaac..077668c 100644 --- a/VirtualFS.Tests/RootFileSystemTest.cs +++ b/VirtualFS.Tests/RootFileSystemTest.cs @@ -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)"/"); } -} \ No newline at end of file + + [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); + } +} diff --git a/VirtualFS.Tests/VirtualFS.Tests.csproj b/VirtualFS.Tests/VirtualFS.Tests.csproj index 151af00..be155d6 100644 --- a/VirtualFS.Tests/VirtualFS.Tests.csproj +++ b/VirtualFS.Tests/VirtualFS.Tests.csproj @@ -1,27 +1,29 @@  - net8.0 + net10.0 enable enable - + Exe false true + true - - - - + + + + all + + + + + - - - - diff --git a/VirtualFS.sln b/VirtualFS.sln index de4a1dc..f7565dd 100644 --- a/VirtualFS.sln +++ b/VirtualFS.sln @@ -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 diff --git a/VirtualFS/VirtualFS.csproj b/VirtualFS/VirtualFS.csproj index 03558f9..00b5c1c 100644 --- a/VirtualFS/VirtualFS.csproj +++ b/VirtualFS/VirtualFS.csproj @@ -1,31 +1,30 @@ - - netstandard2.0;net472;net6.0;net7.0;net8.0 - Virtual File System library. - Copyright © RUSSEK Software 2012-2024 - RUSSEK Software - Grzegorz Russek - 1.6 - https://git.dr4cul4.pl/RUSSEK-Software/VirtualFS - https://dr4cul4.pl - VirtualFS - MIT - + + netstandard2.0;net472;net6.0;net8.0;net10.0 + Virtual File System library. + Copyright © RUSSEK Software 2012-2026 + RUSSEK Software + Grzegorz Russek + VirtualFS + 1.6 + https://git.dr4cul4.pl/RUSSEK-Software/VirtualFS + https://dr4cul4.pl + MIT + false + true + snupkg + - - true - snupkg - + + + + + + - - - - - - - + - +