feat: add overloads that allow to the the buffer size for the copy
This commit is contained in:
parent
77199944fe
commit
cce841a06e
3 changed files with 152 additions and 28 deletions
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue