Files
NixOS_WindowsWrapper/tests/NixWslWrapper.Tests/InfrastructureTests.cs
T

53 lines
1.8 KiB
C#

using System;
using System.IO;
using System.Text;
using NixWslWrapper.Infrastructure.IO;
using NixWslWrapper.Infrastructure.Executors;
using Xunit;
namespace NixWslWrapper.Tests
{
public class InfrastructureTests
{
[Fact]
public void ThreadedStreamCopier_ValidStream_ShouldCopyEntireContent()
{
var content = "Hello, Nix WSL Wrapper! Stream copying should work flawlessly.";
byte[] bytes = Encoding.UTF8.GetBytes(content);
using var input = new MemoryStream(bytes);
using var output = new MemoryStream();
var copier = new ThreadedStreamCopier(64); // small buffer to force multiple reads
copier.Copy(input, output);
byte[] resultBytes = output.ToArray();
string result = Encoding.UTF8.GetString(resultBytes);
Assert.Equal(content, result);
}
[Fact]
public void ProcessBuilder_ValidConfiguration_ShouldBuildCorrectProcessStartInfo()
{
var builder = new ProcessBuilder()
.SetFileName("my-app.exe")
.SetArguments("--arg1 val1")
.RedirectInput(true)
.RedirectOutput(true)
.RedirectError(true)
.UseShellExecute(false)
.CreateNoWindow(true);
var startInfo = builder.Build();
Assert.Equal("my-app.exe", startInfo.FileName);
Assert.Equal("--arg1 val1", startInfo.Arguments);
Assert.True(startInfo.RedirectStandardInput);
Assert.True(startInfo.RedirectStandardOutput);
Assert.True(startInfo.RedirectStandardError);
Assert.False(startInfo.UseShellExecute);
Assert.True(startInfo.CreateNoWindow);
}
}
}