using Xunit; using ytLive.Services; namespace ytLive.Tests; /// /// Local recording filename rules (TASK 18): /// ty-<yyyyMMdd>-<HHmm start>-<fff>-<hh2mm2 length>.mp4. /// Recordings start with a 0000 length placeholder and are renamed on stop. /// public class RecordingFileTests { /// Two instances started in the same minute must not compute the same /// path, or both ffmpeg processes write one file and the take is lost. The /// millisecond segment is what separates them (dev multi-instance, recording /// one instance with the other). [Fact] public void TwoStartsInTheSameMinute_ProduceDifferentNames() { var first = new DateTime(2026, 9, 27, 14, 54, 0, 123); var second = new DateTime(2026, 9, 27, 14, 54, 0, 456); Assert.NotEqual(RecordingFile.BuildStartName(first), RecordingFile.BuildStartName(second)); } /// The ms segment must also survive the rename-on-stop, or the final /// name could collide with a different take started in the same minute. [Fact] public void MillisecondsSurviveTheRenameOnStop() { var start = new DateTime(2026, 9, 27, 14, 54, 0, 123); var name = RecordingFile.BuildFinalName(start, TimeSpan.FromMinutes(5)); Assert.Equal("ty-20260927-1454-123-0005", name); } [Fact] public void BuildStartName_UsesDateHourAndMinute_WithZeroLength() { var start = new DateTime(2026, 8, 29, 14, 5, 0); Assert.Equal("ty-20260829-1405-000-0000", RecordingFile.BuildStartName(start)); } [Fact] public void BuildStartName_PadsSingleDigitHourAndMinute() { var start = new DateTime(2026, 1, 2, 9, 7, 0); Assert.Equal("ty-20260102-0907-000-0000", RecordingFile.BuildStartName(start)); } [Fact] public void BuildFinalName_ShortRecording_IsHhmmOfLength() { var start = new DateTime(2026, 8, 29, 14, 5, 0); var length = TimeSpan.FromMinutes(2); Assert.Equal("ty-20260829-1405-000-0002", RecordingFile.BuildFinalName(start, length)); } [Fact] public void BuildFinalName_HourAndMinutes_ConcatenatesHh2Mm2() { var start = new DateTime(2026, 8, 29, 14, 5, 0); var length = new TimeSpan(1, 15, 0); // 1h 15m Assert.Equal("ty-20260829-1405-000-0115", RecordingFile.BuildFinalName(start, length)); } [Fact] public void BuildFinalName_OverFlowHours_ShowsTotalHours() { var start = new DateTime(2026, 8, 29, 14, 5, 0); var length = new TimeSpan(12, 30, 0); // 12h 30m Assert.Equal("ty-20260829-1405-000-1230", RecordingFile.BuildFinalName(start, length)); } }