feat: add overloads that allow to the the buffer size for the copy
All checks were successful
default / dotnet-default-workflow (pull_request) Successful in 1m18s
default / dotnet-default-workflow (push) Successful in 1m14s

This commit is contained in:
Louis Seubert 2026-08-25 20:04:13 +02:00
commit cce841a06e
3 changed files with 152 additions and 28 deletions

View file

@ -64,6 +64,42 @@ internal sealed class PipingTests
await Assert.That(result.StandardOutput.Trim()).IsEqualTo("Hello World!");
}
[Test]
public async Task I_can_execute_a_command_and_pipe_the_stdin_from_a_stream_with_a_custom_buffer_size()
{
// Arrange
using var source = new MemoryStream("Hello World!"u8.ToArray());
var cmd = PipeSource.FromStream(source, 1) |
new Command(Testing.Fixture.Program.FilePath)
.WithArguments("echo-stdin");
// Act
var result = await cmd.ExecuteBufferedAsync();
// Assert
await Assert.That(result.StandardOutput.Trim()).IsEqualTo("Hello World!");
}
[Test]
public async Task I_can_execute_a_command_and_pipe_the_stdin_from_a_file_with_a_custom_buffer_size()
{
// Arrange
using var dir = TestTempDirectory.Create();
var filePath = Path.Combine(dir.Path, "input.txt");
await File.WriteAllTextAsync(filePath, "Hello World!");
var cmd = PipeSource.FromFile(filePath, 1) |
new Command(Testing.Fixture.Program.FilePath)
.WithArguments("echo-stdin");
// Act
var result = await cmd.ExecuteBufferedAsync();
// Assert
await Assert.That(result.StandardOutput.Trim()).IsEqualTo("Hello World!");
}
[Test]
public async Task I_can_execute_a_command_and_pipe_the_stdin_from_memory()
{
@ -220,6 +256,43 @@ internal sealed class PipingTests
await Assert.That(stream.Length).IsEqualTo(100_000);
}
[Test]
public async Task I_can_execute_a_command_and_pipe_the_stdout_into_a_stream_with_a_custom_buffer_size()
{
// Arrange
using var stream = new MemoryStream();
var target = PipeTarget.ToStream(stream, 1);
var cmd = new Command(Testing.Fixture.Program.FilePath)
.WithArguments(["generate", "blob", "--length", "100000"]) |
target;
// Act
await cmd.ExecuteAsync();
// Assert
await Assert.That(stream.Length).IsEqualTo(100_000);
}
[Test]
public async Task I_can_execute_a_command_and_pipe_the_stdout_into_a_file_with_a_custom_buffer_size()
{
// Arrange
using var dir = TestTempDirectory.Create();
var filePath = Path.Combine(dir.Path, "output.bin");
var target = PipeTarget.ToFile(filePath, 1);
var cmd = new Command(Testing.Fixture.Program.FilePath)
.WithArguments(["generate", "blob", "--length", "100000"]) |
target;
// Act
await cmd.ExecuteAsync();
// Assert
await Assert.That(new FileInfo(filePath).Length).IsEqualTo(100_000);
}
[Test]
public async Task I_can_execute_a_command_and_pipe_the_stdout_into_a_string_builder()
{