using Xunit;
using Svrnty.MCP.Gateway.Infrastructure.Transport;
using Svrnty.MCP.Gateway.Core.Models;
namespace Svrnty.MCP.Gateway.Infrastructure.Tests.Transport;
///
/// Unit tests for transport factory logic.
/// Tests transport creation based on server configuration.
///
public class TransportFactoryTests
{
[Fact]
public void StdioTransport_WithValidCommand_CreatesSuccessfully()
{
// Arrange & Act
var transport = new StdioServerTransport("echo", new[] { "test" });
// Assert
Assert.NotNull(transport);
Assert.False(transport.IsConnected);
}
[Fact]
public void StdioTransport_WithEmptyArgs_CreatesSuccessfully()
{
// Arrange & Act
var transport = new StdioServerTransport("ls", Array.Empty());
// Assert
Assert.NotNull(transport);
}
[Fact]
public void HttpTransport_WithValidUrl_CreatesSuccessfully()
{
// Arrange & Act
var transport = new HttpServerTransport("http://localhost:8080");
// Assert
Assert.NotNull(transport);
Assert.False(transport.IsConnected);
}
[Fact]
public void HttpTransport_WithHttpsUrl_CreatesSuccessfully()
{
// Arrange & Act
var transport = new HttpServerTransport("https://api.example.com");
// Assert
Assert.NotNull(transport);
}
[Fact]
public void StdioTransport_WithNullArgs_UsesEmptyArray()
{
// Arrange & Act
var transport = new StdioServerTransport("echo", null!);
// Assert
Assert.NotNull(transport);
}
[Theory]
[InlineData("http://localhost:5000")]
[InlineData("https://api.example.com:8443")]
[InlineData("http://192.168.1.1:3000")]
public void HttpTransport_WithVariousUrls_CreatesSuccessfully(string baseUrl)
{
// Arrange & Act
var transport = new HttpServerTransport(baseUrl);
// Assert
Assert.NotNull(transport);
Assert.False(transport.IsConnected);
}
[Theory]
[InlineData("dotnet", "run")]
[InlineData("python3", "server.py")]
[InlineData("node", "index.js")]
public void StdioTransport_WithVariousCommands_CreatesSuccessfully(string command, string arg)
{
// Arrange & Act
var transport = new StdioServerTransport(command, new[] { arg });
// Assert
Assert.NotNull(transport);
}
[Fact]
public void StdioTransport_Dispose_CanBeCalledMultipleTimes()
{
// Arrange
var transport = new StdioServerTransport("echo", new[] { "test" });
// Act & Assert - should not throw
transport.Dispose();
transport.Dispose();
}
[Fact]
public void HttpTransport_Dispose_CanBeCalledMultipleTimes()
{
// Arrange
var httpClient = new HttpClient();
var transport = new HttpServerTransport("http://localhost:5000", httpClient);
// Act & Assert - should not throw
transport.Dispose();
transport.Dispose();
}
[Fact]
public void HttpTransport_WithCustomHttpClient_UsesProvidedClient()
{
// Arrange
var customHttpClient = new HttpClient();
customHttpClient.Timeout = TimeSpan.FromSeconds(5);
// Act
var transport = new HttpServerTransport("http://localhost:5000", customHttpClient);
// Assert
Assert.NotNull(transport);
}
}