using System; using System.IO; using Paca.Mobile.Core; using Paca.Tests.Infrastructure; using Xunit; namespace Paca.Tests.Core; /// /// Gate 179 ~ 182: 스마트 대역폭 스케줄러 & 야간 오프피크 자동 큐잉 엔진 기계적 검증 /// public class SmartBandwidthSchedulerGateTests { [Fact] public void Gate179_BandwidthSchedulePolicy_Immediate_AlwaysAllowed() { var policy = BandwidthSchedulePolicy.ImmediateUncapped; var now = new DateTimeOffset(2026, 9, 4, 14, 0, 0, TimeSpan.FromHours(9)); // 오후 2시 Assert.True(policy.IsDownloadAllowed(now)); Assert.Equal(0, policy.GetCurrentRateLimitBytesPerSec(now)); // 0 = 무제한 } [Fact] public void Gate180_BandwidthSchedulePolicy_NightOwl_TimeWindow() { // 01:00 ~ 06:00 야간 정책 var policy = new BandwidthSchedulePolicy( ScheduleMode.NightOwlOffPeak, StartHour: 1, EndHour: 6, ThrottledBytesPerSec: 0 ); // 오후 14:00 -> 다운로드 대기(false) var afternoon = new DateTimeOffset(2026, 9, 4, 14, 30, 0, TimeSpan.FromHours(9)); Assert.False(policy.IsDownloadAllowed(afternoon)); // 새벽 03:00 -> 다운로드 허용(true) var midnight = new DateTimeOffset(2026, 9, 4, 3, 0, 0, TimeSpan.FromHours(9)); Assert.True(policy.IsDownloadAllowed(midnight)); } [Fact] public void Gate181_BandwidthSchedulePolicy_BusinessHours_Throttling() { // 09:00 ~ 18:00 업무 시간 1MB/s 제한, 그 외 무제한 var policy = new BandwidthSchedulePolicy( ScheduleMode.BusinessHoursThrottled, StartHour: 9, EndHour: 18, ThrottledBytesPerSec: 1_048_576 // 1 MB/s ); // 오전 11:00 -> 스로틀 적용 (1MB/s) var workingTime = new DateTimeOffset(2026, 9, 4, 11, 0, 0, TimeSpan.FromHours(9)); Assert.True(policy.IsDownloadAllowed(workingTime)); Assert.Equal(1_048_576, policy.GetCurrentRateLimitBytesPerSec(workingTime)); // 밤 21:00 -> 무제한 (0) var evening = new DateTimeOffset(2026, 9, 4, 21, 0, 0, TimeSpan.FromHours(9)); Assert.True(policy.IsDownloadAllowed(evening)); Assert.Equal(0, policy.GetCurrentRateLimitBytesPerSec(evening)); } [Fact] public void Gate182_ServerHost_SchedulePolicy_Endpoint_Audit() { var serverHostPath = Path.Combine(SourceTree.Root, "src", "Paca.Server", "ServerHost.cs"); Assert.True(File.Exists(serverHostPath), "ServerHost.cs must exist"); var code = File.ReadAllText(serverHostPath); Assert.Contains("/api/config/schedule", code); } }