Initial commit: Nix WSL Wrapper project with DDD, Clean Code, and tests

This commit is contained in:
Marek Novák
2026-07-01 02:04:43 +02:00
commit 161eb7d387
22 changed files with 932 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
using System;
using NixWslWrapper.Core.Domain;
using Xunit;
namespace NixWslWrapper.Tests
{
public class CoreTests
{
[Fact]
public void WslTarget_ValidParameters_ShouldConstructCorrectly()
{
var target = new WslTarget("Debian", "root", "/some/path");
Assert.Equal("Debian", target.Distribution);
Assert.Equal("root", target.User);
Assert.Equal("/some/path", target.NixProfilePath);
}
[Theory]
[InlineData("", "root", "/path")]
[InlineData("Debian", "", "/path")]
[InlineData("Debian", "root", "")]
[InlineData(null, "root", "/path")]
[InlineData("Debian", null, "/path")]
[InlineData("Debian", "root", null)]
public void WslTarget_InvalidParameters_ShouldThrowArgumentException(string? distro, string? user, string? profile)
{
Assert.Throws<ArgumentException>(() => new WslTarget(distro!, user!, profile!));
}
[Fact]
public void WslTarget_Equality_ShouldBeTrueForSameValues()
{
var target1 = new WslTarget("Debian", "root", "/path");
var target2 = new WslTarget("debian", "ROOT", "/path"); // case-insensitive for distro/user
Assert.Equal(target1, target2);
}
[Fact]
public void NixArguments_EmptyArgs_ShouldReturnEmptyEscapedString()
{
var args = new NixArguments(Array.Empty<string>());
Assert.Equal(string.Empty, args.ToEscapedString());
}
[Fact]
public void NixArguments_WithSpecialCharacters_ShouldEscapeDoubleQuotes()
{
var args = new NixArguments(new[] { "run", "nixpkgs#hello", "--argstr", "msg", "hello \"world\"" });
string escaped = args.ToEscapedString();
Assert.Equal("\"run\" \"nixpkgs#hello\" \"--argstr\" \"msg\" \"hello \\\"world\\\"\"", escaped);
}
[Fact]
public void ExecutionResult_Success_ShouldSetCorrectProperties()
{
var result = ExecutionResult.Success();
Assert.True(result.IsSuccess);
Assert.Equal(0, result.ExitCode);
Assert.Null(result.ErrorMessage);
}
[Fact]
public void ExecutionResult_Failure_ShouldSetCorrectProperties()
{
var result = ExecutionResult.Failure(5, "Access Denied");
Assert.False(result.IsSuccess);
Assert.Equal(5, result.ExitCode);
Assert.Equal("Access Denied", result.ErrorMessage);
}
}
}