using OpenHarbor.MCP.Client.Core.Models; using Xunit; namespace OpenHarbor.MCP.Client.Core.Tests.Models; /// /// Unit tests for McpServerConfig and transport configurations. /// Tests configuration creation and default values. /// public class McpServerConfigTests { [Fact] public void Constructor_WithStdioTransport_CreatesConfig() { // Arrange var transport = new StdioTransportConfig { Type = "Stdio", Command = "dotnet", Args = new[] { "run", "--project", "test.csproj" } }; // Act var config = new McpServerConfig { Name = "test-server", Transport = transport }; // Assert Assert.Equal("test-server", config.Name); Assert.IsType(config.Transport); Assert.Equal(TimeSpan.FromSeconds(30), config.Timeout); Assert.True(config.Enabled); } [Fact] public void Constructor_WithHttpTransport_CreatesConfig() { // Arrange var transport = new HttpTransportConfig { Type = "Http", BaseUrl = "https://api.example.com/mcp" }; // Act var config = new McpServerConfig { Name = "http-server", Transport = transport }; // Assert Assert.Equal("http-server", config.Name); Assert.IsType(config.Transport); Assert.Equal("https://api.example.com/mcp", ((HttpTransportConfig)config.Transport).BaseUrl); } [Fact] public void Constructor_WithCustomTimeout_SetsTimeout() { // Arrange var transport = new StdioTransportConfig { Type = "Stdio", Command = "node", Args = new[] { "server.js" } }; // Act var config = new McpServerConfig { Name = "custom-timeout-server", Transport = transport, Timeout = TimeSpan.FromMinutes(5) }; // Assert Assert.Equal(TimeSpan.FromMinutes(5), config.Timeout); } [Fact] public void Constructor_WithEnabledFalse_SetsEnabledFalse() { // Arrange var transport = new StdioTransportConfig { Type = "Stdio", Command = "test" }; // Act var config = new McpServerConfig { Name = "disabled-server", Transport = transport, Enabled = false }; // Assert Assert.False(config.Enabled); } [Fact] public void StdioTransportConfig_WithEmptyArgs_HasEmptyArray() { // Arrange & Act var transport = new StdioTransportConfig { Type = "Stdio", Command = "test" }; // Assert Assert.Empty(transport.Args); } [Fact] public void HttpTransportConfig_WithApiKey_StoresApiKey() { // Arrange & Act var transport = new HttpTransportConfig { Type = "Http", BaseUrl = "https://secure.example.com/mcp", ApiKey = "test-api-key-123" }; // Assert Assert.Equal("test-api-key-123", transport.ApiKey); } [Fact] public void HttpTransportConfig_WithoutApiKey_HasNullApiKey() { // Arrange & Act var transport = new HttpTransportConfig { Type = "Http", BaseUrl = "https://public.example.com/mcp" }; // Assert Assert.Null(transport.ApiKey); } }