2026-11-29 15:06:19 +01:00
|
|
|
|
using System;
|
2026-11-29 14:42:16 +01:00
|
|
|
|
using ReminderOrganizer.Core;
|
|
|
|
|
|
using ReminderOrganizer.Models;
|
|
|
|
|
|
using ReminderOrganizer.Services;
|
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ReminderOrganizer.Tests
|
|
|
|
|
|
{
|
|
|
|
|
|
public class BirthdayTests
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly DateTime Today = new(2026, 11, 29);
|
|
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
|
[InlineData("19.03.", 19, 3, null)]
|
|
|
|
|
|
[InlineData("19.3", 19, 3, null)]
|
|
|
|
|
|
[InlineData("19.03.1986", 19, 3, 1986)]
|
|
|
|
|
|
[InlineData("19.3.86", 19, 3, 1986)]
|
|
|
|
|
|
[InlineData("1.1.05", 1, 1, 2005)]
|
|
|
|
|
|
[InlineData("1986-03-19", 19, 3, 1986)]
|
|
|
|
|
|
[InlineData(" 29.02. ", 29, 2, null)]
|
|
|
|
|
|
public void Parses_quick_input(string input, int day, int month, int? year)
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.True(BirthdayInput.TryParse(input, Today, out var d, out var m, out var y));
|
|
|
|
|
|
Assert.Equal((day, month, year), (d, m, y));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
|
[InlineData("")]
|
|
|
|
|
|
[InlineData("32.01.")]
|
|
|
|
|
|
[InlineData("10.13.")]
|
|
|
|
|
|
[InlineData("29.02.2023")] // not a leap year
|
|
|
|
|
|
[InlineData("01.01.2030")] // future
|
|
|
|
|
|
[InlineData("abc")]
|
|
|
|
|
|
public void Rejects_bad_input(string input)
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.False(BirthdayInput.TryParse(input, Today, out _, out _, out _));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void Next_birthday_this_year_or_next()
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.Equal(new DateTime(2026, 12, 14, 9, 0, 0), ReminderTask.NextBirthday(14, 12, Today));
|
|
|
|
|
|
Assert.Equal(new DateTime(2027, 3, 19, 9, 0, 0), ReminderTask.NextBirthday(19, 3, Today));
|
|
|
|
|
|
Assert.Equal(new DateTime(2026, 11, 29, 9, 0, 0), ReminderTask.NextBirthday(29, 11, Today)); // today counts
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void Leap_day_birthday_falls_back_to_28th()
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.Equal(new DateTime(2027, 2, 28, 9, 0, 0), ReminderTask.NextBirthday(29, 2, Today));
|
|
|
|
|
|
Assert.Equal(new DateTime(2028, 2, 29, 9, 0, 0), ReminderTask.NextBirthday(29, 2, new DateTime(2027, 3, 1)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void Migration_marks_yearly_tasks_in_birthday_folders_once()
|
|
|
|
|
|
{
|
|
|
|
|
|
var data = new AppData();
|
|
|
|
|
|
var bday = new Folder("Geburtstage");
|
|
|
|
|
|
bday.Tasks.Add(new ReminderTask("Oma", "", new DateTime(2027, 1, 27)) { IsRecurring = true, RecurrenceType = RecurrenceType.Yearly });
|
|
|
|
|
|
bday.Tasks.Add(new ReminderTask("Einmalig", "", new DateTime(2027, 1, 27)));
|
|
|
|
|
|
var work = new Folder("Arbeit");
|
|
|
|
|
|
work.Tasks.Add(new ReminderTask("Jahresbericht", "", new DateTime(2027, 1, 27)) { IsRecurring = true, RecurrenceType = RecurrenceType.Yearly });
|
|
|
|
|
|
data.Folders.Add(bday);
|
|
|
|
|
|
data.Folders.Add(work);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(1, data.MigrateBirthdays());
|
2026-11-29 15:06:19 +01:00
|
|
|
|
Assert.True(bday.Tasks[0].IsAnniversary);
|
|
|
|
|
|
Assert.False(bday.Tasks[1].IsAnniversary);
|
|
|
|
|
|
Assert.False(work.Tasks[0].IsAnniversary);
|
2026-11-29 14:42:16 +01:00
|
|
|
|
Assert.Equal(0, data.MigrateBirthdays());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void Birthday_display_has_no_time()
|
|
|
|
|
|
{
|
|
|
|
|
|
ReminderTask.DisplayCulture = () => new System.Globalization.CultureInfo("de-DE");
|
2026-11-29 15:06:19 +01:00
|
|
|
|
var t = new ReminderTask("x", "", new DateTime(2027, 3, 19, 9, 0, 0)) { IsAnniversary = true };
|
2026-11-29 14:42:16 +01:00
|
|
|
|
Assert.Equal("19. März", t.DisplayDate);
|
|
|
|
|
|
Assert.Equal("MÄR", t.MonthText);
|
2026-11-29 15:06:19 +01:00
|
|
|
|
t.IsAnniversary = false;
|
2026-11-29 14:42:16 +01:00
|
|
|
|
Assert.Equal("19.03.2027 09:00", t.DisplayDate);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void Ics_birthday_is_all_day()
|
|
|
|
|
|
{
|
|
|
|
|
|
var data = new AppData();
|
|
|
|
|
|
var f = new Folder("Geburtstage");
|
|
|
|
|
|
f.Tasks.Add(new ReminderTask("Oma", "", new DateTime(2027, 1, 27, 9, 0, 0))
|
2026-11-29 15:06:19 +01:00
|
|
|
|
{ IsAnniversary = true, IsRecurring = true, RecurrenceType = RecurrenceType.Yearly, LeadDays = 1 });
|
2026-11-29 14:42:16 +01:00
|
|
|
|
data.Folders.Add(f);
|
|
|
|
|
|
var ics = IcsExport.Build(data, DateTime.UtcNow);
|
|
|
|
|
|
Assert.Contains("DTSTART;VALUE=DATE:20270127", ics);
|
|
|
|
|
|
Assert.DoesNotContain("DURATION", ics);
|
|
|
|
|
|
Assert.Contains("TRIGGER:-P0DT15H", ics); // 09:00 the day before
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|