Skip to content

Commit

Permalink
more test changes for github actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
natekford committed Jan 25, 2024
1 parent 8686b30 commit 252cf38
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/SongProcessor.UI/UIUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public static async Task<bool> 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");
}

Expand Down
8 changes: 7 additions & 1 deletion src/SongProcessor/Utils/ProcessUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public static class ProcessUtils
{
private static readonly IReadOnlyList<Environment.SpecialFolder> SpecialFolders
= GetValues<Environment.SpecialFolder>();

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)
{
Expand All @@ -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))
{
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion tests/SongProcessor.Tests/Models/AnimeComparer_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 4 additions & 11 deletions tests/SongProcessor.Tests/Utils/FileUtils_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/SongProcessor.Tests/Utils/ProcessUtils_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 252cf38

Please sign in to comment.