Skip to content

Commit

Permalink
Merge pull request #1946 from Nexus-Mods/feat/synchronizer-tests
Browse files Browse the repository at this point in the history
Add test for #1924 fix: ingesting changes to existing files
  • Loading branch information
Al12rs authored Aug 27, 2024
2 parents 5c946ad + 3a5fcc7 commit c3fa36f
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## 1 - Loadout Created (A) - Synced:
Added a new loadout and synced it.
### Initial State - (0) - Tx:100000000000005
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
### Last Synced State - (0) - Tx:100000000000008
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
### Current State - (0) - Tx:100000000000008
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
### Loadout A - (0)
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |



## 2 - Added bin/newFile - Synced:
Added a new file to the game and synced it.
### Initial State - (0) - Tx:100000000000005
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
### Last Synced State - (1) - Tx:10000000000000B
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000001, Game, bin/newFile.txt) | 0xA52B286A3E7F4D91 | 12 B | Tx:10000000000000B |
### Current State - (1) - Tx:10000000000000B
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000001, Game, bin/newFile.txt) | 0xA52B286A3E7F4D91 | 12 B | Tx:10000000000000B |
### Loadout A - (1)
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000003, Game, bin/newFile.txt) | 0xA52B286A3E7F4D91 | 12 B | Tx:10000000000000B |



## 2 - Updated the file - Synced:
Updated the new file file and synced it.
### Initial State - (0) - Tx:100000000000005
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
### Last Synced State - (1) - Tx:10000000000000E
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000001, Game, bin/newFile.txt) | 0xCBF180132E60CE25 | 21 B | Tx:10000000000000E |
### Current State - (1) - Tx:10000000000000E
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000001, Game, bin/newFile.txt) | 0xCBF180132E60CE25 | 21 B | Tx:10000000000000E |
### Loadout A - (1)
| Path | Hash | Size | TxId |
| --- | --- | --- | --- |
| (EId:200000000000003, Game, bin/newFile.txt) | 0xCBF180132E60CE25 | 21 B | Tx:10000000000000E |



Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Text;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Games.TestFramework;
using Xunit.Abstractions;

namespace NexusMods.DataModel.Synchronizer.Tests;

public class GeneralFileManagementTests (ITestOutputHelper helper) : ACyberpunkIsolatedGameTest<GeneralModManagementTests>(helper)
{
[Fact]
public async Task SynchronizerFileManagementTest()
{
var sb = new StringBuilder();

await Synchronizer.RescanGameFiles(GameInstallation);
var loadoutA = await CreateLoadout(false);
loadoutA = await Synchronizer.Synchronize(loadoutA);
await Synchronizer.RescanGameFiles(GameInstallation);

LogDiskState(sb, "## 1 - Loadout Created (A) - Synced",
"""
Added a new loadout and synced it.
""", [loadoutA]);

// Add a new file to the game
var newfileGamePath = new GamePath(LocationId.Game, "bin/newFile.txt");
var newFileFullPath = GameInstallation.LocationsRegister.GetResolvedPath(newfileGamePath);
newFileFullPath.Parent.CreateDirectory();
await newFileFullPath.WriteAllTextAsync("Hello World!");

await Synchronizer.RescanGameFiles(GameInstallation);
loadoutA = await Synchronizer.Synchronize(loadoutA);
await Synchronizer.RescanGameFiles(GameInstallation);

LogDiskState(sb, "## 2 - Added bin/newFile - Synced",
"""
Added a new file to the game and synced it.
""", [loadoutA]);

// Update the new file contents
await newFileFullPath.WriteAllTextAsync("Hello World! Updated!");

await Synchronizer.RescanGameFiles(GameInstallation);
loadoutA = await Synchronizer.Synchronize(loadoutA);
await Synchronizer.RescanGameFiles(GameInstallation);

LogDiskState(sb, "## 2 - Updated the file - Synced",
"""
Updated the new file file and synced it.
""", [loadoutA]);

await Verify(sb.ToString(), extension: "md");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@

<ItemGroup>
<None Remove="CanResetToGameOriginalState.md.verified.txt" />
<None Update="GeneralModManagementTests.SynchronizerAddAndDisableMods.verified.md">
<DependentUpon>GeneralModManagementTests.cs</DependentUpon>
</None>
<None Update="GeneralFileManagementTests.SynchronizerFileManagementTest.verified.md">
<DependentUpon>GeneralFileManagementTests.cs</DependentUpon>
</None>
</ItemGroup>

</Project>

0 comments on commit c3fa36f

Please sign in to comment.