From 629b3d7d9f0d024a67e0837018727fb69128cfbe Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Wed, 5 Nov 2025 06:48:49 -0600 Subject: [PATCH] fix effective block tests (#2600) * fix effective block tests running on github * update dependencies * pass tz again * use tzconvert for time zones in tests * temporary logging * maybe fix * test cleanup --- .../ErsatzTV.Application.csproj | 2 +- .../BlockScheduling/EffectiveBlockTests.cs | 31 ++++++++++--------- ErsatzTV.Core/ErsatzTV.Core.csproj | 4 +-- .../BlockScheduling/BlockPlayoutBuilder.cs | 7 +++-- .../BlockScheduling/EffectiveBlock.cs | 19 +++++++----- .../ErsatzTV.Infrastructure.Tests.csproj | 2 +- .../ErsatzTV.Infrastructure.csproj | 6 ++-- .../ErsatzTV.Scanner.Tests.csproj | 2 +- ErsatzTV.Scanner/ErsatzTV.Scanner.csproj | 2 +- ErsatzTV/ErsatzTV.csproj | 6 ++-- 10 files changed, 45 insertions(+), 36 deletions(-) diff --git a/ErsatzTV.Application/ErsatzTV.Application.csproj b/ErsatzTV.Application/ErsatzTV.Application.csproj index ebb13c86d..270790807 100644 --- a/ErsatzTV.Application/ErsatzTV.Application.csproj +++ b/ErsatzTV.Application/ErsatzTV.Application.csproj @@ -22,7 +22,7 @@ - + diff --git a/ErsatzTV.Core.Tests/Scheduling/BlockScheduling/EffectiveBlockTests.cs b/ErsatzTV.Core.Tests/Scheduling/BlockScheduling/EffectiveBlockTests.cs index 59e872d8a..6c4762c5a 100644 --- a/ErsatzTV.Core.Tests/Scheduling/BlockScheduling/EffectiveBlockTests.cs +++ b/ErsatzTV.Core.Tests/Scheduling/BlockScheduling/EffectiveBlockTests.cs @@ -2,13 +2,14 @@ using ErsatzTV.Core.Domain.Scheduling; using ErsatzTV.Core.Scheduling.BlockScheduling; using NUnit.Framework; using Shouldly; +using TimeZoneConverter; namespace ErsatzTV.Core.Tests.Scheduling.BlockScheduling; -public static class EffectiveBlockTests +public class EffectiveBlockTests { - private static DateTimeOffset GetLocalDate(int year, int month, int day) => - new(year, month, day, 0, 0, 0, TimeSpan.FromHours(-6)); + private static DateTimeOffset GetLocalDate(int year, int month, int day, TimeZoneInfo tz) => + new(year, month, day, 0, 0, 0, tz.GetUtcOffset(new DateTime(year, month, day))); private static Template SingleBlockTemplate(DateTimeOffset dateUpdated) { @@ -60,9 +61,10 @@ public static class EffectiveBlockTests } ]; - DateTimeOffset start = GetLocalDate(2024, 1, 15).AddHours(9); + TimeZoneInfo tz = TimeZoneInfo.Local; + DateTimeOffset start = GetLocalDate(2024, 1, 15, tz).AddHours(9); - List result = EffectiveBlock.GetEffectiveBlocks(templates, start, 5); + List result = EffectiveBlock.GetEffectiveBlocks(templates, start, tz, 5); result.Count.ShouldBe(0); } @@ -85,20 +87,21 @@ public static class EffectiveBlockTests } ]; - DateTimeOffset start = GetLocalDate(2024, 1, 15).AddHours(9); + TimeZoneInfo tz = TimeZoneInfo.Local; + DateTimeOffset start = GetLocalDate(2024, 1, 15, tz).AddHours(9); - List result = EffectiveBlock.GetEffectiveBlocks(templates, start, 5); + List result = EffectiveBlock.GetEffectiveBlocks(templates, start, tz, 5); result.Count.ShouldBe(3); result[0].Start.DayOfWeek.ShouldBe(DayOfWeek.Monday); - result[0].Start.Date.ShouldBe(GetLocalDate(2024, 1, 15).Date); + result[0].Start.Date.ShouldBe(GetLocalDate(2024, 1, 15, tz).Date); result[1].Start.DayOfWeek.ShouldBe(DayOfWeek.Wednesday); - result[1].Start.Date.ShouldBe(GetLocalDate(2024, 1, 17).Date); + result[1].Start.Date.ShouldBe(GetLocalDate(2024, 1, 17, tz).Date); result[2].Start.DayOfWeek.ShouldBe(DayOfWeek.Friday); - result[2].Start.Date.ShouldBe(GetLocalDate(2024, 1, 19).Date); + result[2].Start.Date.ShouldBe(GetLocalDate(2024, 1, 19, tz).Date); } [Test] @@ -121,11 +124,11 @@ public static class EffectiveBlockTests // In 2024, DST starts on March 10 for America/Chicago // For Windows, this would be "Central Standard Time" - var tz = TimeZoneInfo.FindSystemTimeZoneById("America/Chicago"); + var tz = TZConvert.GetTimeZoneInfo("America/Chicago"); var start = new DateTime(2024, 3, 9, 0, 0, 0, DateTimeKind.Unspecified); var dto = new DateTimeOffset(start, tz.GetUtcOffset(start)); - List result = EffectiveBlock.GetEffectiveBlocks(templates, dto, 5); + List result = EffectiveBlock.GetEffectiveBlocks(templates, dto, tz, 5); result.Count.ShouldBe(5); @@ -160,11 +163,11 @@ public static class EffectiveBlockTests // In 2024, DST ends on Nov 3 for America/Chicago // For Windows, this would be "Central Standard Time" - var tz = TimeZoneInfo.FindSystemTimeZoneById("America/Chicago"); + var tz = TZConvert.GetTimeZoneInfo("America/Chicago"); var start = new DateTime(2024, 11, 2, 0, 0, 0, DateTimeKind.Unspecified); var dto = new DateTimeOffset(start, tz.GetUtcOffset(start)); - List result = EffectiveBlock.GetEffectiveBlocks(templates, dto, 5); + List result = EffectiveBlock.GetEffectiveBlocks(templates, dto, tz, 5); result.Count.ShouldBe(5); diff --git a/ErsatzTV.Core/ErsatzTV.Core.csproj b/ErsatzTV.Core/ErsatzTV.Core.csproj index 01f2ecc23..14d26a497 100644 --- a/ErsatzTV.Core/ErsatzTV.Core.csproj +++ b/ErsatzTV.Core/ErsatzTV.Core.csproj @@ -25,10 +25,10 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs b/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs index 2076ed696..8e3a57146 100644 --- a/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs +++ b/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs @@ -54,8 +54,11 @@ public class BlockPlayoutBuilder( int daysToBuild = await GetDaysToBuild(cancellationToken); // get blocks to schedule - List blocksToSchedule = - EffectiveBlock.GetEffectiveBlocks(referenceData.PlayoutTemplates, start, daysToBuild); + List blocksToSchedule = EffectiveBlock.GetEffectiveBlocks( + referenceData.PlayoutTemplates, + start, + TimeZoneInfo.Local, + daysToBuild); if (blocksToSchedule.Count == 0) { diff --git a/ErsatzTV.Core/Scheduling/BlockScheduling/EffectiveBlock.cs b/ErsatzTV.Core/Scheduling/BlockScheduling/EffectiveBlock.cs index 9a4d3b29f..022fb97d0 100644 --- a/ErsatzTV.Core/Scheduling/BlockScheduling/EffectiveBlock.cs +++ b/ErsatzTV.Core/Scheduling/BlockScheduling/EffectiveBlock.cs @@ -7,14 +7,13 @@ internal record EffectiveBlock(Block Block, BlockKey BlockKey, DateTimeOffset St public static List GetEffectiveBlocks( ICollection templates, DateTimeOffset start, + TimeZoneInfo timeZone, int daysToBuild) { - var timeZone = TimeZoneInfo.Local; - DateTimeOffset finish = start.AddDays(daysToBuild); var effectiveBlocks = new List(); - DateTimeOffset current = start.Date; + DateTimeOffset current = new DateTimeOffset(start.Year, start.Month, start.Day, 0, 0, 0, start.Offset); while (current < finish) { Option maybeTemplate = PlayoutTemplateSelector.GetPlayoutTemplateFor(templates, current); @@ -23,12 +22,12 @@ internal record EffectiveBlock(Block Block, BlockKey BlockKey, DateTimeOffset St // logger.LogDebug( // "Will schedule day {Date} using template {Template}", // current, - // playoutTemplate.Template.Name); + // playoutTemplate.Template.Id); DateTimeOffset today = current; var newBlocks = playoutTemplate.Template.Items - .Map(i => ToEffectiveBlock(playoutTemplate, i, today)) + .Map(i => ToEffectiveBlock(playoutTemplate, i, today, timeZone)) .Map(NormalizeGuideMode) .ToList(); @@ -48,7 +47,8 @@ internal record EffectiveBlock(Block Block, BlockKey BlockKey, DateTimeOffset St private static EffectiveBlock ToEffectiveBlock( PlayoutTemplate playoutTemplate, TemplateItem templateItem, - DateTimeOffset current) + DateTimeOffset current, + TimeZoneInfo timeZone) { var blockStartTime = new DateTime( current.Year, @@ -59,10 +59,13 @@ internal record EffectiveBlock(Block Block, BlockKey BlockKey, DateTimeOffset St 0, DateTimeKind.Unspecified); - // use the system's local time zone - var timeZone = TimeZoneInfo.Local; var blockStart = new DateTimeOffset(blockStartTime, timeZone.GetUtcOffset(blockStartTime)); + // logger.LogDebug( + // "Starting block {Block} at {BlockStart}", + // templateItem.Block.Name, + // blockStart); + return new EffectiveBlock( templateItem.Block, new BlockKey(templateItem.Block, templateItem.Template, playoutTemplate), diff --git a/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj b/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj index 06ffb0075..a96dfa840 100644 --- a/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj +++ b/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj @@ -13,7 +13,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj b/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj index 9a0e15d81..d3758473d 100644 --- a/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj +++ b/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj @@ -14,7 +14,7 @@ - + @@ -34,8 +34,8 @@ - - + + diff --git a/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj b/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj index 67c16b410..874f98463 100644 --- a/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj +++ b/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj @@ -14,7 +14,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/ErsatzTV.Scanner/ErsatzTV.Scanner.csproj b/ErsatzTV.Scanner/ErsatzTV.Scanner.csproj index 0becaa252..02921e056 100644 --- a/ErsatzTV.Scanner/ErsatzTV.Scanner.csproj +++ b/ErsatzTV.Scanner/ErsatzTV.Scanner.csproj @@ -31,7 +31,7 @@ - + diff --git a/ErsatzTV/ErsatzTV.csproj b/ErsatzTV/ErsatzTV.csproj index 1fa1884e2..e4670752c 100644 --- a/ErsatzTV/ErsatzTV.csproj +++ b/ErsatzTV/ErsatzTV.csproj @@ -30,9 +30,9 @@ - + - + @@ -57,7 +57,7 @@ - +