From 252cf3898ec4f038c7dfc5415c24fc8134a86c03 Mon Sep 17 00:00:00 2001 From: natekford Date: Wed, 24 Jan 2024 23:42:18 -0800 Subject: [PATCH] more test changes for github actions. --- src/SongProcessor.UI/UIUtils.cs | 4 +++- src/SongProcessor/Utils/ProcessUtils.cs | 8 +++++++- .../Models/AnimeComparer_Tests.cs | 3 ++- .../SongProcessor.Tests/Utils/FileUtils_Tests.cs | 15 ++++----------- .../Utils/ProcessUtils_Tests.cs | 4 ++-- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/SongProcessor.UI/UIUtils.cs b/src/SongProcessor.UI/UIUtils.cs index 156664d..34cc3ca 100644 --- a/src/SongProcessor.UI/UIUtils.cs +++ b/src/SongProcessor.UI/UIUtils.cs @@ -26,7 +26,9 @@ public static async Task ConfirmAsync( this IMessageBoxManager manager, string? directory) { - directory = Directory.Exists(directory) ? directory! : Environment.CurrentDirectory; + directory = Directory.Exists(directory) + ? directory! + : Directory.GetCurrentDirectory(); return manager.GetDirectoryAsync(directory, "Directory"); } diff --git a/src/SongProcessor/Utils/ProcessUtils.cs b/src/SongProcessor/Utils/ProcessUtils.cs index fc55e66..5f2d1cf 100644 --- a/src/SongProcessor/Utils/ProcessUtils.cs +++ b/src/SongProcessor/Utils/ProcessUtils.cs @@ -25,8 +25,11 @@ public static class ProcessUtils { private static readonly IReadOnlyList SpecialFolders = GetValues(); + public static Program FFmpeg { get; } = FindProgram("ffmpeg"); public static Program FFprobe { get; } = FindProgram("ffprobe"); + public static string Root { get; } + = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()); public static Process CreateProcess(string program, string args) { @@ -48,7 +51,7 @@ public static Process CreateProcess(string program, string args) public static Program FindProgram(string program) { - program = OperatingSystem.IsWindows() ? $"{program}.exe" : program; + program = GetProgramName(program); //Look through every directory and any subfolders they have called bin foreach (var dir in GetDirectories(program)) { @@ -64,6 +67,9 @@ public static Program FindProgram(string program) throw new InvalidOperationException($"Unable to find {program}."); } + public static string GetProgramName(string program) + => OperatingSystem.IsWindows() ? $"{program}.exe" : program; + public static Process OnCancel( this Process process, EventHandler callback, diff --git a/tests/SongProcessor.Tests/Models/AnimeComparer_Tests.cs b/tests/SongProcessor.Tests/Models/AnimeComparer_Tests.cs index ecb63e9..150b635 100644 --- a/tests/SongProcessor.Tests/Models/AnimeComparer_Tests.cs +++ b/tests/SongProcessor.Tests/Models/AnimeComparer_Tests.cs @@ -3,13 +3,14 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using SongProcessor.Models; +using SongProcessor.Utils; namespace SongProcessor.Tests.Models; [TestClass] public sealed class AnimeComparer_Tests { - private static Anime Anime { get; } = new Anime(@"C:\anime.amq", new AnimeBase + private static Anime Anime { get; } = new Anime(Path.Combine(ProcessUtils.Root, "anime.amq"), new AnimeBase { Id = 73, Name = "Anime", diff --git a/tests/SongProcessor.Tests/Utils/FileUtils_Tests.cs b/tests/SongProcessor.Tests/Utils/FileUtils_Tests.cs index ef4aae0..1f25bd6 100644 --- a/tests/SongProcessor.Tests/Utils/FileUtils_Tests.cs +++ b/tests/SongProcessor.Tests/Utils/FileUtils_Tests.cs @@ -9,15 +9,8 @@ namespace SongProcessor.Tests.Utils; [TestClass] public sealed class FileUtils_Tests { - public static string Dir { get; } + public static string Dir { get; } = Path.Combine(ProcessUtils.Root, "joe", "mama"); public static string Name { get; } = "dn.txt"; - public static string Root { get; } - - static FileUtils_Tests() - { - Root = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()); - Dir = Path.Combine(Root, "joe", "mama"); - } [TestMethod] public void EnsureAbsolutePathNotQualified_Test() @@ -28,19 +21,19 @@ public void EnsureAbsolutePathNotQualified_Test() [TestMethod] public void EnsureAbsolutePathPathNull_Test() - => FileUtils.EnsureAbsoluteFile(Root, null).Should().BeNull(); + => FileUtils.EnsureAbsoluteFile(ProcessUtils.Root, null).Should().BeNull(); [TestMethod] public void EnsureAbsolutePathQualified_Test() { - var path = Path.Combine(Root, Name); + var path = Path.Combine(ProcessUtils.Root, Name); FileUtils.EnsureAbsoluteFile(Dir, path).Should().Be(path); } [TestMethod] public void GetRelativeOrAbsolutePathAbsolute_Test() { - var path = Path.Combine(Root, Name); + var path = Path.Combine(ProcessUtils.Root, Name); FileUtils.GetRelativeOrAbsoluteFile(Dir, path).Should().Be(path); } diff --git a/tests/SongProcessor.Tests/Utils/ProcessUtils_Tests.cs b/tests/SongProcessor.Tests/Utils/ProcessUtils_Tests.cs index 68d33cc..7718851 100644 --- a/tests/SongProcessor.Tests/Utils/ProcessUtils_Tests.cs +++ b/tests/SongProcessor.Tests/Utils/ProcessUtils_Tests.cs @@ -20,9 +20,9 @@ public void FindProgram_Test() public void FindProgramBin_Test() { const string PROGRAM = "joemama"; - var dir = Path.Combine(Environment.CurrentDirectory, "bin"); + var dir = Path.Combine(Directory.GetCurrentDirectory(), "bin"); Directory.CreateDirectory(dir); - var path = Path.Combine(dir, $"{PROGRAM}.exe"); + var path = Path.Combine(dir, ProcessUtils.GetProgramName(PROGRAM)); File.Create(path).Dispose(); _ = ProcessUtils.FindProgram(PROGRAM);