From b2331b94a82d4fb51db65666acd1d6ef1be1c9f6 Mon Sep 17 00:00:00 2001 From: Philippe Matray Date: Sat, 11 Mar 2023 20:10:12 +0100 Subject: [PATCH] Add method to IVirtualFileSystem + comments and test --- docs/api/IVirtualFileSystem.GetRootPath().md | 14 ++++++++++++++ docs/api/IVirtualFileSystem.md | 1 + docs/api/VFS.GetRootPath().md | 16 ++++++++++++++++ docs/api/VFS.md | 1 + docs/api/VirtualFileSystem.md | 2 ++ docs/links | 2 ++ .../Contracts/IVirtualFileSystem.cs | 6 ++++++ .../VFS.Commands.cs | 1 - .../VFS.Queries.cs | 8 ++++---- .../Models/VirtualFileSystemTests.cs | 17 +++++++++++++++++ 10 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 docs/api/IVirtualFileSystem.GetRootPath().md create mode 100644 docs/api/VFS.GetRootPath().md diff --git a/docs/api/IVirtualFileSystem.GetRootPath().md b/docs/api/IVirtualFileSystem.GetRootPath().md new file mode 100644 index 0000000..1434531 --- /dev/null +++ b/docs/api/IVirtualFileSystem.GetRootPath().md @@ -0,0 +1,14 @@ +#### [Atypical.VirtualFileSystem.Core](VirtualFileSystem.md 'VirtualFileSystem') +### [Atypical.VirtualFileSystem.Core.Contracts](VirtualFileSystem.md#Atypical.VirtualFileSystem.Core.Contracts 'Atypical.VirtualFileSystem.Core.Contracts').[IVirtualFileSystem](IVirtualFileSystem.md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem') + +## IVirtualFileSystem.GetRootPath() Method + +Gets the path of the root directory. + +```csharp +Atypical.VirtualFileSystem.Core.Abstractions.VFSPath GetRootPath(); +``` + +#### Returns +[VFSPath](VFSPath.md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSPath') +The path of the root directory. \ No newline at end of file diff --git a/docs/api/IVirtualFileSystem.md b/docs/api/IVirtualFileSystem.md index 6686466..6cb4d91 100644 --- a/docs/api/IVirtualFileSystem.md +++ b/docs/api/IVirtualFileSystem.md @@ -37,6 +37,7 @@ Derived | [GetDirectory(string)](IVirtualFileSystem.GetDirectory(string).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetDirectory(string)') | Gets a file node by its path.
The path must be absolute. | | [GetFile(VFSFilePath)](IVirtualFileSystem.GetFile(VFSFilePath).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetFile(Atypical.VirtualFileSystem.Core.ValueObjects.VFSFilePath)') | Gets a file node by its path.
The path must be absolute. | | [GetFile(string)](IVirtualFileSystem.GetFile(string).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetFile(string)') | Gets a file node by its path.
The path must be absolute. | +| [GetRootPath()](IVirtualFileSystem.GetRootPath().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetRootPath()') | Gets the path of the root directory. | | [IsEmpty()](IVirtualFileSystem.IsEmpty().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.IsEmpty()') | Indicates whether the file system is empty.
This is the case if the root directory is empty. | | [TryGetDirectory(VFSDirectoryPath, IDirectoryNode)](IVirtualFileSystem.TryGetDirectory(VFSDirectoryPath,IDirectoryNode).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.TryGetDirectory(Atypical.VirtualFileSystem.Core.ValueObjects.VFSDirectoryPath, Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode)') | Try to get a directory node by its path.
The path must be absolute.
If the directory node does not exist, this method returns `false`
and [directory](IVirtualFileSystem.TryGetDirectory(VFSDirectoryPath,IDirectoryNode).md#Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.TryGetDirectory(Atypical.VirtualFileSystem.Core.ValueObjects.VFSDirectoryPath,Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode).directory 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.TryGetDirectory(Atypical.VirtualFileSystem.Core.ValueObjects.VFSDirectoryPath, Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode).directory') is set to `null`. | | [TryGetDirectory(string, IDirectoryNode)](IVirtualFileSystem.TryGetDirectory(string,IDirectoryNode).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.TryGetDirectory(string, Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode)') | Try to get a directory node by its path.
The path must be absolute.
If the directory node does not exist, this method returns `false`
and [directory](IVirtualFileSystem.TryGetDirectory(string,IDirectoryNode).md#Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.TryGetDirectory(string,Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode).directory 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.TryGetDirectory(string, Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode).directory') is set to `null`. | diff --git a/docs/api/VFS.GetRootPath().md b/docs/api/VFS.GetRootPath().md new file mode 100644 index 0000000..95f68a9 --- /dev/null +++ b/docs/api/VFS.GetRootPath().md @@ -0,0 +1,16 @@ +#### [Atypical.VirtualFileSystem.Core](VirtualFileSystem.md 'VirtualFileSystem') +### [Atypical.VirtualFileSystem.Core](VirtualFileSystem.md#Atypical.VirtualFileSystem.Core 'Atypical.VirtualFileSystem.Core').[VFS](VFS.md 'Atypical.VirtualFileSystem.Core.VFS') + +## VFS.GetRootPath() Method + +Gets the path of the root directory. + +```csharp +public Atypical.VirtualFileSystem.Core.Abstractions.VFSPath GetRootPath(); +``` + +Implements [GetRootPath()](IVirtualFileSystem.GetRootPath().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetRootPath()') + +#### Returns +[VFSPath](VFSPath.md 'Atypical.VirtualFileSystem.Core.Abstractions.VFSPath') +The path of the root directory. \ No newline at end of file diff --git a/docs/api/VFS.md b/docs/api/VFS.md index 0034517..b2d61d7 100644 --- a/docs/api/VFS.md +++ b/docs/api/VFS.md @@ -43,6 +43,7 @@ Implements [IVirtualFileSystem](IVirtualFileSystem.md 'Atypical.VirtualFileSyste | [GetDirectory(string)](VFS.GetDirectory(string).md 'Atypical.VirtualFileSystem.Core.VFS.GetDirectory(string)') | Gets a file node by its path.
The path must be absolute. | | [GetFile(VFSFilePath)](VFS.GetFile(VFSFilePath).md 'Atypical.VirtualFileSystem.Core.VFS.GetFile(Atypical.VirtualFileSystem.Core.ValueObjects.VFSFilePath)') | Gets a file node by its path.
The path must be absolute. | | [GetFile(string)](VFS.GetFile(string).md 'Atypical.VirtualFileSystem.Core.VFS.GetFile(string)') | Gets a file node by its path.
The path must be absolute. | +| [GetRootPath()](VFS.GetRootPath().md 'Atypical.VirtualFileSystem.Core.VFS.GetRootPath()') | Gets the path of the root directory. | | [IsEmpty()](VFS.IsEmpty().md 'Atypical.VirtualFileSystem.Core.VFS.IsEmpty()') | Indicates whether the file system is empty.
This is the case if the root directory is empty. | | [ToString()](VFS.ToString().md 'Atypical.VirtualFileSystem.Core.VFS.ToString()') | Returns the index as an ASCII tree. | | [TryGetDirectory(VFSDirectoryPath, IDirectoryNode)](VFS.TryGetDirectory(VFSDirectoryPath,IDirectoryNode).md 'Atypical.VirtualFileSystem.Core.VFS.TryGetDirectory(Atypical.VirtualFileSystem.Core.ValueObjects.VFSDirectoryPath, Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode)') | Try to get a directory node by its path.
The path must be absolute.
If the directory node does not exist, this method returns `false`
and [directory](VFS.TryGetDirectory(VFSDirectoryPath,IDirectoryNode).md#Atypical.VirtualFileSystem.Core.VFS.TryGetDirectory(Atypical.VirtualFileSystem.Core.ValueObjects.VFSDirectoryPath,Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode).directory 'Atypical.VirtualFileSystem.Core.VFS.TryGetDirectory(Atypical.VirtualFileSystem.Core.ValueObjects.VFSDirectoryPath, Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode).directory') is set to `null`. | diff --git a/docs/api/VirtualFileSystem.md b/docs/api/VirtualFileSystem.md index 1a36b88..a653b3f 100644 --- a/docs/api/VirtualFileSystem.md +++ b/docs/api/VirtualFileSystem.md @@ -43,6 +43,7 @@ The path must be absolute. - **[GetFile(string)](VFS.GetFile(string).md 'Atypical.VirtualFileSystem.Core.VFS.GetFile(string)')** `Method` Gets a file node by its path. The path must be absolute. + - **[GetRootPath()](VFS.GetRootPath().md 'Atypical.VirtualFileSystem.Core.VFS.GetRootPath()')** `Method` Gets the path of the root directory. - **[IsEmpty()](VFS.IsEmpty().md 'Atypical.VirtualFileSystem.Core.VFS.IsEmpty()')** `Method` Indicates whether the file system is empty. This is the case if the root directory is empty. - **[ToString()](VFS.ToString().md 'Atypical.VirtualFileSystem.Core.VFS.ToString()')** `Method` Returns the index as an ASCII tree. @@ -171,6 +172,7 @@ The path must be absolute. - **[GetFile(string)](IVirtualFileSystem.GetFile(string).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetFile(string)')** `Method` Gets a file node by its path. The path must be absolute. + - **[GetRootPath()](IVirtualFileSystem.GetRootPath().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetRootPath()')** `Method` Gets the path of the root directory. - **[IsEmpty()](IVirtualFileSystem.IsEmpty().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.IsEmpty()')** `Method` Indicates whether the file system is empty. This is the case if the root directory is empty. - **[TryGetDirectory(VFSDirectoryPath, IDirectoryNode)](IVirtualFileSystem.TryGetDirectory(VFSDirectoryPath,IDirectoryNode).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.TryGetDirectory(Atypical.VirtualFileSystem.Core.ValueObjects.VFSDirectoryPath, Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode)')** `Method` Try to get a directory node by its path. diff --git a/docs/links b/docs/links index 2631a17..8bda2ed 100644 --- a/docs/links +++ b/docs/links @@ -12,6 +12,7 @@ M:Atypical.VirtualFileSystem.Core.VFS.DeleteFile(System.String)|VFS.DeleteFile(s M:Atypical.VirtualFileSystem.Core.VFS.#ctor|VFS.VFS().md|VFS() M:Atypical.VirtualFileSystem.Core.VFS.ToString|VFS.ToString().md|ToString() M:Atypical.VirtualFileSystem.Core.VFS.IsEmpty|VFS.IsEmpty().md|IsEmpty() +M:Atypical.VirtualFileSystem.Core.VFS.GetRootPath|VFS.GetRootPath().md|GetRootPath() M:Atypical.VirtualFileSystem.Core.VFS.GetDirectory(Atypical.VirtualFileSystem.Core.ValueObjects.VFSDirectoryPath)|VFS.GetDirectory(VFSDirectoryPath).md|GetDirectory(VFSDirectoryPath) M:Atypical.VirtualFileSystem.Core.VFS.GetDirectory(System.String)|VFS.GetDirectory(string).md|GetDirectory(string) M:Atypical.VirtualFileSystem.Core.VFS.TryGetDirectory(Atypical.VirtualFileSystem.Core.ValueObjects.VFSDirectoryPath,Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode@)|VFS.TryGetDirectory(VFSDirectoryPath,IDirectoryNode).md|TryGetDirectory(VFSDirectoryPath, IDirectoryNode) @@ -91,6 +92,7 @@ T:Atypical.VirtualFileSystem.Core.Contracts.IRootNode|IRootNode.md|IRootNode P:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.Root|IVirtualFileSystem.Root.md|Root P:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.Index|IVirtualFileSystem.Index.md|Index M:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.IsEmpty|IVirtualFileSystem.IsEmpty().md|IsEmpty() +M:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetRootPath|IVirtualFileSystem.GetRootPath().md|GetRootPath() M:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetDirectory(Atypical.VirtualFileSystem.Core.ValueObjects.VFSDirectoryPath)|IVirtualFileSystem.GetDirectory(VFSDirectoryPath).md|GetDirectory(VFSDirectoryPath) M:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetDirectory(System.String)|IVirtualFileSystem.GetDirectory(string).md|GetDirectory(string) M:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.TryGetDirectory(Atypical.VirtualFileSystem.Core.ValueObjects.VFSDirectoryPath,Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode@)|IVirtualFileSystem.TryGetDirectory(VFSDirectoryPath,IDirectoryNode).md|TryGetDirectory(VFSDirectoryPath, IDirectoryNode) diff --git a/src/Atypical.VirtualFileSystem.Core/Contracts/IVirtualFileSystem.cs b/src/Atypical.VirtualFileSystem.Core/Contracts/IVirtualFileSystem.cs index 4fe117c..2d69493 100644 --- a/src/Atypical.VirtualFileSystem.Core/Contracts/IVirtualFileSystem.cs +++ b/src/Atypical.VirtualFileSystem.Core/Contracts/IVirtualFileSystem.cs @@ -31,6 +31,12 @@ public interface IVirtualFileSystem /// This is the case if the root directory is empty. /// bool IsEmpty(); + + /// + /// Gets the path of the root directory. + /// + /// The path of the root directory. + VFSPath GetRootPath(); /// /// Gets a directory node by its path. diff --git a/src/Atypical.VirtualFileSystem.Core/VFS.Commands.cs b/src/Atypical.VirtualFileSystem.Core/VFS.Commands.cs index bd05400..82cc8f4 100644 --- a/src/Atypical.VirtualFileSystem.Core/VFS.Commands.cs +++ b/src/Atypical.VirtualFileSystem.Core/VFS.Commands.cs @@ -1,7 +1,6 @@ namespace Atypical.VirtualFileSystem.Core; public partial record VFS - : IVirtualFileSystem { /// public IVirtualFileSystem CreateDirectory(VFSDirectoryPath directoryPath) diff --git a/src/Atypical.VirtualFileSystem.Core/VFS.Queries.cs b/src/Atypical.VirtualFileSystem.Core/VFS.Queries.cs index 89bde25..b88185a 100644 --- a/src/Atypical.VirtualFileSystem.Core/VFS.Queries.cs +++ b/src/Atypical.VirtualFileSystem.Core/VFS.Queries.cs @@ -1,14 +1,14 @@ namespace Atypical.VirtualFileSystem.Core; public partial record VFS - : IVirtualFileSystem { - public VFSPath GetRootPath() - => this.Root.Path; - /// public bool IsEmpty() => this.Index.Count == 0; + + /// + public VFSPath GetRootPath() + => this.Root.Path; /// public IDirectoryNode GetDirectory(VFSDirectoryPath directoryPath) diff --git a/tests/Atypical.VirtualFileSystem.UnitTests/Models/VirtualFileSystemTests.cs b/tests/Atypical.VirtualFileSystem.UnitTests/Models/VirtualFileSystemTests.cs index 9430906..3bd7dc7 100644 --- a/tests/Atypical.VirtualFileSystem.UnitTests/Models/VirtualFileSystemTests.cs +++ b/tests/Atypical.VirtualFileSystem.UnitTests/Models/VirtualFileSystemTests.cs @@ -29,6 +29,23 @@ public void Constructor_creates_a_new_file_system() } } + public class MethodGetRootPath + { + [Fact] + public void GetRootPath_returns_the_root_path() + { + // Arrange + IVirtualFileSystem vfs = new VFS(); + + // Act + var rootPath = vfs.GetRootPath(); + + // Assert + rootPath.Should().NotBeNull(); + rootPath.Value.Should().Be("vfs://"); + } + } + public class MethodGetDirectory { [Fact]