using System.Security.Cryptography;
using XFEExtension.NetCore.XUnit.Attributes;
using XFEEDToolBox.Core.Data;
namespace XFEEDToolBox.Test;
[TestFixture]
public class GameEventRecoveryTests
{
[Test] public void DamagedIndexIsPreservedAndOriginalJournalReplayRebuildsAPersistentGeneration()
{
using var temp=new TemporaryDirectory();var path=temp.File("events.db");
File.WriteAllText(path,"damaged SQLite header");var original=SHA256.HashData(File.ReadAllBytes(path));
var repository=new GameEventRepository(path);repository.Initialize();
Check.That(repository.LastRecovery is not null);Check.That(repository.DatabasePath!=path);
Check.That(original.SequenceEqual(SHA256.HashData(File.ReadAllBytes(path))));
var row=new GameJournalRecord("Journal.log",10,DateTimeOffset.UtcNow,"LoadGame","{\"event\":\"LoadGame\",\"FID\":\"F1\"}");
Check.Equal(1,repository.Insert([row]));Check.Equal(0,repository.Insert([row]));
var reopened=new GameEventRepository(path);reopened.Initialize();
Check.Equal(repository.DatabasePath,reopened.DatabasePath);Check.That(reopened.LastRecovery is null);
Check.Equal(1L,reopened.Query().Count);
}
[Test] public void HealthyIndexKeepsItsFileAndHistory()
{
using var temp=new TemporaryDirectory();var path=temp.File("events.db");
var repository=new GameEventRepository(path);repository.Initialize();
repository.Insert([new("Journal.log",10,DateTimeOffset.UtcNow,"Docked","{\"event\":\"Docked\"}")]);
var reopened=new GameEventRepository(path);reopened.Initialize();
Check.Equal(path,reopened.DatabasePath);Check.That(reopened.LastRecovery is null);Check.Equal(1L,reopened.Query().Count);
Check.That(!File.Exists(path+".active"));
}
}
using System.Security.Cryptography;
using XFEExtension.NetCore.XUnit.Attributes;
using XFEEDToolBox.Core.Data;
namespace XFEEDToolBox.Test;
[TestFixture]
public class GameEventRecoveryTests
{
[Test] public void DamagedIndexIsPreservedAndOriginalJournalReplayRebuildsAPersistentGeneration()
{
using var temp=new TemporaryDirectory();var path=temp.File("events.db");
File.WriteAllText(path,"damaged SQLite header");var original=SHA256.HashData(File.ReadAllBytes(path));
var repository=new GameEventRepository(path);repository.Initialize();
Check.That(repository.LastRecovery is not null);Check.That(repository.DatabasePath!=path);
Check.That(original.SequenceEqual(SHA256.HashData(File.ReadAllBytes(path))));
var row=new GameJournalRecord("Journal.log",10,DateTimeOffset.UtcNow,"LoadGame","{\"event\":\"LoadGame\",\"FID\":\"F1\"}");
Check.Equal(1,repository.Insert([row]));Check.Equal(0,repository.Insert([row]));
var reopened=new GameEventRepository(path);reopened.Initialize();
Check.Equal(repository.DatabasePath,reopened.DatabasePath);Check.That(reopened.LastRecovery is null);
Check.Equal(1L,reopened.Query().Count);
}
[Test] public void HealthyIndexKeepsItsFileAndHistory()
{
using var temp=new TemporaryDirectory();var path=temp.File("events.db");
var repository=new GameEventRepository(path);repository.Initialize();
repository.Insert([new("Journal.log",10,DateTimeOffset.UtcNow,"Docked","{\"event\":\"Docked\"}")]);
var reopened=new GameEventRepository(path);reopened.Initialize();
Check.Equal(path,reopened.DatabasePath);Check.That(reopened.LastRecovery is null);Check.Equal(1L,reopened.Query().Count);
Check.That(!File.Exists(path+".active"));
}
}