using System; using System.IO; using LDUninstaller.Core.Services; using Xunit; namespace LDUninstaller.Tests { public class FileUnlockerServiceTests { [Fact] public void ResolveTarget_StandardDirectory_ReturnsDirectly() { string testDir = Path.GetTempPath().TrimEnd('\\'); var (folder, file, lnk) = FileUnlockerService.ResolveTarget(testDir); Assert.Equal(testDir, folder, ignoreCase: true); Assert.Null(file); Assert.Null(lnk); } [Fact] public void UnlockAndDestroy_DangerousWindowsDirectory_BlockedBySafetyGuard() { string winDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows); var result = FileUnlockerService.UnlockAndDestroy(winDir); Assert.False(result.Success); Assert.NotEmpty(result.ErrorMessages); Assert.Contains("GÜVENLİK ENGELİ", result.ErrorMessages[0]); } [Fact] public void InspectLocks_NonExistentPath_ReturnsEmptyWithoutThrowing() { string fakePath = Path.Combine(Path.GetTempPath(), "NonExistentDir_" + Guid.NewGuid()); var locks = FileUnlockerService.InspectLocks(fakePath); Assert.NotNull(locks); Assert.Empty(locks); } [Fact] public void UnlockAndDestroy_SafeTempDirectory_SuccessfullyDestroys() { string tempFolder = Path.Combine(Path.GetTempPath(), "LDUnlockerTest_" + Guid.NewGuid().ToString("N")); Directory.CreateDirectory(tempFolder); string testFile = Path.Combine(tempFolder, "locked_mock.txt"); File.WriteAllText(testFile, "test data for unlocker"); try { Assert.True(Directory.Exists(tempFolder)); var result = FileUnlockerService.UnlockAndDestroy(tempFolder, sendToRecycleBin: false); Assert.True(result.Success); Assert.False(Directory.Exists(tempFolder)); } finally { if (Directory.Exists(tempFolder)) { try { Directory.Delete(tempFolder, true); } catch { } } } } } }