@@ -2,63 +2,62 @@ namespace VirtualFileSystem.UnitTests.SystemOperations.Commands;
22
33public class VirtualFileSystem_MethodCreateDirectory_Tests : VirtualFileSystemTestsBase
44{
5+ private readonly IVirtualFileSystem _vfs = CreateVFS ( ) ;
6+ private VFSDirectoryPath _directoryPath = new ( "dir1" ) ;
7+
8+ private void Act ( )
9+ => _vfs . CreateDirectory ( _directoryPath ) ;
10+
511 [ Fact ]
612 public void CreateDirectory_creates_a_directory ( )
713 {
8- // Arrange
9- var vfs = CreateVFS ( ) ;
10- VFSDirectoryPath directoryPath = new ( "dir1" ) ;
11-
1214 // Act
13- vfs . CreateDirectory ( directoryPath ) ;
15+ Act ( ) ;
1416
1517 // Assert
16- vfs . IsEmpty . Should ( ) . BeFalse ( ) ;
17- vfs . Index . RawIndex . Should ( ) . NotBeEmpty ( ) ;
18- vfs . Index . RawIndex . Should ( ) . HaveCount ( 1 ) ;
19- vfs . Index . RawIndex . Should ( ) . ContainKey ( new VFSDirectoryPath ( "vfs://dir1" ) ) ;
20- vfs . Root . IsDirectory . Should ( ) . BeTrue ( ) ;
21- vfs . Root . IsFile . Should ( ) . BeFalse ( ) ;
22- vfs . Root . Path . Value . Should ( ) . Be ( "vfs://" ) ;
23- vfs . Root . CreationTime . Should ( ) . BeCloseTo ( DateTime . Now , TimeSpan . FromHours ( 1 ) ) ;
18+ _vfs . IsEmpty . Should ( ) . BeFalse ( ) ;
19+ _vfs . Index . RawIndex . Should ( ) . NotBeEmpty ( ) ;
20+ _vfs . Index . RawIndex . Should ( ) . HaveCount ( 1 ) ;
21+ _vfs . Index . RawIndex . Should ( ) . ContainKey ( new VFSDirectoryPath ( "vfs://dir1" ) ) ;
22+ _vfs . Root . IsDirectory . Should ( ) . BeTrue ( ) ;
23+ _vfs . Root . IsFile . Should ( ) . BeFalse ( ) ;
24+ _vfs . Root . Path . Value . Should ( ) . Be ( "vfs://" ) ;
25+ _vfs . Root . CreationTime . Should ( ) . BeCloseTo ( DateTime . Now , TimeSpan . FromHours ( 1 ) ) ;
2426 }
2527
2628 [ Fact ]
2729 public void CreateDirectory_creates_a_directory_and_its_parents ( )
2830 {
2931 // Arrange
30- var vfs = CreateVFS ( ) ;
31- VFSDirectoryPath directoryPath = new ( "dir1/dir2/dir3" ) ;
32+ _directoryPath = new ( "dir1/dir2/dir3" ) ;
3233
3334 // Act
34- vfs . CreateDirectory ( directoryPath ) ;
35+ Act ( ) ;
3536
3637 // Assert
37- vfs . Index . RawIndex . Should ( ) . NotBeEmpty ( ) ;
38- vfs . Index . RawIndex . Should ( ) . HaveCount ( 3 ) ; // dir1 + dir2 + dir3
39- vfs . Index . RawIndex . Should ( ) . ContainKey ( directoryPath ) ;
40- vfs . Index . RawIndex . Should ( ) . ContainKey ( new VFSDirectoryPath ( "vfs://dir1" ) ) ;
41- vfs . Index . RawIndex . Should ( ) . ContainKey ( new VFSDirectoryPath ( "vfs://dir1/dir2" ) ) ;
42- vfs . Index . RawIndex . Should ( ) . ContainKey ( new VFSDirectoryPath ( "vfs://dir1/dir2/dir3" ) ) ;
38+ _vfs . Index . RawIndex . Should ( ) . NotBeEmpty ( ) ;
39+ _vfs . Index . RawIndex . Should ( ) . HaveCount ( 3 ) ; // dir1 + dir2 + dir3
40+ _vfs . Index . RawIndex . Should ( ) . ContainKey ( _directoryPath ) ;
41+ _vfs . Index . RawIndex . Should ( ) . ContainKey ( new VFSDirectoryPath ( "vfs://dir1" ) ) ;
42+ _vfs . Index . RawIndex . Should ( ) . ContainKey ( new VFSDirectoryPath ( "vfs://dir1/dir2" ) ) ;
43+ _vfs . Index . RawIndex . Should ( ) . ContainKey ( new VFSDirectoryPath ( "vfs://dir1/dir2/dir3" ) ) ;
4344
44- vfs . Index [ new VFSDirectoryPath ( "vfs://dir1" ) ] . Should ( ) . BeAssignableTo < IDirectoryNode > ( ) ;
45- vfs . Index [ new VFSDirectoryPath ( "vfs://dir1/dir2" ) ] . Should ( ) . BeAssignableTo < IDirectoryNode > ( ) ;
46- vfs . Index [ new VFSDirectoryPath ( "vfs://dir1/dir2/dir3" ) ] . Should ( ) . BeAssignableTo < IDirectoryNode > ( ) ;
45+ _vfs . Index [ new VFSDirectoryPath ( "vfs://dir1" ) ] . Should ( ) . BeAssignableTo < IDirectoryNode > ( ) ;
46+ _vfs . Index [ new VFSDirectoryPath ( "vfs://dir1/dir2" ) ] . Should ( ) . BeAssignableTo < IDirectoryNode > ( ) ;
47+ _vfs . Index [ new VFSDirectoryPath ( "vfs://dir1/dir2/dir3" ) ] . Should ( ) . BeAssignableTo < IDirectoryNode > ( ) ;
4748
48- vfs . Index [ new VFSDirectoryPath ( "vfs://dir1" ) ] . As < IDirectoryNode > ( ) . Directories . Should ( ) . NotBeEmpty ( ) ;
49- vfs . Index [ new VFSDirectoryPath ( "vfs://dir1" ) ] . As < IDirectoryNode > ( ) . Directories . Should ( ) . HaveCount ( 1 ) ;
49+ _vfs . Index [ new VFSDirectoryPath ( "vfs://dir1" ) ] . As < IDirectoryNode > ( ) . Directories . Should ( ) . NotBeEmpty ( ) ;
50+ _vfs . Index [ new VFSDirectoryPath ( "vfs://dir1" ) ] . As < IDirectoryNode > ( ) . Directories . Should ( ) . HaveCount ( 1 ) ;
5051 }
5152
5253 [ Fact ]
5354 public void CreateDirectory_throws_an_exception_if_the_directory_already_exists ( )
5455 {
5556 // Arrange
56- var vfs = CreateVFS ( ) ;
57- var directoryPath = new VFSDirectoryPath ( "dir1" ) ;
58- vfs . CreateDirectory ( directoryPath ) ;
57+ Act ( ) ;
5958
6059 // Act
61- Action action = ( ) => vfs . CreateDirectory ( directoryPath ) ;
60+ var action = Act ;
6261
6362 // Assert
6463 action . Should ( )
@@ -69,11 +68,8 @@ public void CreateDirectory_throws_an_exception_if_the_directory_already_exists(
6968 [ Fact ]
7069 public void CreateDirectory_throws_an_exception_if_the_path_is_the_root_directory ( )
7170 {
72- // Arrange
73- var vfs = CreateVFS ( ) ;
74-
7571 // Act
76- Action action = ( ) => vfs . CreateDirectory ( new VFSRootPath ( ) ) ;
72+ Action action = ( ) => _vfs . CreateDirectory ( new VFSRootPath ( ) ) ;
7773
7874 // Assert
7975 action . Should ( )
@@ -85,18 +81,16 @@ public void CreateDirectory_throws_an_exception_if_the_path_is_the_root_director
8581 public void CreateDirectory_raises_a_DirectoryCreated_event ( )
8682 {
8783 // Arrange
88- var vfs = CreateVFS ( ) ;
89- VFSDirectoryPath directoryPath = new ( "dir1" ) ;
90- bool eventRaised = false ;
84+ var eventRaised = false ;
9185
92- vfs . DirectoryCreated += ( args ) =>
86+ _vfs . DirectoryCreated += args =>
9387 {
9488 eventRaised = true ;
95- args . Path . Should ( ) . Be ( directoryPath ) ;
89+ args . Path . Should ( ) . Be ( _directoryPath ) ;
9690 } ;
9791
9892 // Act
99- vfs . CreateDirectory ( directoryPath ) ;
93+ Act ( ) ;
10094
10195 // Assert
10296 eventRaised . Should ( ) . BeTrue ( ) ;
@@ -105,19 +99,15 @@ public void CreateDirectory_raises_a_DirectoryCreated_event()
10599 [ Fact ]
106100 public void CreateDirectory_adds_a_change_to_the_ChangeHistory ( )
107101 {
108- // Arrange
109- var vfs = CreateVFS ( ) ;
110- var directoryPath = new VFSDirectoryPath ( "dir1" ) ;
111-
112102 // Act
113- vfs . CreateDirectory ( directoryPath ) ;
103+ Act ( ) ;
114104
115105 // Retrieve the change from the UndoStack
116- var change = vfs . ChangeHistory . UndoStack . First ( ) ;
106+ var change = _vfs . ChangeHistory . UndoStack . First ( ) ;
117107
118108 // Assert
119- vfs . ChangeHistory . UndoStack . Should ( ) . ContainEquivalentOf ( change ) ;
120- vfs . ChangeHistory . UndoStack . Should ( ) . HaveCount ( 1 ) ;
121- vfs . ChangeHistory . RedoStack . Should ( ) . BeEmpty ( ) ;
109+ _vfs . ChangeHistory . UndoStack . Should ( ) . ContainEquivalentOf ( change ) ;
110+ _vfs . ChangeHistory . UndoStack . Should ( ) . HaveCount ( 1 ) ;
111+ _vfs . ChangeHistory . RedoStack . Should ( ) . BeEmpty ( ) ;
122112 }
123113}
0 commit comments