@@ -16,6 +16,33 @@ namespace NexusMods.DataModel.Synchronizer.Tests;
16
16
/// </summary>
17
17
public class SynchronizerUnitTests ( ITestOutputHelper testOutputHelper ) : ACyberpunkIsolatedGameTest < SynchronizerUnitTests > ( testOutputHelper )
18
18
{
19
+
20
+ [ Fact ]
21
+ [ GithubIssue ( 2077 ) ]
22
+ public async Task EmptyFoldersAreRemovedWhenSwitchingLoadouts ( )
23
+ {
24
+ var loadoutA = await CreateLoadout ( ) ;
25
+
26
+ var nestedFile = new GamePath ( LocationId . Game , "a/b/nested.txt" ) ;
27
+ var nestedFileFullPath = GameInstallation . LocationsRegister . GetResolvedPath ( nestedFile ) ;
28
+
29
+ nestedFileFullPath . Parent . CreateDirectory ( ) ;
30
+ await nestedFileFullPath . WriteAllTextAsync ( "Nested File" ) ;
31
+
32
+ loadoutA = await Synchronizer . Synchronize ( loadoutA ) ;
33
+
34
+ loadoutA . Items . Should ( ) . ContainSingle ( f => f . Name == "nested.txt" ) ;
35
+
36
+ // Create new empty loadout
37
+ var loadoutB = await CreateLoadout ( ) ;
38
+
39
+ // Switch to empty loadout
40
+ loadoutB = await Synchronizer . Synchronize ( loadoutB ) ;
41
+
42
+ // 'a/' directory should be deleted
43
+ nestedFileFullPath . Parent . Parent . DirectoryExists ( ) . Should ( ) . BeFalse ( ) ;
44
+ }
45
+
19
46
[ Fact ]
20
47
[ GithubIssue ( 1925 ) ]
21
48
public async Task EmptyChildFoldersDontDeleteNonEmptyParents ( )
@@ -38,7 +65,6 @@ public async Task EmptyChildFoldersDontDeleteNonEmptyParents()
38
65
39
66
loadout . Items . Should ( ) . ContainSingle ( f => f . Name == "parent.txt" ) ;
40
67
loadout . Items . Should ( ) . ContainSingle ( f => f . Name == "grandchild.txt" ) ;
41
-
42
68
43
69
44
70
using ( var tx = Connection . BeginTransaction ( ) )
@@ -50,8 +76,15 @@ public async Task EmptyChildFoldersDontDeleteNonEmptyParents()
50
76
51
77
loadout = loadout . Rebase ( ) ;
52
78
loadout = await Synchronizer . Synchronize ( loadout ) ;
53
-
79
+
80
+ // a/b/c/grandchild.txt
54
81
grandChildFileFullPath . FileExists . Should ( ) . BeFalse ( ) ;
82
+ // a/b/c
83
+ grandChildFileFullPath . Parent . DirectoryExists ( ) . Should ( ) . BeFalse ( ) ;
84
+ // a/b
85
+ grandChildFileFullPath . Parent . Parent . DirectoryExists ( ) . Should ( ) . BeFalse ( ) ;
86
+
87
+ // a/parent.txt
55
88
parentFileFullPath . FileExists . Should ( ) . BeTrue ( ) ;
56
89
}
57
90
0 commit comments