Files
ReminderOrganizer/Tests/SyncTests.cs
Michi 33459bdec7 Snooze notifications, morning summary, ICS import, data folder sync
- Windows toast notifications with snooze (10 min / 1 h / tomorrow) and
  done buttons; balloon fallback; works when Windows starts the app
- Recurring entries snooze via SnoozedUntil without moving their date;
  lead reminders keep the real date
- Morning summary once a day from a chosen hour (pure DailySummary)
- iCalendar import incl. Google birthday calendar, folded lines, UTC,
  alarms, own export round trip, duplicates skipped by UID, undo
- Data folder selectable (location.json pointer), file watcher reloads
  changes from another PC (own writes ignored)
- Themed date picker calendar, WPF tray menu, arrow/Home/End/Space keys
- 90 tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 20:37:20 +01:00

67 lines
2.3 KiB
C#

using System;
using System.IO;
using System.Threading.Tasks;
using ReminderOrganizer.Models;
using ReminderOrganizer.Services;
using Xunit;
namespace ReminderOrganizer.Tests
{
public class SyncTests : IDisposable
{
private readonly string _root = Path.Combine(Path.GetTempPath(), "ro-sync-" + Guid.NewGuid().ToString("N"));
public void Dispose()
{
try { Directory.Delete(_root, true); } catch { }
}
[Fact]
public void Pointer_file_round_trip()
{
var app = Path.Combine(_root, "app");
var cloud = Path.Combine(_root, "OneDrive", "Reminders");
Directory.CreateDirectory(cloud);
Assert.Null(DataService.ReadPointer(app));
DataService.WritePointer(app, cloud);
Assert.Equal(cloud, DataService.ReadPointer(app));
DataService.WritePointer(app, app); // back to the app folder = no pointer
Assert.Null(DataService.ReadPointer(app));
}
[Fact]
public void Pointer_to_missing_folder_is_ignored()
{
var app = Path.Combine(_root, "app");
DataService.WritePointer(app, Path.Combine(_root, "gone"));
Directory.CreateDirectory(Path.Combine(_root, "gone"));
Directory.Delete(Path.Combine(_root, "gone"));
Assert.Null(DataService.ReadPointer(app));
}
[Fact]
public async Task Own_writes_are_not_external_but_other_writes_are()
{
var ds = new DataService(Path.Combine(_root, "data"));
await ds.SaveAsync(new AppData());
Assert.False(ds.IsExternalChange());
await Task.Delay(30);
File.WriteAllText(ds.DataFilePath, "{\"Folders\":[]}"); // "another PC"
File.SetLastWriteTimeUtc(ds.DataFilePath, DateTime.UtcNow.AddSeconds(2));
Assert.True(ds.IsExternalChange());
Assert.False(ds.IsExternalChange()); // reported once
}
[Fact]
public void Switching_folder_uses_new_file()
{
var ds = new DataService(Path.Combine(_root, "a"));
ds.SwitchTo(Path.Combine(_root, "b"));
Assert.Equal(Path.Combine(_root, "b", "tasks.json"), ds.DataFilePath);
}
}
}