process/src/process.tests/ValidationTests.cs
Louis Seubert 1e4687aff6
Some checks failed
default / dotnet-default-workflow (push) Failing after 54s
build: initial project release
2026-01-20 22:58:15 +01:00

58 lines
No EOL
1.6 KiB
C#

// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
using Geekeey.Process.Buffered;
namespace Geekeey.Process.Tests;
internal sealed class ValidationTests
{
private static Command Exit()
{
return new Command(Testing.Fixture.Program.FilePath)
.WithArguments(["exit", "1"]);
}
[Test]
public async Task I_can_try_to_execute_a_command_and_get_an_error_if_it_returns_a_non_zero_exit_code()
{
// Arrange
var cmd = Exit();
// Act & Assert
await Assert.That(async () => await cmd.ExecuteAsync()).Throws<CommandExecutionException>().And
.Member(static exception => exception.Message, static source => source.Contains("a non-zero exit code (1)")).And
.Member(static exception => exception.ExitCode, static source => source.IsEqualTo(1));
}
[Test]
public async Task I_can_try_to_execute_a_command_with_buffering_and_get_a_detailed_error_if_it_returns_a_non_zero_exit_code()
{
// Arrange
var cmd = Exit();
// Act & Assert
await Assert.That(async () => await cmd.ExecuteBufferedAsync()).Throws<CommandExecutionException>().And
.Member(static exception => exception.Message, static source => source.Contains("Exit code set to 1")).And
.Member(static exception => exception.ExitCode, static source => source.IsEqualTo(1));
}
[Test]
public async Task I_can_execute_a_command_without_validating_the_exit_code()
{
// Arrange
var cmd = Exit()
.WithExitValidation(ValidationMode.None);
// Act
var result = await cmd.ExecuteAsync();
// Assert
using (Assert.Multiple())
{
await Assert.That(result.ExitCode).IsEqualTo(1);
await Assert.That(result.IsSuccess).IsFalse();
}
}
}