Browse Source

add more safety and a couple tests

pull/2935/head
Jason Dove 1 month ago
parent
commit
2daf89194b
No known key found for this signature in database
  1. 48
      ErsatzTV.Core.Tests/Scheduling/AlternateScheduleSelectorTests.cs
  2. 6
      ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs
  3. 6
      ErsatzTV.Core/Scheduling/YamlScheduling/Models/YamlPlayoutScheduleItem.cs

48
ErsatzTV.Core.Tests/Scheduling/AlternateScheduleSelectorTests.cs

@ -863,5 +863,53 @@ public static class AlternateScheduleSelectorTests
result.IsNone.ShouldBeFalse(); result.IsNone.ShouldBeFalse();
} }
[Test]
public void LimitToDateRange_13th_Month_Should_Not_Crash()
{
var template = new PlayoutTemplate
{
DaysOfWeek = AlternateScheduleSelector.AllDaysOfWeek(),
DaysOfMonth = AlternateScheduleSelector.AllDaysOfMonth(),
MonthsOfYear = AlternateScheduleSelector.AllMonthsOfYear(),
LimitToDateRange = true,
StartMonth = 13,
StartDay = 30,
StartYear = 2022,
EndMonth = 13,
EndDay = 30,
EndYear = 2023
};
Option<PlayoutTemplate> result = AlternateScheduleSelector.GetScheduleForDate(
new List<PlayoutTemplate> { template },
new DateTimeOffset(2023, 3, 1, 0, 0, 0, Offset));
result.IsNone.ShouldBeTrue();
}
[Test]
public void LimitToDateRange_0th_Day_Should_Not_Crash()
{
var template = new PlayoutTemplate
{
DaysOfWeek = AlternateScheduleSelector.AllDaysOfWeek(),
DaysOfMonth = AlternateScheduleSelector.AllDaysOfMonth(),
MonthsOfYear = AlternateScheduleSelector.AllMonthsOfYear(),
LimitToDateRange = true,
StartMonth = 12,
StartDay = 0,
StartYear = 2022,
EndMonth = 12,
EndDay = 0,
EndYear = 2023
};
Option<PlayoutTemplate> result = AlternateScheduleSelector.GetScheduleForDate(
new List<PlayoutTemplate> { template },
new DateTimeOffset(2023, 3, 1, 0, 0, 0, Offset));
result.IsNone.ShouldBeTrue();
}
} }
} }

6
ErsatzTV.Core/Scheduling/AlternateScheduleSelector.cs

@ -26,6 +26,12 @@ public static class AlternateScheduleSelector
{ {
if (item.LimitToDateRange) if (item.LimitToDateRange)
{ {
if (item.StartMonth is < 1 or > 12 || item.EndMonth is < 1 or > 12 || item.StartDay < 1 ||
item.EndDay < 1)
{
continue;
}
bool reverse = item.StartMonth * 100 + item.StartDay > bool reverse = item.StartMonth * 100 + item.StartDay >
item.EndMonth * 100 + item.EndDay; item.EndMonth * 100 + item.EndDay;

6
ErsatzTV.Core/Scheduling/YamlScheduling/Models/YamlPlayoutScheduleItem.cs

@ -23,13 +23,13 @@ public class YamlPlayoutScheduleItem : IAlternateScheduleItem
// schedules are purely date-range based, so every day/month is eligible // schedules are purely date-range based, so every day/month is eligible
[YamlIgnore] [YamlIgnore]
public ICollection<DayOfWeek> DaysOfWeek => Enum.GetValues<DayOfWeek>(); public ICollection<DayOfWeek> DaysOfWeek => AlternateScheduleSelector.AllDaysOfWeek();
[YamlIgnore] [YamlIgnore]
public ICollection<int> DaysOfMonth => Enumerable.Range(1, 31).ToList(); public ICollection<int> DaysOfMonth => AlternateScheduleSelector.AllDaysOfMonth();
[YamlIgnore] [YamlIgnore]
public ICollection<int> MonthsOfYear => Enumerable.Range(1, 12).ToList(); public ICollection<int> MonthsOfYear => AlternateScheduleSelector.AllMonthsOfYear();
[YamlIgnore] [YamlIgnore]
public bool LimitToDateRange => true; public bool LimitToDateRange => true;

Loading…
Cancel
Save