From 9344af62cd0e92c40acef0e5ec8b7c9b570b689d Mon Sep 17 00:00:00 2001 From: "Dylan R. E. Moonfire" Date: Tue, 7 Dec 2021 17:34:02 -0600 Subject: [PATCH] test: simplifying failure tests --- .../MfGames.ToolBuilder.Tests.csproj | 1 + .../SampleToolTests.cs | 40 +++++++------------ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/tests/MfGames.ToolBuilder.Tests/MfGames.ToolBuilder.Tests.csproj b/tests/MfGames.ToolBuilder.Tests/MfGames.ToolBuilder.Tests.csproj index 2cd09ed..3e77c78 100644 --- a/tests/MfGames.ToolBuilder.Tests/MfGames.ToolBuilder.Tests.csproj +++ b/tests/MfGames.ToolBuilder.Tests/MfGames.ToolBuilder.Tests.csproj @@ -12,6 +12,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/tests/MfGames.ToolBuilder.Tests/SampleToolTests.cs b/tests/MfGames.ToolBuilder.Tests/SampleToolTests.cs index 1a87832..8850897 100644 --- a/tests/MfGames.ToolBuilder.Tests/SampleToolTests.cs +++ b/tests/MfGames.ToolBuilder.Tests/SampleToolTests.cs @@ -7,6 +7,8 @@ using System.Threading.Tasks; using CliWrap; using CliWrap.Exceptions; +using MfGames.IO.Extensions; + using Xunit; namespace MfGames.ToolBuilder.Tests @@ -21,7 +23,7 @@ namespace MfGames.ToolBuilder.Tests public void CrashCommandFails() { // Run the executable using CliWrap. - FileInfo projectFile = GetProjectFile(); + FileInfo projectFile = this.GetProjectFile(); StringBuilder output = new(); CancellationToken cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(20)) @@ -46,15 +48,15 @@ namespace MfGames.ToolBuilder.Tests Assert.NotNull(exception); } - [Fact(Skip = "Not working in CI for some reason")] + [Fact] public async Task TableCommandWorks() { // Run the executable using CliWrap. - FileInfo projectFile = GetProjectFile(); + FileInfo projectFile = this.GetProjectFile(); StringBuilder output = new(); - CancellationToken cancellationToken = - new CancellationTokenSource(TimeSpan.FromSeconds(20)) - .Token; + var delay = TimeSpan.FromMinutes(1); + CancellationTokenSource cancellationTokenSource = new(delay); + CancellationToken cancellationToken = cancellationTokenSource.Token; CommandResult result = await Cli.Wrap("dotnet") .WithArguments( @@ -87,27 +89,13 @@ namespace MfGames.ToolBuilder.Tests /// /// Gets the file object representing the sample tool's project. /// - private static FileInfo GetProjectFile() + private FileInfo GetProjectFile() { - // Loop up until we find the directory that contains it. - var parent = new DirectoryInfo(Environment.CurrentDirectory); - - while (parent?.GetDirectories("SampleTool").Length == 0) - { - parent = parent.Parent; - } - - // If we got a null, we can't find it. - if (parent == null) - { - throw new DirectoryNotFoundException( - "Cannot find sample tool directory from " - + Environment.CurrentDirectory); - } - - // Get the project file inside there. - DirectoryInfo directory = parent.GetDirectories("SampleTool")[0]; - FileInfo file = directory.GetFiles("SampleTool.csproj")[0]; + FileInfo file = this + .GetType() + .GetDirectory() + .FindGitRoot() + !.GetFile("tests", "SampleTool", "SampleTool.csproj"); return file; }