using System; using System.Collections.Generic; using System.IO; using Paca.Mobile.Core; using Xunit; namespace Paca.Tests.Core; /// /// Gate 211 ~ 214: 스마트 중복 다운로드 방지 및 파일명 충돌 해소 엔진 기계적 검증 /// public class SmartDeduplicationAndCollisionGateTests { [Fact] public void Gate211_Deduplication_Identifies_Same_Video_Id() { var existingLibrary = new List { new("dQw4w9WgXcQ", "Rick Astley - Never Gonna Give You Up.mp4", "/media/rick.mp4", 50_000_000) }; var engine = new MediaDeduplicationEngine(existingLibrary); // 다른 URL 형식이지만 동일한 YouTube 비디오 ID var result = engine.CheckDuplicate("https://youtu.be/dQw4w9WgXcQ?si=trackingToken"); Assert.True(result.IsDuplicate); Assert.Equal("Rick Astley - Never Gonna Give You Up.mp4", result.ExistingFileName); Assert.True(result.CanReuseExisting); } [Fact] public void Gate212_Deduplication_Allows_New_Video() { var existingLibrary = new List { new("dQw4w9WgXcQ", "Rick.mp4", "/media/rick.mp4", 50_000_000) }; var engine = new MediaDeduplicationEngine(existingLibrary); var result = engine.CheckDuplicate("https://www.youtube.com/watch?v=newVideoId999"); Assert.False(result.IsDuplicate); Assert.Null(result.ExistingFileName); } [Fact] public void Gate213_CollisionResolver_Generates_Numbered_Suffix() { var tempDir = Path.Combine(Path.GetTempPath(), "Paca_Collision_Test_" + Guid.NewGuid().ToString("N")); Directory.CreateDirectory(tempDir); try { // 원본 파일 생성 var originalPath = Path.Combine(tempDir, "Nature_4K.mp4"); File.WriteAllText(originalPath, "original"); // 1차 충돌 시 -> Nature_4K (1).mp4 var safePath1 = FileCollisionResolver.ResolveSafePath(tempDir, "Nature_4K.mp4"); Assert.Equal(Path.Combine(tempDir, "Nature_4K (1).mp4"), safePath1); // Nature_4K (1).mp4도 생성해둠 File.WriteAllText(safePath1, "existing (1)"); // 2차 충돌 시 -> Nature_4K (2).mp4 var safePath2 = FileCollisionResolver.ResolveSafePath(tempDir, "Nature_4K.mp4"); Assert.Equal(Path.Combine(tempDir, "Nature_4K (2).mp4"), safePath2); } finally { if (Directory.Exists(tempDir)) Directory.Delete(tempDir, recursive: true); } } [Fact] public void Gate214_CollisionResolver_Preserves_When_No_Conflict() { var tempDir = Path.Combine(Path.GetTempPath(), "Paca_NoCollision_" + Guid.NewGuid().ToString("N")); Directory.CreateDirectory(tempDir); try { var safePath = FileCollisionResolver.ResolveSafePath(tempDir, "FreshVideo.mp4"); Assert.Equal(Path.Combine(tempDir, "FreshVideo.mp4"), safePath); } finally { if (Directory.Exists(tempDir)) Directory.Delete(tempDir, recursive: true); } } }