using LehrerApp.Sync.Models; using Xunit; namespace LehrerApp.Sync.Tests; public sealed class EventQueueTests { [Fact] public void MarkReviewed_EntferntKonfliktAusDerUnreviewedListe() { using var temp = new TempEventQueue(); var conflict = new ConflictEntry { LocalEvent = MakeEvent(), RemoteEvent = MakeEvent(), Resolution = "LocalWon", }; temp.Queue.AddConflict(conflict); temp.Queue.MarkReviewed(conflict.Id); Assert.Empty(temp.Queue.GetUnreviewed()); Assert.Equal(0, temp.Queue.ConflictCount()); } [Fact] public void MarkReviewed_UnbekannteId_TutNichtsUndWirftNicht() { using var temp = new TempEventQueue(); var exception = Record.Exception(() => temp.Queue.MarkReviewed(Guid.NewGuid())); Assert.Null(exception); } private static SyncEvent MakeEvent() => new() { DeviceId = "desktop-1", DeviceType = DeviceType.Desktop, EntityType = "Student", EntityId = Guid.NewGuid().ToString(), Operation = "Save", Payload = "{}", }; private sealed class TempEventQueue : IDisposable { private readonly string _directory = Path.Combine( Path.GetTempPath(), $"lehrerapp-sync-tests-eventqueue-{Guid.NewGuid():N}"); public EventQueue Queue { get; } public TempEventQueue() { Directory.CreateDirectory(_directory); Queue = new EventQueue(Path.Combine(_directory, "queue.db")); } public void Dispose() { Queue.Dispose(); if (Directory.Exists(_directory)) Directory.Delete(_directory, recursive: true); } } }