|
| 1 | +namespace RipSharp.Tests.Core; |
| 2 | + |
| 3 | +public class PrerequisiteCheckerTests |
| 4 | +{ |
| 5 | + [Fact] |
| 6 | + public void GetMissingTools_WhenPathIsEmpty_ReturnsAllRequiredTools() |
| 7 | + { |
| 8 | + var missing = PrerequisiteChecker.GetMissingTools(null, isWindows: false, _ => false); |
| 9 | + |
| 10 | + missing.Should().Contain(PrerequisiteChecker.RequiredTools); |
| 11 | + } |
| 12 | + |
| 13 | + [Theory] |
| 14 | + [MemberData(nameof(NonWindowsAllPresentCases))] |
| 15 | + public void GetMissingTools_WhenNonWindowsPathsContainTools_ReturnsNoneMissing(string pathValue, string[] existingFiles) |
| 16 | + { |
| 17 | + var missing = PrerequisiteChecker.GetMissingTools(pathValue, isWindows: false, CreateSet(existingFiles).Contains); |
| 18 | + |
| 19 | + missing.Should().BeEmpty(); |
| 20 | + } |
| 21 | + |
| 22 | + [Theory] |
| 23 | + [MemberData(nameof(NonWindowsMissingCases))] |
| 24 | + public void GetMissingTools_WhenNonWindowsMissingTool_ReturnsMissingTool(string pathValue, string[] existingFiles, string expectedMissing) |
| 25 | + { |
| 26 | + var missing = PrerequisiteChecker.GetMissingTools(pathValue, isWindows: false, CreateSet(existingFiles).Contains); |
| 27 | + |
| 28 | + missing.Should().ContainSingle().Which.Should().Be(expectedMissing); |
| 29 | + } |
| 30 | + |
| 31 | + [Theory] |
| 32 | + [MemberData(nameof(WindowsAllPresentCases))] |
| 33 | + public void GetMissingTools_WhenWindowsPathsContainExecutableExtensions_ReturnsNoneMissing(string pathValue, string[] existingFiles) |
| 34 | + { |
| 35 | + var missing = PrerequisiteChecker.GetMissingTools(pathValue, isWindows: true, CreateSet(existingFiles).Contains); |
| 36 | + |
| 37 | + missing.Should().BeEmpty(); |
| 38 | + } |
| 39 | + |
| 40 | + [Theory] |
| 41 | + [MemberData(nameof(WindowsMissingCases))] |
| 42 | + public void GetMissingTools_WhenWindowsMissingTool_ReturnsMissingTool(string pathValue, string[] existingFiles, string expectedMissing) |
| 43 | + { |
| 44 | + var missing = PrerequisiteChecker.GetMissingTools(pathValue, isWindows: true, CreateSet(existingFiles).Contains); |
| 45 | + |
| 46 | + missing.Should().ContainSingle().Which.Should().Be(expectedMissing); |
| 47 | + } |
| 48 | + |
| 49 | + public static IEnumerable<object[]> NonWindowsAllPresentCases() |
| 50 | + { |
| 51 | + yield return new object[] |
| 52 | + { |
| 53 | + BuildPath("/usr/local/bin", "/usr/bin"), |
| 54 | + new[] { Path.Combine("/usr/bin", "makemkvcon"), Path.Combine("/usr/local/bin", "ffmpeg") } |
| 55 | + }; |
| 56 | + |
| 57 | + yield return new object[] |
| 58 | + { |
| 59 | + BuildPath("/usr/bin", "/opt/bin"), |
| 60 | + new[] { Path.Combine("/usr/bin", "makemkvcon"), Path.Combine("/opt/bin", "ffmpeg") } |
| 61 | + }; |
| 62 | + |
| 63 | + yield return new object[] |
| 64 | + { |
| 65 | + BuildPath("/opt/homebrew/bin", "/usr/local/bin"), |
| 66 | + new[] { Path.Combine("/opt/homebrew/bin", "ffmpeg"), Path.Combine("/usr/local/bin", "makemkvcon") } |
| 67 | + }; |
| 68 | + } |
| 69 | + |
| 70 | + public static IEnumerable<object[]> NonWindowsMissingCases() |
| 71 | + { |
| 72 | + yield return new object[] |
| 73 | + { |
| 74 | + BuildPath("/usr/bin", "/opt/bin"), |
| 75 | + new[] { Path.Combine("/opt/bin", "ffmpeg") }, |
| 76 | + "makemkvcon" |
| 77 | + }; |
| 78 | + |
| 79 | + yield return new object[] |
| 80 | + { |
| 81 | + BuildPath("/usr/bin", "/opt/bin"), |
| 82 | + new[] { Path.Combine("/usr/bin", "makemkvcon") }, |
| 83 | + "ffmpeg" |
| 84 | + }; |
| 85 | + |
| 86 | + yield return new object[] |
| 87 | + { |
| 88 | + BuildPath("/opt/homebrew/bin", "/usr/local/bin"), |
| 89 | + new[] { Path.Combine("/opt/homebrew/bin", "ffmpeg") }, |
| 90 | + "makemkvcon" |
| 91 | + }; |
| 92 | + } |
| 93 | + |
| 94 | + public static IEnumerable<object[]> WindowsAllPresentCases() |
| 95 | + { |
| 96 | + var baseDir = Path.Combine("C_Tools"); |
| 97 | + yield return new object[] |
| 98 | + { |
| 99 | + BuildPath(baseDir), |
| 100 | + new[] { Path.Combine(baseDir, "makemkvcon.exe"), Path.Combine(baseDir, "ffmpeg.cmd") } |
| 101 | + }; |
| 102 | + } |
| 103 | + |
| 104 | + public static IEnumerable<object[]> WindowsMissingCases() |
| 105 | + { |
| 106 | + var baseDir = Path.Combine("C_Tools"); |
| 107 | + yield return new object[] |
| 108 | + { |
| 109 | + BuildPath(baseDir), |
| 110 | + new[] { Path.Combine(baseDir, "makemkvcon.exe") }, |
| 111 | + "ffmpeg" |
| 112 | + }; |
| 113 | + |
| 114 | + yield return new object[] |
| 115 | + { |
| 116 | + BuildPath(baseDir), |
| 117 | + new[] { Path.Combine(baseDir, "ffmpeg.exe") }, |
| 118 | + "makemkvcon" |
| 119 | + }; |
| 120 | + } |
| 121 | + |
| 122 | + private static string BuildPath(params string[] parts) |
| 123 | + { |
| 124 | + return string.Join(Path.PathSeparator, parts); |
| 125 | + } |
| 126 | + |
| 127 | + private static HashSet<string> CreateSet(IEnumerable<string> paths) |
| 128 | + { |
| 129 | + return new HashSet<string>(paths, StringComparer.OrdinalIgnoreCase); |
| 130 | + } |
| 131 | +} |
0 commit comments