Skip to content

Commit 46c8707

Browse files
authored
Merge pull request #35 from Atypical-Consulting/tostring
Get a summary from the ToString method
2 parents 1a6e11e + e43bd59 commit 46c8707

File tree

10 files changed

+87
-11
lines changed

10 files changed

+87
-11
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#### [Atypical.VirtualFileSystem.Core](VirtualFileSystem.md 'VirtualFileSystem')
2+
### [Atypical.VirtualFileSystem.Core.Contracts](VirtualFileSystem.md#Atypical.VirtualFileSystem.Core.Contracts 'Atypical.VirtualFileSystem.Core.Contracts').[IVirtualFileSystem](IVirtualFileSystem.md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem')
3+
4+
## IVirtualFileSystem.GetTree() Method
5+
6+
Gets the tree of the file system.
7+
8+
```csharp
9+
string GetTree();
10+
```
11+
12+
#### Returns
13+
[System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')
14+
The tree of the file system.

docs/api/IVirtualFileSystem.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Derived
3838
| [GetFile(VFSFilePath)](IVirtualFileSystem.GetFile(VFSFilePath).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetFile(Atypical.VirtualFileSystem.Core.ValueObjects.VFSFilePath)') | Gets a file node by its path.<br/>The path must be absolute. |
3939
| [GetFile(string)](IVirtualFileSystem.GetFile(string).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetFile(string)') | Gets a file node by its path.<br/>The path must be absolute. |
4040
| [GetRootPath()](IVirtualFileSystem.GetRootPath().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetRootPath()') | Gets the path of the root directory. |
41+
| [GetTree()](IVirtualFileSystem.GetTree().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetTree()') | Gets the tree of the file system. |
4142
| [IsEmpty()](IVirtualFileSystem.IsEmpty().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.IsEmpty()') | Indicates whether the file system is empty.<br/>This is the case if the root directory is empty. |
4243
| [SelectDirectories(Func&lt;IDirectoryNode,bool&gt;)](IVirtualFileSystem.SelectDirectories(Func_IDirectoryNode,bool_).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.SelectDirectories(System.Func<Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode,bool>)') | Finds all directory nodes that match the specified predicate. |
4344
| [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.<br/>The path must be absolute.<br/>If the directory node does not exist, this method returns `false`<br/>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`. |

docs/api/VFS.GetTree().md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#### [Atypical.VirtualFileSystem.Core](VirtualFileSystem.md 'VirtualFileSystem')
2+
### [Atypical.VirtualFileSystem.Core](VirtualFileSystem.md#Atypical.VirtualFileSystem.Core 'Atypical.VirtualFileSystem.Core').[VFS](VFS.md 'Atypical.VirtualFileSystem.Core.VFS')
3+
4+
## VFS.GetTree() Method
5+
6+
Gets the tree of the file system.
7+
8+
```csharp
9+
public string GetTree();
10+
```
11+
12+
Implements [GetTree()](IVirtualFileSystem.GetTree().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetTree()')
13+
14+
#### Returns
15+
[System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String')
16+
The tree of the file system.

docs/api/VFS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Implements [IVirtualFileSystem](IVirtualFileSystem.md 'Atypical.VirtualFileSyste
4444
| [GetFile(VFSFilePath)](VFS.GetFile(VFSFilePath).md 'Atypical.VirtualFileSystem.Core.VFS.GetFile(Atypical.VirtualFileSystem.Core.ValueObjects.VFSFilePath)') | Gets a file node by its path.<br/>The path must be absolute. |
4545
| [GetFile(string)](VFS.GetFile(string).md 'Atypical.VirtualFileSystem.Core.VFS.GetFile(string)') | Gets a file node by its path.<br/>The path must be absolute. |
4646
| [GetRootPath()](VFS.GetRootPath().md 'Atypical.VirtualFileSystem.Core.VFS.GetRootPath()') | Gets the path of the root directory. |
47+
| [GetTree()](VFS.GetTree().md 'Atypical.VirtualFileSystem.Core.VFS.GetTree()') | Gets the tree of the file system. |
4748
| [IsEmpty()](VFS.IsEmpty().md 'Atypical.VirtualFileSystem.Core.VFS.IsEmpty()') | Indicates whether the file system is empty.<br/>This is the case if the root directory is empty. |
4849
| [SelectDirectories(Func&lt;IDirectoryNode,bool&gt;)](VFS.SelectDirectories(Func_IDirectoryNode,bool_).md 'Atypical.VirtualFileSystem.Core.VFS.SelectDirectories(System.Func<Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode,bool>)') | Finds all directory nodes that match the specified predicate. |
4950
| [ToString()](VFS.ToString().md 'Atypical.VirtualFileSystem.Core.VFS.ToString()') | Returns the index as an ASCII tree. |

docs/api/VirtualFileSystem.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
- **[GetFile(string)](VFS.GetFile(string).md 'Atypical.VirtualFileSystem.Core.VFS.GetFile(string)')** `Method` Gets a file node by its path.
4545
The path must be absolute.
4646
- **[GetRootPath()](VFS.GetRootPath().md 'Atypical.VirtualFileSystem.Core.VFS.GetRootPath()')** `Method` Gets the path of the root directory.
47+
- **[GetTree()](VFS.GetTree().md 'Atypical.VirtualFileSystem.Core.VFS.GetTree()')** `Method` Gets the tree of the file system.
4748
- **[IsEmpty()](VFS.IsEmpty().md 'Atypical.VirtualFileSystem.Core.VFS.IsEmpty()')** `Method` Indicates whether the file system is empty.
4849
This is the case if the root directory is empty.
4950
- **[SelectDirectories(Func&lt;IDirectoryNode,bool&gt;)](VFS.SelectDirectories(Func_IDirectoryNode,bool_).md 'Atypical.VirtualFileSystem.Core.VFS.SelectDirectories(System.Func<Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode,bool>)')** `Method` Finds all directory nodes that match the specified predicate.
@@ -174,6 +175,7 @@
174175
- **[GetFile(string)](IVirtualFileSystem.GetFile(string).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetFile(string)')** `Method` Gets a file node by its path.
175176
The path must be absolute.
176177
- **[GetRootPath()](IVirtualFileSystem.GetRootPath().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetRootPath()')** `Method` Gets the path of the root directory.
178+
- **[GetTree()](IVirtualFileSystem.GetTree().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetTree()')** `Method` Gets the tree of the file system.
177179
- **[IsEmpty()](IVirtualFileSystem.IsEmpty().md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.IsEmpty()')** `Method` Indicates whether the file system is empty.
178180
This is the case if the root directory is empty.
179181
- **[SelectDirectories(Func&lt;IDirectoryNode,bool&gt;)](IVirtualFileSystem.SelectDirectories(Func_IDirectoryNode,bool_).md 'Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.SelectDirectories(System.Func<Atypical.VirtualFileSystem.Core.Contracts.IDirectoryNode,bool>)')** `Method` Finds all directory nodes that match the specified predicate.

docs/links

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ M:Atypical.VirtualFileSystem.Core.VFS.TryGetFile(Atypical.VirtualFileSystem.Core
2626
M:Atypical.VirtualFileSystem.Core.VFS.TryGetFile(System.String,Atypical.VirtualFileSystem.Core.Contracts.IFileNode@)|VFS.TryGetFile(string,IFileNode).md|TryGetFile(string, IFileNode)
2727
M:Atypical.VirtualFileSystem.Core.VFS.FindFiles|VFS.FindFiles().md|FindFiles()
2828
M:Atypical.VirtualFileSystem.Core.VFS.FindFiles(System.Text.RegularExpressions.Regex)|VFS.FindFiles(Regex).md|FindFiles(Regex)
29+
M:Atypical.VirtualFileSystem.Core.VFS.GetTree|VFS.GetTree().md|GetTree()
2930
N:Atypical.VirtualFileSystem.Core|VirtualFileSystem.md#Atypical.VirtualFileSystem.Core|Atypical.VirtualFileSystem.Core
3031
T:Atypical.VirtualFileSystem.Core.VFS|VFS.md|VFS
3132
F:Atypical.VirtualFileSystem.Core.VFSConstants.ROOT_PATH|VFSConstants.ROOT_PATH.md|ROOT_PATH
@@ -115,6 +116,7 @@ M:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.DeleteFile(Atypic
115116
M:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.DeleteFile(System.String)|IVirtualFileSystem.DeleteFile(string).md|DeleteFile(string)
116117
M:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.FindFiles|IVirtualFileSystem.FindFiles().md|FindFiles()
117118
M:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.FindFiles(System.Text.RegularExpressions.Regex)|IVirtualFileSystem.FindFiles(Regex).md|FindFiles(Regex)
119+
M:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem.GetTree|IVirtualFileSystem.GetTree().md|GetTree()
118120
T:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystem|IVirtualFileSystem.md|IVirtualFileSystem
119121
M:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystemFactory.CreateFileSystem|IVirtualFileSystemFactory.CreateFileSystem().md|CreateFileSystem()
120122
T:Atypical.VirtualFileSystem.Core.Contracts.IVirtualFileSystemFactory|IVirtualFileSystemFactory.md|IVirtualFileSystemFactory

src/Atypical.VirtualFileSystem.Core/Contracts/IVirtualFileSystem.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,11 @@ IEnumerable<IDirectoryNode> SelectDirectories(
210210
/// <param name="regexPattern">The regular expression pattern.</param>
211211
/// <returns>The file nodes.</returns>
212212
IEnumerable<IFileNode> FindFiles(Regex regexPattern);
213+
214+
// GetTree
215+
/// <summary>
216+
/// Gets the tree of the file system.
217+
/// </summary>
218+
/// <returns>The tree of the file system.</returns>
219+
string GetTree();
213220
}

src/Atypical.VirtualFileSystem.Core/VFS.Queries.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public IEnumerable<IFileNode> FindFiles()
9191
public IEnumerable<IFileNode> FindFiles(Regex regexPattern)
9292
=> FindFiles().Where(f => regexPattern.IsMatch(f.Path.Value));
9393

94+
/// <inheritdoc cref="IVirtualFileSystem.GetTree()" />
9495
public string GetTree()
9596
{
9697
var sb = new StringBuilder();

src/Atypical.VirtualFileSystem.Core/VFS.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ public VFS()
3838
/// </returns>
3939
public override string ToString()
4040
{
41-
return GetTree();
41+
var files = Index.Values.Count(x => x.IsFile);
42+
var directories = Index.Values.Count(x => x.IsDirectory);
43+
44+
return new StringBuilder()
45+
.Append("VFS:")
46+
.Append($" {files} files")
47+
.Append(',')
48+
.Append($" {directories} directories")
49+
.ToString();
4250
}
4351

4452
internal void AddToIndex(IVirtualFileSystemNode node)

tests/Atypical.VirtualFileSystem.UnitTests/Models/VirtualFileSystemTests.cs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -575,23 +575,23 @@ public void FindFiles_with_valid_data_returns_a_list_of_files_with_content_and_n
575575
}
576576
}
577577

578-
public class MethodToString
578+
public class MethodGetTree
579579
{
580580
[Fact]
581-
public void ToString_returns_root_directory()
581+
public void GetTree_returns_root_directory()
582582
{
583583
// Arrange
584584
IVirtualFileSystem vfs = new VFS();
585585

586586
// Act
587-
var result = vfs.ToString();
587+
var result = vfs.GetTree();
588588

589589
// Assert
590590
result.Should().Be("vfs://");
591591
}
592592

593593
[Fact]
594-
public void ToString_returns_3_files_as_ASCII_tree()
594+
public void GetTree_returns_3_files_as_ASCII_tree()
595595
{
596596
// Arrange
597597
var expected = """
@@ -607,14 +607,14 @@ public void ToString_returns_3_files_as_ASCII_tree()
607607
.CreateFile("file3.txt");
608608

609609
// Act
610-
var result = vfs.ToString();
610+
var result = vfs.GetTree();
611611

612612
// Assert
613613
result.Should().Be(expected);
614614
}
615615

616616
[Fact]
617-
public void ToString_returns_3_directories_as_ASCII_tree()
617+
public void GetTree_returns_3_directories_as_ASCII_tree()
618618
{
619619
// Arrange
620620
var expected = """
@@ -630,14 +630,14 @@ public void ToString_returns_3_directories_as_ASCII_tree()
630630
.CreateDirectory("dir3");
631631

632632
// Act
633-
var result = vfs.ToString();
633+
var result = vfs.GetTree();
634634

635635
// Assert
636636
result.Should().Be(expected);
637637
}
638638

639639
[Fact]
640-
public void ToString_returns_3_files_and_3_directories_as_ASCII_tree()
640+
public void GetTree_returns_3_files_and_3_directories_as_ASCII_tree()
641641
{
642642
// Arrange
643643
var expected = """
@@ -668,14 +668,14 @@ public void ToString_returns_3_files_and_3_directories_as_ASCII_tree()
668668
.CreateFile("dir3/file3.txt");
669669

670670
// Act
671-
var result = vfs.ToString();
671+
var result = vfs.GetTree();
672672

673673
// Assert
674674
result.Should().Be(expected);
675675
}
676676

677677
[Fact]
678-
public void ToString_returns_a_complex_tree()
678+
public void GetTree_returns_a_complex_tree()
679679
{
680680
// Arrange
681681
var expected = """
@@ -726,6 +726,30 @@ public void ToString_returns_a_complex_tree()
726726
.CreateFile("dir3/file2.txt")
727727
.CreateFile("dir3/file3.txt");
728728

729+
// Act
730+
var result = vfs.GetTree();
731+
732+
// Assert
733+
result.Should().Be(expected);
734+
}
735+
}
736+
737+
public class MethodToString
738+
{
739+
[Fact]
740+
public void ToString_returns_a_summary_of_the_VFS()
741+
{
742+
// Arrange
743+
const string expected = "VFS: 3 files, 3 directories";
744+
745+
var vfs = new VFS()
746+
.CreateFile("file1.txt")
747+
.CreateFile("file2.txt")
748+
.CreateFile("file3.txt")
749+
.CreateDirectory("dir1")
750+
.CreateDirectory("dir2")
751+
.CreateDirectory("dir3");
752+
729753
// Act
730754
var result = vfs.ToString();
731755

0 commit comments

Comments
 (0)