Skip to content

Commit

Permalink
chore: Refactor CLIRunner namespace and update integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devantler committed Aug 4, 2024
1 parent 30826ba commit 67579ab
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
72 changes: 36 additions & 36 deletions Devantler.CLIRunner.Tests/CLIRunnerTests/RunAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
namespace Devantler.CLIRunner.Tests.Integration;

/// <summary>
/// Integration tests for the <see cref="CLIRunner.RunAsync"/> method.
/// Integration tests for the <see cref="Runner.RunAsync"/> method.
/// </summary>
public class RunAsyncTests
{
/// <summary>
/// Tests that the <see cref="CLIRunner.RunAsync"/> method returns the expected exit code and stdout result
/// </summary>
/// <returns></returns>
[Fact]
/// <summary>
/// Tests that the <see cref="Runner.RunAsync"/> method returns the expected exit code and stdout result
/// </summary>
/// <returns></returns>
[Fact]
public async Task RunAsync_WithValidCommand_ReturnsZeroExitCodeAndStdout()
{
// Arrange
Expand All @@ -22,22 +22,22 @@ public async Task RunAsync_WithValidCommand_ReturnsZeroExitCodeAndStdout()
var validation = CommandResultValidation.ZeroExitCode;
bool silent = false;

// Act
var (exitCode, result) = await CLIRunner.RunAsync(command, cancellationToken, validation, silent).ConfigureAwait(false);
// Act
var (exitCode, result) = await Runner.RunAsync(command, cancellationToken, validation, silent);

// Assert
Assert.Equal(0, exitCode);
// Assert
Assert.Equal(0, exitCode);
Assert.Contains("Hello, World!", result, StringComparison.Ordinal);

// Cleanup
Environment.SetEnvironmentVariable("DEBUG", null);
}

/// <summary>
/// Tests that the <see cref="CLIRunner.RunAsync"/> method returns the expected exit code and stderr result
/// </summary>
/// <returns></returns>
[Fact]
/// <summary>
/// Tests that the <see cref="Runner.RunAsync"/> method returns the expected exit code and stderr result
/// </summary>
/// <returns></returns>
[Fact]
public async Task RunAsync_WithInvalidCommand_ReturnsOneExitCodeAndNoOutput()
{
// Arrange
Expand All @@ -47,19 +47,19 @@ public async Task RunAsync_WithInvalidCommand_ReturnsOneExitCodeAndNoOutput()
var validation = CommandResultValidation.ZeroExitCode;
bool silent = false;

// Act
var (exitCode, result) = await CLIRunner.RunAsync(command, cancellationToken, validation, silent).ConfigureAwait(false);
// Act
var (exitCode, result) = await Runner.RunAsync(command, cancellationToken, validation, silent);

// Assert
Assert.Equal(1, exitCode);
// Assert
Assert.Equal(1, exitCode);
Assert.True(string.IsNullOrEmpty(result));
}

/// <summary>
/// Tests that the <see cref="CLIRunner.RunAsync"/> method returns the expected exit code and stderr result
/// </summary>
/// <returns></returns>
[Fact]
/// <summary>
/// Tests that the <see cref="Runner.RunAsync"/> method returns the expected exit code and stderr result
/// </summary>
/// <returns></returns>
[Fact]
public async Task RunAsync_WithInvalidArgument_ReturnsOneExitCodeAndStderr()
{
// Arrange
Expand All @@ -69,18 +69,18 @@ public async Task RunAsync_WithInvalidArgument_ReturnsOneExitCodeAndStderr()
var cancellationToken = CancellationToken.None;
bool silent = false;

// Act
var (exitCode, result) = await CLIRunner.RunAsync(command, cancellationToken, CommandResultValidation.ZeroExitCode, silent).ConfigureAwait(false);
// Act
var (exitCode, result) = await Runner.RunAsync(command, cancellationToken, CommandResultValidation.ZeroExitCode, silent);

// Assert
Assert.Equal(1, exitCode);
// Assert
Assert.Equal(1, exitCode);
Assert.True(!string.IsNullOrEmpty(result));
}

/// <summary>
/// Tests that the <see cref="CLIRunner.RunAsync"/> method throws an <see cref="ArgumentNullException"/> when the command is null
/// </summary>
[Fact]
/// <summary>
/// Tests that the <see cref="Runner.RunAsync"/> method throws an <see cref="ArgumentNullException"/> when the command is null
/// </summary>
[Fact]
public async Task RunAsync_WithNullCommand_ReturnsArgumentNullException()
{
// Arrange
Expand All @@ -89,11 +89,11 @@ public async Task RunAsync_WithNullCommand_ReturnsArgumentNullException()
var validation = CommandResultValidation.ZeroExitCode;
bool silent = false;

// Act
async Task Act() => await CLIRunner.RunAsync(command, cancellationToken, validation, silent).ConfigureAwait(false);
// Act
async Task Act() => await Runner.RunAsync(command, cancellationToken, validation, silent).ConfigureAwait(false);

// Assert
_ = await Assert.ThrowsAsync<ArgumentNullException>(Act);
// Assert
_ = await Assert.ThrowsAsync<ArgumentNullException>(Act);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Devantler.CLIRunner;
/// <summary>
/// A class to run CLI commands and capture their output.
/// </summary>
public static class CLIRunner
public static class Runner
{
/// <summary>
/// Run a CLI command and capture its output.
Expand Down

0 comments on commit 67579ab

Please sign in to comment.