Skip to content

Commit 56f8bf5

Browse files
committed
Add regression test for removing empty folders during profile switch
1 parent 0d0a565 commit 56f8bf5

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

tests/NexusMods.DataModel.Synchronizer.Tests/SynchronizerUnitTests.cs

+35-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,33 @@ namespace NexusMods.DataModel.Synchronizer.Tests;
1616
/// </summary>
1717
public class SynchronizerUnitTests(ITestOutputHelper testOutputHelper) : ACyberpunkIsolatedGameTest<SynchronizerUnitTests>(testOutputHelper)
1818
{
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+
1946
[Fact]
2047
[GithubIssue(1925)]
2148
public async Task EmptyChildFoldersDontDeleteNonEmptyParents()
@@ -38,7 +65,6 @@ public async Task EmptyChildFoldersDontDeleteNonEmptyParents()
3865

3966
loadout.Items.Should().ContainSingle(f => f.Name == "parent.txt");
4067
loadout.Items.Should().ContainSingle(f => f.Name == "grandchild.txt");
41-
4268

4369

4470
using (var tx = Connection.BeginTransaction())
@@ -50,8 +76,15 @@ public async Task EmptyChildFoldersDontDeleteNonEmptyParents()
5076

5177
loadout = loadout.Rebase();
5278
loadout = await Synchronizer.Synchronize(loadout);
53-
79+
80+
// a/b/c/grandchild.txt
5481
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
5588
parentFileFullPath.FileExists.Should().BeTrue();
5689
}
5790

0 commit comments

Comments
 (0)