Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.8" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
Expand Down
129 changes: 129 additions & 0 deletions Foundation.Data.Doublets.Cli.Tests/ServerModeIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using Xunit;
using System.Diagnostics;
using System.IO;

namespace Foundation.Data.Doublets.Cli.Tests
{
public class ServerModeIntegrationTests : IDisposable
{
private string _tempDbFile;

public ServerModeIntegrationTests()
{
_tempDbFile = Path.GetTempFileName();
}

public void Dispose()
{
if (File.Exists(_tempDbFile))
{
File.Delete(_tempDbFile);
}
}

[Fact]
public void Should_Show_Server_Option_In_Help()
{
// Arrange & Act
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"run --project {GetCliProjectPath()} -- --help",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
}
};

process.Start();
var output = process.StandardOutput.ReadToEnd();
process.WaitForExit();

// Assert
Assert.Contains("--server", output);
Assert.Contains("Start server listening on a port", output);
Assert.Contains("--port", output);
Assert.Contains("Port to listen on when in server mode", output);
}

[Fact]
public void Should_Start_Server_With_Correct_Output()
{
// Arrange & Act
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"run --project {GetCliProjectPath()} -- --server --port 0 --db {_tempDbFile}",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
}
};

process.Start();

// Wait a short time to capture startup output
var outputBuffer = "";
var startTime = DateTime.Now;

while ((DateTime.Now - startTime).TotalSeconds < 3)
{
if (!process.StandardOutput.EndOfStream)
{
outputBuffer += process.StandardOutput.ReadLine() + "\n";
}

if (outputBuffer.Contains("LiNo WebSocket server started"))
{
break;
}

Thread.Sleep(100);
}

process.Kill();
process.WaitForExit();

// Assert
Assert.Contains("LiNo WebSocket server started", outputBuffer);
Assert.Contains("Press Ctrl+C to stop the server", outputBuffer);
}

[Fact]
public void Should_Preserve_Normal_CLI_Functionality()
{
// Arrange & Act
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"run --project {GetCliProjectPath()} -- --db {_tempDbFile} '() ((1 1))' --changes --after",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
}
};

process.Start();
var output = process.StandardOutput.ReadToEnd();
process.WaitForExit();

// Assert - Normal CLI functionality should work
Assert.Equal(0, process.ExitCode);
Assert.Contains("(1: 1 1)", output); // Should show created link
}

private string GetCliProjectPath()
{
// Get the current test directory and navigate to the CLI project
var currentDir = Directory.GetCurrentDirectory();
var projectRoot = Directory.GetParent(currentDir)?.Parent?.Parent?.FullName;
return Path.Combine(projectRoot ?? currentDir, "Foundation.Data.Doublets.Cli");
}
}
}
Loading